Data forwarding method and device, equipment and storage medium

By determining the forwarding priority in the data forwarding device according to the data type and sending data according to the priority on the serial transceiver interface, the problem of data being easily discarded in the prior art is solved, and communication efficiency and the utilization of the serial bus are improved. Rate.

CN119484429APending Publication Date: 2025-02-18BEIJING URBAN CONSTR INTELLIGENT CONTROL TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411332103.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

In the prior art, since the communication rate of the serial device is extremely low, the gateway becomes a "funnel" of data. When the data bandwidth received by the network interface is higher than the transmission bandwidth of the serial interface, the data is easily blocked and discarded.

Method used

By determining the forwarding priority according to the data type in the data forwarding device, the forwarding priority of the control command is higher than the query request, the data in the data forwarding queue is sent to the slave device according to the priority.

Benefits of technology

It effectively avoids data discarding, improves the utilization rate of the serial bus, and improves communication efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119484429A_ABST
    Figure CN119484429A_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of communications, and provides a data forwarding method, apparatus and device, and a storage medium, the method being applied to a data forwarding device, the data forwarding device comprising a network interface end and a serial transmit-receive interface end, the method comprising: using the network interface end to determine the data type of first data sent by a master device; the data type comprises a control command or a query request, and the forwarding priority of the control command is higher than that of the query request; submitting the first data to a data forwarding queue of a serial transceiving interface end by using a network interface end; and sending the first data in the data forwarding queue to the slave device according to the data type of the first data by using the serial transceiving interface end. According to the invention, data can be prevented from being discarded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a data forwarding method, device, equipment and storage medium. Background Art

[0002] The Modbus protocol is a communication method that allows data exchange between Programmable Logic Controllers (PLCs) and computers. Electronic devices can exchange information over serial lines using the Modbus protocol. The Modbus protocol has been widely accepted and widely used in Building Management Systems (BMS) and Industrial Automation Systems (IAS). It is easy to use, reliable, and it is open source and can be used for free in any device or application. Modbus is often used in situations where multiple instruments and control devices transmit signals to a central controller or system to collect and analyze data. Industrial automation and Supervisory Control And Data Acquisition (SCADA) systems often use the Modbus protocol.

[0003] With the development of network technology, especially the popularization of cloud computing and big data, the industry generally uses Ethernet, optical fiber and wireless networks to transmit data. However, in traditional fields such as rail transit and industrial monitoring, there are still a large number of devices using the Modbus protocol. Therefore, a device that forwards Modbus protocol data between serial devices and network interfaces is needed (hereinafter referred to as a "gateway", specifically referring to this type of gateway that forwards Modbus data between the network and serial interface devices).

[0004] The master device is generally a high-performance computing device such as an industrial computer or server, which obtains the status information of the slave device and issues control commands through the Ethernet + Modbus protocol. The slave device is an industrial device or sensor, which receives queries or control commands from the master, responds to these commands, and replies to them. Traditionally, slave devices generally use serial bus interfaces, while master devices generally use Ethernet interfaces, so a gateway is required to forward data between the two interfaces.

[0005] The most widely used technology is the implementation method of most "serial port servers" and "serial port communication gateways", that is, to implement a queue, and send the data received by the network interface of the gateway from the serial interface end, and the data received by the serial interface is sent by the network interface. If the data bandwidth received by the network interface is higher than the sending bandwidth of the serial interface, it is put into the queue for buffering. If the queue is full, the data that cannot be accommodated will be discarded. In other words, in the prior art, due to the extremely low communication rate of the serial device, the gateway becomes a "funnel" for data. If the amount of data sent through the network interface exceeds the transmission capacity of the serial device, the data cannot be forwarded to the serial device in time after arriving at the gateway, which is likely to cause data congestion, resulting in data being discarded. Summary of the invention

[0006] In view of the above-mentioned defects in the prior art, the present invention provides a data forwarding method, device, equipment and storage medium, which can prevent data from being discarded.

[0007] In a first aspect, the present invention provides a data forwarding method, which is applied to a data forwarding device, wherein the data forwarding device includes a network interface end and a serial transceiver interface end; the method includes: Determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The serial transceiver interface is used to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0008] According to a data forwarding method provided by the present invention, submitting the first data to a data forwarding queue of the serial transceiver interface end according to the data type of the first data includes: In a case where the first data is the control command, submitting the control command to the data forwarding queue; In the case where the first data is the query request, querying whether there is data to be queried in the cache of the data forwarding device according to the query request; the query request includes a slave device address, a function code, a query start address, a query quantity, and a cyclic redundancy check code corresponding to the data to be queried, the query start address is used to determine the address of the register to be queried, the slave device includes at least one register, and the register is used to store and transfer data; In the case where the data to be queried does not exist in the cache of the data forwarding device, submitting a query request that does not hit the cache to the data forwarding queue; When the data to be queried is in the cache of the data forwarding device, determining whether the data to be queried is within a validity period according to a cache timestamp corresponding to the data to be queried; In the case that the data to be queried is not within the validity period, the query request whose cache has expired is submitted to the data forwarding queue.

[0009] According to a data forwarding method provided by the present invention, the cache miss query request is used for the slave device to perform data query according to the cache miss query request, and the second data corresponding to the cache miss query request is returned to the data forwarding device; the second data corresponding to the cache miss query request includes the query result corresponding to the cache miss query request and the cache timestamp corresponding to the query result; the cache invalidated query request is used for the slave device to perform data query according to the cache invalidated query request, and the second data corresponding to the cache invalidated query request is returned to the data forwarding device; the second data corresponding to the cache invalidated query request includes the query result corresponding to the cache invalidated query request and the cache timestamp corresponding to the query result.

[0010] According to a data forwarding method provided by the present invention, the forwarding priority of the control command is higher than the forwarding priority of the query request for cache miss, and the forwarding priority of the query request for cache miss is higher than the query request for cache invalidation; the sending of the first data in the data forwarding queue to a slave device according to the data type of the first data includes: Determining whether there is a control command in the data forwarding queue; When the control command is present in the data forwarding queue, sending the control command to the slave device; In the case of determining that there is no control command in the data forwarding queue, determining whether there is a query request with the cache miss in the data forwarding queue; If there is a query request for the cache miss in the data forwarding queue, sending the query request for the cache miss in the data forwarding queue to the slave device; If there is a query request with a cache miss in the data forwarding queue, the query request with a cache failure in the data forwarding queue is sent to the slave device.

[0011] According to a data forwarding method provided by the present invention, the method further includes: In response to receiving the second data, when a preset number of bytes of the second data are received, the preset number of bytes of the second data are parsed, and whether the second data is a legal message is determined according to the parsing result and the message legality condition; wherein the message legality condition includes at least one of the following: the device identification and function code corresponding to the second data are the same as the device identification and function code in the query request; the cyclic redundancy check code corresponding to the second data is the same as the cyclic redundancy check code in the query request; and the length of the second data meets a preset threshold; When it is determined that the second data is a legal message, the second data is stored in the data forwarding device.

[0012] According to a data forwarding method provided by the present invention, the first data includes a plurality of adjacent query requests; and sending the first data in the data forwarding queue to a slave device according to the data type of the first data includes: Merging the multiple adjacent query requests to obtain a merged query request; The merged query request is sent to the slave device.

[0013] In a second aspect, the present invention further provides a data forwarding device, which is applied to a data forwarding device, wherein the data forwarding device comprises a network interface terminal and a serial transceiver interface terminal; the device comprises: A parsing module, configured to determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The forwarding module is used to use the serial transceiver interface to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0014] In a third aspect, the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data forwarding method described above is implemented.

[0015] In a fourth aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the data forwarding methods described above.

[0016] In a fifth aspect, the present invention further provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the data forwarding methods described above.

[0017] The present invention provides a data forwarding method, apparatus, device and storage medium. The method is applied to a data forwarding device, which includes a network interface end and a serial transceiver interface end. First, the network interface end is used to determine the data type of the first data sent by the master device, wherein the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; then, the network interface end is used to submit the first data to the data forwarding queue of the serial transceiver interface end; and then, the serial transceiver interface end is used to send the first data in the data forwarding queue to the slave device according to the data type of the first data.

[0018] In the present invention, after receiving the first data sent by the master device, the network interface end of the data forwarding device parses the first data to obtain the data type of the first data, and submits the first data to the data forwarding queue of the serial transceiver interface end, wherein, because different data types have different forwarding priorities, the forwarding priority of the control command is higher than the forwarding priority of the query request. The serial transceiver interface end is used to send the first data in the data forwarding queue to the slave device according to the priority of different types of data, thereby avoiding data being discarded. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 This is one of the flow charts of the data forwarding method provided by the present invention.

[0021] Figure 2 It is a structural schematic diagram of the data forwarding system provided by the present invention.

[0022] Figure 3 This is the second flow chart of the data forwarding method provided by the present invention.

[0023] Figure 4 This is the third flow chart of the data forwarding method provided by the present invention.

[0024] Figure 5 It is a structural schematic diagram of the data forwarding device provided by the present invention.

[0025] Figure 6It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments 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.

[0027] Combine the following Figure 1-Figure 6 The data forwarding method, device, equipment and storage medium of the present invention are described.

[0028] Figure 1 It is one of the flow charts of the data forwarding method provided by the present invention, which is applied to a data forwarding device, wherein the data forwarding device includes a network interface terminal and a serial transceiver interface terminal, such as Figure 1 As shown, the method includes the following: Step 101: using a network interface terminal, determining a data type of first data sent by a master device; the data type includes a control command or a query request, and a forwarding priority of a control command is higher than a forwarding priority of a query request; Specifically, the execution subject of this embodiment is an application data forwarding device, such as a gateway. The present invention is used to send the first data in the data forwarding queue to the slave device according to the priority of different types of data to avoid data being discarded.

[0029] Figure 2 is a structural diagram of the data forwarding system provided by the present invention, such as Figure 2 As shown, the system includes a master end (also known as a master device), a gateway (data forwarding device) and a slave end. The master end and the gateway communicate via Ethernet, and the gateway and the slave end communicate via a serial bus. The data forwarding device gateway has two interfaces. The port on the left side of the gateway in the figure that interacts with the master end is the network interface end, and the port on the right side of the gateway in the figure that interacts with the slave end is the serial transceiver interface end.

[0030] It should be noted that the master device, or the master end, is generally a high-performance computing device such as an industrial computer or server, which obtains the status information of industrial equipment and sensors and issues control commands through the Ethernet + Modbus protocol. The slave device, or the slave end, is usually an industrial device or sensor, which receives queries or control commands from the master device, responds to these commands, and replies to them. Traditionally, slave devices generally use serial bus interfaces, while master devices generally use Ethernet interfaces, so data forwarding devices such as gateways are required to forward data between the two interfaces.

[0031] In the data forwarding method of this embodiment, first, the data type of the first data sent by the master device is determined using the network interface of the data forwarding device. Specifically, after receiving the first data sent by the master device, the data forwarding device can parse the first data to determine the data type of the first data.

[0032] Among them, control commands and query requests are basic operations in the Modbus protocol, and the corresponding data types are control commands or query requests. Control commands are usually sent by the master device to the slave device to change the state of the slave device or perform specific operations. For example, the master device can send a command to read or write the register value of the slave device. The query request is initiated by the master device to obtain the status information or data of the slave device. After receiving the query request, the slave device returns a corresponding response message according to the content of the request. In addition, the function code in the Modbus protocol defines the operation type of the request and response. For example, function code 03 (hexadecimal 0x03) is used to read the value of the holding register, and function code 06 (hexadecimal 0x06) is used to write a value to a single holding register. In addition, the Modbus protocol also specifies some error codes, which are represented by adding 0x80 to the function code to indicate an abnormal state in the response. It should be noted that in the present invention, the forwarding priority of the control command is higher than the forwarding priority of the query request.

[0033] Step 102: using the network interface end, submitting the first data to the data forwarding queue of the serial transceiver interface end; Specifically, after determining the data type of the first data, the network interface end can be further utilized to submit the first data to the data forwarding queue of the serial transceiver interface end according to the data type of the first data. For example, different types of first data are first submitted to the queue of the serial transceiver interface end for queuing, and at the same time, the data forwarding priorities of various data types are agreed upon to facilitate the serial transceiver interface end to forward data in order of priority.

[0034] Step 103: Using the serial transceiver interface, send the first data in the data forwarding queue to the slave device according to the data type of the first data.

[0035] Specifically, it can be understood that the data type of the first data is different, and the forwarding priority of different types of data can be pre-defined. The data forwarding priority is used to characterize the probability that the data forwarding device will give priority to forwarding each type of data in the data forwarding queue at the same time. The higher the priority, the higher the probability that the data forwarding device will give priority to forwarding each type of data.

[0036] Furthermore, the first data in the data forwarding queue can be sent to the data forwarding queue of the serial transceiver interface of the slave device by combining the forwarding priorities of various data types, thereby improving the utilization of the serial bus, thereby improving communication efficiency and avoiding data loss.

[0037] The method provided in this embodiment is applied to a data forwarding device, which includes a network interface end and a serial transceiver interface end. First, the network interface end is used to determine the data type of the first data sent by the master device, wherein the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; then, the network interface end is used to submit the first data to the data forwarding queue of the serial transceiver interface end; and then, the serial transceiver interface end is used to send the first data in the data forwarding queue to the slave device according to the data type of the first data.

[0038] In the present invention, after receiving the first data sent by the master device, the network interface end of the data forwarding device parses the first data to obtain the data type of the first data, and submits the first data to the data forwarding queue of the serial transceiver interface end, wherein, because different data types have different forwarding priorities, the forwarding priority of the control command is higher than the forwarding priority of the query request. The serial transceiver interface end is used to send the first data in the data forwarding queue to the slave device according to the priority of different types of data, thereby avoiding data being discarded.

[0039] According to a data forwarding method provided by the present invention, submitting the first data to a data forwarding queue of a serial transceiver interface end according to the data type of the first data includes: In the case where the first data is a control command, submitting the control command to the data forwarding queue; In the case where the first data is a query request, query whether there is data to be queried in the cache of the data forwarding device according to the query request; the query request includes a slave device address, a function code, a query start address, a query quantity, and a cyclic redundancy check code corresponding to the data to be queried, the query start address is used to determine the address of the register to be queried, and the slave device includes at least one register, and the register is used to store and transfer data; When there is no data to be queried in the cache of the data forwarding device, submitting the query request that does not hit the cache to the data forwarding queue; When there is data to be queried in the cache of the data forwarding device, determining whether the data to be queried is within the validity period according to the cache timestamp corresponding to the data to be queried; When the data to be queried is not within the validity period, the query request whose cache has expired is submitted to the data forwarding queue.

[0040] Specifically, in some embodiments, because the data type includes a control command or a query request, different data types have different forwarding priorities, and the forwarding priority of the control command is higher than the forwarding priority of the query request. Based on this, step 102 of submitting the first data to the data forwarding queue of the serial transceiver interface end can be implemented in the following manner: In the case where the first data is a control command, the control command is submitted to the data forwarding queue for queuing. It is understandable that the data forwarding priority of the control command can be high. It is understandable that in addition to sending the query request, the master device also sends a control message and writes into certain registers. Such messages are not cached but forwarded immediately.

[0041] In the case where the first data is a query request, the query request is further parsed, wherein the query request may be a register query request, and the register is used to store data. In the Modbus protocol, a register query request is a communication transaction that allows the master device (client) to read the status or value of a specific register on the slave device (server). This request is mainly used for data acquisition and monitoring to ensure that the system can obtain real-time or latest data on the slave device. The register query request consists of the following parts:

[0042] The function code is used to indicate the type of query request. The following are several common register query requests and their functions: 1. Read coil status (function code 0x01): Read the status of the coil register. Each coil corresponds to a bit, and the status can be ON (1) or OFF (0).

[0043] 2. Read discrete input status (function code 0x02): Read the status of discrete input registers. These inputs usually come from sensors or other switching devices, and the status is also ON or OFF.

[0044] 3. Read holding registers (function code 0x03): Read the values ​​in the holding registers. These registers are readable and writable and are used to store data that needs to be maintained, such as set points, configuration parameters, etc.

[0045] 4. Read input registers (function code 0x04): Read the values ​​in the input registers, which are usually read-only and used to store the values ​​of analog input signals or other data that needs to be reported.

[0046] 5. Read multiple coil status (function code 0x0F, used only in Modbus Plus): Read the status of multiple coil registers, allowing the status of multiple coils to be read in one request.

[0047] 6. Read multiple holding registers (function code 0x0B, used only in Modbus Plus): Read the values ​​of multiple holding registers, allowing the values ​​of multiple holding registers to be read in one request.

[0048] Furthermore, based on the "device address", "function code", "query start address" and "query quantity" in the register query request, it is possible to further query whether there is a corresponding register value in the local cache of the gateway, that is, to query whether there is data to be queried in the cache of the data forwarding device according to the query request. The query request includes the slave device address, function code, query start address, query quantity, and cyclic redundancy check code corresponding to the data to be queried. The query start address is used to determine the address of the register to be queried. The slave device includes at least one register, and the register is used to store and transfer data.

[0049] If there is no data to be queried in the cache of the data forwarding device, the query request that does not hit the cache is submitted to the data forwarding queue.

[0050] When there is data to be queried in the cache of the data forwarding device, it is determined whether the data to be queried is within the validity period according to the cache timestamp corresponding to the data to be queried. That is, if there is data to be queried, it is further determined whether the cache timestamp of the data to be queried is within the validity period (the validity period is configurable).

[0051] If the timestamp is within the validity period, the register value can be directly returned to the master according to the Modbus protocol, and the timestamp of this access can be recorded. Specifically, if there is no corresponding register value in the local cache, the query content of the master is forwarded to the slave, and after the slave returns the query result, it is returned to the master, and the query result is cached, and the timestamp is recorded in the query result to facilitate the subsequent determination of whether the cached value is within the validity period.

[0052] When the data to be queried is not within the validity period, the query request with expired cache is submitted to the data forwarding queue. Specifically, if the cache timestamp of the data to be queried exceeds the validity period, it means that the communication between the gateway and the slave device fails, and an error is returned directly to the master.

[0053] Optionally, the data forwarding device gateway may periodically check the access timestamps of the cached query results. For caches that have not been accessed for a period of time (configurable), it may be considered that the master end no longer needs the data and delete the data from the cache to free up memory space.

[0054] For example, Figure 3 This is a second flow chart of the data forwarding method provided by the present invention, such as Figure 3 As shown, the method includes: Step 301: Receive data.

[0055] Receive data sent by the master device.

[0056] Step 302: determine whether the data is a control command; If the result of executing step 302 is yes, execute step 303; Step 303: submit the control command to the queue of the serial transceiver interface for queuing (priority: high); If the execution result of step 302 is no, execute step 304; Step 304: Check whether there is data to be queried in the cache; If the execution result of step 304 is no, execute step 305; Step 305: submit the data to the queue of the serial transceiver interface for queuing (priority: medium); If the result of step 304 is yes, execute step 306; Step 306: determine whether the data to be queried is within the validity period; If the execution result of step 306 is no, execute step 307; Step 307: submit the data to the queue of the serial transceiver interface for queuing (priority: medium); If the result of step 306 is yes, execute step 308; Step 308: Return the query result based on the cached data.

[0057] The method provided in this embodiment directly submits the control command to the data forwarding queue when the first data is a control command. When the first data is a query request, it is queried whether there is data to be queried in the cache of the data forwarding device according to the query request. When there is no data to be queried in the cache of the data forwarding device, the query request with cache miss is submitted to the data forwarding queue. When there is data to be queried in the cache of the data forwarding device, it is determined whether the data to be queried is within the validity period according to the cache timestamp corresponding to the data to be queried. When the data to be queried is not within the validity period, the query request with cache invalidation is submitted to the data forwarding queue, so that the query result is returned after the query request is received from the device later, so that the data forwarding device caches the query result locally. The data forwarding device avoids repeated transmission of the same data on the serial bus by caching the query results within a certain time range, and avoids the problem of inconsistency between the cache status and the actual status through the regular refresh and invalidation mechanism of the cache, thereby improving the utilization rate of the bus, improving communication efficiency, and avoiding data loss.

[0058] According to a data forwarding method provided by the present invention, a cache miss query request is used for a slave device to perform a data query according to the cache miss query request, and the second data corresponding to the cache miss query request is returned to the data forwarding device; the second data corresponding to the cache miss query request includes the query result corresponding to the cache miss query request and the cache timestamp corresponding to the query result; the cache invalidated query request is used for a slave device to perform a data query according to the cache invalidated query request, and the second data corresponding to the cache invalidated query request is returned to the data forwarding device; the second data corresponding to the cache invalidated query request includes the query result corresponding to the cache invalidated query request and the cache timestamp corresponding to the query result.

[0059] Specifically, in some embodiments, after the query request of cache miss is sent to the slave device, the slave device performs data query in the register according to the query request of cache miss, and returns the second data (i.e., query result) corresponding to the query request of cache miss to the data forwarding device, so that the data forwarding device stores the second data (i.e., query result) corresponding to the query request of cache miss in the cache, which is convenient for the master device to query, and the second data corresponding to the query request of cache miss includes the query result corresponding to the query request of cache miss and the cache timestamp corresponding to the query result. It can be understood that because the data forwarding device returns the query result directly from the cache, it can cope with multiple master terminals querying at the same time, and the number of master terminals supporting simultaneous query is only subject to the processing capacity of the data forwarding device gateway.

[0060] Correspondingly, the cache-expired query request is used for the slave device to perform data query according to the cache-expired query request, and return the second data corresponding to the cache-expired query request to the data forwarding device; the second data corresponding to the cache-expired query request includes the query result corresponding to the cache-expired query request and the cache timestamp corresponding to the query result.

[0061] The method provided in this embodiment can cope with simultaneous queries from multiple masters because the data forwarding device directly returns the query results from the cache. The number of masters supporting simultaneous queries is only limited by the processing capacity of the data forwarding device gateway, and the communication efficiency is also greatly improved.

[0062] According to a data forwarding method provided by the present invention, the forwarding priority of the control command is higher than the forwarding priority of the query request of the cache miss, and the forwarding priority of the query request of the cache miss is higher than the query request of the cache invalidated; sending the first data in the data forwarding queue to the slave device according to the data type of the first data, comprising: Determine whether there is a control command in the data forwarding queue; When there is a control command in the data forwarding queue, the control command is sent to the slave device; When it is determined that there is no control command in the data forwarding queue, determining whether there is a query request with cache miss in the data forwarding queue; If there is a query request with a cache miss in the data forwarding queue, the query request with a cache miss in the data forwarding queue is sent to the slave device; If there is a query request with a cache miss in the data forwarding queue, the query request with a cache failure in the data forwarding queue is sent to the slave device.

[0063] Specifically, in some embodiments, the forwarding priority of each data type is ranked as follows: The forwarding priority of the control command is higher than the forwarding priority of the query request of the cache miss, and the forwarding priority of the query request of the cache miss is higher than the query request of the cache expired.

[0064] Correspondingly, in step 103, the first data in the data forwarding queue is sent to the slave device according to the data type of the first data, and the data type with a high priority is preferentially forwarded. The process can be implemented by the following steps, including: First, it is determined whether there is a control command in the data forwarding queue. The determination result includes: there is a control command or there is no control command. Different steps are performed according to different determination results, as follows: When there is a control command in the data forwarding queue, the control command is directly sent to the slave device.

[0065] On the contrary, when it is determined that there is no control command in the data forwarding queue, it is further determined whether there is a cache miss query request in the data forwarding queue. If there is a cache miss query request, the cache miss query request in the data forwarding queue is sent to the slave device; if there is no cache miss query request in the data forwarding queue, the cache invalid query request in the data forwarding queue is sent to the slave device. By analogy, the data in the data forwarding queue can be sent to the slave device according to the forwarding priority, so as to maximize the utilization of the serial bus, improve communication efficiency, and avoid data being discarded.

[0066] For example, Figure 4 FIG. 3 is a flow chart of the data forwarding method provided by the present invention, which shows the forwarding process of the serial bus transmitting end for the data in the data forwarding queue, such as Figure 4 As shown, the method includes: Step 401, determine whether there is a control message in the queue; If the execution result of step 401 is yes, then execute step 402; Step 402: Send the control message; If the execution result of step 401 is no, then execute step 403; Step 403: determine whether there is a query message in the queue that does not hit the cache; If the result of step 403 is yes, then step 404 is executed; Step 404: Send out the query message that does not hit the cache; If the execution result of step 403 is no, then execute step 405; Step 405: Find the query message that will be invalidated earliest

[0067] Step 406: Send out the earliest invalid query message.

[0068] The method provided in this embodiment is that the serial transceiver interface end can prioritize the data in the queue for the data to be sent, the forwarding priority of the control command is higher than the forwarding priority of the query request of the cache miss, the forwarding priority of the query request of the cache miss is higher than the query request of the cache expired, and the data in the data forwarding queue is forwarded according to the data forwarding priority, that is, the control message is transmitted first, followed by the query message of the cache miss, and then the query message of the cache periodically refreshed, and the query message that expires first is refreshed first, so that the tight bandwidth of the serial bus can be used to transmit the most important and urgent messages in an orderly manner, which can improve the utilization rate of the serial bus and improve the communication efficiency.

[0069] According to a data forwarding method provided by the present invention, the method further includes: In response to receiving the second data, when a preset number of bytes of the second data are received, the preset number of bytes of the second data are parsed, and whether the second data is a legal message is determined according to the parsing result and the message legality condition; wherein the message legality condition includes at least one of the following: the device identification and function code corresponding to the second data are the same as the device identification and function code in the query request; the cyclic redundancy check code corresponding to the second data is the same as the cyclic redundancy check code in the query request; and the length of the second data meets a preset threshold; When it is determined that the second data is a legitimate message, the second data is stored in the data forwarding device.

[0070] Specifically, in some embodiments, the method further includes processing the received data in a timely manner after determining that the received data is complete, so as to avoid unnecessary waiting time: It is understandable that the serial interface uses a data stream mode, and there is no clear boundary between two messages, which is separated by idle time. Therefore, in the traditional receiving method, if no new data is received for a period of time, it is considered that a message has been transmitted. Therefore, it is always necessary to wait for a period of idle time. During this period, data cannot be transmitted, which easily leads to a waste of bandwidth.

[0071] When receiving data, the data forwarding device (such as a gateway) of this embodiment responds to receiving the second data. When a preset number of bytes of the second data are received, the serial transceiver interface end can parse the preset number of bytes of the second data, and determine whether the second data is a legal message based on the parsing result and the message legality condition. For example, each time one or more bytes are received, the received second data is parsed. When it conforms to a legal Modbus message, it is processed. The advantage of doing so is that there is no need to wait for the bus timeout. The next query or control message can be sent immediately after an interval of 3.5 characters as specified in the Modbus RTU protocol.

[0072] Among them, the message legality condition includes at least one of the following: the device identification and function code corresponding to the second data are the same as the device identification and function code in the query request; the cyclic redundancy check code CRC corresponding to the second data is the same as the cyclic redundancy check code CRC in the query request; and the length of the second data meets the preset threshold. It should be noted that the message legality condition is used to determine whether the second data is a legal message, and the message legality condition can also be determined according to actual needs, and is not limited to the above message legality condition.

[0073] Further, when it is determined that the second data is a legitimate message, the second data can be stored in the data forwarding device. Specifically, when it is determined that the second data is a legitimate message, the second data can be processed, for example, the second data (such as cache results) can be stored according to preset fields, and stored in the cache of the data forwarding device (such as a gateway), so as to facilitate subsequent rapid query by the main device and improve data query efficiency.

[0074] The method provided in this embodiment does not perform any additional waiting except for the interval specified by the protocol, and can fully utilize the transmission time of the serial bus, thereby improving the utilization rate of the serial bus and further improving the efficiency of data query.

[0075] According to a data forwarding method provided by the present invention, first data includes a plurality of adjacent query requests; and sending the first data in a data forwarding queue to a slave device according to the data type of the first data includes: Merging multiple adjacent query requests to obtain a merged query request; Send the merged query request to the slave device.

[0076] Specifically, in some embodiments, the first data includes multiple adjacent query requests, wherein adjacent query requests can be understood as query start addresses (registers) corresponding to each query request being adjacent, that is, each query request is a query for adjacent registers. When the first data includes multiple adjacent query requests, the serial bus interface can merge the multiple adjacent query requests when sending the query request to the slave device, and send them to the slave device at one time, thereby improving the utilization efficiency of the serial bus.

[0077] Exemplarily, the specific implementation process of merging query requests for adjacent registers is as follows: First, multiple adjacent query requests are merged to obtain a merged query request. It should be noted that the number of registers that can be queried in the merged query request is multiple, and the maximum number is no more than 127. It is understandable that when the Modbus protocol queries registers, 1 to 127 registers can be queried at a time. Taking the most commonly used Modbus RTU protocol as an example, if one register is queried, the query message sent is 8 bytes long, and the query result message returned is 7 bytes long, of which only 2 bytes are valid data, and the rest are auxiliary communication content. Ignoring the delay between sending and receiving, the transmission efficiency is 13%; if 127 registers are queried, the query message sent is still 8 bytes long, and the query result message returned is 259 bytes long, 254 bytes are valid data, and the transmission efficiency is 95.1%. It can be seen that the more registers are queried at one time, the higher the communication efficiency. Therefore, splicing adjacent registers (that is, splicing adjacent query requests) can improve communication efficiency.

[0078] Then, the combined query request is sent to the slave device using the serial bus of the data forwarding device, thereby improving the utilization efficiency of the serial bus.

[0079] The method provided in this embodiment combines multiple adjacent query requests and sends the combined query requests to the slave device, which can improve the utilization rate of the serial bus and thus improve the communication efficiency.

[0080] The data forwarding device provided by the present invention is described below. The data forwarding device described below and the data forwarding method described above can be referenced to each other.

[0081] Figure 5 : is a structural diagram of a data forwarding device provided by the present invention. The data forwarding device 500 is applied to a data forwarding device, and the data forwarding device includes a network interface end and a serial transceiver interface end; the data forwarding device 500 includes: The parsing module 510 is used to determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The forwarding module 520 is used to use the serial transceiver interface to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0082] The device provided in this embodiment is applied to a data forwarding device, which includes a network interface end and a serial transceiver interface end. First, the parsing module 510 uses the network interface end to determine the data type of the first data sent by the master device, wherein the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; then, the network interface end is used to submit the first data to the data forwarding queue of the serial transceiver interface end; and then, the forwarding module 520 uses the serial transceiver interface end to send the first data in the data forwarding queue to the slave device according to the data type of the first data.

[0083] In the present invention, after receiving the first data sent by the master device, the network interface end of the data forwarding device parses the first data to obtain the data type of the first data, and submits the first data to the data forwarding queue of the serial transceiver interface end, wherein, because different data types have different forwarding priorities, the forwarding priority of the control command is higher than the forwarding priority of the query request. The serial transceiver interface end is used to send the first data in the data forwarding queue to the slave device according to the priority of different types of data, thereby avoiding data being discarded.

[0084] According to a data forwarding device 500 provided by the present invention, the parsing module 510 is specifically used for: In a case where the first data is the control command, submitting the control command to the data forwarding queue; In the case where the first data is the query request, querying whether there is data to be queried in the cache of the data forwarding device according to the query request; the query request includes a slave device address, a function code, a query start address, a query quantity, and a cyclic redundancy check code corresponding to the data to be queried, the query start address is used to determine the address of the register to be queried, the slave device includes at least one register, and the register is used to store and transfer data; In the case where the data to be queried does not exist in the cache of the data forwarding device, submitting a query request that does not hit the cache to the data forwarding queue; When the data to be queried is in the cache of the data forwarding device, determining whether the data to be queried is within a validity period according to a cache timestamp corresponding to the data to be queried; In the case that the data to be queried is not within the validity period, the query request whose cache has expired is submitted to the data forwarding queue.

[0085] According to a data forwarding device 500 provided by the present invention, the cache miss query request is used for the slave device to perform data query according to the cache miss query request, and the second data corresponding to the cache miss query request is returned to the data forwarding device; the second data corresponding to the cache miss query request includes the query result corresponding to the cache miss query request and the cache timestamp corresponding to the query result; the cache invalidated query request is used for the slave device to perform data query according to the cache invalidated query request, and the second data corresponding to the cache invalidated query request is returned to the data forwarding device; the second data corresponding to the cache invalidated query request includes the query result corresponding to the cache invalidated query request and the cache timestamp corresponding to the query result.

[0086] According to a data forwarding device 500 provided by the present invention, the forwarding priority of the control command is higher than the forwarding priority of the query request of the cache miss, and the forwarding priority of the query request of the cache miss is higher than the query request of the cache expired; the forwarding module 520 is specifically used to: Determining whether there is a control command in the data forwarding queue; When the control command is present in the data forwarding queue, sending the control command to the slave device; In the case of determining that there is no control command in the data forwarding queue, determining whether there is a query request with the cache miss in the data forwarding queue; If there is a query request for the cache miss in the data forwarding queue, sending the query request for the cache miss in the data forwarding queue to the slave device; If there is a query request with a cache miss in the data forwarding queue, the query request with a cache failure in the data forwarding queue is sent to the slave device.

[0087] According to a data forwarding device 500 provided by the present invention, the device further includes a cache module; The cache module is used to: In response to receiving the second data, when a preset number of bytes of the second data are received, the preset number of bytes of the second data are parsed, and whether the second data is a legal message is determined according to the parsing result and the message legality condition; wherein the message legality condition includes at least one of the following: the device identification and function code corresponding to the second data are the same as the device identification and function code in the query request; the cyclic redundancy check code corresponding to the second data is the same as the cyclic redundancy check code in the query request; and the length of the second data meets a preset threshold; When it is determined that the second data is a legal message, the second data is stored in the data forwarding device.

[0088] According to a data forwarding device 500 provided by the present invention, the first data includes a plurality of adjacent query requests; The forwarding module 520 is specifically used for: Merging the multiple adjacent query requests to obtain a merged query request; The merged query request is sent to the slave device.

[0089] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the data forwarding method, which is applied to a data forwarding device, wherein the data forwarding device includes a network interface terminal and a serial transceiver interface terminal; the method includes: Determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The serial transceiver interface is used to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0090] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0091] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the data forwarding method provided by the above methods, the method is applied to a data forwarding device, the data forwarding device includes a network interface end and a serial transceiver interface end; the method includes: Determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The serial transceiver interface is used to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0092] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the data forwarding method provided by the above methods, the method being applied to a data forwarding device, the data forwarding device comprising a network interface terminal and a serial transceiver interface terminal; the method comprising: Determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The serial transceiver interface is used to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

[0093] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0094] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0095] 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 deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data forwarding method, characterized in that: Applied to a data forwarding device, the data forwarding device includes a network interface end and a serial transceiver interface end; the method includes: Determine the data type of the first data sent by the master device by using the network interface; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface; The serial transceiver interface is used to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

2. The data forwarding method according to claim 1, characterized in that: Submitting the first data to the data forwarding queue of the serial transceiver interface end includes: In a case where the first data is the control command, submitting the control command to the data forwarding queue; In the case where the first data is the query request, querying whether there is data to be queried in the cache of the data forwarding device according to the query request; the query request includes a slave device address, a function code, a query start address, a query quantity, and a cyclic redundancy check code corresponding to the data to be queried, the query start address is used to determine the address of the register to be queried, the slave device includes at least one register, and the register is used to store and transfer data; In the case where the data to be queried does not exist in the cache of the data forwarding device, submitting a query request that does not hit the cache to the data forwarding queue; When the data to be queried is in the cache of the data forwarding device, determining whether the data to be queried is within a validity period according to a cache timestamp corresponding to the data to be queried; In the case that the data to be queried is not within the validity period, the query request whose cache has expired is submitted to the data forwarding queue.

3. The data forwarding method according to claim 2, characterized in that: The cache miss query request is used for the slave device to perform data query according to the cache miss query request, and return the second data corresponding to the cache miss query request to the data forwarding device; the second data corresponding to the cache miss query request includes the query result corresponding to the cache miss query request and the cache timestamp corresponding to the query result; the cache invalidated query request is used for the slave device to perform data query according to the cache invalidated query request, and return the second data corresponding to the cache invalidated query request to the data forwarding device; The second data corresponding to the query request whose cache has expired includes the query result corresponding to the query request whose cache has expired and the cache timestamp corresponding to the query result.

4. The data forwarding method according to claim 3, characterized in that: The forwarding priority of the control command is higher than the forwarding priority of the query request for the cache miss, and the forwarding priority of the query request for the cache miss is higher than the query request for the cache expired; The sending the first data in the data forwarding queue to a slave device according to the data type of the first data includes: Determining whether there is a control command in the data forwarding queue; When the control command is present in the data forwarding queue, sending the control command to the slave device; In the case of determining that there is no control command in the data forwarding queue, determining whether there is a query request with the cache miss in the data forwarding queue; If there is a query request for the cache miss in the data forwarding queue, sending the query request for the cache miss in the data forwarding queue to the slave device; If there is a query request with a cache miss in the data forwarding queue, the query request with a cache failure in the data forwarding queue is sent to the slave device.

5. The data forwarding method according to claim 3, characterized in that: The method further comprises: In response to receiving the second data, when a preset number of bytes of the second data are received, the preset number of bytes of the second data are parsed, and whether the second data is a legal message is determined according to the parsing result and the message legality condition; wherein the message legality condition includes at least one of the following: the device identification and function code corresponding to the second data are the same as the device identification and function code in the query request; the cyclic redundancy check code corresponding to the second data is the same as the cyclic redundancy check code in the query request; and the length of the second data meets a preset threshold; When it is determined that the second data is a legal message, the second data is stored in the data forwarding device.

6. The data forwarding method according to any one of claims 1 to 5, characterized in that: The first data includes a plurality of adjacent query requests; The sending the first data in the data forwarding queue to a slave device according to the data type of the first data includes: Merging the multiple adjacent query requests to obtain a merged query request; The merged query request is sent to the slave device.

7. A data forwarding device, characterized in that: Applied to data forwarding equipment, the data forwarding equipment includes a network interface end and a serial transceiver interface end; the device includes: A parsing module, configured to determine the data type of the first data sent by the master device by using the network interface end; the data type includes a control command or a query request, and the forwarding priority of the control command is higher than the forwarding priority of the query request; Using the network interface, submitting the first data to a data forwarding queue of the serial transceiver interface according to a data type of the first data; The forwarding module is used to use the serial transceiver interface to send the first data in the data forwarding queue to a slave device according to the data type of the first data.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the data forwarding method according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data forwarding method according to any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the data forwarding method according to any one of claims 1 to 6 is implemented.

Citation Information

Cited By

  • Data control system and measurement and control system

    CN121072797A

  • Data control system and measurement and control system

    CN121072797B