Method for processing multi-master data access of Modbus gateway
By merging data request messages from the Modbus master station within the Modbus gateway and dynamically adjusting their priorities, the latency issue of the Modbus gateway under multi-host access was resolved, achieving more efficient data processing and response.
Patent Information
- Application Number
- CN202211607197.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-14
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2042-12-14
AI Technical Summary
In industrial settings, Modbus gateways experience delays and unresponsiveness when dealing with multi-host data access due to the lower serial communication rate compared to the network communication rate. Existing technologies lack comprehensive consideration of request list latency, which may lead to tasks with excessively long waiting times being ignored.
By constructing subset rules within the Modbus gateway to merge data request messages from the Modbus master station, the priority of waiting data access is dynamically adjusted, response time is estimated, and the priority list is updated in real time to ensure that all valid requests are sent within the specified time.
It effectively reduces the overall data request message processing latency, improves the response rate, reduces the probability of no response, and returns the correct data response within a limited number of retries.
Smart Images

Figure CN116016017B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of communication equipment, in particular to a method for processing multi-host data access by Modbus gateway. BACKGROUND
[0002] Modbus is a kind of serial communication protocol, which has become one of the industry standards in the field of industrial communication, and is a commonly used connection method between industrial electronic devices. Modbus gateway is a network hub communication protocol conversion device, which is widely used in the industrial field. Its function is to convert the request of TCP master station to RTU / ASCII slave station. The TCP master station communicates with the Modbus gateway through the network, and the Modbus gateway communicates with the RTU / ASCII slave station through the serial port. In the industrial field, there are multiple hosts accessing the slave machine on a serial communication bus. If multiple hosts send out request commands at the same time and the Modbus gateway does not store the response data of these commands, due to the question and answer property of Modbus protocol, the Modbus gateway needs to forward the commands to the slave station through the serial port and wait for the response of the slave station before issuing the next command. Since the serial communication rate is much lower than the network communication rate, the Modbus gateway needs to efficiently and flexibly forward the request commands of the TCP master station to the RTU / ASCII slave station. However, when the request commands are too many, processing the commands one by one according to the connection order of the master station may cause large delay or no response.
[0003] Chinese patent application with publication number CN103792928A provides an industrial field data acquisition and analysis system, which combines the Modbus data requests of the same device and the same data type address in sequence to reduce the queue length, processes according to the queue order, receives the response of the Modbus device or network, and then analyzes the Modbus response. However, this scheme lacks comprehensive consideration of the delay of the request list, and tasks with too long waiting time may be ignored or not responded for a long time. Therefore, it is necessary to provide a Modbus gateway processing multi-host data access method that can consider the queue length and the waiting time of each task. SUMMARY
[0004] Therefore, the present application provides a Modbus gateway processing multi-host data access method that can consider the waiting time of Modbus commands and dynamically adjust the priority of waiting data access.
[0005] The technical solution of the present application is as follows: the present application provides a Modbus gateway processing multi-host data access method, which includes the following steps:
[0006] S1: connecting several Modbus master stations on the network port side of the Modbus gateway; connecting several Modbus slave stations on the serial port side of the Modbus gateway;
[0007] S2: pre-building the device numbers of the several Modbus master stations and the device numbers of the several Modbus slave stations in the Modbus gateway; the Modbus gateway, in a period of time, counting the first data request messages from one or more Modbus master stations; the Modbus gateway built-in subset rules, merging the first data request messages that can be merged to obtain a list of second data request messages, and recording the waiting forwarding time T1 of each second data request message; the Modbus gateway estimates the time and of the second data request message sent and responded via the serial port side, and records it as T2; sending each second data request message to the corresponding Modbus slave station through the serial port side of the Modbus gateway according to the priority;
[0008] S3: after the Modbus slave station receives the corresponding second data request message, it responds to generate several second data response messages; the Modbus slave station sends the second data response message to the Modbus gateway through the serial port side; the Modbus gateway updates the priority of the second data request message to be sent in the list in real time;
[0009] S4: the Modbus gateway puts the received second data response message into the cache, extracts the content of the second data response message, and further generates several first data response messages corresponding to the first data request message according to the merging order of the first data request message; and returns each first data response message to each Modbus master station.
[0010] On the basis of the above technical scheme, preferably, the first data request message in step S2 comprises sequentially arranged start field, device number of the Modbus master station, device number of the Modbus slave station requested to read, start address and register address offset of the register address of the accessed Modbus slave station, and end field.
[0011] The second data request message comprises sequentially arranged start field, device number of at least one Modbus master station, device number of the Modbus slave station requested to read, start address and register address offset of the register address of the accessed Modbus slave station corresponding to at least one first data request message in the second data request message, and end field.
[0012] Preferably, the Modbus gateway in step S2 builds in subset rules to merge the first data request messages that can be merged to obtain the list of second data request messages. The different data requests from the same or different Modbus master stations are merged according to the device number of the slave station. The different data requests that can be merged have the following requirements: 1) the device numbers of the accessed Modbus slave stations are the same; 2) the ranges of the register addresses of the Modbus slave stations corresponding to at least one first data request message are all within the range of the register addresses of the Modbus slave station corresponding to another first data request message; 3) the operation types within the range of the register addresses of the Modbus slave station are the same, such as read operation or write operation; and 4) the time when the Modbus slave station is required to respond is within the same response cycle.
[0013] Further preferably, the step S2 records the waiting forwarding time T1 of the second data request message respectively, which is calculated from the time when the Modbus gateway receives the second data request message.
[0014] The estimated time and T2 of the second data request message sent and responded via the serial port side is the sum A1 of the transmission time of the second data request message sent by the Modbus gateway to the corresponding Modbus slave station via the serial port side and the transmission time of the second data response message expected to be returned by the Modbus slave station, and the necessary processing time delay A2. The transmission time sum A1 is proportional to the byte length of the second data request message and the second data response message. The processing time delay A2 is proportional to the machine cycle of the Modbus slave station. The time and T2 of the serial port side return and response is A1+A2.
[0015] Preferably, the transmission time sum A1 in the estimated time and T2 of the second data request message sent and responded via the serial port side is A1 = [the number of bits of a single byte * (the byte length of the second data request message + the byte length of the response of the Modbus slave station)] / the baud rate of the serial port, unit: second.
[0016] Preferably, the Modbus gateway in step S3 updates the priority of the second data request message to be sent in the list in real time, which satisfies the following rules at the same time:
[0017] 1) If the second data request message is merged from at least two different first data request messages, the priority thereof is always higher than that of the second data request message composed of a single first data request message in the list. The waiting forwarding time T1 of each first data request message is not calculated separately, but only the waiting forwarding time T1 of the merged second data request message is calculated.
[0018] 2) The priority of the second data request message with more first data request messages is always higher than the priority of the second data request message with less first data request messages; if the number of first data request messages of different second data request messages is the same, the priority of the second data request message is higher if the waiting time T1 is longer;
[0019] 3) The priority P of the second data request message composed of a single first data request message is T1 / T2; the higher the value of the priority P, the higher the priority in the list; if the value of the priority P of the second data request message composed of different single first data request messages is the same, the priority is higher if the waiting time T1 is longer.
[0020] Further preferably, for the second data request message with a priority P value lower than the median of the priorities in the current list, if the Modbus gateway still fails to send the second data request message to the Modbus slave station within the specified time threshold T3, the Modbus gateway actively returns an error code to the Modbus master station to prompt the Modbus master station that the current sending of the second data request message is delayed, sets the priority of the corresponding second data request message to the lowest, and extends the survival time of the second data request message by T1, until the second data request message is executed again in sequence and the corresponding second data response message is returned.
[0021] Further preferably, if the Modbus gateway sends the second data request message to the Modbus slave station, the Modbus slave station is busy or unresponsive, resulting in the Modbus gateway failing to receive the second data response message returned by the Modbus slave station within the time threshold T3, the Modbus gateway further configures a retry number B1 and a retry cumulative time T4; and the priority of the current second data request message is moved one position forward in the list, the survival time of the second data request message is extended by T1, and the retry number B1 is reduced by 1, until the Modbus gateway successfully receives the second data response message returned by the Modbus slave station within the time threshold T3, or the retry number reaches zero to terminate the execution of the second data request message, and returns an error code to one or more Modbus master stations corresponding to the second data request message.
[0022] Further preferably, the Modbus gateway of step S4 caches the received second data response message, extracts the content of the second data response message, and further generates a plurality of first data response messages corresponding to the first data request message according to the merging order of the first data request message; and returns each first data response message to each Modbus master station, which extracts and sorts the content of the register address of the corresponding Modbus slave station in the second data response message according to the starting address of the register address and the register address offset of the Modbus slave station corresponding to at least one first data request message merged in the second data request message, to respond to the data read request of each first data request message.
[0023] The application provides a Modbus gateway processing multiple host data access method, which has the following beneficial effects compared with the prior art:
[0024] (1) The application merges the first data request message from the same Modbus master station or different Modbus master stations based on the built-in subset rule through the Modbus gateway, forms a list based on the second data request message, adjusts the processing priority of the second data request message in the list in real time through the waiting time of the second data request message and the return time of the estimated data response message, and reduces the processing delay and the probability of non-response of the overall first data request message;
[0025] (2) The application comprehensively considers the constraint conditions, limits the merging conditions and the state after merging of the first data request message, and adjusts the priority order, so as to send all valid first data request messages within the specified time threshold T3 and return valid data response messages or error codes within a limited number of retries. BRIEF DESCRIPTION OF DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description only constitute some embodiments of the application, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0027] Figure 1 The flowchart of the application is a Modbus gateway processing multiple host data access method.
[0028] Figure 2 The application is a Modbus gateway processing multiple host data access method.
[0029] Figure 3 This is a schematic diagram illustrating how a first data request message of a Modbus gateway for processing multi-host data access is merged into a second data request message according to built-in subset rules, as per the present invention.
[0030] Figure 4 This is a schematic diagram illustrating a scenario where different first data request messages can be merged in a Modbus gateway method for handling multi-host data access according to the present invention.
[0031] Figure 5 This is a schematic diagram illustrating a scenario where different first data request messages cannot be merged in a Modbus gateway method for handling multi-host data access according to the present invention. Detailed Implementation
[0032] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0033] The technical solution of this invention is implemented as follows: Figure 1 As shown in Figure 5, this invention provides a method for a Modbus gateway to handle multi-host data access, comprising the following steps:
[0034] S1: Connect several Modbus masters in parallel on the network port side of the Modbus gateway; connect several Modbus slaves in parallel on the serial port side of the Modbus gateway; the transmission rate on the network port side is much higher than the transmission rate on the serial port side.
[0035] S2: Several Modbus master device numbers and several Modbus slave device numbers have been pre-built within the Modbus gateway; the Modbus gateway counts the first data request messages from one or more Modbus masters over a period of time; the Modbus gateway has built-in subset rules to merge the first data request messages that can be merged to obtain a list of second data request messages, and records the waiting time T1 for each second data request message; the Modbus gateway estimates the sum of the time for the second data request message to be sent and responded to via the serial port side, records it as T2, and sends each second data request message to the corresponding Modbus slave via the serial port side of the Modbus gateway according to priority.
[0036] The time period mentioned here can be considered as the time after system initialization, and from this time, the Modbus gateway receives all the first data request messages sent by the Modbus master station. The built-in subset rule in the Modbus gateway is to save time overhead, and the first data request messages sent by different Modbus master stations with the same operation, accessing the same Modbus slave station, and having partially the same discrete register address points or continuous register address intervals, are combined into a specific second data request message. The first data request messages that cannot be combined will also generate a corresponding second data request message, but the content is different from the content of the second data request message combined with two or more different first data request messages.
[0037] Before performing the built-in subset rule combination operation based on the first data request message, the device numbers of a plurality of Modbus master stations and the device numbers of a plurality of Modbus slave stations need to be pre-constructed in the Modbus gateway, so as to identify the source and destination of the second data request message.
[0038] As shown in Figure 4 and Figure 5 , the first data request message includes sequentially arranged start field, device number of the Modbus master station, device number of the Modbus slave station requested to read, start address and register address offset of the register address of the accessed Modbus slave station, and end field.
[0039] The second data request message includes sequentially arranged start field, device number of at least one Modbus master station, device number of the Modbus slave station requested to read, start address and register address offset of the register address of the accessed Modbus slave station corresponding to at least one first data request message in the second data request message, and end field.
[0040] When the operations performed by two or more first data request messages on the device number of the Modbus slave station are the same, such as reading or writing at the same time, and the start address and address offset of the register address of the Modbus slave station requested to be accessed by one first data request message are completely contained in the start address and address offset of the register address of the Modbus slave station requested to be accessed by another first data request message, then the two can be combined, and in the address field of the combined second data request message, a mark can be added to mark the partially overlapping start address and address offset, such as the star mark shown in the figure, to facilitate splitting again later.
[0041] It is also mentioned here that the Modbus gateway has built-in subset rules, which selectively merge the first data request to obtain the list of second data requests. Different data requests from the same or different Modbus master stations are merged according to the device number of the slave station. The different data requests that can be merged have the following requirements: 1) The device numbers of the accessed Modbus slave stations are the same; 2) The range of the register addresses of the Modbus slave station corresponding to at least one first data request message is located within the range of the register addresses of the Modbus slave station corresponding to another first data request message; 3) The operation types in the range of the register addresses of the Modbus slave station are the same, such as read or write operation; 4) The time required for the Modbus slave station to respond is located within the same response cycle. The response cycle here is an integer multiple of the machine cycle of the Modbus slave station. Within the same response cycle, the contents of the Modbus slave station register after being written with data will not be overwritten and remain unchanged.
[0042] In combination Figure 4 and Figure 5 It is explained that Figure 4 One of the first data request messages in requires access to three independent Modbus slave stations S001 register addresses, and the register address offset is 1, marked as S001-R; another first data request message requires access to six independent Modbus slave stations S001 register addresses, and the register address offset is not completely the same, but the address required to be accessed by the previous first data request message is completely within the range of the register address required to be accessed by the current message. The operation type and the device number of the Modbus slave station are the same, so they can be merged. The device number of the master station in the second data request message after merging records the device numbers of two different Modbus master stations, and the register address and offset of the Modbus master station accessed are also marked.
[0043] Figure 5 The read and write operation types of the two first data request messages in are different, and the accessed register addresses are not associated with each other, so they cannot be merged and exist independently in the list.
[0044] The Modbus gateway also estimates the time and T2 of sending and responding of the second data request message via the serial port side, which is the sum of the transmission time A1 of the second data request message currently processed by the Modbus gateway via the serial port side to the corresponding Modbus slave station and the time of the second data response message expected to be returned by the Modbus slave station, and the necessary processing time delay A2; the transmission time sum A1 is proportional to the byte length of the second data request message and the second data response message; the processing time delay A2 is proportional to the machine cycle of the Modbus slave station; the time and T2 of sending and responding of the serial port side is A1+A2.
[0045] In the above, A1 = [(number of bits of a single byte) * (byte length of the second data request message + byte length of the response of the Modbus slave station)] / serial port baud rate. For example, if the number of register addresses accessed by the Modbus slave station is 10, the byte length of the second data request message is 8 bytes, and the byte length of the response of the Modbus slave station is 25 bytes; the serial port baud rate is usually 9600bps, each byte includes 1 start bit, 8 data bits, and 1 stop bit, i.e. A1 = [(1+8+1)*(8+25)] / 9600 = 0.034375 seconds. Of course, the serial port baud rate can also be 19200bps or 4800bps, but the value of T2 needs to be recalculated. The time and T2 of sending and responding of the second data request message via the serial port side is the estimated value under the condition of smooth bidirectional access of the serial port side to the Modbus slave station.
[0046] S3: After the Modbus slave station receives the corresponding second data request message, it responds and generates a plurality of second data response messages; the Modbus slave station sends the second data response message to the Modbus gateway via the serial port side; and the Modbus gateway updates the priority of the second data request message to be sent in the list in real time.
[0047] The Modbus gateway updates the priority of the second data request message to be sent in the list in real time in this step, which is set to avoid that some or part of the second data request messages in the list wait for too long time to be sent, and the priority adjustment in the list needs to meet the following rules:
[0048] 1) If the second data request message is merged from at least two different first data request messages, its priority is always higher than that of the second data request message composed of a single first data request message in the list; the waiting forwarding time T1 of each first data request message is not calculated separately, but only the waiting forwarding time T1 of the merged second data request message is counted; the waiting forwarding time T1 of the second data request message composed of a single first data request message is calculated separately;
[0049] 2) The priority of the second data request message with more merged first data request messages is always higher than that of the second data request message with less merged first data request messages; if the number of merged first data request messages of different second data request messages is the same, the larger the waiting forwarding time T1 of the second data request message, the higher the priority; further, if the waiting forwarding time T1 is also equal, further consider the estimated time and T2 of the second data request message via the serial port side sending and response, the smaller the T2 of the second data request message, the higher the priority;
[0050] 3) The priority P of the second data request message composed of a single first data request message is T1 / T2; the larger the value of the priority P, the higher the priority in the list; if the value of the priority P of the second data request message composed of different single first data request messages is the same, the larger the waiting forwarding time T1 of the second data request message, the higher the priority.
[0051] The above arranged priority is considered when the Modbus gateway sends each second data request message in the list to the Modbus slave station, but this priority is not fixed, that is, after sending a second data request message and receiving a response or response timeout, the priority of each second data request message in the list is adjusted once, so as to realize the function of real-time updating the priority of each second data request message in the list.
[0052] As a further improvement of the present solution, if the priority P of the second data request message is lower than the median of the priorities in the current list, and the Modbus gateway still fails to send the second data request message to the Modbus slave within the specified time threshold T3, i.e. T1 > T3, then the Modbus gateway actively returns an error code to the Modbus master, indicating that the current second data request message is delayed, and sets the priority of the corresponding second data request message to the lowest, and extends the survival time of the second data request message by T1, until the second data request message is executed again in sequence and the corresponding second data response message is returned. After the execution of the second data request message, the response data is returned to the master, and the second data request message is deleted from the list.
[0053] As a preferred embodiment, if the Modbus gateway sends the second data request message to the Modbus slave, and the Modbus slave is busy or unresponsive, causing the Modbus gateway to fail to receive the second data response message returned by the Modbus slave within the time threshold T3, then the Modbus gateway is further configured with a retry number B1 and a retry cumulative time T4; and the priority of the current second data request message is moved one position in the list, the survival time of the second data request message is extended by T1, and the retry number B1 is reduced by 1, until the Modbus gateway successfully receives the second data response message returned by the Modbus slave within the time threshold T3, or the retry number reaches zero to terminate the execution of the second data request message, and return an error code to one or more Modbus masters corresponding to the second data request message. The retry cumulative time T4 can be an integer multiple of the time threshold T3; the retry number B1 is also an integer. The phenomenon of congestion or unresponsiveness may occur in the serial port, and setting sufficient retry number or limiting certain retry cumulative time is beneficial to ensure the return of reliable response content.
[0054] S4: The Modbus gateway brings the received second data response message to the cache, extracts the content of the second data response message, and further generates a plurality of first data response messages corresponding to the first data request message according to the merging order of the first data request message; and returns each first data response message to each Modbus master.
[0055] Specifically, after the Modbus gateway receives the second data response message, the content of the corresponding Modbus slave register address in the second data response message is extracted and sorted according to the starting address and register address offset of the Modbus slave corresponding to at least one first data request message contained in the second data request message, to respond to the data read request of each first data request message.
[0056] The second data response message mentioned above includes a start field, one or more device numbers of the Modbus master station currently accessing the Modbus slave station, a current Modbus slave station device number, contents of the accessed register address, and an end field; after receiving the second data request message, the Modbus slave station copies the contents in the corresponding register, sequentially arranges the contents according to the format of the second data response message, marks the contents in the register accessed by multiple first data request messages, indicating that the contents belong to the contents commonly used by the multiple first data request messages, encapsulates the contents to form the second data response message. If the second data response message is for the second data request message that combines at least two first data request messages, the second data response message needs to be further split into two or more first data response messages. The structure of the first data response message is similar to that of the first data request message, except that the first data response message internally stores the data in the discrete point start address and the address offset of the register address of the Modbus slave station that the Modbus master station needs to call.
[0057] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for a Modbus gateway to handle multi-host data access, characterized in that, Includes the following steps: S1: Connect several Modbus masters in parallel on the network port side of the Modbus gateway; connect several Modbus slaves in parallel on the serial port side of the Modbus gateway; S2: Several Modbus master device numbers and several Modbus slave device numbers have been pre-built within the Modbus gateway; the Modbus gateway counts the first data request messages from one or more Modbus masters over a period of time; the Modbus gateway has built-in subset rules to merge the first data request messages that can be merged to obtain a list of second data request messages, and records the waiting time T1 for each second data request message; the Modbus gateway estimates the sum of the time for the second data request message to be sent and responded to via the serial port side, records it as T2, and sends each second data request message to the corresponding Modbus slave via the serial port side of the Modbus gateway according to priority; S3: After receiving the corresponding second data request message, the Modbus slave station responds by generating several second data response messages; the Modbus slave station sends the second data response messages to the Modbus gateway through the serial port; the Modbus gateway updates the priority of the second data request messages to be sent in the list in real time. The priority of the second data request message to be sent in the Modbus gateway's real-time update list in step S3 is determined by simultaneously satisfying the following rules: 1) If a second data request message is merged from at least two different first data request messages, its priority is always higher than that of a second data request message composed of a single first data request message in the list; the waiting time T1 of each merged first data request message is not calculated separately, only the waiting time T1 of the merged second data request message is counted. 2) The priority of merging second data request packets with a larger number of first data request packets is always higher than the priority of merging second data request packets with a smaller number of first data request packets; If different second data request messages merge the same number of first data request messages, the longer the waiting time T1 of the second data request message, the higher its priority. 3) The priority P of the second data request message, which consists of a single first data request message, is T1 / T2; the larger the priority P value, the higher the priority in the list. If the priority P of a second data request message composed of different single first data request messages is the same, then the larger the waiting time T1 of the second data request message, the higher the priority. S4: The Modbus gateway adds the received second data response message to the cache, extracts the content of the second data response message, and further generates several first data response messages corresponding to the first data request message according to the merging order of the first data request message; The first data response message is then returned to each Modbus master station.
2. The method for processing multi-host data access via a Modbus gateway according to claim 1, characterized in that, The first data request message in step S2 includes a start field for sequential setting, the device number of the Modbus master station, the device number of the Modbus slave station to be read, the start address and offset of the register address of the accessed Modbus slave station, and an end field. The second data request message includes a start field for sequential settings, the device number of at least one Modbus master station, the device number of the Modbus slave station to be read, the start address and register address offset of the register address of the Modbus slave station to be accessed corresponding to at least one first data request message within the second data request message, and an end field.
3. The method for processing multi-host data access via a Modbus gateway according to claim 2, characterized in that, Step S2, which involves the Modbus gateway's built-in subset rules, merges eligible first data request messages to obtain a list of second data request messages. This is done based on the slave device number, merging different data requests from the same or different Modbus masters. The different data requests that can be merged have the following requirements: 1) The accessed Modbus slave device numbers are the same; 2) The range of register addresses of at least one first data request message corresponding to the Modbus slave is entirely within the range of register addresses of another first data request message corresponding to the Modbus slave; 3) The operation types within the range of Modbus slave register addresses are the same; 4) The Modbus slave responses must be within the same response cycle.
4. The method for processing multi-host data access via a Modbus gateway according to claim 3, characterized in that, The waiting time T1 for the second data request message, as described in step S2, is calculated from the moment the Modbus gateway receives the second data request message. The estimated time T2 for the second data request message to be sent and responded to via the serial port side is based on the sum of the transmission times A1 (the time it takes for the second data request message currently being processed by the Modbus gateway to be sent to the corresponding Modbus slave via the serial port side and the time it takes for the Modbus slave to return the second data response message) and the processing time delay A2. The sum of the transmission times A1 is proportional to the sum of the byte lengths of the second data request message and the second data response message. The processing time delay A2 is proportional to the machine cycle of the Modbus slave. The time for the serial port to return and respond is T2 = A1 + A2.
5. A method for processing multi-host data access via a Modbus gateway according to claim 4, characterized in that, The estimated sum of the time for sending and responding to the second data request message via the serial port side and the transmission time in T2, A1, is calculated by setting A1 = [the number of bits in a single byte]. [(Byte length of the second data request message + byte length of the Modbus slave's response)] / serial port baud rate, in seconds.
6. A method for processing multi-host data access via a Modbus gateway according to claim 1, characterized in that, If a second data request message with a priority P value lower than the median priority in the current list is not sent to the Modbus slave station by the Modbus gateway within the specified time threshold T3, the Modbus gateway will proactively return an error code to the Modbus master station, indicating that the current second data request message has a large transmission delay. The Modbus gateway will also set the priority of the corresponding second data request message to the lowest level and extend the lifespan of the second data request message by T1 until the second data request message is executed again and the corresponding second data response message is returned.
7. A method for processing multi-host data access via a Modbus gateway according to claim 6, characterized in that, If the Modbus gateway sends a second data request message to a Modbus slave, and the slave is busy or unresponsive, causing the Modbus gateway to fail to receive a second data response message from the slave within the time threshold T3, the Modbus gateway further configures the retry count B1 and the retry accumulation time T4; it also moves the priority of the current second data request message one position forward in the list, extends the lifespan of the second data request message by T1, and decrements the retry count B1 by 1, until the Modbus gateway successfully receives the second data response message from the slave within the time threshold T3, or terminates the execution of the second data request message when the retry count reaches zero, and returns an error code to one or more Modbus masters corresponding to the second data request message.
8. A method for processing multi-host data access via a Modbus gateway according to claim 1, characterized in that, In step S4, the Modbus gateway adds the received second data response message to the cache, extracts the content of the second data response message, and further generates several first data response messages corresponding to the first data request message according to the merging order of the first data request messages. The first data response message is returned to each Modbus master station by extracting and sorting the contents of the corresponding Modbus slave station's register address in the second data response message according to the starting address and register address offset of the register address of at least one first data request message merged in the second data request message, in response to the data read request of each first data request message.
Citation Information
Patent Citations
Industrial field data collecting and analyzing system based on Modbus
CN103792928A
Method for accessing slave by multiple hosts, expansion device and storage medium
CN107590099A