Communication system, communication method, and second master device

By introducing a second master device into the Modbus bus system, using the data storage area and data packet search and analysis module to listen and parse communication data packets in real time, the problem of adding the second master device to acquire slave data under the limit of a single master device is solved, and the coexistence of multiple master devices and the simplification of the system is realized.

CN120216431APending Publication Date: 2025-06-27WUXI HUAYING MICROELECTRONICS TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202311807059.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-25
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

In the existing Modbus bus system, due to the single master device characteristics, the slave data cannot be directly obtained when adding the second master device, and interaction needs to be carried out through the intermediate master device, resulting in system complexity and the necessity of hardware replacement.

Method used

Without changing the original hardware system, by adding a second master device to the bus, the device includes a data storage area and a data packet search and parsing module, monitoring the bus data in real time, searching and parsing communication data packets between the first master device and the slave device, thereby obtaining the data of the slave device.

Benefits of technology

The function of adding a second master device to the original hardware system is realized, allowing multiple master devices to coexist, simplifying the system structure and reducing the need for hardware replacement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120216431A_ABST
    Figure CN120216431A_ABST
Patent Text Reader

Abstract

The invention discloses a communication system, a communication method and a second master device. The second master device monitors a bus in the communication system in real time, receives all data sent by the bus, and sequentially stores the received data into a data storage area; and the second master device searches the data in the data storage area to obtain a first communication data packet of the first master device and a second communication data packet replied by the target slave device. Thus, on the premise that an original hardware system is almost not changed, the second master device can be added to obtain the data in the slave device, and therefore the effect of multiple master devices is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communications, and particularly to a communication system, a communication method, and a second master device.

Background Art

[0002] The Modbus protocol layer (Modbus is a serial communication protocol published by Modicon in 1979 for programmable logic controller communication) is a master / slave architecture protocol. A communication system based on Modbus usually includes a master device and one or more slave devices. Each slave device has a unique address. A Modbus instruction contains the address of the target slave device. All slave devices will receive the Modbus instruction, but only the target slave device with the specified address will execute and respond to the instruction (except for address 0. An instruction specifying address 0 is a broadcast instruction, and all devices that receive the instruction will run but will not respond to the instruction).

[0003] The Modbus physical layer applies RS232 or RS485 networks. The electrical characteristic of RS232 is a full-duplex communication method, which can only have a single master device and a single slave device. The electrical characteristic of RS485 is half-duplex and can achieve a single master device and multiple slave devices. Since in industrial automation control, often a master device needs to communicate with multiple slave devices simultaneously, most of the application hardware of the Modbus protocol uses the RS485 method. Due to the characteristics of the physical layer and protocol layer of Modbus, there is only one master device on the bus at the same time.

[0004] Figure 1 It is an architecture diagram of an existing communication system based on Modbus. As Figure 1 shown, the communication system includes a master device M1 and five slave devices S1 - S5. In normal polling, the master device M1 starts to send out a communication data packet. The slave devices S1 to S5 will all receive the communication data packet (according to the voltage difference on the bus). The communication data packet contains the slave device address. Therefore, when the slave device confirms that the slave device address in the communication data packet sent by the master device refers to its own address, the slave device will immediately reply to the corresponding communication data packet. After receiving the reply from the target slave device, the master device M1 will then send communication data packets corresponding to other slave devices for data query or modification.

[0005] In a traditional Modbus bus, since there is only one master device M1, if another master device M2 needs to be added and it wants to know the data of slave devices S1 - S5, the master device M1 has to be used as an intermediary for communication between the master device M2 and M1. The master device M2 obtains the data of slave devices S1 to S5 from M1. For example, if S1 to S5 are on-site temperature control instruments and M1 is the upper computer of the on-site human-machine interface, when a second master device M2 needs to be added to the bus to monitor the data of S1 and S5, a power protection circuit for heating, which is the responsibility of the master device M2, is added to the PLC hardware. When any one of the temperature control instruments from S1 to S5 overheats, M2 needs to immediately disconnect the power protection circuit for heating. At this time, due to the single-master device characteristic, the M2 device cannot collect the data of S1 to S5 and can only interact with M1. However, if the master device M1 is a closed device (does not support the protocol for communication with M2, or is an encrypted third-party device that cannot be maintained and modified anymore), then the master device M2 will be in a passive position and a large number of corresponding hardware components in the system need to be replaced to achieve the function.

[0006] Therefore, it is necessary to propose a new solution to overcome the problems in the prior art.

[0007] It should be noted that the above introduction of the technical background is only for the convenience of clearly and completely explaining the technical solution of the present application and facilitating the understanding of those skilled in the art. It cannot be considered that the above technical solutions are well-known to those skilled in the art just because these solutions are described in the background art part of the present application.

Summary of the Invention

[0008] The purpose of the present invention is to provide a communication system, a communication method, and a second master device, which can add a second master device to obtain data from slave devices with almost no change to the original hardware system, thereby achieving the effect of multiple master devices.

[0009] To achieve the above object, the present invention provides a communication system, which includes: a bus; a first master device connected to the bus, which broadcasts and sends a first communication data packet through the bus, wherein the first communication data packet includes a slave device address, a function code, and address information; one or more slave devices connected to the bus, each slave device receives the first communication data packet sent by the first master device through the bus, and determines whether the slave device address in the received first communication data packet is the same as its own slave device address. If they are the same, the slave device is the target slave device, and the target slave device replies with a second communication data packet through the bus, wherein the second communication data packet includes a slave device address, a function code, and data information; a second master device connected to the bus, which includes a data storage area and a data packet search and parsing module, wherein the second master device monitors the bus in real time, receives all the data sent through the bus, and sequentially stores the received data into the data storage area, and the data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

[0010] In a further embodiment, the address information in the first communication data packet includes a register start address and a register quantity, the data information in the second communication data packet includes the number of bytes and the data of each register, and both the first communication data and the second communication data packet include a CRC check code, and the check range of the CRC check code is all the previous bytes in the data packet.

[0011] In a further embodiment, the second master device prestores the function code and address information in the first communication data packet that the first master device can send. The data packet search and parsing module uses the prestored function code and address information of the first communication data packet as a set of data to match a set of consecutive data in the search box of the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and the prestored function code and address information of the first communication data packet are still used as a set of data to match a set of consecutive data in the search box of the data storage area. If the match is successful, the previous set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the next set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area, and the candidate first communication data packet is subjected to CRC check. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, the data in the data storage area continues to be matched to search for the first communication data packet. After the first communication data packet is successfully searched in the data storage area, a segment of data after the first communication data packet in the data storage area is regarded as a candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, the data in the data storage area continues to be matched to search for the first communication data packet.

[0012] In a further embodiment, when verifying the candidate second communication data packet, first judge whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If it is different, continue to match the data in the data storage area to search for the first communication data packet. If it is the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet is successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. Determine the size of the candidate second communication data packet according to the number of bytes in the candidate second communication data packet.

[0013] In a further embodiment, the first master device and the slave device communicate based on the Modbus protocol. In the communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the register start address occupies two bytes, the register quantity occupies two bytes, and the CRC check code occupies two bytes. The number of bytes in the second communication data packet is 1 byte. The function codes in the first communication data packet and the second communication data packet both represent queries.

[0014] According to another aspect of the present invention, the present invention provides a second master device in a communication system. The communication system includes a bus, a first master device connected to the bus, and one or more slave devices connected to the bus. The first master device broadcasts and sends a first communication data packet through the bus, where the first communication data packet includes a slave device address, a function code, and address information. Each slave device receives the first communication data packet sent by the first master device through the bus and determines whether the slave device address in the received first communication data packet is the same as its own slave device address. If it is the same, the slave device is the target slave device. The target slave device replies with a second communication data packet through the bus, where the second communication data packet includes a slave device address, a function code, and data information. The second master device is a second master device connected to the bus. The second master device includes a data storage area and a data packet search and parsing module. The second master device monitors the bus in real time, receives all data sent through the bus, and sequentially stores the received data in the data storage area. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

[0015] In a further embodiment, the address information in the first communication data packet includes the register start address and the number of registers, the data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data and the second communication data packet include a CRC check code. The check range of the CRC check code is all the previous bytes within the data packet. The second master device pre-stores the function code and address information in the first communication data packet that the first master device can send. The data packet search and parsing module uses the pre-stored function code and address information of the first communication data packet as a set of data to match a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the pre-stored function code and address information of the first communication data packet are used as a set of data to continue matching a set of consecutive data in the search box in the data storage area. If the match is successful, the previous segment of data of the set of consecutive data that matches successfully in the data storage area is considered the slave device address, and the subsequent segment of data of the set of consecutive data that matches successfully in the data storage area is considered the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area. The candidate first communication data packet is subjected to CRC check. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, the data in the data storage area continues to be matched to search for the first communication data packet. After the first communication data packet is successfully searched in the data storage area, the subsequent segment of data after the first communication data packet in the data storage area is considered a candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, the data in the data storage area continues to be matched to search for the first communication data packet.

[0016] In a further embodiment, when verifying a candidate second communication data packet, first determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet has been successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet, and determine the size of the candidate second communication data packet according to the number of bytes in the candidate second communication data packet. Communication between the first master device and the slave device is based on the Modbus protocol. In the communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the register start address occupies two bytes, the register quantity occupies two bytes, and the CRC check code occupies two bytes. The number of bytes in the second communication data packet is 1 byte, and the function codes in the first communication data packet and the second communication data packet both represent queries.

[0017] According to another aspect of the present invention, based on the communication method of the second master device described above, it includes: the second master device monitors the bus in real time, receives all data sent through the bus, and sequentially stores the received data in the data storage area; the data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

[0018] In a further embodiment, the address information in the first communication data packet includes the register start address and the number of registers, the data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data and the second communication data packet include a CRC check code. The check range of the CRC check code is all the previous bytes in the data packet. The second master device pre-stores the function code and address information in the first communication data packet that the first master device can send. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device in the data in the data storage area, including: the data packet search and parsing module uses the function code and address information of the pre-stored first communication data packet as a set of data to match a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the function code and address information of the pre-stored first communication data packet are used as a set of data to match a set of consecutive data in the search box in the data storage area again. If the match is successful, the previous section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the latter section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area; perform a CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet; after successfully searching for the first communication data packet in the data storage area, it is considered that a section of data after the first communication data packet in the data storage area is a candidate second communication data packet, and verify the candidate second communication data packet. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

[0019] In a further embodiment, the verification of the candidate second communication data packet includes:

[0020] First, determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform a CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet is successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet.

[0021] Compared with the prior art, without substantially changing the original hardware system, the present invention can add a second master device to monitor the bus, thereby obtaining data from the slave device, so as to achieve the effect of multiple master devices.

[0022] Therefore, it should be understood that providing this summary is only for the purpose of summarizing some embodiments to provide a basic understanding of some aspects of the present invention. Therefore, the above embodiments are only examples and should not be construed as narrowing the scope or concept of the present invention in any way. By reading the following detailed description and the accompanying drawings, the features, appearances, and advantages of each embodiment will be obvious, and the drawings show the principles of some embodiments by way of example.

Description of the Drawings

[0023] In combination with the accompanying drawings and the following detailed description, the present invention will be more easily understood, where the same reference numerals correspond to the same structural components, and:

[0024] Figure 1 is the architecture diagram of an existing communication system based on the Modbus protocol;

[0025] Figure 2 is the architecture diagram of the communication system based on the Modbus protocol in the present invention;

[0026] Figure 3 is the data structure diagram of the communication data packet of the Modbus protocol;

[0027] Figure 4 is the data structure diagram of a first communication data packet sent from the master device to the slave device;

[0028] Figure 5 is the data structure diagram of a second communication data packet replied from the slave device to the master device;

[0029] Figure 6 is the schematic diagram of searching for the first communication data packet in the data storage area;

[0030] Figure 7 is the schematic diagram of continuing to search for the second communication data packet after the first communication data packet is found in the data storage area.

Specific Embodiments

[0031] Some embodiments of the present invention will be described more fully hereinafter with reference to the accompanying drawings, in which some, but not all embodiments of the invention are shown. In fact, the various embodiments of the present invention may be embodied in many different forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art. For example, unless otherwise specified, referring to something as first, second, etc. should not be construed as implying a particular order. Additionally, something may be described as above something (unless otherwise specified) while actually being below it, and vice versa; similarly, something described as on the left may be on the right, and vice versa. The same reference numeral always represents the same element.

[0032] The RS485 physical layer relies on the voltage difference between two signal lines, A and B, to transmit data. When a device sends a data signal, all the other devices on the bus can receive the signal. Due to the physical characteristics, only one device can send a signal at the same time. If an additional device is added to the RS485 bus and this device knows the current bus message format of the RS485, then by setting up a large buffer data storage area, the data sent and received by the original master device on the bus can be captured by the newly added master device. The newly added master device can obtain the data of the slave device it wants by parsing its own received data storage area. In summary, this solution can achieve adding additional stations in the original bus system to obtain the data of the other slave devices. Based on the above principle, the present invention provides a communication system that can add a second master device to monitor the bus to obtain the data in the slave devices with almost no change to the original hardware system, thus achieving the effect of multiple master devices.

[0033] Figure 2 It is the architecture diagram of the communication system based on the Modbus protocol in the present invention. As Figure 2 shown, the communication system includes a bus, a first master device M1 connected to the bus, one or more slave devices S1 - S5 connected to the bus, and a second master device M2 connected to the bus.

[0034] It should be noted that Figure 2 shows 5 slave devices, and actually there can be other numbers of slave devices, such as 1, 2, 6, 8, etc. In Figure 2 , the second master device M2 is connected to the bus by a dotted line, and this dotted line only indicates that it is not a real master device. It can only receive the data sent on the bus and cannot send data through the bus. In fact, the second master device M2 is also physically connected to the bus by a cable. In the present invention, the Modbus protocol is taken as an example for introduction. Obviously, the present invention can be extended to other protocols with similar functions.

[0035] The first master device M1 broadcasts and sends a first communication data packet (which can also be referred to as a first message) through the bus. The first communication data packet includes a slave device address, a function code, and address information. Each of the slave devices S1 - S5 receives the first communication data packet sent by the first master device M1 through the bus, and determines whether the slave device address in the received first communication data packet is the same as its own slave device address. If it is the same, the slave device is the target slave device. The target slave device replies with a second communication data packet (which can also be referred to as a second message) through the bus. The second communication data packet includes a slave device address, a function code, and data information.

[0036] Figure 3 It is the data structure diagram of the communication data packet for the Modbus protocol. Figure 4 It is the data structure diagram of a first communication data packet sent from the master device to the slave device. Figure 5 It is the data structure diagram of a second communication data packet replied from the slave device to the master device. Specifically, the address information in the first communication data packet includes the register start address and the register quantity. The data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data and the second communication data packet include a CRC check code, and the check range of the CRC check code is all the previous bytes in the data packet.

[0037] As Figure 3-4 shown, in the first communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the register start address occupies two bytes, the register quantity occupies two bytes, and the CRC check code occupies two bytes. In the second communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the number of bytes is 1 byte, the data of each register occupies two bytes, and the CRC check code occupies two bytes. In this embodiment, the function code is 0x03, which represents a query. That is, Figure 4 the first communication data packet in Figure 5 is the first communication data packet for query, and the first communication data packet in

[0038] is the second communication data packet for replying to the query instruction. Actually, the function code can also represent other functions. In this embodiment, the case where the function code represents a query is taken as an example for introduction.

[0039] The second master device M2 includes a data storage area and a data packet search and parsing module. The second master device M2 monitors the bus in real time, receives all the data sent through the bus, and stores the received data into the data storage area in sequence. That is to say, whether it is the first communication data packet sent by the first master device M1 or the second communication data packet replied by the slave device, both will be monitored and received by the second master device M2. The data storage area needs to have a certain capacity to store a relatively large amount of data. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

[0040] In one embodiment, the function codes and address information in the first communication data packets that the first master device can send are pre-stored in the second master device M2. For example, when the first master device sends a query for the data of 6 registers starting from register 40019, the content of the first communication data packet is fixed. Assume that the slave device address to be queried is 02, and the content of the first communication data packet is: 02 03 001200 06 65fe (hexadecimal), where 02 is the slave device address, 03 is the function code indicating query, 001200 represents the starting address 40019, and 65fe represents the CRC check code. It can be seen that for the query instruction, the function code, the starting address of the register, and the number of registers in the first communication data packet can be fixed in advance. The part that cannot be fixed is the CRC check code, and the CRC check code is determined by the slave device address, the function code, the starting address of the register, and the number of registers.

[0041] Specifically, such as Figure 6As shown, the data packet search and parsing module matches the function code and address information of the pre-stored first communication data packet as a set of data with a set of consecutive data in the search box in the data storage area. Since the function code and address information (including the register start address and the number of registers) of the first communication data packet total 5 bytes, the size of the search box in the data storage area is also 5 bytes. The data packet search and parsing module matches the 5 bytes of the pre-stored first communication data packet with the 5 bytes in the search box in the data storage area. If they are the same, it is considered a successful match; if not, it is considered a failed match. If the match fails, the search box in the data storage area is moved backward by one byte, and the function code and address information of the pre-stored first communication data packet are continued to be matched as a set of data with a set of consecutive data in the search box in the data storage area. If the match is successful, the previous segment of data (such as 1 byte) of the set of consecutive data that matches successfully in the data storage area is considered the slave device address, and the subsequent segment of data (such as 2 bytes) of the set of consecutive data that matches successfully in the data storage area is considered the CRC check code, so as to search for a candidate first communication data packet in the data storage area. Take Figure 6 as an example. If the function code and address information of the pre-stored first communication data packet are matched in the 6th - 10th bytes of the data storage area, then the 5th byte is considered the slave device address, and the 11th - 12th bytes are considered the CRC check code. If the match fails in the 6th - 10th bytes of the data storage area, the search box is continued to be moved backward by 1 byte, that is, the data in the search box is the 7th - 11th bytes, and the match is performed in the 7th - 11th bytes.

[0042] Perform a CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. How to perform the CRC check is a mature technology in the prior art and will not be repeated in this article.

[0043] As Figure 7 shown, after successfully searching for the first communication data packet in the data storage area, the subsequent segment of data after the first communication data packet in the data storage area is considered a candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

[0044] Specifically, as Figure 7As shown, when verifying the candidate second communication data packet, first determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet has been successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. It should be noted that the size of the candidate second communication data packet, that is, the last byte of the candidate second communication data packet, can be determined according to the number of bytes (number 3) in the candidate second communication data packet.

[0045] In this way, the first communication data packet of the first master device and the second communication data packet replied by the target slave device can be searched from the data in the data storage area. By the same method, each first communication data packet sent by the first master device and each second communication data packet replied by the target slave device can be searched.

[0046] After a period of time, according to the first-in, first-out principle, the data that has been matched in front of the search box in the data storage area can be cleared to make new storage space available.

[0047] In an embodiment, according to one aspect of the present invention, the present invention further provides a second master device M2 in a communication system. The second master device M2 is connected to the second master device M2 on the bus. The second master device M2 includes a data storage area and a data packet search and parsing module. The second master device M2 monitors the bus in real time, receives all the data sent through the bus, and stores the received data in the data storage area in sequence. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

[0048] The function codes and address information in the first communication data packet that the first master device can send are pre-stored in the second master device M2.

[0049] The data packet search and parsing module matches the function code and address information of the pre-stored first communication data packet as a set of data with a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and the function code and address information of the pre-stored first communication data packet are still used as a set of data to match with a set of consecutive data in the search box in the data storage area. If the match is successful, the previous set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the next set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area.

[0050] Perform CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet.

[0051] After successfully searching for the first communication data packet in the data storage area, it is considered that the next set of data after the first communication data packet in the data storage area is the candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

[0052] Specifically, when verifying the candidate second communication data packet, first judge whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If it is different, continue to match the data in the data storage area to search for the first communication data packet. If it is the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet is successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet.

[0053] In one embodiment, according to one aspect of the present invention, the present invention further provides a communication method based on the second master device M2, which includes: the second master device M2 monitors the bus in real time, receives all the data sent through the bus, and stores the received data into the data storage area in sequence; the data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device in the data in the data storage area.

[0054] Specifically, the data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area, including:

[0055] The data packet search and parsing module matches the function code and address information of the pre-stored first communication data packet as a set of data with a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the function code and address information of the pre-stored first communication data packet are used as a set of data to continue matching with a set of consecutive data in the search box in the data storage area. If the match is successful, the previous section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the next section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area;

[0056] Perform CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet;

[0057] After successfully searching for the first communication data packet in the data storage area, it is considered that the section of data after the first communication data packet in the data storage area is the candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

[0058] In one embodiment, the verification of the candidate second communication data packet includes:

[0059] First, determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet is successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet.

[0060] In summary, the advantages and features of the present invention are:

[0061] 1) Without substantially changing the original hardware system, a second master device can be added to monitor the bus to obtain data from slave devices, thus achieving the effect of multiple master devices.

[0062] 2) Set up a data storage area for receiving data. According to the content and characteristics of Modbus communication data packets, search for register addresses and CRC check data to extract data efficiently in a loop.

[0063] Combined with the description of the accompanying drawings and the specific embodiments of the present invention, the details of the present invention can be more clearly understood. However, the specific embodiments of the present invention described herein are only for the purpose of explaining the present invention and cannot be understood in any way as a limitation of the present invention. Under the teaching of the present invention, those skilled in the art can conceive any possible variations based on the present invention, and these should all be regarded as belonging to the scope of the present invention. It should be noted that when an element is referred to as being "disposed on" another element, it can be directly on the other element or there may also be an intermediate element. When an element is considered to be "connected" to another element, it can be directly connected to the other element or there may be an intermediate element at the same time.

[0064] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which this application belongs. The terms used in the specification of this application herein are only for the purpose of describing specific embodiments and are not intended to limit this application. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.

[0065] Many modifications and other embodiments of the present invention relate to those skilled in the art who have relevant industry knowledge and some original data. Therefore, it should be understood that the present invention is not limited to the specific embodiments disclosed, but also includes other embodiments modified within the scope of the appended claims. In addition, although the foregoing description and the related drawings describe the implementation of specific embodiments of elements and functions in combination, within the scope of the appended claims, different combinations of elements and functions achieved by substitution are also included. The appended claims also include combinations of elements and functions different from those clearly described above. Although specific terms are used herein, they are only for general descriptive purposes and are not used for limiting purposes.

Claims

1. A communication system, characterized in that, It includes: A bus; A first master device connected to the bus, which broadcasts and sends a first communication data packet through the bus, where the first communication data packet includes a slave device address, a function code, and address information; One or more slave devices connected to the bus. Each slave device receives the first communication data packet sent by the first master device through the bus and determines whether the slave device address in the received first communication data packet is the same as its own slave device address. If it is the same, the slave device is the target slave device, and the target slave device replies with a second communication data packet through the bus, where the second communication data packet includes a slave device address, a function code, and data information; And A second master device connected to the bus, which includes a data storage area and a data packet search and parsing module. The second master device monitors the bus in real time, receives all the data sent through the bus, and sequentially stores the received data in the data storage area. The data packet search and parsing module searches in the data in the data storage area to obtain the first communication data packet of the first master device and the second communication data packet replied by the target slave device.

2. The communication system according to claim 1, characterized in that, The address information in the first communication data packet includes the starting address of the register and the number of registers, and the data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data packet and the second communication data packet include a CRC check code, and the check range of the CRC check code is all the previous bytes in the data packet.

3. The communication system according to claim 2, wherein The function code and address information in the first communication data packet that the first master device can send are pre-stored in the second master device. The data packet search and parsing module matches the pre-stored function code and address information of the first communication data packet as a set of data with a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the pre-stored function code and address information of the first communication data packet are used as a set of data to continue matching with a set of consecutive data in the search box in the data storage area. If the match is successful, the previous segment of data of the set of consecutive data that matches successfully in the data storage area is considered the slave device address, and the subsequent segment of data of the set of consecutive data that matches successfully in the data storage area is considered the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area. Perform a CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. After successfully searching for the first communication data packet in the data storage area, a section of data after the first communication data packet in the data storage area is considered as a candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet has been successfully searched for in the data storage area. If the verification fails, the data in the data storage area continues to be matched to search for the first communication data packet.

4. The communication system according to claim 3, wherein When verifying the candidate second communication data packet, first determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet has been successfully searched for. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. Determine the size of the candidate second communication data packet according to the number of bytes in the candidate second communication data packet.

5. The communication system according to claim 2, wherein Communication between the first master device and the slave device is based on the Modbus protocol. In the communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the register start address occupies two bytes, the register quantity occupies two bytes, and the CRC check code occupies two bytes. The number of bytes in the second communication data packet is 1 byte. The function codes in the first communication data packet and the second communication data packet both represent queries.

6. The second master device in a communication system, the communication system comprising a bus, a first master device connected to the bus, and one or more slave devices connected to the bus, the first master device broadcasting and sending a first communication data packet through the bus, wherein the first communication data packet includes a slave device address, a function code, and address information, each slave device receives the first communication data packet sent by the first master device through the bus, and determines whether the slave device address in the received first communication data packet is the same as its own slave device address, if the same, the slave device is the target slave device, and the target slave device replies with a second communication data packet through the bus, wherein the second communication data packet includes a slave device address, a function code, and data information, characterized in that, The second master device is connected to the second master device on the bus. The second master device includes a data storage area and a data packet search and parsing module. The second master device monitors the bus in real time, receives all the data sent through the bus, and stores the received data into the data storage area in sequence. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device from the data in the data storage area.

7. The second master device according to claim 6, characterized in that, The address information in the first communication data packet includes the register start address and the register quantity. The data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data and the second communication data packet include a CRC check code. The check range of the CRC check code is all the previous bytes in the data packet. The function code and address information in the first communication data packet that the first master device can send are pre-stored in the second master device. The data packet search and parsing module matches the function code and address information of the pre-stored first communication data packet as a set of data with a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the function code and address information of the pre-stored first communication data packet are used as a set of data to continue matching with a set of consecutive data in the search box in the data storage area. If the match is successful, the previous set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the next set of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched in the data storage area. Perform CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet is successfully searched in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. After successfully searching for the first communication data packet in the data storage area, it is considered that the next set of data after the first communication data packet in the data storage area is the candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet is successfully searched in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

8. The second master device according to claim 7, wherein When verifying the candidate second communication data packet, first judge whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If it is different, continue to match the data in the data storage area to search for the first communication data packet. If it is the same, continue to perform CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet is successfully searched. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. Determine the size of the candidate second communication data packet according to the number of bytes in the candidate second communication data packet. Communication between the first master device and the slave device is based on the Modbus protocol. In the communication data packet, the slave device address occupies 1 byte, the function code occupies 1 byte, the register start address occupies two bytes, the register quantity occupies two bytes, and the CRC check code occupies two bytes. The number of bytes in the second communication data packet is 1 byte. The function codes in the first communication data packet and the second communication data packet both represent queries.

9. A communication method for a second master device according to any one of claims 6-8, characterized in that, It includes: The second master device monitors the bus in real time, receives all the data sent through the bus, and stores the received data into the data storage area in sequence. The data packet search and parsing module searches for the first communication data packet of the first master device and the second communication data packet replied by the target slave device in the data in the data storage area.

10. The communication method according to claim 9, characterized in that, The address information in the first communication data packet includes the starting address of the register and the number of registers. The data information in the second communication data packet includes the number of bytes and the data of each register. Both the first communication data and the second communication data packet include a CRC check code. The check range of the CRC check code is all the previous bytes in the data packet. The second master device pre-stores the function code and address information in the first communication data packet that the first master device can send. The steps for the data packet search and parsing module to search for the first communication data packet of the first master device and the second communication data packet replied by the target slave device in the data in the data storage area include: The data packet search and parsing module uses the pre-stored function code and address information of the first communication data packet as a set of data to match a set of consecutive data in the search box in the data storage area. If the match fails, the search box in the data storage area is moved backward by one byte, and then the pre-stored function code and address information of the first communication data packet are used as a set of data to match a set of consecutive data in the search box in the data storage area again. If the match is successful, the previous section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the slave device address, and the latter section of data of the set of consecutive data that matches successfully in the data storage area is regarded as the CRC check code. In this way, a candidate first communication data packet is searched for in the data storage area. Perform a CRC check on the candidate first communication data packet. If the CRC check passes, it is considered that the first communication data packet has been successfully searched for in the data storage area. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet. After successfully searching for the first communication data packet in the data storage area, it is considered that a section of data after the first communication data packet in the data storage area is a candidate second communication data packet, and the candidate second communication data packet is verified. If the verification passes, it is considered that the second communication data packet has been successfully searched for in the data storage area. If the verification fails, continue to match the data in the data storage area to search for the first communication data packet.

11. The communication method according to claim 10, wherein The verification of the candidate second communication data packet includes: First, determine whether the slave device address in the candidate second communication data packet is the same as the slave device address in the successfully searched first communication data packet. If they are different, continue to match the data in the data storage area to search for the first communication data packet. If they are the same, continue to perform a CRC check on the candidate second communication data packet. If the CRC check passes, it is considered that the second communication data packet has been successfully searched for. If the CRC check fails, continue to match the data in the data storage area to search for the first communication data packet.

Citation Information

Cited By

  • Serial port communication system and method

    CN121233522A