Master-slave integrated Modbus RTU gateway and communication system
By designing a master-slave integrated Modbus RTU gateway, using the working state switching of the RS-485 communication module, the two-way transmission of master and slave data in the industrial control system is realized, solving the problem of single function and high cost of existing Modbus RTU gateway , improves the flexibility and maintainability of the system.
Patent Information
- Application Number
- CN202411249515.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-11-22
AI Technical Summary
The existing Modbus RTU gateways can only implement a single function, which is costly and poorly flexible, making it difficult to meet the bidirectional transmission requirements of master and slave data in industrial control systems.
A master-slave-in Modbus RTU gateway is designed. Through the control module and multiple RS-485 communication modules, the working mode tags are analyzed according to the received configuration data, and the working status of the RS-485 communication module is switched to realize the master station. It switches the function of the slave station and supports parallel processing of multiple RS-485 communication modules, reducing system costs and improving flexibility.
The two-way transmission of master and slave data in industrial control systems is realized, reducing the cost of increasing modules, improving the flexibility and maintainability of the system, and meeting diverse data transmission needs.
Smart Images

Figure CN119011339A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data communication, and in particular to a master-slave integrated Modbus RTU gateway and communication system. Background Art
[0002] With the rapid development of new technologies such as computer science and industrial control, computer monitoring systems have developed from early centralized monitoring to fully distributed. In the application of industrial automation, the application scope of distributed control systems DCS continues to expand. The processed data not only includes data from I / O modules in the system itself, but also data from third-party devices, especially data from various Modbus RTU slave devices. In order to effectively introduce third-party data into the DCS system, a Modbus RTU master gateway is needed. At the same time, in addition to introducing third-party slave device data into the DCS system, there are also many existing industrial control requirements that require the data inside the DCS to be open to third-party systems. At this time, a Modbus RTU slave gateway is needed as a link channel for DCS to provide data to third-party systems. Most of the ModbusRTU gateways currently used can only achieve the above single function, with high cost and poor flexibility. Summary of the invention
[0003] In view of the deficiencies in the prior art, the present invention provides a master-slave integrated Modbus RTU gateway, comprising a control module and a plurality of RS-485 communication modules respectively connected to the control module, wherein the control module is configured to configure each RS-485 communication module after receiving configuration data, wherein the configuration data comprises a plurality of bus configuration data structures corresponding to each RS-485 communication module, and the bus configuration data structure comprises a working mode label; after receiving new configuration data, the control module parses each bus configuration data structure and obtains the working mode label, wherein the working mode label comprises a master station label or a slave station label, and if it is a master station label, the corresponding RS-485 communication module is switched to the master station working state, and if it is a slave station label, the corresponding RS-485 communication module is switched to the slave station working state.
[0004] Preferably, four RS-485 communication modules are included, and the bus configuration data structure also includes basic communication parameters for configuring corresponding RS-485 communication modules, and the basic communication parameters include but are not limited to baud rate, data bit and stop bit.
[0005] Preferably, the control module is configured to determine whether to switch the working state of each current RS-485 communication module based on the received new configuration data; suspend the current communication operation of the RS-485 communication module to be switched in working state, and perform the communication operation in the switched working state after the switching is completed, while maintaining the working state of other RS-485 communication modules that are not switched in working state.
[0006] Preferably, it also includes a memory, which contains multiple communication buffers corresponding to each RS-485 communication module, wherein each communication buffer includes a master station buffer area and a slave station buffer area, and the RS-485 communication module is configured to select and use the corresponding buffer area according to its own working state; wherein the RS-485 communication module is configured to, if it is in the master station working state, after real-time data communication acquisition of the Modbus slave station device, store the collected Modbus slave station device data in the master station buffer area of the RS-485 communication module corresponding to the communication buffer; if it is in the slave station working state, communicate with the connected external controller according to the Modbus master station device command using the private INET protocol, and after storing the data required by the Modbus master station device obtained from the controller in the slave station buffer area of the corresponding communication buffer, respond and feedback to the Modbus master station device.
[0007] Preferably, each RS-485 communication module is configured to perform data transmission and reception operations through corresponding independent threads and independent communication state machines.
[0008] The present invention also discloses a Modbus communication system, comprising a DCS controller, a Modbus master station device, and the Modbus RTU gateway as described above, wherein the Modbus master station device communicates with the DCS controller via the Modbus RTU gateway, wherein: the Modbus master station device is configured to send a data read instruction to an RS-485 communication module in a slave working state of the Modbus RTU gateway; The RTU gateway is configured to forward the data read instruction sent by the Modbus master device to the DCS controller after receiving it; the DCS controller is used to interrupt the reception of Modbus communication data after receiving the data read instruction, and query whether the Modbus address table data is currently being updated, the Modbus address table is a slave data area established in the controller memory by the DCS controller through the Modbus slave data configuration; if the DCS controller is currently updating the Modbus address table data, the data read instruction is cached until the update is completed and then the data read instruction is called; if the DCS controller is not currently updating the Modbus address table data, the corresponding slave data is obtained from the MODBUS address table data according to the data read instruction, and after being packaged, the data is fed back to the Modbus RTU gateway.
[0009] Preferably, the Modbus master station device is connected to the corresponding RS-485 communication module in the Modbus RTU gateway via a 485 bus, wherein the corresponding RS-485 communication module is configured to be in a slave station working state.
[0010] Preferably, the Modbus communication data packet for data interaction between the Modbus RTU gateway and the DCS controller through the control network consists of a command sequence, an identifier, a length value, a slave station address, a function code and Modbus data, wherein the command sequence represents the data sequence number, the identifier is used to represent the master station index in the gateway, the length value is the length of subsequent data, the function code is used by the controller to identify different responses of errors and correctness in the Modbus data, and the Modbus data is data processed and configured according to the standard Modbus protocol.
[0011] Preferably, at least one Modbus slave device is further included, and each Modbus slave device is connected to a corresponding RS-485 communication module in the Modbus RTU gateway via a 485 bus, wherein the corresponding RS-485 communication module is configured to be in a master station working state.
[0012] Preferably, after receiving the data write instruction from the Modbus master device forwarded by the Modbus RTU gateway, the DCS controller interrupts receiving the Modbus communication data and queries whether the Modbus address table data is currently being updated; if the Modbus address table data is currently being updated, the data write instruction is cached until the update is completed and then the data write instruction is retrieved and parsed; if the Modbus address table data is not currently being updated, the data write instruction is directly parsed; the required write data obtained by the parsing is entered into the corresponding Modbus address table data, and the write flag of the Modbus address is configured and the response information is fed back to the Modbus RTU gateway; and in the data processing flow, according to the data write flag of the Modbus address table data, the data is written back to the actual operation data area of the DCS controller.
[0013] The master-slave integrated Modbus RTU gateway and communication system disclosed in the present invention include a control module and a plurality of RS-485 communication modules respectively connected to the control module, wherein the control module is configured to configure each RS-485 communication module after receiving configuration data, and the configuration data includes a plurality of bus configuration data structures corresponding to each RS-485 communication module; after receiving new configuration data, the control module parses each bus configuration data structure and obtains a working mode label, and if it is a master station label, the corresponding RS-485 communication module is switched to the master station working state, and if it is a slave station label, the corresponding RS-485 communication module is switched to the slave station working state. Thus, the master and slave station requirements in the industrial control system can be realized by only one Modbus RTU gateway, reducing the cost of adding modules and making the scheme of the entire system more flexible and changeable.
[0014] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0016] Figure 1 This is a structural block diagram of a master-slave integrated Modbus RTU gateway disclosed in one embodiment of the present invention.
[0017] Figure 2 A schematic diagram of the structure of a Modbus communication system disclosed in one embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0019] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0020] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may include that the first and second features are in direct contact, or may include that the first and second features are not in direct contact but are in contact through another feature between them. Moreover, a first feature being "above", "above" and "above" a second feature includes that the first feature is directly above and obliquely above the second feature, or simply indicates that the first feature is higher in level than the second feature. A first feature being "below", "below" and "below" a second feature includes that the first feature is directly below and obliquely below the second feature, or simply indicates that the first feature is lower in level than the second feature.
[0021] Unless otherwise defined, the technical or scientific terms used herein shall have the common meanings understood by persons with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one" or "a" do not indicate a quantity limitation, but indicate the existence of at least one.
[0022] As attached Figure 1As shown, this embodiment discloses a master-slave Modbus RTU gateway 1, including a control module 11 and a plurality of RS-485 communication modules 111-114 respectively connected to the control module, wherein the control module 11 is configured to configure each RS-485 communication module after receiving configuration data, wherein the configuration data includes a plurality of bus configuration data structures corresponding to each RS-485 communication module. The bus configuration data structure includes a working mode tag. After receiving the new configuration data, the control module parses each bus configuration data structure and obtains the working mode tag, and the working mode tag includes a master station tag or a slave station tag. If it is a master station tag, the corresponding RS-485 communication module is switched to the master station working state, and if it is a slave station tag, the corresponding RS-485 communication module is switched to the slave station working state.
[0023] Specifically, each of the RS-485 communication modules 111-114 corresponds to a 485 bus in the figure for data transmission and communication. The configuration data structure is configured in units of each bus to enhance the modularity and scalability of the system. The configuration data structure corresponding to each bus contains a working mode status word, which is used to identify the current working mode of the bus. After obtaining the new configuration, the gateway parses the working mode status word of each bus. If it is the master station state, the current bus runs the master station program, and if it is a slave station, the slave station program is run. When an RS-485 communication module runs the master station program, it actively sends a communication request to the modbus slave station device connected to the RS-485 bus according to the configuration, and stores the collected modbus slave station device data in the memory in the gateway. When an RS-485 communication module runs the slave station program, it obtains the corresponding data in the gateway memory according to the instruction of the Modbus master station device to which it is connected, and responds and feedbacks to the Modbus master station device. Wherein, each RS-485 communication module is configured to perform data transmission and reception operations through corresponding independent threads and independent communication state machines.
[0024] Specifically, each bus implements the communication program through a separate thread, and each is configured with an independent communication state machine to realize the sending and receiving of 485 communication. Under the real-time system scheduling, the communication processing between each bus is independent of each other, and does not interfere with or affect each other. For example, if bus 1 is configured as the master station mode, when performing real-time data interaction with a third-party slave device, bus 2 configured as the slave station mode can also immediately respond to the data command of the third-party master station, and its response time is less than 20ms. In this embodiment, the Modbus RTU gateway includes four RS-485 communication modules, and the bus configuration data structure also includes basic communication parameters for configuring the corresponding RS-485 communication modules, and the basic communication parameters include but are not limited to baud rate, data bit and stop bit. In the whole system, four buses are processed in parallel, which significantly improves the overall efficiency of the gateway in processing data.
[0025] In this embodiment, the control module is configured to determine whether to switch the working state of each current RS-485 communication module based on the received new configuration data; suspend the current communication operation of the RS-485 communication module to be switched in working state, and perform the communication operation in the switched working state after the switching is completed, while maintaining the working state of other RS-485 communication modules that are not switched in working state.
[0026] Specifically, when performing configuration, the change of the master or slave working state of one bus will not affect other buses that have not undergone configuration changes, and the remaining buses will maintain the working state under the original configuration. Only the bus that is explicitly designated to switch between master and slave states will briefly interrupt the current communication activity to adjust the internal state, and communicate in the modified working state after the adjustment, ensuring the stability and independence between the various parts of the system, while improving the overall flexibility and maintainability of the system.
[0027] In this embodiment, a memory is also included, wherein the memory includes multiple communication buffers corresponding to each RS-485 communication module, wherein each communication buffer includes a master station buffer area and a slave station buffer area, and the RS-485 communication module is configured to select and use the corresponding buffer area according to its own working state; wherein the RS-485 communication module is configured to, if it is in the master station working state, after real-time data communication acquisition of the Modbus slave station device, store the collected Modbus slave station device data in the master station buffer area of the communication buffer corresponding to the RS-485 communication module; if it is in the slave station working state, communicate with the connected external controller according to the Modbus master station device command using the private INET protocol, and after storing the data required by the Modbus master station device obtained from the controller in the slave station buffer area of the corresponding communication buffer, respond and feedback to the Modbus master station device.
[0028] Specifically, each bus is equipped with an independent communication cache area, including a master cache area and a slave cache area. Each bus intelligently selects to use the corresponding cache area according to the current working status. When the bus is configured in master mode, the data of the third-party slave device is collected in real time, and the collected third-party slave device data is stored in the master cache area. On the contrary, if the bus is configured in slave mode, it receives commands from the third-party master device, exchanges data with the controller through the internal private INET protocol to obtain the data required by the third-party master from the controller, and after storing the data in the slave cache area, responds to the third-party master, reducing the waiting time and conflict of data processing and ensuring the efficiency of the data processing process.
[0029] Furthermore, this embodiment also includes a fault diagnosis mechanism, which gives the gateway the function of performing diagnosis on a bus basis, including command diagnosis and bus diagnosis, so as to comprehensively monitor and evaluate the health status of the bus. Through the corresponding diagnostic information, the current operating status of the bus can be known in real time.
[0030] The master-slave integrated Modbus RTU gateway disclosed in this embodiment includes a control module and a plurality of RS-485 communication modules respectively connected to the control module, wherein the control module configures each RS-485 communication module after receiving configuration data, and parses each bus configuration data structure after receiving new configuration data to switch the working mode of each RS-485 communication module, and switches the corresponding RS-485 communication module to the master working state when the configuration data contains a master tag, and switches the corresponding RS-485 communication module to the slave working state when the configuration data contains a slave tag, so that the Modbus RTU gateway can realize the collection of data from third-party slave station devices, and perform data transmission between the DCS system and the third-party devices when receiving instructions from the third-party master station devices. Through a gateway module and corresponding configurations, the master and slave station requirements in the industrial control system are realized, the cost of adding modules is reduced, and the functionality and diversity of the Modbus RTU gateway and the communication system in which it is located are increased.
[0031] In another embodiment, a Modbus communication system is also disclosed, as shown in the attached Figure 2As shown, the communication system includes a DCS controller 1, a Modbus master device 21 or 23, and a Modbus RTU gateway 1 as described in any of the above embodiments, wherein the Modbus master device 2 communicates with the DCS controller 3 via the Modbus RTU gateway 1. The Modbus master device 21 or 23 is connected to the corresponding RS-485 communication module in the Modbus RTU gateway 1 via a 485 bus, wherein the corresponding RS-485 communication module is configured to be in a slave working state. At this time, the Modbus master device 21 or 23 is configured to send a data read instruction to the RS-485 communication module in the slave working state of the Modbus RTU gateway. The Modbus RTU gateway 3 is configured to forward the data read instruction sent by the Modbus master device to the DCS controller after receiving it. The DCS controller 3 is configured to interrupt receiving Modbus communication data after receiving the data reading instruction, and query whether the Modbus address table data is currently being updated. The Modbus address table is a slave data area established in the controller memory by the DCS controller through the Modbus slave data configuration.
[0032] In this embodiment, the Modbus RTU gateway 1 can parse the configuration information, obtain the working mode status word therein and set the working state of the corresponding 485 bus to the slave state. At this time, the Modbus RTU gateway 1 will serve as the corresponding Modbus slave link interface for the Modbus master device to link and communicate. After receiving the data read command sent by the Modbus master device, the data read command is forwarded to the DCS controller 31 through the switch in a udp point-to-point manner through the control network. After receiving the communication data forwarded by the Modbus RTU gateway 1, the DCS controller 3 parses it, obtains the read command sent by the Modbus master device 21 or 23, and obtains the corresponding slave data from the Modbus address table of the controller according to the read instruction for packetization, and sends it back to the Modbus master device 21 or 23 through the Modbus RTU gateway 1, completing the entire Modbus data reading process and realizing the external output of the DCS internal data.
[0033] In this embodiment, the communication data sent by the Modbus RTU gateway to the DCS controller through the control network includes a Modbus communication data packet including a master station command and a time stamp. The time stamp includes a UTC time stamp and a millisecond time stamp to facilitate command distinction and tracing. The Modbus communication data packet consists of a command sequence, an identifier, a length value, a slave station address, a function code and Modbus data, wherein the command sequence represents the data sequence number, the identifier is used to represent the master station index in the gateway, the length value is the length of the subsequent data, and the function code is used by the controller to identify different responses to errors and correctness in the Modbus data, and the Modbus data is data processed and configured according to the standard Modbus protocol. The communication data packet may also include a check code for detecting whether an error occurs in the data during transmission, such as a CRC16 check code, and its overall data format is shown in the following table:
[0034] Command sequence Identifier Length value Unit identifier (slave address) Function code Modbus Data CRC16 checksum 2 bytes 2 bytes 2 bytes 1 byte 1 byte n bytes 2 bytes
[0035] Except for CRC16, which is in little-endian representation, all other data are in big-endian representation. For example, identifier: the low byte represents the master station index 0-3 in the gateway, and is copied and returned when the controller responds. Length value: the length of the subsequent data, which is filled in by the controller according to the actual response data. Slave station address: copied and returned when the controller responds. Function code: when the controller needs to respond to an error in the Modbus data, for example, the function code can be 0x80, and the normal response function code is copied and returned. Modbus data: processed according to the standard Modbus protocol. CRC16 check: Calculate CRC16 starting from the slave station address, and do not respond when CRC is incorrect.
[0036] The response data packet sent by the DCS controller to the Modbus slave gateway is consistent with the data format of the Modbus communication data packet that the Modbus slave gateway exchanges data with the DCS controller through the control network, including command sequence, identifier, length, slave address, function code, data, CRC16 checksum, etc. Among them, the command code, identifier, and slave address are obtained by the DCS controller by copying the Modbus communication data packet, and writing them into the response data packet for return; the length value is the length of the subsequent data, and the controller fills it in according to the actual response situation; the function code returns the corresponding value in the Modbus communication data packet when the controller responds normally, and returns "function code|0x80" in the case of an error response; the Modbus data is processed according to the standard Modbus protocol. After receiving the response data packet, the Modbus slave gateway verifies and calculates the CRC16 checksum, and forwards the qualified data to the Modbus master device. The DCS controller retrieves the data in the Modbus address table data to provide the Modbus master device with all kinds of data in the required DCS process, thereby improving the operating efficiency of the DCS system.
[0037] In addition, the DCS controller also contains a Modbus address table, which records the address information of each Modbus slave device, including but not limited to data type, device address, register address, etc., and is generated and updated in the memory according to the configuration of each slave data, so that the Modbus master device can read and call it when needed. Among them, the DCS controller is connected to the slave gateway of each protocol including the Modbus protocol, receives and stores the data of each slave, and performs custom configuration according to the received slave data after receiving the read instruction, and defines the data content provided to the outside. The configuration content includes but is not limited to the bit ID configuration, data length configuration, and data type configuration.
[0038] In this embodiment, in order to avoid the impact of executing the Modbus master station device read command on the DCS process data processing process, the DCS controller first determines the current state of the Modbus address table data after receiving the read command; if the DCS controller is currently updating the Modbus address table data when receiving the Modbus read command, the data read instruction is cached until the Modbus address table data is updated and then the data read instruction is called. If the DCS controller is not currently updating the Modbus address table data, the corresponding slave station data is obtained from the MODBUS address table data according to the data read instruction, and after being packaged, it is fed back to the Modbus RTU gateway. That is, after receiving the data, the DCS controller first determines the current state of the Modbus address table data; if the controller is updating the Modbus address table data when receiving the Modbus read command, the controller caches the read command and responds to the read command after the Modbus address table data is updated, thereby preventing data reading operations during the update of the Modbus address table data, and interrupting the reception of the Modbus master device command after receiving the data read instruction forwarded by the Modbus slave gateway to ensure the integrity of the Modbus master device reading the DCS data. If the Modbus address table data is not being refreshed when receiving the Modbus read data instruction, the gateway data is directly responded. Among them, for the command response of the coil and offline input, the controller supports the conversion of bytes and bits, that is, the controller memory is stored in bytes, and in the Modbus command data, it needs to be converted into bits.
[0039] In this embodiment, the third-party device can also actively send a data write instruction. At this time, the DCS controller is also configured to interrupt the reception of Modbus communication data after receiving the data write instruction from the Modbus master device forwarded by the Modbus RTU gateway, and query whether the Modbus address table data is currently being updated; if the Modbus address table data is currently being updated, the data write instruction is cached until the update is completed and then the data write instruction is retrieved and parsed; if the Modbus address table data is not currently being updated, the data write instruction is directly parsed; the required write data obtained by the parsing is entered into the corresponding Modbus address table data, and the write flag of the Modbus address is configured and the response information is fed back to the Modbus RTU gateway; and in the data processing flow, according to the data write flag of the Modbus address table data, the data is written back to the actual operation data area of the DCS controller.
[0040] Specifically, the DCS controller also interrupts the reception of Modbus communication data and determines the update status of the Modbus address table data to ensure that no data write operation is performed during the update of the Modbus address table data, so as to prevent conflicts between the execution of the Modbus master device write instruction and the data storage and processing process inside the DCS, resulting in data anomalies, defects, errors, etc. When the controller does not update the Modbus address table data, it directly writes the data into the Modbus address table and sets the write flag of the Modbus address to respond to the write command; if the Modbus address table is being updated, the write command is cached, and the data is written into the Modbus address table after the controller has updated the Modbus address table, and the write flag of the Modbus address is set to respond to the gateway write command. The Modbus master device writes data to each device of the user-defined configuration in the DCS process control by sending a write command, thereby improving the scalability of the Modbus master device command.
[0041] In this embodiment, the DCS controller can configure the configuration according to the Modbus slave station data in the periodic scheduling task. After monitoring the data write flag of the Modbus address, the data in the Modbus address table is written into the bit number data and variable data area of the DCS controller; at the same time, the corresponding bit number data and variable data are obtained and entered into the Modbus address table to complete the update of the Modbus address table data.
[0042] Among them, the DCS controller also has some abnormal response situations. For example, when the CRC16 check code is incorrect, the DCS will not respond; when the data length and the actual data field in the write multiple registers (FC15) / write multiple coils (FC16) command are inconsistent, the DCS controller will also not respond. For example, for the command 01 10 00 00 00 01 04 11 22CA18, the command indicates that the 4 bytes of data provided should be written into 1 register, but 1 register has only 2 bytes and cannot be written. The data length and the actual data field are inconsistent, and the DCS controller does not respond.
[0043] The DCS controller in the above embodiment can configure the Modbus slave data according to the received slave data, customize the data content and data format provided to the outside, generate Modbus address table data, and update the Modbus address table data according to the customized configuration. After the Modbus master sends a read instruction to the DCS controller through the Modbus slave gateway, the DCS controller is interrupted from receiving the Modbus master command and judging whether the Modbus address table data is currently being updated to avoid data conflicts. When the Modbus address table is not updated or the update is completed, the Modbus master read instruction is executed to obtain the corresponding slave data from the Modbus address table for data packaging, so that the Modbus master can access the various collected data and process data selected by the user in the DCS control process and can be provided to the Modbus master, thereby enhancing the system flexibility and scalability, and improving the data utilization and system operation efficiency.
[0044] Furthermore, as attached Figure 2 As shown, the Modbus communication system also includes at least one Modbus slave device 22 or 24, and each Modbus slave device is connected to the corresponding RS-485 communication module in the Modbus RTU gateway 1 through the 485 bus, wherein the corresponding RS-485 communication module is configured to be in the master station working state. At this time, the Modbus RTU gateway 1 is configured to send a data acquisition instruction to the Modbus slave device 22 or 24. The Modbus slave device 22 or 24 is configured to perform data acquisition operations after receiving the data acquisition instruction sent by the Modbus RTU gateway 1 and send the collected data to the Modbus RTU gateway 1. After receiving the data collected by the Modbus slave device, the Modbus RTU gateway 1 stores the data in the master station buffer area and sends it to the DCS system to realize the entire data collection and storage process of the Modbus slave device.
[0045] By using a master-slave Modbus RTU gateway in the Modbus communication system, the number of Modbus RTU gateways required can be effectively reduced. By configuring the master station working status and slave station working status of each RS-485 communication module of the Modbus RTU gateway itself, it can meet the different master and slave station requirements in the industrial control system, reduce the cost of the gateway module, and make the whole system solution more flexible and changeable.
[0046] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0047] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
[0048] In conclusion, the above is only a preferred embodiment of the present invention, and all equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the patent of the present invention.
Claims
1. A master-slave Modbus RTU gateway, characterized by: The invention comprises a control module and a plurality of RS-485 communication modules respectively connected to the control module, wherein the control module is configured to configure each RS-485 communication module after receiving configuration data, wherein the configuration data comprises a plurality of bus configuration data structures corresponding to each RS-485 communication module, and the bus configuration data structure comprises a working mode tag; After receiving the new configuration data, the control module parses each bus configuration data structure and obtains the working mode tag, which includes a master station tag or a slave station tag. If it is a master station tag, the corresponding RS-485 communication module is switched to the master station working state; if it is a slave station tag, the corresponding RS-485 communication module is switched to the slave station working state.
2. The master-slave integrated Modbus RTU gateway according to claim 1, characterized in that: It includes four RS-485 communication modules, and the bus configuration data structure also includes basic communication parameters for configuring corresponding RS-485 communication modules, and the basic communication parameters include but are not limited to baud rate, data bit and stop bit.
3. The master-slave integrated Modbus RTU gateway according to claim 2, characterized in that: The control module is configured to determine whether to switch the working state of each current RS-485 communication module according to the received new configuration data; suspend the current communication operation of the RS-485 communication module to be switched in working state, and perform the communication operation in the switched working state after the switching is completed, while maintaining the working state of other RS-485 communication modules that are not switched in working state.
4. The master-slave integrated Modbus RTU gateway according to claim 3, characterized in that: It also includes a memory, wherein the memory includes a plurality of communication buffers corresponding to each RS-485 communication module, wherein each communication buffer includes a master station buffer area and a slave station buffer area, and the RS-485 communication module is configured to select and use a corresponding buffer area according to its own working state; The RS-485 communication module is configured to store the collected Modbus slave device data in the master station buffer area corresponding to the communication buffer of the RS-485 communication module after real-time data communication collection of the Modbus slave device if it is in the master station working state; If it is in slave working state, it communicates with the connected external controller using the private INET protocol according to the Modbus master device command, and stores the data required by the Modbus master device obtained from the controller in the slave buffer area of the corresponding communication buffer, and then responds and feedbacks to the Modbus master device.
5. The master-slave integrated Modbus RTU gateway according to claim 4, characterized in that: Each RS-485 communication module is configured to perform data transmission and reception operations through corresponding independent threads and independent communication state machines.
6. A Modbus communication system, characterized in that: The invention comprises a DCS controller, a Modbus master station device, and a Modbus RTU gateway according to any one of claims 1 to 5, wherein the Modbus master station device communicates with the DCS controller through the Modbus RTU gateway, wherein: The Modbus master device is configured to send a data read instruction to the RS-485 communication module in the slave working state of the Modbus RTU gateway; The Modbus RTU gateway is configured to forward the data read command sent by the Modbus master device to the DCS controller after receiving it; The DCS controller is used to interrupt the reception of Modbus communication data after receiving the data reading instruction, and to query whether the Modbus address table data is currently being updated, wherein the Modbus address table is a slave station data area established in the controller memory by the DCS controller through the Modbus slave station data configuration; if the DCS controller is currently updating the Modbus address table data, the data reading instruction is cached until the update is completed and then the data reading instruction is called; if the DCS controller is not currently updating the Modbus address table data, the corresponding slave station data is obtained from the MODBUS address table data according to the data reading instruction, and after being packaged, the data is fed back to the Modbus RTU gateway.
7. The Modbus communication system according to claim 6, characterized in that: The Modbus master device is connected to the corresponding RS-485 communication module in the Modbus RTU gateway through the 485 bus, wherein the corresponding RS-485 communication module is configured to be in a slave working state.
8. The Modbus communication system according to claim 7, characterized in that: The Modbus communication data packet that the Modbus RTU gateway uses to interact with the DCS controller through the control network consists of a command sequence, an identifier, a length value, a slave station address, a function code, and Modbus data, wherein the command sequence represents the data sequence number, the identifier is used to represent the master station index in the gateway, the length value is the length of the subsequent data, the function code is used for the controller to identify different responses to errors and correctness in the Modbus data, and the Modbus data is data processed and configured according to the standard Modbus protocol.
9. The Modbus communication system according to claim 8, characterized in that: It also includes at least one Modbus slave device, each Modbus slave device is connected to the corresponding RS-485 communication module in the Modbus RTU gateway through a 485 bus, wherein the corresponding RS-485 communication module is configured to be in a master station working state.
10. The Modbus communication system according to claim 9, characterized in that: After receiving the data write instruction from the Modbus master device forwarded by the Modbus RTU gateway, the DCS controller interrupts receiving the Modbus communication data and inquires whether the Modbus address table data is currently being updated; if the Modbus address table data is currently being updated, the data write instruction is cached until the update is completed and then the data write instruction is retrieved and parsed; if the Modbus address table data is not currently being updated, the data write instruction is directly parsed; the required write data obtained by the parsing is entered into the corresponding Modbus address table data, and the write flag of the Modbus address is configured and the response information is fed back to the Modbus RTU gateway; and in the data processing flow, according to the data write flag of the Modbus address table data, the data is written back to the actual operation data area of the DCS controller.
Citation Information
Cited By
Modbus RTU equipment routing module based on host asynchronous proxy
CN119728333A
RS485 bus-based host extension method, apparatus and device, and storage medium
CN119847967A
Host Expansion Method, Device, Equipment and Storage Medium Based on RS485 Bus
CN119847967B
