CN110311847B - Batch data transmission method and device - Google Patents
Batch data transmission method and device Download PDFInfo
- Publication number
- CN110311847B CN110311847B CN201910559877.7A CN201910559877A CN110311847B CN 110311847 B CN110311847 B CN 110311847B CN 201910559877 A CN201910559877 A CN 201910559877A CN 110311847 B CN110311847 B CN 110311847B
- Authority
- CN
- China
- Prior art keywords
- modbus
- request
- message
- sending
- messages
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 230000005540 biological transmission Effects 0.000 title claims abstract description 100
- 238000000034 method Methods 0.000 title claims abstract description 79
- 230000004044 response Effects 0.000 claims abstract description 123
- 230000008569 process Effects 0.000 claims description 29
- 238000012545 processing Methods 0.000 claims description 6
- 230000006854 communication Effects 0.000 description 32
- 238000004891 communication Methods 0.000 description 31
- 101100259931 Neurospora crassa (strain ATCC 24698 / 74-OR23-1A / CBS 708.71 / DSM 1257 / FGSC 987) tba-1 gene Proteins 0.000 description 10
- 101150087593 tba-2 gene Proteins 0.000 description 10
- 101100368940 Caenorhabditis elegans tbb-2 gene Proteins 0.000 description 9
- 238000010586 diagram Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 7
- 238000007796 conventional method Methods 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 4
- 238000012937 correction Methods 0.000 description 3
- 230000007246 mechanism Effects 0.000 description 2
- 230000001360 synchronised effect Effects 0.000 description 2
- 241000271175 Neomysis integer Species 0.000 description 1
- 230000002159 abnormal effect Effects 0.000 description 1
- 125000004122 cyclic group Chemical group 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000003780 insertion Methods 0.000 description 1
- 230000037431 insertion Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
- 230000007723 transport mechanism Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H02—GENERATION; CONVERSION OR DISTRIBUTION OF ELECTRIC POWER
- H02J—CIRCUIT ARRANGEMENTS OR SYSTEMS FOR SUPPLYING OR DISTRIBUTING ELECTRIC POWER; SYSTEMS FOR STORING ELECTRIC ENERGY
- H02J13/00—Circuit arrangements for providing remote indication of network conditions, e.g. an instantaneous record of the open or closed condition of each circuitbreaker in the network; Circuit arrangements for providing remote control of switching means in a power distribution network, e.g. switching in and out of current consumers by using a pulse code signal carried by the network
- H02J13/00006—Circuit arrangements for providing remote indication of network conditions, e.g. an instantaneous record of the open or closed condition of each circuitbreaker in the network; Circuit arrangements for providing remote control of switching means in a power distribution network, e.g. switching in and out of current consumers by using a pulse code signal carried by the network characterised by information or instructions transport means between the monitoring, controlling or managing units and monitored, controlled or operated power network element or electrical equipment
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/403—Bus networks with centralised control, e.g. polling
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40228—Modbus
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Power Engineering (AREA)
- Communication Control (AREA)
Abstract
本申请公开了一种批量数据传输方法和装置,所述批量数据传输方法包括生成n条Modbus请求报文,并按照预设顺序批量发送所述n条Modbus请求报文,n为大于或等于1的整数;在预设的超时时间间隔内,接收返回的m条Modbus应答报文,并根据接收的Modbus应答报文判定本次批量发送是否成功,其中,m为0至n之间的整数。本申请通过批量发送多条Modbus请求报文并在预设的超时时间间隔内,接收返回的多条Modbus应答报文,大大缩短了数据传输的时间,极大地减免了延迟给从站校时所带来的误差。
The present application discloses a batch data transmission method and device. The batch data transmission method includes generating n Modbus request messages and sending the n Modbus request messages in batches according to a preset sequence, where n is greater than or equal to 1 An integer of ; within the preset timeout interval, receive m returned Modbus response messages, and determine whether the batch transmission is successful according to the received Modbus response messages, where m is an integer between 0 and n. In this application, by sending multiple Modbus request messages in batches and receiving multiple returned Modbus response messages within a preset timeout interval, the data transmission time is greatly shortened, and the delay to the slave station for time calibration is greatly reduced. errors caused.
Description
技术领域technical field
本申请涉及但不限于通信技术领域,尤其涉及一种批量数据传输方法和装置。The present application relates to, but is not limited to, the field of communication technologies, and in particular, relates to a method and apparatus for batch data transmission.
背景技术Background technique
Modbus协议是工业自动化领域广泛应用的应答通信协议,已经成为通用工业标准。应答通信协议的一个特点是先问先得、依次应答。Modbus协议分为基于串口(RS-232、RS-422、RS-485)的Modbus RTU(Remote Terminal Unit,RTU,远程终端单元)协议和基于传输控制协议/因特网互联协议(Transmission Control Protocol/Internet Protocol,TCP/IP)的Modbus TCP协议。如图1所示,Modbus通信使用主(Master,也称主站)—从(Slave,也称从站、设备)技术,主站初始化传输(Query,也叫查询/请求,依次查询称为轮询),从站根据主站查询提供的数据作出相应反应。主站可单独和从站通信,也能以广播方式和所有从站通信。如果单独通信,从站返回一消息作为回应,如果是以广播方式查询的,则从站不作任何回应。Modbus protocol is a widely used response communication protocol in the field of industrial automation, and has become a general industrial standard. A feature of the answering communication protocol is that it is first-ask, first-served, and answer-in-sequence. Modbus protocol is divided into Modbus RTU (Remote Terminal Unit, RTU, Remote Terminal Unit) protocol based on serial port (RS-232, RS-422, RS-485) and Transmission Control Protocol/Internet Protocol (Transmission Control Protocol/Internet Protocol) , TCP/IP) Modbus TCP protocol. As shown in Figure 1, Modbus communication uses the master (Master, also known as the master station)-slave (Slave, also known as the slave station, equipment) technology, the master station initializes the transmission (Query, also known as query/request, and the query in turn is called the wheel query), the slave station responds accordingly according to the data provided by the master station query. The master station can communicate with the slave stations individually, and can also communicate with all the slave stations in a broadcast manner. If it communicates alone, the slave station returns a message as a response. If it is queried by broadcast, the slave station does not respond.
在Modbus协议中,只有主站才有发起Query的权利,从站只有收到Query后,才有权利向主站发送应答(Response)报文。换言之,在Modbus协议中,主站只能通过Query/Response才能获得从站的数据,从站永远不能向主站主动上送任何报文。如图2所示,主站某一时刻向从站发送一个请求,从站收到请求后,对请求进行辨识,并给主站发送应答报文作为给主站的回执,主站收到应答报文后此次请求会话即成功完成。在图2中,我们记一次请求/应答的时间为Ts,即:从主站发送一个请求起计时开始,从站收到请求并进行内部处理,然后从站给主站发送应答报文,主站收到从站应答为计时结束所对应的间隔时间。显然,Ts由三部分组成,其一是从主站发送一个请求起,到从站收到请求的时间间隔,我们记为Ta;其二是,从站对该请求进行内部处理的时间消耗,我们记为Tb;其三时,从站给主站发送应答报文,主站收到从站应答的时间间隔,我们记为Tc。即Ts=Ta+Tb+Tc。In the Modbus protocol, only the master station has the right to initiate a Query, and the slave station has the right to send a Response message to the master station only after receiving the Query. In other words, in the Modbus protocol, the master station can only obtain the data of the slave station through Query/Response, and the slave station can never actively send any message to the master station. As shown in Figure 2, the master station sends a request to the slave station at a certain time. After the slave station receives the request, it identifies the request and sends a response message to the master station as a receipt to the master station. The master station receives the response After the message is sent, the request session is successfully completed. In Figure 2, we record the time of a request/response as Ts, that is, the timing starts from the time the master station sends a request, the slave station receives the request and processes it internally, and then the slave station sends a response message to the master station. The interval time corresponding to the end of timing when the station receives the response from the slave station. Obviously, Ts consists of three parts, one is the time interval from when the master sends a request to when the slave receives the request, which we denote as Ta; the other is the time consumed by the slave to process the request internally, We denote it as Tb; in the third time, the slave station sends a response message to the master station, and the time interval for the master station to receive the response from the slave station, we denote it as Tc. That is, Ts=Ta+Tb+Tc.
如图3所示,主站从轮询表中依次读取一条请求,作为本次待发送请求,然后根据该请求生成发送报文,成功发送报文后启动超时定时器(假设超时时间为TimeOut)。如果主站在TimeOut时间内,成功接收到了设备的应答报文,主站会处理该应答报文,然后主站会进入下一次发送待命状态;如果主站在TimeOut时间内,没能成功接收到设备的应答报文,则认为此次请求失败,主站进入超时处理(记一次发送失败,连续失败时则需要对链路进行重连),然后主站会进入下次发送待命状态,如此周而复始。As shown in Figure 3, the master station sequentially reads a request from the polling table as the request to be sent this time, and then generates a sending message according to the request, and starts the timeout timer after successfully sending the message (assuming the timeout time is TimeOut ). If the master station successfully receives the response message from the device within the TimeOut time, the master station will process the response message, and then the master station will enter the next sending standby state; if the master station fails to successfully receive the response message within the TimeOut time If the device responds with a response message, it is considered that the request failed, and the master station enters timeout processing (record one transmission failure, and the link needs to be reconnected if it fails continuously), and then the master station will enter the next sending standby state, and so on. .
Modbus协议作为典型的请求/应答型通信协议,常规的流程总是一问一答,即上次的请求要么超时,要么得到应答,才会进入下一次的发送请求。在Modbus协议的实际应用中,有时会遇到某一种操作需要包含n次请求/应答才能完成的,例如,某些含使能位操作的遥控操作,时间信息包含在多条报文中的校时操作。这些遥控操作和校时,当然也是由请求/应答组合来完成的,所以,常规流程下,这类遥控和校时也是通过一问一答的串行同步操作来完成的。Modbus protocol, as a typical request/response communication protocol, the conventional process is always one question and one answer, that is, the last request either timed out or got an answer before entering the next sending request. In the practical application of the Modbus protocol, it is sometimes encountered that a certain operation requires n requests/responses to be completed. school hours operation. These remote control operations and time adjustment are of course also completed by the request/response combination. Therefore, under the conventional process, such remote control and time adjustment are also completed through a serial synchronous operation of one question and one answer.
常规方法下,上述遥控和校时操作严格遵循Modbus规约的常规流程,过程繁琐,操作时间冗长,特别是对于校时操作,其操作时间越长,所带来的校时误差往往越大。Under the conventional method, the above-mentioned remote control and time-checking operations strictly follow the conventional process of the Modbus protocol, the process is cumbersome and the operation time is lengthy, especially for the time-checking operation, the longer the operation time, the greater the time-checking error.
发明内容SUMMARY OF THE INVENTION
本申请提供了一种批量数据传输方法和装置,能够大幅缩短数据传输的时间。The present application provides a batch data transmission method and apparatus, which can greatly shorten the data transmission time.
本发明实施例提供了一种批量数据传输方法,包括:The embodiment of the present invention provides a batch data transmission method, including:
生成n条Modbus请求报文,并按照预设顺序批量发送所述n条Modbus请求报文,其中,n为大于或等于1的整数;generating n Modbus request messages, and sending the n Modbus request messages in batches in a preset order, where n is an integer greater than or equal to 1;
在预设的超时时间间隔内,接收返回的m条Modbus应答报文,并根据接收的Modbus应答报文判定本次批量发送是否成功,其中,m为0至n之间的整数。Within the preset timeout interval, receive m returned Modbus response messages, and determine whether the batch transmission is successful according to the received Modbus response messages, where m is an integer between 0 and n.
在一种示例性实施例中,在所述按照预设顺序批量发送所述n条Modbus请求报文时,所述方法还包括:In an exemplary embodiment, when the n Modbus request messages are sent in batches in a preset order, the method further includes:
设置独占标识,所述独占标识用于在批量发送所述n条Modbus请求报文的过程中,禁止除所述n条Modbus请求报文之外的其他报文的发送。An exclusive identifier is set, and the exclusive identifier is used to prohibit the sending of other messages except the n Modbus request messages in the process of sending the n Modbus request messages in batches.
在一种示例性实施例中,发送所述n条Modbus请求报文的时间为TAb,完成n次批量发送和接收的时间为TBb,In an exemplary embodiment, the time for sending the n Modbus request messages is TAb, and the time for completing n batches of sending and receiving is TBb,
TAb=(n-1)*(Ta+T0)+Ta,TAb=(n-1)*(Ta+T0)+Ta,
TBb=(n-1)*(Ta+T0)+Ts,TBb=(n-1)*(Ta+T0)+Ts,
其中:*为乘号,Ta为从主站发送一个请求报文起,到从站收到请求报文的时间间隔;Among them: * is the multiplication number, Ta is the time interval from the time the master station sends a request message to the slave station receives the request message;
T0为主站发送间隔时间;T0 sends the interval time to the master station;
Ts=Ta+Tb+Tc;Ts=Ta+Tb+Tc;
Tb为从站对该请求报文进行内部处理的时间消耗;Tb is the time consumption for the internal processing of the request message by the slave station;
Tc为从从站给主站发送一个应答报文起,到主站收到从站应答报文的时间间隔。Tc is the time interval from when the slave station sends a response message to the master station until the master station receives the response message from the slave station.
在一种示例性实施例中,在顺序发送前n-1个请求报文时,均不启动超时TimeOut定时器,只在发送第n条请求报文后才启动TimeOut定时器。In an exemplary embodiment, when the first n-1 request packets are sent sequentially, the timeout TimeOut timer is not started, and the TimeOut timer is started only after the nth request packet is sent.
在一种示例性实施例中,在所述生成n条Modbus请求报文的步骤之后且所述按照预设顺序批量发送所述n条Modbus请求报文的步骤之前,所述方法还包括:In an exemplary embodiment, after the step of generating n Modbus request messages and before the step of sending the n Modbus request messages in batches in a preset order, the method further includes:
配置所述n条Modbus请求报文中的一条或多条为关键请求报文;Configure one or more of the n Modbus request messages as key request messages;
所述根据接收的Modbus应答报文判定本次批量发送是否成功,包括:The determining whether the batch transmission is successful according to the received Modbus response message includes:
如果在所述预设的超时时间间隔内接收到了与所有关键请求报文一一对应的所述Modbus应答报文,则判定本次批量发送成功;If the Modbus response message corresponding to all key request messages one-to-one is received within the preset timeout interval, it is determined that this batch transmission is successful;
如果在所述预设的超时时间间隔内没有接收到与所有关键请求报文一一对应的所述Modbus应答报文,则判定本次批量发送失败。If the Modbus response message corresponding to all the key request messages is not received within the preset timeout time interval, it is determined that this batch transmission fails.
在一种示例性实施例中,所述Modbus请求报文包括Modbus TCP报文或Modbus RTU报文;所述Modbus应答报文包括Modbus TCP报文或Modbus RTU报文。In an exemplary embodiment, the Modbus request message includes a Modbus TCP message or a Modbus RTU message; the Modbus response message includes a Modbus TCP message or a Modbus RTU message.
在一种示例性实施例中,当所述Modbus请求报文和所述Modbus应答报文为ModbusTCP报文时,每成功发送一个请求报文,就把该请求报文保存到本地第一发送请求列表AQS,在AQS中包含n个请求报文的有效信息,另外,还包括每个请求报文的RF和KQ标志,其中,RF标志用于指示是否收到与该请求报文对应的应答报文,KQ标志用于指示该请求报文是否为关键请求报文。In an exemplary embodiment, when the Modbus request message and the Modbus response message are Modbus TCP messages, each time a request message is successfully sent, the request message is saved to the local first sending request message The list AQS contains the valid information of n request messages, and also includes the RF and KQ flags of each request message, where the RF flag is used to indicate whether a response message corresponding to the request message is received message, the KQ flag is used to indicate whether the request message is a key request message.
在一种示例性实施例中,当所述Modbus请求报文和所述Modbus应答报文为ModbusRTU报文时,将生成的n条请求报文在发送前存入本地第二发送请求列表TM,或者,在批量发送成功后将这些请求报文依次存入TM;在TM中包含n个请求报文的有效信息,另外,还包括每个请求报文的RF和KQ标志,其中,RF标志用于指示是否收到与该请求报文对应的应答报文,KQ标志用于指示该请求报文是否为关键请求报文。In an exemplary embodiment, when the Modbus request message and the Modbus response message are Modbus RTU messages, the generated n request messages are stored in the local second sending request list TM before being sent, Or, after the batch transmission is successful, these request messages are stored in the TM in turn; the valid information of n request messages is included in the TM, and the RF and KQ flags of each request message are also included. In order to indicate whether a response message corresponding to the request message is received, the KQ flag is used to indicate whether the request message is a key request message.
本发明实施例还提供了一种批量数据传输装置,包括处理器及存储器,其中:所述处理器用于执行存储器中存储的程序,以实现如以上任一项所述的批量数据传输方法的步骤。An embodiment of the present invention further provides a batch data transmission device, including a processor and a memory, wherein: the processor is configured to execute a program stored in the memory, so as to implement the steps of the method for batch data transmission as described in any of the above .
本发明实施例还提供了一种批量数据传输装置,包括批量发送模块和批量接收模块,其中:The embodiment of the present invention also provides a batch data transmission device, including a batch sending module and a batch receiving module, wherein:
批量发送模块,用于生成n条Modbus请求报文,并按照预设顺序批量发送所述n条Modbus请求报文,其中,n为大于或等于1的整数;a batch sending module, configured to generate n Modbus request messages, and send the n Modbus request messages in batches according to a preset sequence, where n is an integer greater than or equal to 1;
批量接收模块,用于在预设的超时时间间隔内,接收返回的m条Modbus应答报文,并根据接收的Modbus应答报文判定本次批量发送是否成功,其中,m为0至n之间的整数。The batch receiving module is used to receive m Modbus response messages returned within a preset timeout interval, and determine whether the batch transmission is successful according to the received Modbus response messages, where m is between 0 and n the integer.
与相关技术相比,本申请的批量数据传输方法和装置,通过批量发送多条Modbus请求报文并在预设的超时时间间隔内,接收返回的多条Modbus应答报文,大大缩短了数据传输的时间,极大地减免了延迟给从站校时所带来的误差。Compared with the related art, the batch data transmission method and device of the present application greatly shorten data transmission by sending multiple Modbus request messages in batches and receiving multiple returned Modbus response messages within a preset timeout interval. time, which greatly reduces the error caused by the delay to the slave station calibration.
本申请的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本申请而了解。本申请的其他优点可通过在说明书、权利要求书以及附图中所描述的方案来实现和获得。Other features and advantages of the present application will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practice of the present application. Other advantages of the present application may be realized and attained by the means described in the specification, claims and drawings.
附图说明Description of drawings
附图用来提供对本申请技术方案的理解,并且构成说明书的一部分,与本申请的实施例一起用于解释本申请的技术方案,并不构成对本申请技术方案的限制。The accompanying drawings are used to provide an understanding of the technical solutions of the present application, and constitute a part of the specification. They are used to explain the technical solutions of the present application together with the embodiments of the present application, and do not constitute a limitation on the technical solutions of the present application.
图1为相关技术中的一种Modbus主从通信网络示意图;1 is a schematic diagram of a Modbus master-slave communication network in the related art;
图2为相关技术中的一种Modbus协议主从通信常规序列图;Fig. 2 is a kind of Modbus protocol master-slave communication conventional sequence diagram in the related art;
图3为相关技术中的一种Modbus数据传输方法的流程示意图;3 is a schematic flowchart of a Modbus data transmission method in the related art;
图4为相关技术中的一种Modbus六步遥控流程示意图;Fig. 4 is a kind of Modbus six-step remote control flow schematic diagram in the related art;
图5为相关技术中的一种Modbus六步校时流程示意图;Fig. 5 is a kind of Modbus six-step timing calibration flow schematic diagram in the related art;
图6为本发明实施例的一种批量数据传输方法的流程示意图;6 is a schematic flowchart of a batch data transmission method according to an embodiment of the present invention;
图7为本发明实施例的另一种批量数据传输方法的流程示意图;7 is a schematic flowchart of another batch data transmission method according to an embodiment of the present invention;
图8为本发明实施例的Modbus主从通信网络示意图;8 is a schematic diagram of a Modbus master-slave communication network according to an embodiment of the present invention;
图9为本发明实施例的一种批量遥控流程示意图;9 is a schematic diagram of a batch remote control process according to an embodiment of the present invention;
图10为本发明实施例的一种批量校时流程示意图;FIG. 10 is a schematic flow chart of a batch timing correction according to an embodiment of the present invention;
图11为本发明实施例的一种批量数据传输装置的结构示意图。FIG. 11 is a schematic structural diagram of a batch data transmission apparatus according to an embodiment of the present invention.
具体实施方式Detailed ways
本申请描述了多个实施例,但是该描述是示例性的,而不是限制性的,并且对于本领域的普通技术人员来说显而易见的是,在本申请所描述的实施例包含的范围内可以有更多的实施例和实现方案。尽管在附图中示出了许多可能的特征组合,并在具体实施方式中进行了讨论,但是所公开的特征的许多其它组合方式也是可能的。除非特意加以限制的情况以外,任何实施例的任何特征或元件可以与任何其它实施例中的任何其他特征或元件结合使用,或可以替代任何其它实施例中的任何其他特征或元件。Various embodiments have been described herein, but the description is exemplary rather than restrictive, and it will be apparent to those of ordinary skill in the art that within the scope of the embodiments described herein, There are many more examples and implementations. Although many possible combinations of features are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are possible. Unless expressly limited, any feature or element of any embodiment may be used in combination with, or may be substituted for, any other feature or element of any other embodiment.
本申请包括并设想了与本领域普通技术人员已知的特征和元件的组合。本申请已经公开的实施例、特征和元件也可以与任何常规特征或元件组合,以形成由权利要求限定的独特的发明方案。任何实施例的任何特征或元件也可以与来自其它发明方案的特征或元件组合,以形成另一个由权利要求限定的独特的发明方案。因此,应当理解,在本申请中示出和/或讨论的任何特征可以单独地或以任何适当的组合来实现。因此,除了根据所附权利要求及其等同替换所做的限制以外,实施例不受其它限制。此外,可以在所附权利要求的保护范围内进行各种修改和改变。This application includes and contemplates combinations with features and elements known to those of ordinary skill in the art. The embodiments, features and elements that have been disclosed in this application can also be combined with any conventional features or elements to form unique inventive solutions as defined by the claims. Any features or elements of any embodiment may also be combined with features or elements from other inventive arrangements to form another unique inventive arrangement defined by the claims. Accordingly, it should be understood that any of the features shown and/or discussed in this application may be implemented alone or in any suitable combination. Accordingly, the embodiments are not to be limited except in accordance with the appended claims and their equivalents. Furthermore, various modifications and changes may be made within the scope of the appended claims.
此外,在描述具有代表性的实施例时,说明书可能已经将方法和/或过程呈现为特定的步骤序列。然而,在该方法或过程不依赖于本文所述步骤的特定顺序的程度上,该方法或过程不应限于所述的特定顺序的步骤。如本领域普通技术人员将理解的,其它的步骤顺序也是可能的。因此,说明书中阐述的步骤的特定顺序不应被解释为对权利要求的限制。此外,针对该方法和/或过程的权利要求不应限于按照所写顺序执行它们的步骤,本领域技术人员可以容易地理解,这些顺序可以变化,并且仍然保持在本申请实施例的精神和范围内。Furthermore, in describing representative embodiments, the specification may have presented methods and/or processes as a particular sequence of steps. However, to the extent that the method or process does not depend on the specific order of steps described herein, the method or process should not be limited to the specific order of steps described. Other sequences of steps are possible, as will be understood by those of ordinary skill in the art. Therefore, the specific order of steps set forth in the specification should not be construed as limitations on the claims. Furthermore, the claims directed to the method and/or process should not be limited to performing their steps in the order written, as those skilled in the art will readily appreciate that these orders may be varied and still remain within the spirit and scope of the embodiments of the present application Inside.
Modbus RTU协议是工业自动化领域广泛应用的应答通信协议,已经成为现场总线(Fieldbus)工业标准。瑞典HMS工业网络有限公司发布的最新工业网络市场报告显示,Modbus RTU协议稳居全球现场总线市场第二的份额。Modbus RTU protocol is a widely used response communication protocol in the field of industrial automation, and has become the field bus (Fieldbus) industry standard. The latest industrial network market report released by Sweden's HMS Industrial Network Co., Ltd. shows that the Modbus RTU protocol ranks second in the global fieldbus market.
Modbus RTU协议可以基于RS-232、RS-422、两线制RS-485以及四线制RS-485的各种串口标准(以下简称串口)进行通信,其中两线制RS-485采用半双工工作方式,即任何时候只能有一点处于发送状态,其他串口标准都是全双工工作方式,即这些串口的数据接收与发送是分开的,可以同时支持数据接收和发送。因此,基于全双工串口的应用层通信协议,提供了应用层批量发送和接收的可能。The Modbus RTU protocol can communicate based on various serial port standards (hereinafter referred to as serial ports) of RS-232, RS-422, two-wire RS-485 and four-wire RS-485, of which the two-wire RS-485 adopts half-duplex Working mode, that is, only one point is in the sending state at any time, other serial port standards are full-duplex working mode, that is, the data receiving and sending of these serial ports are separated, and can support data receiving and sending at the same time. Therefore, the application layer communication protocol based on the full-duplex serial port provides the possibility of batch sending and receiving at the application layer.
本申请的基于Modbus RTU协议的批量数据传输方案工作于全双工串口工作模式。The batch data transmission scheme based on the Modbus RTU protocol of the present application works in a full-duplex serial port working mode.
Modbus TCP报文是把与基础通信层无关的协议数据单元(Protocol Data Unit,PDU)嵌入到开放系统互联(Open System Interconnection,OSI)模型的应用层,并在前添加6字节的报头,同时去掉Modbus RTU协议末尾的校验和部分(因TCP协议自身含循环冗余校验CRC32校验和),而构成的帧。TCP的请求/应答机制能和Modbus本身的主/从机制很好的配合工作。The Modbus TCP message is to embed the Protocol Data Unit (PDU), which has nothing to do with the basic communication layer, into the application layer of the Open System Interconnection (OSI) model, and add a 6-byte header before it. The frame is formed by removing the checksum part at the end of the Modbus RTU protocol (because the TCP protocol itself contains a cyclic redundancy check CRC32 checksum). The request/response mechanism of TCP works well with the master/slave mechanism of Modbus itself.
Modbus TCP报文格式组成:Modbus TCP message format consists of:
报头描述:Header description:
各字段描述如下:The fields are described as follows:
1)事务标识,用于事务配对。Modbus服务端在应答时拷贝来自客户端请求的事务标识。1) Transaction ID, used for transaction pairing. The Modbus server copies the transaction ID from the client request when responding.
请求和应答通过事务标识相对应。因此,在同一时间,TCP连接的事务标识必须是唯一的。标准委员会推荐,事务标识不妨采用简单计数——报文顺序号(简称顺序号),主站每次请求时加1。Modbus TCP协议出现至今已经有十多年,主流厂商都会采用标准的推荐,即事务标识实际就是顺序号。Requests and responses correspond to transaction IDs. Therefore, at the same time, the transaction ID of the TCP connection must be unique. The standards committee recommends that the transaction identification may be a simple count - the message sequence number (referred to as the sequence number), which is incremented by 1 each time the master requests it. It has been more than ten years since the Modbus TCP protocol appeared, and mainstream manufacturers will adopt the standard recommendation, that is, the transaction identifier is actually the sequence number.
2)协议标识,用于系统内的多元标识。Modbus协议用‘0’标识。2) Protocol identification, which is used for multiple identification in the system. Modbus protocol is identified with '0'.
3)长度字段以字节计数,包括单元标识和数据字段。3) The length field is counted in bytes, including the unit identification and data fields.
4)单元标识,用于系统内路由。其典型应用为请求和服务器应答报文返回值在该字段值必须相同。4) Unit identification, used for routing within the system. Its typical application is that the return value of the request and the server response message must be the same in this field.
在某些情况下,单元标识携带远程设备的Modbus从机地址。但在TCP层,Modbus服务端用其IP地址寻址,因此Modbus单元标识就没有实际意义。此时该字段值为0xFF。In some cases, the unit ID carries the Modbus slave address of the remote device. But at the TCP layer, the Modbus server is addressed with its IP address, so the Modbus unit identification is meaningless. At this time, the value of this field is 0xFF.
但如果从站有自己的子网,则设备地址也可以是1~247。But if the slave has its own subnet, the device address can also be from 1 to 247.
顺序号的应用:Application of serial number:
I)对于每个信息,主站会给从站初始化并产生顺序号;I) For each message, the master station will initialize the slave station and generate a sequence number;
II)从站的响应信息应使用从主站发出的相同的顺序号;II) The response information of the slave station shall use the same sequence number sent from the master station;
III)主站应确认从从站收到的顺序号与之前发送给从站的顺序号相同;III) The master should confirm that the sequence number received from the slave is the same as the sequence number previously sent to the slave;
主站增加顺序号数值的原则:The principle for the master station to increase the sequence number value:
A)顺序号用两个字节来储存;A) The sequence number is stored in two bytes;
B)顺序号的范围应是(0-65535)或(0x0000to 0xFFFF);B) The range of sequence number should be (0-65535) or (0x0000to 0xFFFF);
C)顺序号的起始数值应是0;C) The starting value of the sequence number should be 0;
D)对于主站每个发出的报文,包括用于正常轮询、故障轮询、重试信息或控制,主站均应把顺序号数值增加1;D) For each message sent by the master station, including for normal polling, fault polling, retry information or control, the master station should increase the sequence number value by 1;
E)如果主站发现从站的响应信息的顺序号有错误,应不理会该信息,并宣布通讯状态欠佳。E) If the master station finds that the sequence number of the response information of the slave station is wrong, it should ignore the information and announce that the communication state is not good.
综上,Modbus TCP协议具有以下关键特点:In summary, the Modbus TCP protocol has the following key features:
(1)Modbus TCP协议报文的起始两个字节称为“事务标识”,实际就是顺序号。(1) The first two bytes of the Modbus TCP protocol message are called "transaction identifier", which is actually the sequence number.
(2)主站决定顺序号的值,从站必须复制请求中的顺序号作为应答。(2) The master station determines the value of the sequence number, and the slave station must copy the sequence number in the request as a response.
(3)主站每发送一次请求,顺序号都会加一。(3) Each time the master station sends a request, the sequence number will be incremented by one.
假设以下两种Modbus协议(Modbus RTU协议或者Modbus TCP协议)的应用场景:Assume the application scenarios of the following two Modbus protocols (Modbus RTU protocol or Modbus TCP protocol):
常规方法下应用场景1:如图4所示,某个从站装置的遥控,需要分6步,分别是:遥控使能、遥控执行、遥控使能取消、遥控使能、遥控执行清零、遥控使能取消。常规情况下,该遥控的完整过程需要分六轮应答,分别为:1)主站发送遥控使能,从站应答遥控使能;2)主站收到遥控使能应答后,发送遥控执行,从站应答遥控执行;3)主站收到遥控执行应答后,发送遥控使能取消,从站应答遥控使能取消;4)主站收到遥控使能取消后,发送遥控使能,从站应答遥控使能;5)主站收到遥控使能应答后,发送遥控执行清零,从站应答遥控执行清零;6)主站收到遥控执行清零应答后,发送遥控使能取消,从站应答遥控使能取消,主站收到遥控使能取消后完成本轮遥控操作。
常规方法下应用场景2:如图5所示,某个从站装置的校时,需要分6步,主站依次发送功能码6的报文,报文中依次携带主站时间中的年、月、日、时、分、秒。
在使用Modbus RTU协议进行串口通信时,Ta和Tc都和报文字节个数以及串口通信波特率(以下简称波特率)相关,和报文字节个数成正比,和波特率成反比,在经典的9600bps波特率下,传输一个字节的耗时约为1毫秒。Tb则和从站设备有关,取决于设备硬件性能及其软件处理能力,一般Tb在5~20毫秒之间。When using the Modbus RTU protocol for serial communication, Ta and Tc are related to the number of message bytes and the baud rate of serial communication (hereinafter referred to as the baud rate), which are proportional to the number of message bytes and the baud rate. Inversely proportional, at a classic 9600bps baud rate, it takes about 1 millisecond to transmit a byte. Tb is related to the slave device, depending on the hardware performance of the device and its software processing capability. Generally, Tb is between 5 and 20 milliseconds.
为了便于阐述,我们不妨取波特率为9600bps,则传输一个字节的耗时约为1毫秒。一个Modbus RTU的典型请求(功能码1、2、3、4、5、6)的报文长度为8字节,此时,Ta=8毫秒;功能码1、2、3、4的应答报文的长度取决于请求中对应的点数,取值范围6~256字节,则Tc=6~256毫秒;功能码5、6的应该报文也是8字节,此时,Tc=8毫秒。For the sake of illustration, we might as well take the baud rate of 9600bps, and the time-consuming to transmit one byte is about 1 millisecond. The message length of a typical Modbus RTU request (
在Modbus通信中,主站在收到上一次请求的从站应答后,在发送下一个请求前通常需要有一定的主动休息时间,简称主站延迟时间,或主站间隔时间(记为T0),其目的有两个:一是控制主从通信双方的通信流量,二是如果T0为0(表示主站在收到上一次请求的从站应答后,立即发送下一个请求)时,有的从站往往处理不过来,可能会导致通信异常甚至中断。T0的取值范围通常为0~100毫秒。In Modbus communication, after the master station receives the response from the slave station of the previous request, it usually needs to have a certain active rest time before sending the next request, referred to as the master station delay time, or the master station interval time (denoted as T0) , there are two purposes: one is to control the communication flow between the master and slave communication parties, and the other is if T0 is 0 (meaning that the master station immediately sends the next request after receiving the response from the slave station of the previous request), some The slave station is often unable to handle it, which may cause abnormal communication or even interruption. The value range of T0 is usually 0 to 100 milliseconds.
我们记完成n次批量发送的时间为TA,完成n次批量发送和接收的时间为TB。We record the time to complete n batches of sending as TA, and the time to complete n batches of sending and receiving as TB.
为了便于区别,我们特别的记在使用传统的Modbus协议进行通信时,TA为TAa,TB为TBa;记在使用本申请的批量数据传输方案进行通信时,TA为TAb,TB为TBb。In order to facilitate the distinction, we specially note that when using the traditional Modbus protocol for communication, TA is TAa and TB is TBa; when using the batch data transmission scheme of this application for communication, TA is TAb and TB is TBb.
如图2所示,常规方法下,下一次的发送必须等待上次发送/接收完成后才会进行,第1~(n-1)发送/接收的时间均为(Ts+T0),第n次的发送时间为Ta,第n次的发送/接收时间为Ts。Ts=Ta+Tb+Tc,因此,As shown in Figure 2, under the conventional method, the next transmission must wait for the completion of the previous transmission/reception. The transmission time of the nth time is Ta, and the transmission/reception time of the nth time is Ts. Ts=Ta+Tb+Tc, therefore,
TAa=(n-1)*(Ts+T0)+Ta-------(1)TAa=(n-1)*(Ts+T0)+Ta-------(1)
TBa=(n-1)*(Ts+T0)+Ts-------(2)TBa=(n-1)*(Ts+T0)+Ts-------(2)
实施例一批量数据传输方法
如图6所示,本发明实施例提供了一种批量数据传输方法,包括如下步骤:As shown in FIG. 6 , an embodiment of the present invention provides a batch data transmission method, including the following steps:
步骤601:生成n条Modbus请求报文,并按照预设顺序批量发送所述n条Modbus请求报文,其中,n为大于或等于1的整数;Step 601: Generate n Modbus request messages, and send the n Modbus request messages in batches according to a preset sequence, where n is an integer greater than or equal to 1;
在一种示例性实施例中,所述Modbus请求报文包括Modbus RTU报文或Modbus TCP报文。In an exemplary embodiment, the Modbus request message includes a Modbus RTU message or a Modbus TCP message.
在一种示例性实施例中,在所述按照预设顺序批量发送所述n条Modbus请求报文时,所述方法还包括:In an exemplary embodiment, when the n Modbus request messages are sent in batches in a preset order, the method further includes:
设置独占标识,所述独占标识用于在批量发送所述n条Modbus请求报文的过程中,禁止除所述n条Modbus请求报文之外的其他报文的发送。An exclusive identifier is set, and the exclusive identifier is used to prohibit the sending of other messages except the n Modbus request messages in the process of sending the n Modbus request messages in batches.
在该实施例中,在批量发送n条Modbus请求报文时,设置独占标识(简称Lock)为true,批量请求发送完毕后置Lock为false,以确保主站在批量发送n条Modbus请求报文期间,不插入任何其他请求。为什么会有可能插入其他请求呢?因为主站的发送和接收往往是两个独立的线程,有可能在n次批量请求发送到第x(x<n)条请求后,就收到从站的应答了,这时会触发主站的接收回调函数,主站会正常识别、处理接收报文,如果没有Lock标识,则主站可能会触发新一轮请求,从而导致在第x请求后插入意外的请求。有了Lock标识,即便主站在批量发送期间收到从站应答,主站正常接收处理后,随后在检查到Lock标识为true时,主站不会产生新的请求,从而避免主站在批量发送请求期间,插入任何其他请求。In this embodiment, when sending n Modbus request messages in batches, set the exclusive flag (Lock for short) to true, and set Lock to false after the batch request is sent, to ensure that the master station sends n Modbus request messages in batches During this time, no other requests are inserted. Why would it be possible to insert other requests? Because the sending and receiving of the master station are often two independent threads, it is possible to receive the response from the slave station after n batch requests are sent to the x (x<n) request, which will trigger the master station. If there is no Lock flag, the master station may trigger a new round of requests, resulting in the insertion of unexpected requests after the xth request. With the Lock flag, even if the master station receives a response from the slave station during batch transmission, after the master station receives and processes normally, and then checks that the Lock flag is true, the master station will not generate a new request, thus preventing the master station from batching. During the sending of the request, insert any other requests.
采用本申请的批量传输方案后,下一次的发送只需等待上次发送完成后就能进行,第1~(n-1)发送的时间均为(Ta+T0),第n次的发送时间为Ta,即TAb=(n-1)*(Ta+T0)+Ta。下面,我们来计算TBb,我们只需要计算第n个请求发送后的,主站收到它的应答时的时刻(记为TimeN)就能计算出TBb了,因为,应答通信协议的一个特点是先问先得、依次应答,所以只要主站收到第n个请求的应答,说明在此之前主站一定收齐了前面(n-1)个请求的全部应答。按照约定,任意一个请求的发送/接收时间为Ts=Ta+Tb+Tc,因此,本申请中,第n次的发送/接收时间也为Ts。因此:After the batch transmission scheme of the present application is adopted, the next transmission only needs to wait for the completion of the previous transmission. is Ta, that is, TAb=(n-1)*(Ta+T0)+Ta. Next, let's calculate TBb. We only need to calculate the time when the master station receives its response after the nth request is sent (recorded as TimeN) to calculate TBb, because one of the characteristics of the response communication protocol is First ask, first serve, and answer in sequence, so as long as the master station receives the response of the nth request, it means that the master station must have received all the responses of the previous (n-1) requests before that. According to the agreement, the sending/receiving time of any request is Ts=Ta+Tb+Tc. Therefore, in this application, the n-th sending/receiving time is also Ts. therefore:
TAb=(n-1)*(Ta+T0)+Ta;TAb=(n-1)*(Ta+T0)+Ta;
TBb=(n-1)*(Ta+T0)+Ts。TBb=(n-1)*(Ta+T0)+Ts.
在一种示例性实施例中,在按照预设顺序批量发送所述n条Modbus请求报文的步骤之后,所述方法还包括:In an exemplary embodiment, after the step of sending the n Modbus request messages in batches in a preset order, the method further includes:
将发送的Modbus请求报文存入发送请求队列中。Store the sent Modbus request message in the send request queue.
在一种示例性实施例中,在生成n条Modbus请求报文的步骤之后且按照预设顺序批量发送所述n条Modbus请求报文的步骤之前,所述方法还包括:In an exemplary embodiment, after the step of generating n Modbus request messages and before the step of sending the n Modbus request messages in batches in a preset order, the method further includes:
配置n条Modbus请求报文中的一条或多条为关键请求报文。Configure one or more of the n Modbus request messages as key request messages.
在一种示例性实施例中,每两条发送的Modbus请求报文之间设置预设的发送间隔时间,以方便从站辨识不同的请求并且使得从站能处理的过来。In an exemplary embodiment, a preset sending interval is set between every two sent Modbus request packets, so as to facilitate the slave station to identify different requests and enable the slave station to process them.
在一种示例性实施例中,主站在顺序发送前n-1个请求报文时,均不启动超时TimeOut定时器,只在发送第n条请求报文后才启动TimeOut定时器。In an exemplary embodiment, the master station does not start the timeout TimeOut timer when sending the first n-1 request messages in sequence, and starts the TimeOut timer only after sending the nth request message.
步骤602:在预设的超时时间间隔内,接收返回的m条Modbus应答报文,并根据接收的Modbus应答报文判定本次批量发送是否成功,其中,m为0至n之间的整数。Step 602: Receive m returned Modbus response messages within a preset timeout interval, and determine whether the batch transmission is successful according to the received Modbus response messages, where m is an integer between 0 and n.
需要说明的是,由于Modbus TCP协议与Modbus RTU协议具有以下不同点:It should be noted that, because the Modbus TCP protocol and the Modbus RTU protocol have the following differences:
1、物理上以太网TCP协议为全双工,在以太网上的通信节点可同时接收和发送;1. Physically, the Ethernet TCP protocol is full-duplex, and the communication nodes on the Ethernet can receive and send at the same time;
2、作为TCP的应用层协议,Modbus TCP协议报文中包含“包序号”字段(即顺序号),主从双方都可以利用“包序号”来清晰的辨识接收数据流中一条条的Modbus TCP报文;2. As the application layer protocol of TCP, the Modbus TCP protocol message contains the "packet sequence number" field (ie sequence number), and both the master and the slave can use the "packet sequence number" to clearly identify the Modbus TCP in the received data stream. message;
因此,在对接收的Modbus TCP应答报文进行解析时,可以根据Modbus TCP应答报文中的包序号字段及报文的具体内容进行解析;在对接收的Modbus RTU应答报文进行解析时,可以根据Modbus RTU应答报文的具体内容进行解析。Therefore, when parsing the received Modbus TCP response message, it can be parsed according to the packet sequence number field in the Modbus TCP response message and the specific content of the message; when parsing the received Modbus RTU response message, it can be Analyze according to the specific content of the Modbus RTU response message.
在一种示例性实施例中,在接收返回的m条Modbus应答报文的步骤之后,所述方法还包括:In an exemplary embodiment, after the step of receiving the returned m Modbus response messages, the method further includes:
确定每条Modbus应答报文对应的Modbus请求报文,并修改发送请求队列中对应的Modbus请求报文的接收标志RF(Response Flag,0为初始态,1表示本请求已经成功收到设备应答,RF1,RF2,……,RFn分别表示请求1,2,……n的接收标志)。Determine the Modbus request message corresponding to each Modbus response message, and modify the reception flag RF (Response Flag, 0 is the initial state of the corresponding Modbus request message in the sending request queue, 1 indicates that the request has successfully received the device response, RF1, RF2, ..., RFn represent the reception flags of
在一种示例性实施例中,所述根据接收的Modbus应答报文判定本次批量发送是否成功,包括:In an exemplary embodiment, determining whether the batch transmission is successful this time according to the received Modbus response message includes:
如果在预设的超时时间间隔内接收到了与所有发送的Modbus请求报文一一对应的Modbus应答报文,则判定本次批量发送成功;If a Modbus response message corresponding to all sent Modbus request messages is received within the preset timeout interval, it is determined that the batch transmission is successful;
如果在预设的超时时间间隔内没有接收到与所有发送的Modbus请求报文一一对应的Modbus应答报文,则判定本次批量发送失败。If no Modbus response message corresponding to all sent Modbus request messages is received within the preset timeout interval, it is determined that the batch sending fails.
在另一种示例性实施例中,所述根据接收的Modbus应答报文判定本次批量发送是否成功,包括:In another exemplary embodiment, the determining whether the batch transmission is successful this time according to the received Modbus response message includes:
如果在预设的超时时间间隔内接收到了与所有关键请求报文一一对应的Modbus应答报文,则判定本次批量发送成功;If a Modbus response message corresponding to all key request messages is received within the preset timeout interval, it is determined that the batch transmission is successful;
如果在预设的超时时间间隔内没有接收到与所有关键请求报文一一对应的Modbus应答报文,则判定本次批量发送失败。If no Modbus response message corresponding to all key request messages is received within the preset timeout interval, it is determined that this batch transmission fails.
在一种示例性实施例中,所述方法还包括:In an exemplary embodiment, the method further includes:
如果判定本次批量发送成功,删除发送请求队列中所述发送的Modbus请求报文及其标志;If it is determined that this batch transmission is successful, delete the Modbus request message and its flag sent in the transmission request queue;
如果判定本次批量发送失败,检测是否需要重发;如果需要重发,按照预设顺序重新批量发送所述n条Modbus请求报文;如果不需要重发,删除发送请求队列中所述发送的Modbus请求报文及其标志。If it is determined that this batch transmission fails, check whether it needs to be retransmitted; if retransmission is required, retransmit the n Modbus request messages in batches according to the preset order; Modbus request message and its flags.
在一种示例性实施例中,我们假设某个操作,需要包含n次请求/应答才能完成的,对应的n次请求和应答分别记为:Q1/R1,Q2/R2,……,Qn/Rn。In an exemplary embodiment, we assume that an operation needs to include n requests/responses to complete, and the corresponding n requests and responses are respectively recorded as: Q1/R1, Q2/R2, ..., Qn/ Rn.
如图7所示,主站首先检查当前是否需要批量发送请求,如果不需要,则进入主从常规通信流程;如果需要,则进入批量发送请求流程。As shown in Figure 7, the master station first checks whether batch sending requests are currently required, and if not, it enters the master-slave conventional communication process; if necessary, it enters the batch sending request process.
示例性地,在批量发送请求流程中,如果使用的是Modbus TCP协议,先顺序生成此次需要批量发送的n个请求Q1,Q2,……,Qn,然后依次发送请求Q1,Q2,……,Qn,每成功发送一个请求,就把该请求保存到本地第一发送请求列表(Array of Querys Sent,简称AQS),在AQS中还包括RF(Response Flag,初始值为0)和KQ(Key Query,1表示该请求是否关键请求,默认值为1,所有请求的KQ为1表示所有请求都需要返校),并以“包序号”作为AQS的下标索引(我们记这n次请求和应答对应的“包序号”分别为SN1,SN2,……,SNn)。注意,在这n个请求中两个请求之间通常需要有一定的发送间隔时间(记为T0),原因是方便从站辨识不同的请求并且使得从站能处理的过来,T0默认5毫秒并且可调节配置,T0的最小可用值往往取决于从站设备,一般T0由从站方直接给出或者根据实际测试给出。特别说明,T0为设备属性参数,绝非本专利所特别要求或者依赖的特殊参数,这里不再进一步阐述。主站在依次发送成功所有n个请求Q1,Q2,……,Qn后,启动超时定时器,超时时间TimeOut(TimeOut一般为1000毫秒,可配置)。设备在收到请求序列后,会依次应答R1,R2,……,Rn,主站从接收数据流中,根据AQS中的发送信息特别是发送信息中的“包序号”来依次解析出R1,R2,……,Rn,并置相应的返校值RF为1以表示主站成功接收到了R1,R2,……,Rn。主站在每次接收处理后,均检查AQS中所有KQ为1的请求的RF值,如果主站在TimeOut时间内,所有KQ为1的请求的RF均为1了,则表示成功接收了全部关键请求的应答,由于通常所有请求的KQ都为1(可配置),因此通常就意味着接收了全部请求R1,R2,……,Rn的应答,此时,中止TimeOut定时器,并宣告此次批量请求发送事务成功,进入下一轮发送事务;如果在TimeOut超时定时器到达时,只要AQS中任意一个KQ为1的请求的RF不为1,则表示未能成功接收全部关键请求的应答,则宣告此次批量请求发送失败,如果需要重发,则进入重发流程,如果不重发,清除AQS及其标志,则进入下一轮发送事务。Exemplarily, in the batch sending request process, if the Modbus TCP protocol is used, firstly generate n requests Q1, Q2, . , Qn, every time a request is successfully sent, the request is saved to the local first sending request list (Array of Querys Sent, AQS for short), and AQS also includes RF (Response Flag, the initial value is 0) and KQ (Key Query, 1 indicates whether the request is a critical request, the default value is 1, the KQ of all requests is 1, indicating that all requests need to be returned to school), and the "package number" is used as the subscript index of AQS (we record the n requests and The "packet sequence numbers" corresponding to the responses are SN1, SN2, ..., SNn). Note that in these n requests, there is usually a certain sending interval (denoted as T0) between two requests, because it is convenient for the slave to identify different requests and enable the slave to process it. T0 defaults to 5 milliseconds and Adjustable configuration, the minimum available value of T0 often depends on the slave device, generally T0 is given directly by the slave side or given according to actual tests. It is specially stated that T0 is a device attribute parameter, which is by no means a special parameter specifically required or relied on by this patent, and will not be further elaborated here. After the master station successfully sends all n requests Q1, Q2, ..., Qn in sequence, it starts the timeout timer with the timeout time TimeOut (TimeOut is generally 1000 milliseconds, configurable). After the device receives the request sequence, it will respond to R1, R2, ..., Rn in turn. The master station parses out R1 in turn from the received data stream according to the sending information in AQS, especially the "packet sequence number" in the sending information. R2,...,Rn, and juxtapose the corresponding return value RF to 1 to indicate that the master station has successfully received R1, R2,..., Rn. After each receiving process, the master station checks the RF value of all requests with KQ of 1 in AQS. If the master station has the RF value of all requests with KQ of 1 to 1 within the TimeOut time, it means that all requests have been successfully received. The response of the key request, because the KQ of all requests is usually 1 (configurable), it usually means that all the responses of R1, R2, ..., Rn are received. At this time, the TimeOut timer is aborted and this The second batch of requests to send the transaction is successful and enter the next round of sending transactions; if the TimeOut timeout timer arrives, as long as the RF of any request whose KQ is 1 in the AQS is not 1, it means that the response to all key requests has not been successfully received. , it declares that the batch request failed to be sent. If it needs to be retransmitted, it will enter the retransmission process. If it does not retransmit, clear the AQS and its flag, and then enter the next round of sending transactions.
示例性地,在批量发送请求流程中,如果使用的是Modbus RTU协议,主站生成n条顺序发送报文(这n条顺序报文依次记为Q1,Q2,…,Qn-1,Qn),这些请求在发送前存入本地第二发送请求列表(记为TM,TM中包含Q1,Q2,…,Qn-1,Qn有效信息,每个请求还包括RF和KQ标志,RF和KQ含义及用法同上)(也可以在主站依次发送成功后将这些请求存入本地第二发送请求列表TM)。主站在依次发送成功所有n个请求Q1,Q2,……,Qn后,启动超时定时器,超时时间TimeOut(TimeOut一般为1000毫秒,可配置)。设备在收到请求序列后,会依次应答R1,R2,……,Rn,主站从接收数据流中,根据TM中的发送信息来依次解析出R1,R2,……,Rn,并置相应的返校值RF为1以表示主站成功接收到了R1,R2,……,Rn。主站在每次接收处理后,均检查TM中所有KQ为1的请求的RF值,如果主站在TimeOut时间内,所有KQ为1的请求的RF均为1了,则表示成功接收了全部关键请求的应答,由于通常所有请求的KQ都为1(可配置),因此通常就意味着接收了全部请求R1,R2,……,Rn的应答,此时,中止TimeOut定时器,并宣告此次批量请求发送事务成功,进入下一轮发送事务;如果在TimeOut超时定时器到达时,只要TM中任意一个KQ为1的请求的RF不为1,则表示未能成功接收全部关键请求的应答,则宣告此次批量请求发送失败,如果需要重发,则进入重发流程,如果不重发,清除TM及其标志,并进入新一轮应答过程。显然,当n=1时,本申请与常规的一问一答方式完全一致。Exemplarily, in the batch sending request process, if the Modbus RTU protocol is used, the master station generates n sequential sending messages (the n sequential messages are sequentially recorded as Q1, Q2,..., Qn-1, Qn) , these requests are stored in the local second sending request list (denoted as TM, TM contains Q1, Q2, ..., Qn-1, Qn valid information, each request also includes RF and KQ flags, RF and KQ meanings And the usage is the same as above) (the requests can also be stored in the local second sending request list TM after the master station sends the requests in sequence successfully). After the master station successfully sends all n requests Q1, Q2, ..., Qn in sequence, it starts the timeout timer with the timeout time TimeOut (TimeOut is generally 1000 milliseconds, configurable). After the device receives the request sequence, it will respond to R1, R2, ..., Rn in sequence, and the master station will parse out R1, R2, ..., Rn in turn from the received data stream according to the sent information in the TM, and juxtapose the corresponding The return value of RF is 1 to indicate that the master station has successfully received R1, R2, ..., Rn. The master station checks the RF value of all requests with KQ of 1 in the TM after each receiving and processing. If the master station has the RF value of all requests with KQ of 1 to 1 within the TimeOut time, it means that all requests have been successfully received. The response of the key request, because the KQ of all requests is usually 1 (configurable), it usually means that all the responses of R1, R2, ..., Rn are received. At this time, the TimeOut timer is aborted and this The second batch of requests to send the transaction is successful, and the next round of sending transactions is entered; if the TimeOut timeout timer arrives, as long as the RF of any request whose KQ is 1 in the TM is not 1, it means that the response to all key requests has not been successfully received. , it declares that the batch request failed to be sent. If it needs to be retransmitted, it will enter the retransmission process. If it does not retransmit, clear the TM and its flag, and enter a new round of response process. Obviously, when n=1, this application is completely consistent with the conventional one-question-one-answer method.
如图8所示,主站按照本申请的批量传输方案,批量持续发送四个请求,从站依次顺序辨识这四个请求,并依次给主站回复相应的四个应答报文,本图较为形象的表示了本申请执行批量请求时的异步并发处理效果。异步是指一个请求后并不需要等待应答就能发送下一个请求;并发是指在一段连续的时间内,主站持续发送多个请求而期间无设备应答。As shown in Figure 8, the master station continuously sends four requests in batches according to the batch transmission scheme of the present application. The slave station identifies the four requests in sequence and replies to the master station with corresponding four response messages. Visually represents the asynchronous concurrent processing effect when the application executes batch requests. Asynchronous means that the next request can be sent without waiting for a response after a request; concurrency means that in a continuous period of time, the master station continues to send multiple requests without the device responding.
实施例二批量数据传输装置
本发明实施例还提供了一种批量数据传输装置,包括处理器及存储器,其中:所述处理器用于执行存储器中存储的程序,以实现如以上任一项所述的批量数据传输方法的步骤。An embodiment of the present invention further provides a batch data transmission apparatus, including a processor and a memory, wherein: the processor is configured to execute a program stored in the memory, so as to implement the steps of the method for batch data transmission as described in any of the above .
实施例三批量数据传输装置
如图11所示,本发明实施例还提供了一种批量数据传输装置,包括批量发送模块1101和批量接收模块1102,其中:As shown in FIG. 11, an embodiment of the present invention further provides a batch data transmission device, including a
批量发送模块1101,用于生成n条Modbus请求报文,并按照预设顺序批量发送所述n条Modbus请求报文,其中,n为大于或等于1的整数;The
批量接收模块1102,用于在预设的超时时间间隔内,接收返回的m条Modbus应答报文,并根据接收的Modbus应答报文判定本次批量发送是否成功,其中,m为0至n之间的整数。The
在一种示例性实施例中,所述Modbus请求报文包括Modbus RTU报文或Modbus TCP报文;所述Modbus应答报文包括Modbus RTU报文或Modbus TCP报文。In an exemplary embodiment, the Modbus request message includes a Modbus RTU message or a Modbus TCP message; the Modbus response message includes a Modbus RTU message or a Modbus TCP message.
在一种示例性实施例中,当所述Modbus请求报文和所述Modbus应答报文为ModbusTCP报文时,批量发送模块1101每成功发送一个请求报文,就把该请求报文保存到本地第一发送请求列表AQS,在AQS中包含n个请求报文的有效信息,另外,还包括每个请求报文的RF和KQ标志,其中,RF标志用于指示是否收到与该请求报文对应的应答报文,KQ标志用于指示该请求报文是否为关键请求报文。In an exemplary embodiment, when the Modbus request message and the Modbus response message are ModbusTCP messages, each time the
在一种示例性实施例中,当所述Modbus请求报文和所述Modbus应答报文为ModbusRTU报文时,批量发送模块1101将生成的n条请求报文在发送前存入本地第二发送请求列表TM,或者,在主站批量发送成功后将这些请求报文依次存入TM;在TM中包含n个请求报文的有效信息,另外,还包括每个请求报文的RF和KQ标志,其中,RF标志用于指示是否收到与该请求报文对应的应答报文,KQ标志用于指示该请求报文是否为关键请求报文。In an exemplary embodiment, when the Modbus request message and the Modbus response message are Modbus RTU messages, the
在一种示例性实施例中,所述批量发送模块1101还用于:In an exemplary embodiment, the
在按照预设顺序批量发送所述n条Modbus请求报文时,设置独占标识,所述独占标识用于在批量发送所述n条Modbus请求报文的过程中,禁止除所述n条Modbus请求报文之外的其他报文的发送。When sending the n Modbus request messages in batches according to the preset order, an exclusive flag is set, and the exclusive flag is used to prohibit the removal of the n Modbus request messages during the process of sending the n Modbus request messages in batches The sending of other messages other than the message.
在一种示例性实施例中,假设批量发送模块1101发送所述n条Modbus请求报文的时间为TAb,批量接收模块1102完成n次批量发送和接收的时间为TBb,则:In an exemplary embodiment, assuming that the time when the
TAb=(n-1)*(Ta+T0)+Ta,TAb=(n-1)*(Ta+T0)+Ta,
TBb=(n-1)*(Ta+T0)+Ts,TBb=(n-1)*(Ta+T0)+Ts,
其中:*为乘号,Ta为从主站发送一个请求报文起,到从站收到请求报文的时间间隔;Among them: * is the multiplication number, Ta is the time interval from the time the master station sends a request message to the slave station receives the request message;
T0为主站发送间隔时间;T0 sends the interval time to the master station;
Ts=Ta+Tb+Tc;Ts=Ta+Tb+Tc;
Tb为从站对该请求报文进行内部处理的时间消耗;Tb is the time consumption for the internal processing of the request message by the slave station;
Tc为从从站给主站发送一个应答报文起,到主站收到从站应答报文的时间间隔。Tc is the time interval from when the slave station sends a response message to the master station until the master station receives the response message from the slave station.
在一种示例性实施例中,批量发送模块1101在顺序发送前n-1个请求报文时,均不启动超时TimeOut定时器,只在发送第n条请求报文后才启动TimeOut定时器。In an exemplary embodiment, the
在一种示例性实施例中,所述批量发送模块1101还用于:In an exemplary embodiment, the
在按照预设顺序批量发送所述n条Modbus请求报文之后,将所述发送的Modbus请求报文存入发送请求队列中。After the n Modbus request messages are sent in batches according to the preset sequence, the sent Modbus request messages are stored in the sending request queue.
在一种示例性实施例中,所述批量发送模块1101还用于:配置所述n条Modbus请求报文中的一条或多条为关键请求报文。In an exemplary embodiment, the
在一种示例性实施例中,所述批量发送模块1101发送的每两条Modbus请求报文之间设置预设的发送间隔时间,以方便从站辨识不同的请求并且使得从站能处理的过来。In an exemplary embodiment, a preset sending interval is set between each two Modbus request packets sent by the
在一种示例性实施例中,所述批量接收模块1102还用于:In an exemplary embodiment, the
确定每条Modbus应答报文对应的Modbus请求报文,并修改所述发送请求队列中对应的Modbus请求报文的接收标志。Determine the Modbus request message corresponding to each Modbus response message, and modify the reception flag of the corresponding Modbus request message in the sending request queue.
在一种示例性实施例中,所述批量接收模块1102的根据接收的Modbus应答报文判定本次批量发送是否成功,包括:In an exemplary embodiment, the
如果在预设的超时时间间隔内接收到了与所有发送的Modbus请求报文一一对应的Modbus应答报文,则判定本次批量发送成功;If a Modbus response message corresponding to all sent Modbus request messages is received within the preset timeout interval, it is determined that the batch transmission is successful;
如果在预设的超时时间间隔内没有接收到与所有发送的Modbus请求报文一一对应的Modbus应答报文,则判定本次批量发送失败。If no Modbus response message corresponding to all sent Modbus request messages is received within the preset timeout interval, it is determined that this batch transmission fails.
在另一种示例性实施例中,所述批量接收模块1102的根据接收的Modbus应答报文判定本次批量发送是否成功,包括:In another exemplary embodiment, determining whether the batch sending this time is successful according to the received Modbus response message by the
如果在预设的超时时间间隔内接收到了与所有关键请求报文一一对应的Modbus应答报文,则判定本次批量发送成功;If a Modbus response message corresponding to all key request messages is received within the preset timeout interval, it is determined that the batch transmission is successful;
如果在预设的超时时间间隔内没有接收到与所有关键请求报文一一对应的Modbus应答报文,则判定本次批量发送失败。If no Modbus response message corresponding to all key request messages is received within the preset timeout interval, it is determined that this batch transmission fails.
在一种示例性实施例中,所述批量接收模块1102还用于:In an exemplary embodiment, the
如果判定本次批量发送成功,删除发送请求队列中所述发送的Modbus请求报文;If it is determined that this batch transmission is successful, delete the Modbus request message sent in the sending request queue;
如果判定本次批量发送失败,检测是否需要重发;如果需要重发,按照预设顺序重新批量发送所述n条Modbus请求报文;如果不需要重发,删除所述发送请求队列中所述发送的Modbus请求报文。If it is determined that this batch transmission fails, check whether retransmission is required; if retransmission is required, retransmit the n Modbus request messages in batches according to the preset order; if retransmission is not required, delete the description in the transmission request queue Modbus request message sent.
采用本申请的批量传输方案后,下一次的发送只需等待上次发送完成后就能进行,第1~(n-1)发送的时间均为(Ta+T0),第n次的发送时间为Ta,即TAb=(n-1)*(Ta+T0)+Ta。下面,我们来计算TBb,我们只需要计算第n个请求发送后的,主站收到它的应答时的时刻(记为TimeN)就能计算出TBb了,因为,应答通信协议的一个特点是先问先得、依次应答,所以只要主站收到第n个请求的应答,说明在此之前主站一定收齐了前面(n-1)个请求的全部应答。按照约定,任意一个请求的发送/接收时间为Ts=Ta+Tb+Tc,因此,本申请中,第n次的发送/接收时间也为Ts。因此:After the batch transmission scheme of the present application is adopted, the next transmission only needs to wait for the completion of the previous transmission. is Ta, that is, TAb=(n-1)*(Ta+T0)+Ta. Next, let's calculate TBb. We only need to calculate the time when the master station receives its response after the nth request is sent (recorded as TimeN) to calculate TBb, because one of the characteristics of the response communication protocol is First ask, first serve, and answer in sequence, so as long as the master station receives the response of the nth request, it means that the master station must have received all the responses of the previous (n-1) requests before that. According to the agreement, the sending/receiving time of any request is Ts=Ta+Tb+Tc. Therefore, in this application, the n-th sending/receiving time is also Ts. therefore:
TAb=(n-1)*(Ta+T0)+Ta-------(3)TAb=(n-1)*(Ta+T0)+Ta-------(3)
TBb=(n-1)*(Ta+T0)+Ts-------(4)TBb=(n-1)*(Ta+T0)+Ts-------(4)
特别说明,以下表示和计算中,我们隐去单位,注意,时间单位为毫秒。In particular, in the following representations and calculations, we hide the unit, and note that the time unit is milliseconds.
为了便于区别,我们特别的记在使用传统的串口通信时,TA为TAa1,TB为TBa1;记在使用传统的Modbus TCP协议通信时,TA为TAa2,TB为TBa2。In order to facilitate the distinction, we specially note that when using traditional serial communication, TA is TAa1 and TB is TBa1; when using traditional Modbus TCP protocol communication, TA is TAa2 and TB is TBa2.
在串口通信模式下,一般地:In serial communication mode, generally:
Ta=8,Tb∈[5,20],Tc∈[6,256],T0∈[0,100].Ta=8, Tb ∈ [5, 20], Tc ∈ [6, 256], T0 ∈ [0, 100].
我们取以上四个参数的最小值,即:Ta=8,Tb=5,Tc=6,T0=0,可得Ts=19,代入公式(1)~(4),可得:We take the minimum value of the above four parameters, namely: Ta=8, Tb=5, Tc=6, T0=0, we can get Ts=19, and substitute it into formulas (1) to (4), we can get:
TAa 1=19n-11-------(5)
TBa 1=19n-----------(6)
TAb1=8n------------(7)TAb1=8n------------(7)
TBb1=8n+11--------(8)TBb1=8n+11-------(8)
当n=1时,显然,TAa1=TAb1=8=Ta;TBa1=TBb1=19=Ts。When n=1, obviously, TAa1=TAb1=8=Ta; TBa1=TBb1=19=Ts.
当n=6时,TAa1=103,TBa1=114;TAb1=48,TBb1=59。When n=6, TAa1=103, TBa1=114; TAb1=48, TBb1=59.
我们取以上四个参数的最大值,即:Ta=8,Tb=20,Tc=256,T0=100,可得Ts=284,代入公式(1)~(4),可得:We take the maximum value of the above four parameters, namely: Ta=8, Tb=20, Tc=256, T0=100, we can get Ts=284, and substitute it into formulas (1) to (4), we can get:
TAa1=292n-284-------(9)TAa1=292n-284-------(9)
TBa 1=292n-8---------(10)
TAb1=108n-100------(11)TAb1=108n-100------(11)
TBb1=108n+176------(12)TBb1=108n+176------(12)
当n=1时,显然,TAa1=TAb1=8=Ta;TBa1=TBb1=284=Ts。When n=1, obviously, TAa1=TAb1=8=Ta; TBa1=TBb1=284=Ts.
当n=6时,TAa1=1468,TBa1=1744,TAb1=548,TBb1=824。When n=6, TAa1=1468, TBa1=1744, TAb1=548, TBb1=824.
我们取以上四个参数为典型代表值,即:Ta=8,Tb=10,Tc=8,T0=5,可得Ts=26,代入公式(1)~(4),可得:We take the above four parameters as typical representative values, namely: Ta=8, Tb=10, Tc=8, T0=5, we can get Ts=26, and substituting into formulas (1) to (4), we can get:
TAa1=31n-23-------(13)TAa1=31n-23-------(13)
TBa1=31n-5--------(14)TBa1=31n-5-------(14)
TAb1=13n-5--------(15)TAb1=13n-5-------(15)
TBb1=13n+13------(16)TBb1=13n+13------(16)
当n=1时,显然,TAa1=TAb1=8=Ta;TBa1=TBb1=26=Ts。When n=1, obviously, TAa1=TAb1=8=Ta; TBa1=TBb1=26=Ts.
当n=6时,TAa1=163,TBa1=181,TAb1=73,TBb1=91。When n=6, TAa1=163, TBa1=181, TAb1=73, TBb1=91.
当将本申请的批量传输方案应用于上述应用场景1:遥控场景时,如图9所示,主站批量持续发送六个请求,从站依次顺序辨识这六个请求,并依次给主站回复相应的六个应答报文。在典型场景(Ta=8,Tb=10,Tc=8,T0=5)下,使用常规的一对一发送方法时,发送一轮全部遥控事务(TAa)需要163毫秒;使用本申请的批量传输方案时,则只需要73毫秒,相当于常规发送时间的45%;使用常规的一对一发送方法时,完成一轮全部遥控事务(TAb)需要181毫秒;使用本申请的批量传输方案时,则只需要91毫秒,相当于常规完成时间的50%;When the batch transmission scheme of the present application is applied to the above application scenario 1: remote control scenario, as shown in Figure 9, the master station continuously sends six requests in batches, and the slave stations identify the six requests in sequence and reply to the master station in turn The corresponding six response packets. In a typical scenario (Ta=8, Tb=10, Tc=8, T0=5), when using the conventional one-to-one sending method, it takes 163 milliseconds to send a round of all remote control transactions (TAa); When the transmission scheme is used, it only takes 73 milliseconds, which is equivalent to 45% of the normal transmission time; when using the conventional one-to-one transmission method, it takes 181 milliseconds to complete a round of all remote transactions (TAb); when using the batch transmission scheme of this application , it only takes 91 milliseconds, which is equivalent to 50% of the normal completion time;
当将本申请的批量传输方案应用于上述应用场景2:校时场景时,如图10所示,主站批量持续发送六个请求,从站依次顺序辨识这六个请求,并依次给主站回复相应的六个应答报文。在此场景下,我们更应该关注设备收到全部命令的时间,显然,这个值等于TA。在典型场景(Ta=8,Tb=10,Tc=8,T0=5)下,使用常规的一对一发送方法时,发送一轮全部遥控事务(TAa)需要163毫秒;使用本申请的批量传输方案时,则只需要73毫秒,相当于常规发送时间的45%;使用常规的一对一发送方法时,完成一轮全部遥控事务(TAb)需要181毫秒;使用本申请的批量传输方案时,则只需要91毫秒,相当于常规完成时间的50%。进一步地,由于TAb=(n-1)*(Ta+T0)+Ta,对于主站而言,n已知,如前所述,在串口通信下,Ta仅和传输字节和波特率相关,因此T0也已知。我们可以提前计算出TAb=(n-1)*(Ta+T0)+Ta的值,并由主站进行时间补偿,报文中的时间=主站时间+TAb,通过主站的时间补偿,在使用本申请的批量传输方案时,在串口全双工通信时,完全避免了延迟给从站校时所带来的误差。而在常规发送方法下,TAa=(n-1)ⅹ(Ts+T0)+Ta=(n-1)*(Ta+Tb+Tc+T0)+Ta,由于Tb不是常量,这为主站的补偿带来较大难度和误差。When the batch transmission scheme of the present application is applied to the above application scenario 2: time school scenario, as shown in Figure 10, the master station continuously sends six requests in batches, and the slave stations identify the six requests in sequence and send them to the master station in turn. Reply to the corresponding six response packets. In this scenario, we should pay more attention to the time when the device receives all commands. Obviously, this value is equal to TA. In a typical scenario (Ta=8, Tb=10, Tc=8, T0=5), when using the conventional one-to-one sending method, it takes 163 milliseconds to send a round of all remote control transactions (TAa); When the transmission scheme is used, it only takes 73 milliseconds, which is equivalent to 45% of the normal transmission time; when using the conventional one-to-one transmission method, it takes 181 milliseconds to complete a round of all remote transactions (TAb); when using the batch transmission scheme of this application , it only takes 91 milliseconds, which is equivalent to 50% of the normal completion time. Further, since TAb=(n-1)*(Ta+T0)+Ta, for the master station, n is known. As mentioned above, under serial communication, Ta is only related to the transmission bytes and baud rate correlation, so T0 is also known. We can calculate the value of TAb=(n-1)*(Ta+T0)+Ta in advance, and make time compensation by the master station, the time in the message=master station time+TAb, through the time compensation of the master station, When the batch transmission scheme of the present application is used, the error caused by the delay to the time calibration of the slave station is completely avoided during the full-duplex communication of the serial port. In the conventional transmission method, TAa=(n-1)ⅹ(Ts+T0)+Ta=(n-1)*(Ta+Tb+Tc+T0)+Ta, since Tb is not constant, this is the master station The compensation brings greater difficulty and error.
在TCP/IP以太网通信时,在短报文(1024字节以下)传输的情况下,Ta和Tc往往只对网络延迟敏感,和报文长度基本无关。由于Modbus TCP的最大报文长度仅为260字节,在局域网下,Ta和Tc的取值范围通常为1~10毫秒。Tb则和从站设备有关,取决于设备硬件性能及其软件处理能力,一般Tb在5~20毫秒之间。即,在工业局域网中,一般地:In TCP/IP Ethernet communication, in the case of transmission of short messages (below 1024 bytes), Ta and Tc are often only sensitive to network delay, and have little to do with message length. Since the maximum message length of Modbus TCP is only 260 bytes, in a local area network, the value range of Ta and Tc is usually 1 to 10 milliseconds. Tb is related to the slave device, depending on the hardware performance of the device and its software processing capability. Generally, Tb is between 5 and 20 milliseconds. That is, in an industrial LAN, generally:
Ta∈[1,10],Tb∈[5,20],Tc∈[1,10],T0∈[0,100].Ta ∈ [1, 10], Tb ∈ [5, 20], Tc ∈ [1, 10], T0 ∈ [0, 100].
我们取以上四个参数的最小值,即:Ta=1,Tb=5,Tc=1,T0=0,可得Ts=7,代入公式(1)~(4),可得:We take the minimum value of the above four parameters, namely: Ta=1, Tb=5, Tc=1, T0=0, we can get Ts=7, and substitute it into formulas (1) to (4), we can get:
TAa2=7n-6-------(17)TAa2=7n-6-------(17)
TBa 2=7n---------(18)
TAb2=n----------(19)TAb2=n-------(19)
TBb2=n+6-------(20)TBb2=n+6-------(20)
当n=1时,显然,TAa2=TAb2=1=Ta;TBa2=TBb2=7=Ts。When n=1, obviously, TAa2=TAb2=1=Ta; TBa2=TBb2=7=Ts.
当n=6时,TAa2=36,TBa2=42;TAb2=6,TBb2=12。When n=6, TAa2=36, TBa2=42; TAb2=6, TBb2=12.
我们取以上四个参数的最大值,即:Ta=10,Tb=20,Tc=10,T0=100,可得Ts=40,代入公式(1)~(4),可得:We take the maximum value of the above four parameters, namely: Ta=10, Tb=20, Tc=10, T0=100, we can get Ts=40, and substitute it into formulas (1) to (4), we can get:
TAa 2=140n-130-------(21)
TBa 2=140n-100-------(22)
TAb 2=110n-100-------(23)
TBb 2=110n-70--------(24)
当n=1时,显然,TAa2=TAb2=10=Ta;TBa2=TBb2=40=Ts。When n=1, obviously, TAa2=TAb2=10=Ta; TBa2=TBb2=40=Ts.
当n=6时,TAa2=710,TBa2=740,TAb2=560,TBb2=590。When n=6, TAa2=710, TBa2=740, TAb2=560, TBb2=590.
我们取以上四个参数为典型代表值,即:Ta=2,Tb=10,Tc=2,T0=5,可得Ts=14,代入公式(1)~(4),可得:We take the above four parameters as typical representative values, namely: Ta=2, Tb=10, Tc=2, T0=5, we can get Ts=14, and substitute them into formulas (1) to (4), we can get:
TAa2=16n-14-------(25)TAa2=16n-14-------(25)
TBa2=16n-2--------(26)TBa2=16n-2-------(26)
TAb2=7n-5---------(27)TAb2=7n-5---------(27)
TBb2=7n+7---------(28)TBb2=7n+7---------(28)
当n=1时,显然,TAa2=TAb2=2=Ta;TBa2=TBb2=14=Ts。When n=1, obviously, TAa2=TAb2=2=Ta; TBa2=TBb2=14=Ts.
当n=6时,TAa2=82,TBa2=94,TAb2=37,TBb2=49。When n=6, TAa2=82, TBa2=94, TAb2=37, TBb2=49.
当将本申请的批量传输方案应用于上述应用场景1:遥控场景时,在典型场景(Ta=2,Tb=10,Tc=2,T0=5)下,使用常规的一对一发送方法时,发送一轮全部遥控事务(TAa2)需要82毫秒;使用本申请的批量传输方案时,则只需要37毫秒,相当于常规发送时间的45%;使用常规的一对一发送方法时,完成一轮全部遥控事务(TAb2)需要94毫秒;使用本申请的批量传输方案时,则只需要49毫秒,相当于常规完成时间的52%;When the batch transmission scheme of the present application is applied to the above application scenario 1: remote control scenario, in a typical scenario (Ta=2, Tb=10, Tc=2, T0=5), when using the conventional one-to-one transmission method , it takes 82 milliseconds to send one round of all remote control transactions (TAa2); when using the batch transmission scheme of the present application, it only takes 37 milliseconds, which is equivalent to 45% of the normal sending time; when using the conventional one-to-one sending method, one It takes 94 milliseconds to complete all remote transactions (TAb2); when using the batch transmission scheme of this application, it only takes 49 milliseconds, which is equivalent to 52% of the normal completion time;
当将本申请的批量传输方案应用于上述应用场景2:校时场景时,在此场景下,我们更应该关注设备收到全部命令的时间,显然,这个值等于TA。在典型场景(Ta=2,Tb=10,Tc=2,T0=5)下,使用常规的一对一发送方法时,发送一轮全部遥控事务(TAa2)需要82毫秒;使用本申请的批量传输方案时,则只需要37毫秒,相当于常规发送时间的45%。进一步地,由于TAb=(n-1)(Ta+T0)+Ta,对于主站而言,n已知,T0已知,剩下唯一的变量Ta,如前所述,在局域网下,Ta仅和网络延迟相关,大部分情况下Ta都是围绕一个定值T0’窄幅震荡,我们可以提前计算出TAb’=(n-1)*(Ta+T0’)+Ta的值,并由主站进行时间补偿,报文中的时间=主站时间+TAb’,通过主站的时间补偿,使用本申请的批量传输方案时,极大地减免了延迟给从站校时所带来的误差。而在常规的一对一发送方法下,TAa=(n-1)*(Ts+T0)+Ta=(n-1)*(Ta+Tb+Tc+T0)+Ta,这为主站的补偿带来较大难度和误差。When the batch transmission scheme of the present application is applied to the above application scenario 2: the time school scenario, in this scenario, we should pay more attention to the time when the device receives all commands. Obviously, this value is equal to TA. In a typical scenario (Ta=2, Tb=10, Tc=2, T0=5), when using the conventional one-to-one sending method, it takes 82 milliseconds to send one round of all remote control transactions (TAa2); When the transmission scheme is used, it only takes 37 milliseconds, which is equivalent to 45% of the normal transmission time. Further, since TAb=(n-1)(Ta+T0)+Ta, for the master station, n is known and T0 is known, leaving the only variable Ta. As mentioned above, in the local area network, Ta is It is only related to the network delay. In most cases, Ta oscillates in a narrow range around a fixed value T0'. We can calculate the value of TAb'=(n-1)*(Ta+T0')+Ta in advance, and use The master station performs time compensation, the time in the message = the master station time + TAb', through the time compensation of the master station, when using the batch transmission scheme of this application, the error caused by the delay to the slave station time calibration is greatly reduced . In the conventional one-to-one transmission method, TAa=(n-1)*(Ts+T0)+Ta=(n-1)*(Ta+Tb+Tc+T0)+Ta, which is Compensation brings greater difficulty and error.
本申请实现了一种对Modbus协议的批量发送、批量接收的方法,将常规的一问一答的同步串行模式,转换为批量持续发送、再批量持续接收的异步并发方式,异步是指一个请求后并不需要等待应答就能发送下一个请求;并发是指在一段连续的时间内,主站持续发送多个请求而期间无设备应答。The present application implements a method for batch sending and batch receiving of Modbus protocol, which converts the conventional one-question-one-answer synchronous serial mode into an asynchronous concurrent mode of batch continuous sending and batch continuous receiving. Asynchrony refers to a After a request, the next request can be sent without waiting for a response; concurrency means that in a continuous period of time, the master station continues to send multiple requests without a device responding.
在多步遥控模式下,本申请的批量传输方案可以大幅压缩遥控的发送时间以及完整执行时间;In the multi-step remote control mode, the batch transmission scheme of the present application can greatly compress the sending time and complete execution time of the remote control;
在某些时间敏感的多步操作模式下,例如校时操作,本申请的批量传输方案可以通过主站的时间补偿,极大地减免延迟给从站校时所带来的误差;In some time-sensitive multi-step operation modes, such as time correction operation, the batch transmission scheme of the present application can greatly reduce the error caused by the delay to the time correction of the slave station through the time compensation of the master station;
本申请的批量传输方案简洁易懂,无需依赖高性能的软硬件,适用于任何软件/硬件平台。The batch transmission scheme of the present application is simple and easy to understand, does not need to rely on high-performance software and hardware, and is applicable to any software/hardware platform.
本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统、装置中的功能模块/单元可以被实施为软件、固件、硬件及其适当的组合。在硬件实施方式中,在以上描述中提及的功能模块/单元之间的划分不一定对应于物理组件的划分;例如,一个物理组件可以具有多个功能,或者一个功能或步骤可以由若干物理组件合作执行。某些组件或所有组件可以被实施为由处理器,如数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘(DVD)或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。Those of ordinary skill in the art can understand that all or some of the steps in the methods disclosed above, functional modules/units in the systems, and devices can be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be composed of several physical components Components execute cooperatively. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer-readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). As known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile implemented in any method or technology for storage of information, such as computer readable instructions, data structures, program modules or other data flexible, removable and non-removable media. Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cartridges, magnetic tape, magnetic disk storage or other magnetic storage devices, or may Any other medium used to store desired information and which can be accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and can include any information delivery media, as is well known to those of ordinary skill in the art .
Claims (9)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910559877.7A CN110311847B (en) | 2019-06-26 | 2019-06-26 | Batch data transmission method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910559877.7A CN110311847B (en) | 2019-06-26 | 2019-06-26 | Batch data transmission method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110311847A CN110311847A (en) | 2019-10-08 |
CN110311847B true CN110311847B (en) | 2022-08-05 |
Family
ID=68077594
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910559877.7A Active CN110311847B (en) | 2019-06-26 | 2019-06-26 | Batch data transmission method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110311847B (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111294264B (en) * | 2020-02-17 | 2021-12-24 | 北京和利时系统集成有限公司 | Communication method and device based on Modbus TCP protocol |
CN111245687B (en) * | 2020-03-20 | 2021-11-16 | 北京和利时系统工程有限公司 | Communication state updating method and device |
CN111586182B (en) * | 2020-05-11 | 2023-06-06 | 北京和利时系统集成有限公司 | Data transmission method and device |
CN113746647B (en) * | 2020-05-27 | 2023-12-19 | 中国联合网络通信集团有限公司 | Data transmission method, node, electronic device and readable storage medium |
CN111813733B (en) * | 2020-06-30 | 2022-05-13 | 厦门科灿信息技术有限公司 | Synchronous communication method, system and terminal equipment based on Modbus protocol |
CN114019834B (en) * | 2021-11-03 | 2024-02-09 | 深圳市奥拓普科技有限公司 | Yacht control method, yacht control system, storage medium and intelligent terminal |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104205709A (en) * | 2012-02-28 | 2014-12-10 | 三星电子株式会社 | Apparatus and method for transmitting feedback information in wireless communication systems |
CN106533639A (en) * | 2016-12-06 | 2017-03-22 | 迈锐数据(北京)有限公司 | Data retransmission method and device |
CN106561014A (en) * | 2015-11-18 | 2017-04-12 | 天地融科技股份有限公司 | Data transmission method and system, main communication equipment, and slave communication equipment |
CN109327288A (en) * | 2015-12-14 | 2019-02-12 | 华为技术有限公司 | Data transmission acceleration method, device and system |
CN109379355A (en) * | 2018-10-11 | 2019-02-22 | 无锡威孚力达催化净化器有限责任公司 | Adaptive reliable multiwindow data transmission method based on udp protocol |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8195844B2 (en) * | 2007-09-20 | 2012-06-05 | Siemens Aktiengesellschaft | Systems, devices, and/or methods for managing communications |
CN102820959B (en) * | 2011-06-10 | 2015-08-26 | 哈尔滨工业大学 | In Modbus main website and the method for carrying out big data quantity between slave station and communicating |
US20130294322A1 (en) * | 2012-05-04 | 2013-11-07 | Electronics And Telecommunications Research Institute | Apparatus and method for sequentially transmitting data |
EP2939495A4 (en) * | 2012-12-26 | 2016-08-17 | Ict Res Llc | Mobility extensions to industrial-strength wireless sensor networks |
CN103280814B (en) * | 2013-03-26 | 2016-04-20 | 南京南瑞集团公司 | A kind of wind power plant reactive voltage complex control system and method |
CN108762193A (en) * | 2018-07-31 | 2018-11-06 | 吉林大学 | Numerically controlled machine remote data acquire and analysis system |
-
2019
- 2019-06-26 CN CN201910559877.7A patent/CN110311847B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104205709A (en) * | 2012-02-28 | 2014-12-10 | 三星电子株式会社 | Apparatus and method for transmitting feedback information in wireless communication systems |
CN106561014A (en) * | 2015-11-18 | 2017-04-12 | 天地融科技股份有限公司 | Data transmission method and system, main communication equipment, and slave communication equipment |
CN109327288A (en) * | 2015-12-14 | 2019-02-12 | 华为技术有限公司 | Data transmission acceleration method, device and system |
CN106533639A (en) * | 2016-12-06 | 2017-03-22 | 迈锐数据(北京)有限公司 | Data retransmission method and device |
CN109379355A (en) * | 2018-10-11 | 2019-02-22 | 无锡威孚力达催化净化器有限责任公司 | Adaptive reliable multiwindow data transmission method based on udp protocol |
Also Published As
Publication number | Publication date |
---|---|
CN110311847A (en) | 2019-10-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110311847B (en) | Batch data transmission method and device | |
CN108965484B (en) | Internet of things data transmission method, system and terminal | |
CN110649984B (en) | Clock synchronization method and device, computer storage medium and electronic equipment | |
JP2925678B2 (en) | Data communication method and data communication system | |
CN107835040B (en) | Data communication method, equipment and storage medium based on Bluetooth | |
US8284669B2 (en) | Data acknowledgement apparatus and method | |
CN112214441B (en) | Communication switching method, equipment and system based on serial bus polling protocol | |
CN108243017B (en) | Broadcast implementation method, device and equipment | |
US11889255B2 (en) | Communication method between earphones and charging box, charging box, earphones and readable storage medium | |
US6452946B1 (en) | Apparatus and method for improving performance in master and slave communications systems | |
CN109951366A (en) | A Modbus RTU bus controller and control method | |
US20210144078A1 (en) | Performance measurement using extended bi-directional forwarding control packet | |
CN113645008B (en) | Message protocol timeout retransmission method and system based on linked list | |
CN111083016B (en) | Polling table processing method and device, storage medium and equipment | |
EP3304864A1 (en) | Systems and methods for improved trivial file transfer protocol | |
US6570852B1 (en) | Relay communication system | |
CN115442177B (en) | Data communication method and device of CAN (controller area network) | |
CN109995603B (en) | A method, device and electronic device for packet loss measurement under Tag model | |
US11612007B2 (en) | Low power dissipation Bluetooth mesh network system and communication method | |
CN110099001B (en) | Bidirectional forwarding detection time parameter negotiation method and device and electronic equipment | |
JP3647776B2 (en) | System and method for performing reliable multicast on a network | |
CN110492978B (en) | LoRaWAN system capable of achieving rapid confirmation and implementation method thereof | |
CN113726467A (en) | Electronic product data transmission method, system, storage medium and program product | |
CN112714036A (en) | Network quality measurement method, apparatus, device and medium for bundled link | |
CN107204824B (en) | Data transmission method and system for low-speed channel |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20211117 Address after: 100176 room 3412, floor 4, building 3, yard 2, Desheng Middle Road, Beijing Economic and Technological Development Zone, Daxing District, Beijing Applicant after: Beijing Helishi system integration Co.,Ltd. Address before: 100176 No.2, Disheng Middle Road, Yizhuang Economic and Technological Development Zone, Daxing District, Beijing Applicant before: BEIJING HOLLYSYS Co.,Ltd. |
|
TA01 | Transfer of patent application right | ||
GR01 | Patent grant | ||
GR01 | Patent grant |