Multipath serial communication system

Through the multi-channel serial communication system, the shared area and common mapping area are used to realize data interaction of various types of devices, which solves the problems of single mode and poor applicability in MODBUS communication, realizes cross-protocol communication, and improves the applicability of equipment and data transmission stability.

CN120602253APending Publication Date: 2025-09-05CRRC QINGDAO SIFANG ROLLING STOCK RESEARCH INSTITUTE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510790357.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-13
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

In the existing technology, the master-slave communication mode is single, the communication range is limited, the applicability is poor, the MODBUS communication equipment resources are small, the data processing is complex, and it is impossible to interact with multiple devices. The adaptability is low, and the non-standard program lacks abnormal data response and fault handling functions. The parameter configuration process is complicated and the portability is poor.

Method used

A multi-channel serial communication system is used to realize data interaction between various types of serial communication master stations and slave stations through shared areas and common mapping areas. It supports multiple communication modes, uses the serial port and Ethernet under the Linux system for MODBUS communication, configures configuration files to switch device modes, and sets multi-threaded modules for data transmission and fault detection to achieve cross-protocol or cross-type communication.

Benefits of technology

It expands the communication range, improves communication compatibility and applicability, supports multiple communication modes, simplifies equipment expansion operations, reduces wiring costs, ensures the stability and continuity of data transmission, and reduces the risk of fault propagation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120602253A_ABST
    Figure CN120602253A_ABST
Patent Text Reader

Abstract

The invention relates to a multi-channel serial communication system, which comprises a plurality of types of serial communication master stations and a plurality of types of serial communication slave stations, and is characterized in that any serial communication master station performs data interaction with at least one type of serial communication master station through a sharing area and / or a sharing mapping area; sending data to a serial communication slave station of which the type is different from that of the current serial communication master station through another sharing area; data are sent to serial communication slave stations of the same type through the Ethernet and / or serial ports; any serial communication slave station receives data sent by any serial communication master station; receiving data transmitted by the serial communication slave stations of the same type; and obtaining read data, adding offset to the address of the read data, and transmitting data to another serial communication slave station of the same type according to the added offset address. According to the invention, the problems of single communication mode and small communication range in a serial communication protocol are solved, one master station can be connected with multiple devices, the multi-channel communication applicability is higher, and the communication range is wider.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communications, and in particular to a multi-channel serial communication system. Background Art

[0002] The serial communication protocol is a universal standard for industrial fieldbuses that can realize data exchange and control between different devices, and has become one of the more popular communication protocols in the field of workstation automation.

[0003] At present, industrial field devices communicate with embedded gateway middleware through serial communication protocols. An industrial field device acts as a master or slave and supports communication between the master device and the slave device.

[0004] This master-slave communication mode is single, has a limited communication range, and has poor applicability. Summary of the Invention

[0005] The embodiment of the present application provides a multi-channel serial communication system to at least solve the problems of a single master-slave corresponding communication mode, a small communication range, and poor applicability.

[0006] In a first aspect, an embodiment of the present application provides a multi-channel serial communication system, comprising: a serial communication master station and a serial communication slave station, wherein the master station and the slave station are respectively provided with multiple types, wherein: The current serial communication master station exchanges data with at least one type of serial communication master station via a shared area and / or a shared mapping area; sends data to a serial communication slave station of a different type than the current serial communication master station via another shared area; and sends data to a serial communication slave station of the same type via Ethernet and / or a serial port; The current serial communication slave station receives data sent by at least one type of serial communication master station; receives data transmitted by the same type of serial communication slave station; obtains read data, increases the offset of the address of the read data, and transmits the data to another serial communication slave station of the same type according to the increased offset address.

[0007] In some embodiments, the multi-channel serial communication system further includes: a first transmission module and a second transmission module, a shared area is set between the first transmission module and the second transmission module; the first transmission module sets a first thread, communicates with the current serial communication master station through the first thread, obtains data from the current serial communication master station, and saves the data to the shared area; the second transmission module sets a second thread, communicates with a serial communication master station of a different type from the current serial communication master station or a serial communication slave station of a different type from the current serial communication master station through the second thread, the second transmission module obtains data from the shared area, updates internal data, and sends it to a serial communication master station of a different type from the current serial communication master station or a serial communication slave station of a different type from the current serial communication master station.

[0008] In some embodiments, the multi-channel serial communication system further includes: a third transmission module and a fourth transmission module, both of which are connected to the first shared mapping area; the third transmission module sets a third thread, communicates with the current serial communication master station via the third thread, and the current serial communication master station uploads or receives data in the first shared mapping area; the fourth transmission module sets a fourth thread, communicates with another serial communication master station of the same type via the fourth thread, and the other serial communication master station of the same type uploads or receives data in the first shared mapping area.

[0009] In some embodiments, the multi-channel serial communication system further includes: a fifth transmission module and a sixth transmission module, both of which are connected to the second shared mapping area; the fifth transmission module sets a fifth thread, communicates with the current serial communication slave station via the fifth thread, reads data in the current serial communication slave station, and uploads it to the second shared mapping area; the sixth transmission module sets a sixth thread, communicates with another serial communication slave station of the same type via the sixth thread, receives data in the second shared mapping area, adds an offset address to the data, and sends it to another serial communication slave station of the same type.

[0010] In some embodiments, the multi-channel serial communication system further comprises: The detection module detects all threads and determines whether the status of all threads is in a dead state. If so, the threads in the dead state are controlled to automatically restart.

[0011] In some embodiments, the serial communication master station includes a transmission control master station, which is further configured to establish a communication channel with the same type of serial communication slave station via Ethernet based on the IP information, port number and serial communication slave station ID of the configuration file, and periodically call the sending function after the connection to send data to the same type of serial communication slave station.

[0012] In some embodiments, the serial communication slave station includes a transmission control slave station, which is further configured to establish a connection with a control transmission master station, receive data sent by the transmission control master station, and provide feedback based on the received data; determine whether this connection is the first connection, if so, start communication; if not, disconnect the previous connection and then connect this connection.

[0013] In some embodiments, the serial communication master station includes a remote terminal master station, which is further configured to communicate via a serial port, send command data, and receive corresponding feedback data, determine whether the feedback data is qualified, and if so, send another command data; if not, record the abnormal status and send another command data.

[0014] In some embodiments, the serial communication slave station includes a remote terminal slave station, which is further configured to communicate with the remote terminal master station via the serial port according to the port, baud rate and remote terminal slave station ID in the configuration file, receive and determine whether the command data sent by the remote terminal master station is qualified, and if so, reply with feedback data; if not, wait for another command data.

[0015] In some embodiments, the multi-channel serial communication system further comprises: The switching module is configured to switch the communication of multiple serial communication master stations according to the life signal in the data sent by each serial communication master station when the data sent by the multiple serial communication master stations are homologous data. The life signal is used for data continuity detection. If the life signal is normal, the serial communication master station that sends the normal life signal is saved. If the life signal is abnormal, the serial communication master station that sends the abnormal life signal is disconnected.

[0016] Compared with related technologies, the multi-channel serial communication system provided in the embodiment of the present application can communicate with multiple devices through multi-channel communication, and supports multiple communication modes. It solves the problems of single mode, limited communication range and poor applicability of master-slave corresponding communication, and achieves the effect of expanding the communication range and improving communication compatibility and applicability.

[0017] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application; Figure 2 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application; Figure 3 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application; Figure 4 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application; Figure 5 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application; Figure 6 is a flowchart of the transmission control master station in a multi-channel serial communication system according to an embodiment of the present application; Figure 7is a flowchart of a transmission control slave station in a multi-channel serial communication system according to an embodiment of the present application; Figure 8 is a flowchart of a remote terminal master station in a multi-channel serial communication system according to an embodiment of the present application; Figure 9 is a flowchart of a remote terminal slave station in a multi-channel serial communication system according to an embodiment of the present application; Figure 10 3 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solutions and advantages of this application more clearly understood, the present application is described and illustrated below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely used to explain this application and are not intended to limit this application. Based on the embodiments provided in this application, all other embodiments obtained by those of ordinary skill in the art without making any creative efforts are within the scope of protection of this application.

[0020] Obviously, the drawings described below are merely examples or embodiments of the present application. Those skilled in the art can, without inventive effort, apply the present application to other similar scenarios based on these drawings. Furthermore, it is also understood that, although the effort involved in such a development process may be complex and lengthy, for those skilled in the art related to the content disclosed in this application, changes in design, manufacturing, or production based on the technical content disclosed in this application are merely conventional technical means and should not be construed as an insufficiency of the content disclosed in this application.

[0021] References to "embodiments" in this application mean that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it refer to independent or alternative embodiments that are mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described in this application may be combined with other embodiments unless there is a conflict.

[0022] Unless otherwise defined, technical or scientific terms used herein shall have the ordinary meaning as understood by persons of ordinary skill in the art to which this application belongs. The terms "a," "an," "an," "the," and similar expressions used herein do not denote quantitative limitations and may refer to either the singular or the plural. The terms "comprise," "include," "have," and any variations thereof, used herein, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or modules (units) is not limited to the listed steps or units but may also include steps or units not listed, or may include other steps or units inherent to the process, method, product, or apparatus. The terms "connected," "connected," "coupled," and similar expressions used herein are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. As used herein, "plurality" means two or more. "And / or" describes an association between associated objects, indicating that three possible relationships exist. For example, "A and / or B" may mean: A exists alone; A and B exist simultaneously; or B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific order for the objects.

[0023] The Modicon Bus (MODBUS) protocol is a serial communication protocol. As a universal standard for industrial fieldbuses, it enables data exchange and control between different devices and has become one of the most popular communication protocols in industrial automation. MODBUS uses a master-slave model for communication. A MODBUS master sends requests to a MODBUS slave, which then executes operations and responds to the master. The MODBUS master is typically a programmable logic controller (PLC), and field devices act as MODBUS slaves.

[0024] Currently, there are many field devices that support MODBUS and have a wide range of application scenarios. However, most field devices only support one mode and can only function as a MODBUS master or MODBUS slave device. They do not support master-slave mode switching or require modifying complex underlying logic to achieve mode changes.

[0025] It only supports single MODBUS communication of Ethernet or serial port, with few device resources, complex data processing process, inability to interact with multiple devices, and low adaptability.

[0026] However, programs written for specific scenarios are not standard MODBUS. Although they meet the requirements for simple data communication, they lack functions such as abnormal data response and fault handling. The parameter configuration process is complicated, different platforms are not universal, and the portability is poor.

[0027] To solve the above problems, this embodiment provides a multi-channel serial communication system. Figure 1 As shown in the figure, the multi-channel serial communication system is based on the Linux operating system and uses the serial port and Ethernet commonly available in the Linux operating system to communicate with external devices through MODBUS. Using the serial port and Ethernet for communication, the device switches between master and slave modes and configures different communication parameters through configuration files.

[0028] Figure 2-Figure 5 is a structural diagram of a multi-channel serial communication system according to an embodiment of the present application. Figure 2-Figure 5 As shown, the multi-channel serial communication system connects multiple devices as multiple stations through the Linux operating system. The stations are divided into serial communication master stations and serial communication slave stations.

[0029] There are multiple types of serial communication master stations and serial communication slave stations.

[0030] From the perspective of the communication protocol layer, serial communication master stations include transmission control (MOTBUS TCP) master stations and remote terminal (MODBUS RTU) master stations. Serial communication slave stations include transmission control slave stations and remote terminal slave stations.

[0031] like Figure 2 As shown, the current serial communication master station exchanges data with at least one type of serial communication master station via a shared area and / or a shared mapping area.

[0032] like Figure 3 As shown, the current serial communication master station sends data to a serial communication slave station of a different type from the current serial communication master station via another shared area.

[0033] like Figure 4 As shown, the current serial communication master station sends data to the same type of serial communication slave station via Ethernet and / or serial port.

[0034] A shared area within a multi-channel serial communication system allows data exchange between two different stations, for example, between a serial communication master station and another serial communication master station, or between a serial communication master station and a serial communication slave station. A shared area is set up between any two communicating stations. Multiple shared areas can be set up independently and not interoperable. The two communicating stations can be of the same or different types.

[0035] A shared mapping area exists within a multi-channel serial communication system and can be used for data exchange between two serial communication masters or slaves of the same type. A shared mapping area is set up between any two communicating masters or slaves. Multiple shared mapping areas are independent and do not communicate with each other.

[0036] The current serial communication slave station receives data sent by at least one type of serial communication master station and receives data transmitted by the same type of serial communication slave station.

[0037] like Figure 5 As shown, the current serial communication slave station obtains read data, increases the address of the read data by an offset, and transmits the data to another serial communication slave station of the same type according to the increased offset address.

[0038] Through the shared area or shared mapping area, the current serial communication master station can exchange data with other types of serial communication master stations and other types of serial communication slave stations, so that the multi-channel serial communication system can simultaneously support the coexistence of devices with multiple serial communication protocols, support multiple communication modes, expand the communication range, and improve communication compatibility and applicability.

[0039] Serial communication slave stations can use the shared mapping area for data exchange and transmit data through address offset, which can better adapt to long-distance, multi-node industrial scenarios and reduce wiring costs.

[0040] When two serial communication masters or two serial communication slaves communicate, independent shared areas and common mapping areas are set up. If a fault occurs, only the directly connected serial communication master or serial communication slave is affected, which can effectively prevent the fault from spreading.

[0041] In some embodiments, the multi-channel serial communication system further includes: a first transmission module and a second transmission module, wherein a shared area is provided between the first transmission module and the second transmission module. The first transmission module is provided with a first thread, which communicates with the current serial communication master station via the first thread, obtains data from the current serial communication master station, and saves the data to the shared area. The second transmission module is provided with a second thread, which communicates with a serial communication master station of a different type than the current serial communication master station or a serial communication slave station of a different type than the current serial communication master station via the second thread. The second transmission module obtains data from the shared area, updates internal data, and sends the data to a serial communication master station of a different type than the current serial communication master station or a serial communication slave station of a different type than the current serial communication master station.

[0042] The first and second threads run independently, decoupling data acquisition and distribution, preventing them from blocking each other. When adding a new serial communication master or slave, only the second thread's configuration needs to be modified, eliminating the need to restart the entire system. This facilitates dynamic expansion of industrial field equipment and simplifies operation.

[0043] The first transmission module connects to one device, which serves as a transmission control master station. The second transmission module connects to another device, which serves as a remote terminal master station. The shared area serves as a data conversion hub for protocol conversion. Through the first thread, the second thread, and the shared area, two different types of master stations can communicate in real time, achieving cross-protocol or cross-type communication.

[0044] Furthermore, by adjusting the running priority and execution frequency of threads, different types of device communication loads can be adapted, making resource allocation more balanced.

[0045] In some embodiments, the multi-channel serial communication system further includes: a third transmission module and a fourth transmission module, each of which is connected to the first shared mapping area. The third transmission module is provided with a third thread, which communicates with the current serial communication master station via the third thread, and the current serial communication master station uploads or receives data from the first shared mapping area. The fourth transmission module is provided with a fourth thread, which communicates with another serial communication master station of the same type via the fourth thread, and the other serial communication master station of the same type uploads or receives data from the first shared mapping area.

[0046] The third transmission module connects to one device, which acts as the current transmission control master. The fourth transmission module connects to another device, which acts as another transmission control master. Through the third and fourth threads and the shared mapping area, data sharing is achieved between two masters of the same type, ensuring consistent read and write access to the same data across multiple masters, reducing data conflicts, and enabling parallel control of their respective slaves.

[0047] Furthermore, a redundant architecture can be constructed. If the current serial communication master station fails, another serial communication master station of the same type via the fourth thread can obtain real-time data from the mapping area to maintain data transmission and control.

[0048] Furthermore, a data persistence function can be configured in the shared mapping area to record key interaction data of the serial communication master station and form an operation log to meet the needs of industrial systems.

[0049] In some embodiments, the multi-channel serial communication system further includes: a fifth transmission module and a sixth transmission module, both of which are connected to the second shared mapping area. The fifth transmission module is provided with a fifth thread, which communicates with the current serial communication slave station via the fifth thread, reads data from the current serial communication slave station, and uploads the data to the second shared mapping area. The sixth transmission module is provided with a sixth thread, which communicates with another serial communication slave station of the same type via the sixth thread, receives data from the second shared mapping area, adds an offset address to the data, and transmits the data to the other serial communication slave station of the same type.

[0050] Through address offset, a data interaction channel is established between serial communication slave stations, the transmission of read-only data is realized, the system communication mode is expanded, slave station cascade communication is constructed, and data transmission efficiency is improved.

[0051] In some embodiments, the multi-channel serial communication system further comprises: The detection module detects all threads and determines whether the status of all threads is in a dead state. If so, the threads in the dead state are controlled to automatically restart.

[0052] Furthermore, a structure array is used to uniformly manage thread information, all thread control blocks are initialized centrally, and pthread_kill is used to detect thread status, automatically restarting dead threads to ensure smooth data transmission.

[0053] Furthermore, the detection module can set up multi-level monitoring, including thread-level, communication-level, and application-level. The thread-level monitors thread occupancy and memory leaks. The communication-level monitors serial port packet loss and network latency. The application also monitors data continuity. For example, if the Modbus communication packet loss rate exceeds 5%, the thread is automatically restarted.

[0054] Furthermore, during the restart process, multiple restart strategies can be set to reduce the impact of the restart on data transmission.

[0055] Furthermore, when the detection module detects that the thread status is abnormal, it can adjust the thread monitoring frequency and send an early warning.

[0056] In this application, if Figure 10 As shown in the figure, the Ethernet or serial port of the Linux system communicates with multiple external devices using the MODBUS protocol. Using the standard MODBUS protocol, multiple external devices can be configured as transmission control (MOTBUSTCP) master, transmission control slave, remote terminal (MODBUS RTU) master, and remote terminal slave.

[0057] In some embodiments, the serial communication master station includes a transmission control master station, which is further configured to establish a communication channel with the same type of serial communication slave station via Ethernet based on the IP information, port number and serial communication slave station ID of the configuration file, and periodically call the sending function after the connection to send data to the same type of serial communication slave station.

[0058] By matching the corresponding serial communication slave station through the configuration file, the system actively sends instructions according to the needs and waits for the transmission control slave station to reply, thus realizing data interaction between the same type of serial communication master and slave stations, and improving the stability and efficiency of data transmission.

[0059] During the periodic call of the sending function, the sending period can be dynamically adjusted to match the network quality, ensuring stable data transmission and giving priority to the transmission of critical data.

[0060] Furthermore, if Figure 6 As shown in the figure, the transmission control master's workflow is as follows: First, a MODBUS communication instance is created based on the IP address and port number in the configuration file. Success is checked. If not, a failure log is created. If successful, the transmission control slave ID is set and a timer is started. The master waits for the transmission control slave to connect via Ethernet. Once connected, the send function is periodically called according to the timer to send data and wait for data to be received. The send function can be configured with any function code based on the actual application, defining the starting address and data quantity for reading and writing. It also monitors the communication status during the communication process. If the communication status is normal, the communication data is directly processed. If the communication is disconnected or times out, the error information is recorded in the log file, making it easy to locate the cause of any communication failure.

[0061] Any function code can be configured through application layer programming, and interactive data can be directly stored in an array, making data processing more convenient. At the same time, important information during operation can be written into the log file in real time.

[0062] In some embodiments, the serial communication slave station includes a transmission control slave station, further configured to establish a connection with a transmission control master station, receive data sent by the transmission control master station, and provide feedback based on the received data. The slave station determines whether the current connection is an initial connection, and if so, initiates communication; if not, disconnects the previous connection and reconnects the current connection.

[0063] The serial communication slave station receives data transmitted by the serial communication master station, realizes data synchronization, optimizes the disconnection and reconnection mechanism, disconnects and releases resources before reconnecting, avoids the master station from misjudging the slave station failure, reduces resource usage, and maintains communication continuity.

[0064] Further, Figure 7 This is the workflow diagram of the transmission control slave station, such as Figure 7As shown in the figure, the transmission control slave creates a MODBUS communication instance based on the IP address and port number in the configuration file. If creation fails, the slave logs the failure. It sets the transmission control slave ID and connects to the transmission control master via Ethernet. After successfully creating the communication instance, it starts listening. It then waits for commands from the transmission control master and responds to them. When a connection is established with the transmission control master, it determines whether it is a new port connection. If not, it continues receiving data. If so, it determines whether it is the first connection. If so, it establishes the connection and begins receiving data. If not, it closes the previously established port and reestablishes the connection to receive data. This prevents the possibility of system resource exhaustion and subsequent communication failure due to untimely socket closing. Once communication is established, it waits for commands from the transmission control master. Based on the command content, it determines whether the data is normal. If so, it responds accordingly. If not, it logs any abnormalities in the transmission control master command to facilitate troubleshooting.

[0065] In some embodiments, the serial communication master station includes a remote terminal master station, which is further configured to communicate via a serial port, send command data, and receive corresponding feedback data, determine whether the feedback data is qualified, and if so, send another command data; if not, record the abnormal status and send another command data.

[0066] The remote terminal master establishes a communication line with the remote terminal slave, achieving master-slave communication and ensuring the stability of data transmission. At the same time, by judging whether the feedback data is qualified, the communication status is monitored in real time, improving the system's ability to respond to abnormal conditions.

[0067] Further, if Figure 8 As shown in the figure, the remote terminal master station's workflow is as follows: the remote terminal master station reads the port, baud rate, and other parameters set in the configuration file to create and initialize an instance. It then sets the remote terminal slave station ID, starts a timer, and establishes a connection via the board's RS485 serial port. Once the connection is established, it actively sends commands based on application requirements and waits for a response from the remote terminal slave station. When receiving data, it determines whether the data was received successfully. If so, it schedules the next data cycle. If not, it logs the data and then schedules the next data cycle. If instance creation fails or if the received data is abnormal, a log is recorded. This information can be used to analyze abnormalities during remote terminal communication, facilitating troubleshooting.

[0068] In some embodiments, the serial communication slave station includes a remote terminal slave station, which is further configured to communicate with the remote terminal master station via the serial port according to the port, baud rate and remote terminal slave station ID in the configuration file, receive and determine whether the command data sent by the remote terminal master station is qualified, and if so, reply with feedback data; if not, wait for another command data.

[0069] After receiving the command data, the remote terminal slave can determine the legitimacy of the command in advance, reduce invalid processing, and optimize resource allocation. If the command is legal, it will provide feedback based on the command to optimize response capabilities.

[0070] Furthermore, if Figure 9 As shown in the figure, the remote terminal slave's workflow is as follows: the remote terminal slave calls the board's RS485 serial peripheral for communication. It creates a MODBUS communication instance based on the port, baud rate, slave ID, and other parameters set in the configuration file. In the main loop, it receives MODBUS requests. If the received data is correct, it processes the request and responds. If the received request does not meet expectations, it logs it and waits for the next request. The information recorded in the log can be used to analyze abnormalities during MODBUS RTU communication, facilitating fault location.

[0071] In combination with the above embodiments, this application is based on the Linux system and uniformly manages Ethernet and serial communication channels. A new thread is created for each MODBUS communication channel. Thread priorities are set based on the importance and volume of the communication data, giving priority to important communications. When data is exchanged between different threads, a data forwarding mechanism is set between them. When a thread receives specific data, it can accurately forward the data to other threads according to preset rules.

[0072] For example, data received by the MODBUS TCP master is forwarded to the corresponding MODBUS RTU slave and converted into other data formats, and vice versa, thus achieving collaborative work between different communication methods.

[0073] Specifically, in the present application, when a thread receives specific data, the data is accurately forwarded to other threads according to preset rules. An address mapping relationship is established between different threads. Through the first thread, the system is connected to the first device, and the data received from the first device is saved to a fixed address in the shared area. Through the second thread, the system is connected to the second device. The second thread takes out the data in the shared area according to the address mapping relationship and updates its own mapping area data. The data is transmitted to the second device to realize data forwarding. The triggering conditions for data transmission include: periodic timing triggering or event triggering by identifying the received function code and offset address.

[0074] If the raw data needs to be processed, it is converted to another data type as needed for data processing before forwarding. Examples include integer to floating-point conversion, numerical scaling, endianness adjustment, and bitwise operations. For example, conversion between ASCII characters and raw binary data involves splitting a byte into two 4-bit binary bits and decoding and encoding them accordingly.

[0075] Communication between masters and between slaves is achieved by sharing mapping areas. For example, a third device and a fourth device at an industrial site are both connected to the multi-channel serial communication system of this application as master stations for communication. This application connects to the third device via a third thread and to the fourth device via a fourth thread. The third and fourth threads share a mapping area for holding register and coil data, thereby enabling mutual transmission of the two types of data.

[0076] The fifth device and the sixth device at the industrial site are both connected to the multi-channel serial communication system of this application as slave stations for communication. The fifth device is connected via the fifth thread, and the sixth device is connected via the sixth thread. The fifth thread and the sixth thread share the mapping area of ​​the two data holding registers and coils. For the fifth and sixth devices as slave devices, the input register and discrete input data also need to be transmitted. The input register and discrete input data can only be read. This application modifies the mapping method to achieve data transmission. Specifically, the fifth thread reads the input register and discrete input data of the fifth device, and the sixth thread adds an offset address to the read input register and discrete input data, and sends them to the holding register and coil of the sixth device to achieve read-only data transmission. The two devices as slave stations need to define the data address offset in advance.

[0077] Furthermore, the present application adopts thread locks to ensure data consistency, force threads to serially access shared resources, and resolve data competition and logic errors in concurrent environments.

[0078] In some embodiments, the multi-channel serial communication system further comprises: The logging module is configured to record important information during the MODBUS communication process. Important information includes communication parameters set in the configuration file and abnormal information during the communication process.

[0079] The execution process of the logging module includes: initializing the logging module, configuring the log path, setting the log file size and number of log files, traversing the log files and writing them in sequence. When all files are full, clearing the first file and re-polling and writing to ensure that the disk space is not exhausted.

[0080] Log types include: ACTION, WARNING, and ERROR. During operation, important information is written to the log according to its type.

[0081] The master and slave modes of the device can be switched through the configuration file and configured to any MODBUS mode. It supports MODBUS communication with multiple devices at the same time. The threads do not interfere with each other, and the communication process can be recorded in real time.

[0082] Setting parameters such as the IP address, port number, slave ID for MOTBUS TCP communication and the serial port, baud rate, slave ID for MODBUS RTU communication is more convenient and quick through the configuration file.

[0083] After building the corresponding communication instance, wait for the connection to be established, monitor the communication status throughout the process, and record all error information in the log file to facilitate fault location.

[0084] In some embodiments, the multi-channel serial communication system further comprises: The switching module is configured to switch the communication of multiple serial communication master stations according to the life signal in the data sent by each serial communication master station when the data sent by the multiple serial communication master stations are homologous data. The life signal is used for data continuity detection. If the life signal is normal, the serial communication master station that sends the normal life signal is saved. If the life signal is abnormal, the serial communication master station that sends the abnormal life signal is disconnected.

[0085] Specifically, redundant connections are achieved through multi-channel MODBUS communications, and data accuracy is ensured by comparing multi-channel data. When data from different channels are from the same source and the data are inconsistent, the faulty device is judged based on the life signals corresponding to each data, and the data of the normal device is automatically switched to ensure communication continuity and data accuracy.

[0086] The life signal is a signal that is continuously transmitted in a loop following the data to be transmitted during the data transmission process. It has temporal continuity. If the life signal is discontinuous during a certain transmission process, it means that an error has occurred in this transmission.

[0087] The switching module ensures the correctness of data transmission by monitoring the data transmission status in real time. At the same time, it realizes data redundant transmission to ensure uninterrupted data transmission and improve data transmission stability.

[0088] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0089] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0090] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A multi-channel serial communication system, characterized in that: include: Serial communication master station and serial communication slave station, serial communication master station and serial communication slave station are set up in multiple types, among which, The current serial communication master station exchanges data with at least one type of serial communication master station via a shared area and / or a shared mapping area; sends data to a serial communication slave station of a different type than the current serial communication master station via another shared area; and sends data to a serial communication slave station of the same type via Ethernet and / or a serial port; The current serial communication slave station receives data sent by at least one type of serial communication master station; receives data transmitted by the same type of serial communication slave station; obtains read data, increases the offset of the address of the read data, and transmits the data to another serial communication slave station of the same type according to the increased offset address.

2. The multi-channel serial communication system according to claim 1, wherein: Also includes: a first transmission module and a second transmission module, wherein a shared area is provided between the first transmission module and the second transmission module; The first transmission module sets a first thread, communicates with the current serial communication master station via the first thread, obtains data from the current serial communication master station, and saves the data to a shared area; The second transmission module sets a second thread, and communicates with a serial communication master station of a different type from the current serial communication master station or a serial communication slave station of a different type from the current serial communication master station through the second thread. The second transmission module obtains data from the shared area, updates internal data, and sends it to a serial communication master station of a different type from the current serial communication master station or a serial communication slave station of a different type from the current serial communication master station.

3. The multi-channel serial communication system according to claim 1, wherein: Also includes: a third transmission module and a fourth transmission module, wherein the third transmission module and the fourth transmission module are both connected to the first common mapping area; The third transmission module sets a third thread, communicates with the current serial communication master station via the third thread, and the current serial communication master station uploads data or receives data in the first common mapping area; The fourth transmission module sets a fourth thread and communicates with another serial communication master station of the same type via the fourth thread. The other serial communication master station of the same type uploads or receives data in the first common mapping area.

4. The multi-channel serial communication system according to claim 1, wherein: Also includes: a fifth transmission module and a sixth transmission module, both of which are connected to the second common mapping area; The fifth transmission module sets a fifth thread, communicates with the current serial communication slave station via the fifth thread, reads data from the current serial communication slave station, and uploads the data to the second shared mapping area; The sixth transmission module sets a sixth thread, communicates with another serial communication slave station of the same type via the sixth thread, receives data in the second common mapping area, increases the offset address of the data, and sends it to another serial communication slave station of the same type.

5. The multi-channel serial communication system according to any one of claims 2 to 4, characterized in that: Also includes: The detection module detects all threads and determines whether the status of all threads is in a dead state. If so, the threads in the dead state are controlled to automatically restart.

6. The multi-channel serial communication system according to claim 1, wherein: The serial communication master station includes a transmission control master station, which is further configured to establish a communication channel with the same type of serial communication slave station via Ethernet according to the IP information, port number and serial communication slave station ID of the configuration file, and periodically call the sending function after the connection to send data to the same type of serial communication slave station.

7. The multi-channel serial communication system according to claim 6, characterized in that: The serial communication slave station includes a transmission control slave station, which is further configured to establish a connection with the transmission control master station, receive data sent by the transmission control master station, and provide feedback based on the received data; determine whether this connection is the first connection, if so, start communication, if not, disconnect the previous connection and then connect this connection.

8. The multi-channel serial communication system according to claim 1, wherein: The serial communication master station includes a remote terminal master station, which is further configured to communicate via the serial port, send command data, and receive corresponding feedback data, determine whether the feedback data is qualified, if so, send another command data, if not, record the abnormal status and send another command data.

9. The multi-channel serial communication system according to claim 8, characterized in that: The serial communication slave station includes a remote terminal slave station, which is further configured to communicate with the remote terminal master station via the serial port according to the port, baud rate and remote terminal slave station ID in the configuration file, receive and determine whether the instruction data sent by the remote terminal master station is qualified, and if so, reply with feedback data, and if not, wait for another instruction data.

10. The multi-channel serial communication system according to claim 1, wherein: Also includes: The switching module is configured to switch the communication of multiple serial communication master stations according to the life signal in the data sent by each serial communication master station when the data sent by the multiple serial communication master stations are homologous data. The life signal is used for data continuity detection. If the life signal is normal, the serial communication master station that sends the normal life signal is saved. If the life signal is abnormal, the serial communication master station that sends the abnormal life signal is disconnected.