CN117061275A - Polling method, polling device, electronic equipment and storage medium - Google Patents

Polling method, polling device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117061275A
CN117061275A CN202310923775.5A CN202310923775A CN117061275A CN 117061275 A CN117061275 A CN 117061275A CN 202310923775 A CN202310923775 A CN 202310923775A CN 117061275 A CN117061275 A CN 117061275A
Authority
CN
China
Prior art keywords
request
request message
polling
message
continuous
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.)
Pending
Application number
CN202310923775.5A
Other languages
Chinese (zh)
Inventor
宋佳城
万跃敏
胡衍平
吕恒
曹晨鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tanda Technology Co ltd
Original Assignee
Tanda Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Tanda Technology Co ltd filed Critical Tanda Technology Co ltd
Priority to CN202310923775.5A priority Critical patent/CN117061275A/en
Publication of CN117061275A publication Critical patent/CN117061275A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/403Bus networks with centralised control, e.g. polling
    • H04L12/4035Bus networks with centralised control, e.g. polling in which slots of a TDMA packet structure are assigned based on a contention resolution carried out at a master unit
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Small-Scale Networks (AREA)

Abstract

The embodiment of the application is suitable for the technical field of computers, and provides a polling method, a polling device, electronic equipment and a storage medium, wherein the polling method comprises the following steps: according to a message configuration list corresponding to a slave, packaging control instructions with continuous register addresses and the same function code into the same request message to generate a plurality of request messages corresponding to the slave; the message configuration list records the register address corresponding to each control instruction in the slave; responding to a polling instruction, and sequentially transmitting each request message to the slave machine based on the transmission time of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine. The method provided by the embodiment can improve the polling speed of the polling host.

Description

Polling method, polling device, electronic equipment and storage medium
Technical Field
The embodiment of the application belongs to the technical field of computers, and particularly relates to a polling method, a polling device, electronic equipment and a storage medium.
Background
The Modbus protocol is a serial communication protocol commonly used in the industry, and a host can sequentially send a plurality of request messages to a slave through polling of the Modbus protocol, and reads the content stored in a slave register according to a receipt message returned by the slave. In the prior art, after the polling host transmits a request message to the slave, the response piece message can be read according to the uniform waiting time, and if the slave does not return a correct response piece message after the waiting time is exceeded, the polling host can directly give up reading and transmit the next request message to the slave. The prior art fails to set corresponding waiting time according to the conditions of each request message, so that the condition of overlong waiting time is easy to occur. In addition, because the auxiliary generation scheme of the request message is lacking in the prior art, the polling host generally adopts a control instruction to generate a request message for polling, so that the polling host generally cannot maximally utilize the request resource of the request message when sending the request message, and resource waste exists.
Because the prior art has the problems that the waiting time design is unreasonable when the polling host reads the receipt message, the request message generated by the polling host is unreasonable, and the like, the conventional Modbus polling scheme cannot approach the polling time limit value which can be reached by the polling host, so that the polling speed of the conventional Modbus polling scheme is lower.
Disclosure of Invention
In view of the above, the embodiments of the present application provide a polling method, a device, an electronic apparatus, and a storage medium for improving the polling speed of a polling host.
A first aspect of an embodiment of the present application provides a polling method, including:
according to a message configuration list corresponding to a slave, packaging control instructions with continuous register addresses and the same function code into the same request message to generate a plurality of request messages corresponding to the slave; the message configuration list records the register address corresponding to each control instruction in the slave;
responding to a polling instruction, and sequentially transmitting each request message to the slave machine based on the transmission time of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine.
A second aspect of an embodiment of the present application provides a polling apparatus, including:
the request message generating module is used for packaging control instructions with continuous register addresses and the same function code into the same request message according to a message configuration list corresponding to the slave machine so as to generate a plurality of request messages corresponding to the slave machine; the message configuration list records the register address corresponding to each control instruction in the slave;
The polling module is used for responding to a polling instruction and sequentially sending each request message to the slave machine based on the sending time of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine.
A third aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor implementing the polling method as described in the first aspect above when executing the computer program.
A fourth aspect of embodiments of the present application provides a computer readable storage medium storing a computer program which, when executed by a processor, implements a polling method as described in the first aspect above.
A fifth aspect of embodiments of the present application provides a computer program product, which when run on a computer causes the computer to perform the polling method of the first aspect described above.
Compared with the prior art, the embodiment of the application has the following advantages:
According to the embodiment of the application, the polling host can package the control instructions with continuous register addresses and the same function code into the same request message according to the message configuration list corresponding to the slave so as to generate a plurality of request messages corresponding to the slave; responding to the polling command, the polling host can sequentially send each request message to the slave based on the sending time corresponding to each request message; the (n+1) th sending time is that after the polling host reads a receipt message returned by the slave based on the last request message, the polling host sends the next request message to the slave; the N is a positive integer greater than or equal to 1; according to the method provided by the embodiment of the application, when the polling host executes the polling operation, the contents of a plurality of registers of the slave can be continuously read through one request message, so that the polling speed of the polling host can be greatly improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings that are required to be used in the embodiments or the description of the prior art. It is evident that the drawings in the following description are only some embodiments of the present application and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art.
Fig. 1 is a schematic diagram of a polling method according to an embodiment of the present application;
fig. 2 is a schematic diagram of a message configuration list provided in an embodiment of the present application;
fig. 3 is a flowchart of a specific implementation of a polling method S102 according to an embodiment of the present application;
fig. 4 is a flowchart of a specific implementation of a polling method S1022 provided in an embodiment of the present application;
FIG. 5 is a schematic diagram of a receipt message according to an embodiment of the present application;
FIG. 6 is a schematic diagram of a polling operation execution flow according to an embodiment of the present application;
fig. 7 is a flowchart of a specific implementation of a polling method S102 according to an embodiment of the present application;
FIG. 8 is a schematic diagram of a process for generating experience latency provided by an embodiment of the present application;
fig. 9 is a flowchart of a specific implementation of a polling method S101 according to an embodiment of the present application;
fig. 10 is a flowchart of a specific implementation of a polling method S1013 provided in an embodiment of the present application;
FIG. 11 is a schematic flow chart of a request message generation according to an embodiment of the present application;
fig. 12 is a flowchart of a specific implementation of a polling method S1002 provided in an embodiment of the present application;
FIG. 13 is a schematic flow chart of a request message generation method according to an embodiment of the present application;
Fig. 14 is a flowchart of a specific implementation of a polling method S1002 provided in an embodiment of the present application;
FIG. 15 is a schematic diagram of a polling device according to an embodiment of the present application;
fig. 16 is a schematic diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
First, terms that may be related to embodiments of the present application are described herein.
Modbus: the Modbus protocol is a common language used on electronic controllers. Because of the high availability of the Modbus protocol, not only can the controllers communicate with each other via the Modbus protocol, but the controllers can also communicate with other devices via a network (e.g., ethernet) via the Modbus protocol. The Modbus protocol has therefore become a common industry standard. Control equipment produced by different manufacturers can be connected into an industrial network through a Modbus protocol to perform centralized monitoring.
Bus: a computer is composed of a plurality of electronic components, such as a CPU (Central Processing Unit ), a memory, a hard disk and the like, and all the components often need to mutually transmit data. The common channel for data transfer is the bus. In the field of hardware communications, buses often refer to a common channel for data transmission.
Half duplex: data can be transmitted in both directions of one signal carrier, but cannot be transmitted simultaneously. I.e. only one device is sending messages at the same time on the bus.
Polling: polling refers to the process of traversing each element continuously and repeatedly according to a certain algorithm for elements of a certain set. In the case of the Modbus master, the polling is to read the contents of the registers on each slave one by one periodically.
Polling the host: the master station is also called as a device for sending a message for requesting the content of a register in the polling process.
Slave machine: also known as a secondary station, is a device that responds to a host message.
Request message: the message sent when the polling host reads the register information on the slave is essentially a byte array.
Receipt message: the slave responds to the request message sent by the polling host and returns a message containing register contents based on the received request message, which is essentially a byte array.
With the widespread use of the Modbus protocol on a global scale, a polling host (also referred to as a Modbus polling host) using the Modbus protocol has become an indispensable tool for reading Modbus slaves in the industrial field. The Modbus polling host can send a request message to the slave machine in a serial port communication mode by using various programming languages, and obtain and analyze a receipt message. However, the Modbus polling machines on the current market have the technical problems of low speed and long period for reading the content of the slave register. And the existing Modbus polling host has no function of assisting a user in designing a request message.
Because the existing polling host always has the technical problem of overlong polling period, the application platform cannot update the acquisition value corresponding to the register content in time easily due to the fact that the existing polling host is used for polling. The embodiment of the application aims to improve the polling speed of the polling host through three strategies so as to solve the technical problem of overlong polling period.
First, a message design strategy. Through the message design scheme, the polling host can intelligently generate request messages capable of continuously reading a plurality of registers according to the message configuration list corresponding to the slave.
Second, read the policy. And determining experience waiting time corresponding to each request message, and enabling the polling host to read the receipt message according to the experience waiting time corresponding to each request message.
Thirdly, a read-back strategy. The complete receipt message can be read by the polling host through the read-back strategy.
The method provided by the embodiment of the application can automatically reach the optimal state of the response of the slave equipment on a certain bus by polling the host, and the polling time approaches to the limit value.
The technical scheme of the application is described below through specific examples.
Referring to fig. 1, a schematic diagram of a polling method according to an embodiment of the present application is shown, where the polling method may be applied to a polling host. The polling host may be any of a variety of electronic devices. The electronic device may be an electronic device capable of executing a polling instruction, such as a computer, a mainframe computer, a tablet computer, etc., and the polling method specifically may include the following steps:
s101, according to a message configuration list corresponding to a slave, packaging control instructions with continuous register addresses and the same function code into the same request message to generate a plurality of request messages corresponding to the slave; the message configuration list records the register address corresponding to each control instruction in the slave.
In this embodiment, when a user needs to perform a polling operation on a plurality of slaves in an industrial network by a polling master, a polling scheme may be first configured on the polling master. When the user configures the polling scheme, the message configuration list corresponding to the slave can be transmitted to the polling host. After the polling host receives the message configuration list, the polling host may store the message configuration list. The message configuration list may record the register address of each control instruction in the slave and the function code of the register corresponding to each control instruction. The register address may be used to represent a register to which the control instruction corresponds. The polling host can determine the corresponding register of each control instruction in the slave according to the register address. The polling host may obtain the value in the register according to the function code corresponding to the register. And responding to the generation instruction of the user, and packaging the control instruction which has the same function code and has continuous register addresses in the message configuration list into the same request message by the polling host according to the message configuration list corresponding to the slave.
Referring to fig. 2, a schematic diagram of a message configuration list provided in an embodiment of the present application is shown. As shown in fig. 2, the message configuration list may include a plurality of control instructions. Each control instruction may include a register address of the control instruction in the slave, a function code to which the control instruction is applicable, a content executed by a register corresponding to the control instruction, and a meaning of each parameter in the control instruction. It should be noted that, the method provided by the embodiment of the present application may be applied to all polling hosts of the Modbus protocol, such as a polling host that polls through ModbusRTU messages and a polling host that polls through modbusscii messages, and the application does not limit the message type of the request message generated by the polling host. In fig. 2, the device I/O refers to an Input/Output device model (I/O). The MCU parameters refer to micro control unit parameters (Microcontroller Unit, MCU for short). PT100 refers to a platinum thermal resistor having a resistance value of 100 ohms at 0 degrees celsius. BCD codes refer to Binary-Coded Decimal (BCD for short).
In one possible implementation, when there are multiple slaves in the industrial network, one polling master may be used to poll the multiple slaves. In this case, after the polling host generates the request message according to the message configuration list, the polling host may further add a slave label corresponding to the slave in the generated request message according to the slave corresponding to the message configuration list. After the polling host generates the request message, the polling host can write the generated request message into the database for storage.
S102, responding to a polling instruction, and sequentially transmitting each request message to the slave machine based on the transmission time of each request message; the (n+1) th sending time is that after reading a receipt message returned by the slave machine based on a last request message, the next request message is sent to the slave machine; and N is a positive integer greater than or equal to 1.
In this embodiment, when the user needs to acquire information in the slave, a polling command may be initiated to the polling host. The polling host can respond to the polling instruction and sequentially send each request message to the slave based on the sending time of each request message so as to request to acquire the content of each register in the slave through the request message. For the first request message, the polling host may directly send the first request message to the corresponding slave after receiving the polling command and generating the request message, that is, the sending time of the first request message is the time when the polling command is received. The following request message may be specifically based on a preset sending opportunity: after the polling host reads the receipt message returned by the slave based on the last request message, the polling host sends the next request message to the slave.
In one possible implementation, the request address may be included in a request message generated by the polling host. After the polling host generates a plurality of request messages corresponding to the slaves, the request sequence corresponding to each request message can be determined according to the request address corresponding to each request message. The polling host can write each request message and the request sequence corresponding to each request message into a message list for storage. The polling host may also write the message list into a database for storage. When the polling host needs to execute the polling operation, each request message in the message list can be sequentially acquired according to the request sequence, and each request message is sequentially sent to the corresponding slave according to the request sequence.
Specifically, in one possible implementation manner, after receiving a polling instruction initiated by a user, the polling host may sequentially obtain all the request messages corresponding to the slave from the message list according to the request order corresponding to each request message. The polling host can firstly acquire a request with a request sequence of a first sequence from a message list, and send the request message to the slave through a preset communication link. After receiving the request message of the first order, the slave can generate a receipt message based on the request message of the first order and return the receipt message to the polling host. After the polling host reads the receipt message returned by the slave based on the request message of the first order, the polling host can acquire the request message of the second order from the message list, and send the request message of the second order to the slave. When the polling host executes the polling operation, after the receipt message returned by the slave based on the last request message is read each time, the polling host sends the next request message to the slave according to the request sequence until all the request messages in the request list are sent to completion. When the polling host sends the last request message in the request list to the slave and reads the receipt message returned by the slave based on the last request message, the polling host can determine that the current polling operation is completed, that is, the polling host has completed a polling operation of a polling period.
In one possible implementation, when there are multiple slaves in the industrial network, the user-configured polling scheme may also include a corresponding polling order for each slave. The polling host can send request messages to each slave in turn according to the polling sequence corresponding to each slave. Specifically, after all the request messages corresponding to the first slave machine are sent, that is, after the polling master machine polls the first slave machine, the polling master machine can determine the second slave machine according to the polling sequence in the polling scheme. The first slave machine can be any slave machine in the industrial network, and the second slave machine can be the slave machine positioned in the next polling sequence of the first slave machine. And then, the polling host can acquire all request messages corresponding to the second slave from the database according to the slave label corresponding to the second slave. The polling slave can send the request message to the slave based on the sending time of each request message. The polling host can sequentially send request messages to all the slaves in the industrial network until all the request messages of all the slaves in the industrial network are sent.
In this embodiment, since the polling host may encapsulate the control instructions with the same function code and continuous register addresses into the same request message according to the message configuration list corresponding to the slave, when the polling host executes the polling operation, the polling host may continuously read the contents of the plurality of registers of the slave through one request message, so that the polling speed of the polling host may be greatly improved. In actual operation, when the polling host continuously reads the contents of a plurality of registers in the slave through one request message, the response time required by the slave to return a receipt message based on the currently received request message is far shorter than the response time required by the slave to read the same number of registers through a plurality of request messages. For example, experiments have shown that when the master is polled to read the contents of a register in the slave via a request message, the response time required by the slave to return a receipt message based on the currently received request message is around 50 milliseconds. Therefore, when the polling host reads the contents of five registers in the slave sequentially through five request messages, the total response time required by the slave to return five receipt messages based on the five request messages is about 250 milliseconds. However, when the polling host continuously reads the contents of five registers in the slave through one request message, the response time required for the machine to return a receipt message based on the currently received request message is about 60 milliseconds.
Fig. 3 shows a flowchart of a specific implementation of a polling method S102 according to a second embodiment of the present application. Referring to fig. 3, compared to the embodiment described in fig. 3, S102 in the polling method provided in this embodiment includes: s1021 to S1022 are described in detail as follows:
s1021, the first request message is sent to the slave machine based on the sending time of the first request message.
In this embodiment, after the polling host generates all the request messages corresponding to the slave, the polling host may respond to the polling instruction initiated by the user to obtain all the request messages corresponding to the slave from the database, and sequentially send each request message to the slave. The polling master may send the first request message to the slave based on a sending opportunity corresponding to the first request message. In this embodiment, the request order corresponding to the first request message is not limited, and the first request message may be any request message in all request messages corresponding to the slave.
In this embodiment, the first request message may be any request message including experience waiting time. Specifically, when the first request message is the 1 st request message sent by the polling host in the current polling period, that is, when the polling host has not sent the request message in the current polling period, the sending time is the 1 st sending time, the polling host may directly send the first request message to the slave. When the first request message is the (n+1) th request message sent by the polling host in the current polling period, that is, when the sending time is the (n+1) th sending time, the polling host can send the first request message to the slave after reading the receipt message returned by the slave based on the last request message.
And S1022, reading a receipt message returned by the slave machine based on the first request message based on the experience waiting time.
In this embodiment, after the polling host sends the first request message including the experience waiting time to the slave, the polling host may read the response piece message returned by the slave based on the first request message based on the experience waiting time.
In one possible implementation, after the polling host obtains any one request message from the database, it may determine whether the current request message includes an experience waiting time. If the current request message includes experience waiting time, the polling host can determine that the current request message is the first request message. After the polling host transmits the current first request message to the slave, the polling host can wait according to the experience waiting time in the first request message, and after waiting is finished, the polling host reads a receipt message returned by the slave based on the first request message. If the current request message does not include experience waiting time, the polling host can determine that the current request message is a second request message.
In this embodiment, the polling host may wait according to the experience waiting time corresponding to each first request message, and read the receipt message returned by the slave after the waiting is finished. Therefore, the method provided by the embodiment can ensure that the polling host computer can accurately read the receipt message and does not waste excessive time to wait, thereby further reducing the time spent by the polling host computer in a polling period.
Fig. 4 shows a flowchart of a specific implementation of a polling method S1022 according to the third embodiment of the present application. Referring to fig. 4, compared to the embodiment described in fig. 3, S1022 in the polling method provided in this embodiment includes: s401 to S403 are specifically described below:
s401, reading real-time data returned by the slave machine in the experience waiting time.
In this embodiment, after the polling host sends the first request message including the experience waiting time to the slave, the polling host may wait according to the experience waiting time, and read real-time data returned from the slave from the serial port preset by the user in the experience waiting time. The complete receipt message returned by the slave based on the first request message may include a plurality of data segments. When the slave machine responds to the first request message to generate a receipt message, the slave machine can sequentially return each data segment to the polling host machine according to the return sequence of each data segment.
In one possible implementation, referring to fig. 5, a schematic diagram of a receipt message provided by an embodiment of the present application is shown. As shown in FIG. 5, each data segment in the receipt message is sequentially a slave address, a function code, a byte number, a receipt data segment and a receipt check segment from front to back according to the return order. The address of the slave is the message header of the receipt message, and the receipt verification section is the message tail of the receipt message. After receiving the first request message sent by the polling host, the slave can generate and return to the polling host from the message header of the receipt message according to the first request message, and the slave can sequentially generate and return each data segment until the message tail of the receipt message is generated and return the message tail to the polling host, so that the complete receipt message corresponding to the first request message is generated. Because the response time required by the slave to generate the complete receipt message may vary with the environment in which the slave is located, for example, when the temperature of the environment in which the slave is located is higher, the response time required by the slave to respond to the same request message may be longer than the response time required by the slave to respond to the same request message when the temperature is lower. Thus, the real-time data read from the serial port by the polling host based on the empirical latency may not be a complete receipt message.
Thus, in one possible implementation, after the polling host reads the real-time data, it may determine whether the real-time data includes the first data segment by the number of bytes of the real-time data. As the number of bytes corresponding to the three data segments of the slave address, the function code and the number of bytes in the receipt message is fixed, and the sum of the number of bytes of the three data segments is 3 bytes. Therefore, the polling host can calculate the corresponding byte number of the real-time data and judge whether the byte number of the real-time data is greater than or equal to 3 bytes. The polling host may determine whether the real-time data includes the first data segment by determining whether the number of bytes of the real-time data is greater than or equal to 3 bytes. If the polling host determines that the read real-time data is less than 3 bytes, the polling host may determine that the currently read real-time data does not contain the contents of the response piece data segment portion. The polling host can delete the read real-time data, and set the message state corresponding to the first request message as the error state of the last receipt message.
S402, if the real-time data comprises a first data segment, determining a first expected byte number corresponding to the first receipt message according to the byte number of the first data segment.
In this embodiment, after the real-time data is read, if the polling host determines that the read real-time data includes the first data segment, the polling host may calculate the byte number of the first data segment in the real-time data, and determine the first expected byte number corresponding to the real-time data according to the byte number of the first data segment.
In one possible implementation, after the polling host calculates the number of bytes of the real-time data, if the polling host determines that the read real-time data is greater than or equal to 3 bytes, the polling host may determine that the current read real-time data includes the content of the response piece data segment.
In one possible implementation, as shown in FIG. 5, the response piece message returned by the slave may contain multiple data segments. Wherein each data segment can be a slave address, a function code, a byte number, a receipt data segment and a receipt check segment respectively. Wherein the four data segments, namely the slave address, the function code, the byte number and the receipt verification segment, generally occupy 5 bytes in the receipt message. The corresponding first expected number of bytes of real-time data may be equal to the number of bytes of the first data segment in real-time data plus 5.
S403, if the actual byte number of the real-time data is smaller than the first expected byte number, reading the real-time data returned by the slave machine based on a preset interval waiting time interval, and updating the repeated reading times corresponding to the first request message until the real-time data meets a preset message stopping condition or the repeated reading times meet a preset reading stopping condition; the message stopping condition is that the actual byte number of the real-time data is larger than or equal to the second expected byte number; the reading stop condition is that the repeated reading times are larger than or equal to a preset repeated reading threshold value.
In this embodiment, after obtaining the first expected byte number corresponding to the real-time data, the polling host may calculate the actual byte number of the real-time data according to the received real-time data. After determining the actual byte number of the real-time data, the polling host can determine whether the actual byte number of the real-time data is smaller than the first expected byte number corresponding to the real-time data. Because the slaves sequentially generate and return each data segment according to the return sequence of each data segment, if the polling host judges that the actual byte number of the real-time data is smaller than the first expected byte number corresponding to the real-time data, the polling host can determine that the real-time data read at the moment is not a complete receipt message, namely the slaves can not generate and return the complete receipt message within the experience waiting time. At this time, the polling host can wait according to the waiting time interval preset by the user, and intermittently read a plurality of real-time data returned by the slave. The polling host can also increase the repeated reading times corresponding to the first request message while reading a plurality of real-time data returned by the slave at intervals. The polling host can repeatedly read the real-time data returned by the slave machine from the serial port preset by the user for a plurality of times until the real-time data read by the polling host meets the message stop condition preset by the user or the repeated reading times recorded by the polling host meet the reading stop condition preset by the user. The message stopping condition is that the actual byte number of the real-time data is greater than or equal to the second expected byte number. The reading stop condition is that the number of repeated reading is greater than or equal to a preset repeated reading threshold.
In one possible implementation, after the polling host reads one real-time data at each interval, the polling host may calculate a second expected byte number corresponding to the currently read real-time data according to the byte number of the first data segment in the real-time data. The second expected byte number is the expected byte number corresponding to the real-time data read each time when the polling host repeatedly reads the real-time data. The calculation method of the second expected byte number is the same as the calculation method of the first expected byte number, and the details of the calculation method of the first expected byte number are referred to in the specification, and are not described herein. After the polling host calculates the second expected byte number corresponding to the real-time data each time, it can determine whether the actual byte number of the real-time data currently read is greater than or equal to the second expected byte number. If the polling host judges that the actual byte number of the current read real-time data is greater than or equal to the second expected byte number, the polling host can judge that the read real-time data meets the preset message stopping condition of the user, namely the read real-time data is a complete receipt message returned by the slave based on the first request message. At this time, the polling host can determine that the real-time data that is currently read is a receipt message that the slave returns based on the first request message.
In one possible implementation manner, if the polling host determines that the actual number of bytes of the real-time data currently read is less than the second desired number of bytes, the polling host may determine that the real-time data read at this time does not meet the preset message stopping condition of the user, that is, the real-time data read at this time is not a complete receipt message, at this time, the polling host may update the repeated reading times, and determine whether the current repeated reading times meet the preset reading stopping condition of the user. If the polling host determines that the actual byte number of the currently read real-time data is smaller than the second expected byte number and the repeated reading times do not meet the preset reading stop condition of the user, the polling host can wait according to the interval waiting time and continue to repeatedly read the real-time data.
In one possible implementation, the polling host may add one to the number of repeated reads corresponding to the first request message after repeatedly reading one real-time data at a time. After the repeated reading times are added by one each time, the polling host can judge whether the current repeated reading times meet the preset reading stop conditions of the user, and if the repeated reading times meet the preset reading stop conditions of the user, the polling host can stop reading the real-time data. At this time, the polling host may delete the read real-time data, and set the message state corresponding to the first request message to be the state in which the previous receipt message is in error. The polling host can determine whether the repeated reading times satisfy the reading stop condition preset by the user by determining whether the repeated reading times are greater than the repeated reading threshold preset by the user. If the number of repeated readings is greater than the repeated reading threshold set by the user in advance, the polling host can determine that the number of repeated readings satisfies the reading stop condition set by the user in advance. If the number of repeated readings is less than or equal to the repeated reading threshold set by the user in advance, the polling host may determine that the number of repeated readings does not satisfy the reading stop condition set by the user in advance.
In one possible implementation manner, each first request message may further include a repeated reading number preset by a user, and after the polling host repeatedly reads one real-time data each time, the repeated reading number corresponding to the first request message may be reduced. The polling host can subtract one from the repeated reading times corresponding to the first request message after repeatedly reading one real-time data each time. The polling host can judge whether the repeated reading times meet the reading stop condition preset by the user by judging whether the repeated reading times are larger than 0. If the number of repeated readings is greater than 0, the polling host may determine that the number of repeated readings does not satisfy the reading stop condition set in advance by the user. If the number of repeated readings is less than or equal to 0, the polling host may determine that the number of repeated readings satisfies a reading stop condition set in advance by the user.
In one possible implementation manner, referring to fig. 6, a schematic flow chart of a polling operation according to an embodiment of the present application is provided. As shown in fig. 6, the polling host may obtain the experience latency after and in the request message to be transmitted from the message list in response to the polling instruction. The message list may also include a request state corresponding to each request message and a repeated reading number corresponding to each request message preset by a user. If the request message includes experience waiting time, the polling host can determine that the current request message is the first request message. The polling master may send a first request message to the slave and wait according to an empirical wait time. When the waiting time of the polling host meets the experience waiting time, the polling host can attempt to acquire real-time data from a serial port preset by a user. The polling host can write the acquired real-time data into a byte array for storage, and calculates the actual byte number corresponding to the real-time data through the byte array. After obtaining the actual number of bytes, the polling host may determine whether the actual number of bytes is greater than or equal to 3. If the byte number is less than 3, the polling host can discard the acquired real-time data and update the request state corresponding to the first request message in the message list to the error state of the last receipt message.
If the byte number is greater than or equal to 3, the polling host can analyze the real-time data and determine the function code in the real-time data. The polling host may determine whether the acquired function code is less than 5. If the polling host judges that the acquired function code is greater than or equal to 5, the polling host can discard the acquired real-time data and update the request state corresponding to the first request message in the message list to the error state of the last receipt message. If the polling host judges that the acquired function code is smaller than 5, the polling host can analyze the real-time data to acquire a first data segment and the byte number of the first data segment in the real-time data. The polling host may determine the desired number of bytes corresponding to the real-time data by adding 5 to the number of bytes of the first data segment. After determining the expected number of bytes and the actual number of bytes, the polling host may determine whether the expected number of bytes is greater than the actual number of bytes.
If the polling host judges that the expected byte number is smaller than or equal to the actual byte number, the polling host can determine that the currently read real-time data is a receipt message returned by the slave based on the first request message. The polling host may verify that the receipt message is legitimate. If the receipt message is legal, the polling host can analyze the currently acquired receipt message and update the request state corresponding to the first request message in the message list to be a successful return state. If the receipt message is illegal, the polling host can discard the acquired receipt message and update the request state corresponding to the first request message in the message list to the error state of the last receipt message. The polling host can judge whether the receipt message is legal or not by judging whether the receipt message has abnormal conditions preset by a user or not. If the receipt message has any one or more abnormal conditions such as too short message, wrong receipt verification section or disconnection of serial port, the polling host can judge that the current receipt message is illegal. If no abnormal condition occurs in the receipt message, the polling host can judge that the receipt message is legal.
If the polling host determines that the expected byte number is greater than the actual byte number, the polling host may determine whether the number of repeated reads corresponding to the first request message is greater than 0. If the polling host judges that the repeated reading times corresponding to the first request message is less than or equal to 0, the polling host can discard the acquired real-time data and update the request state corresponding to the first request message in the message list to the error state of the last receipt message. If the polling host judges that the repeated reading times corresponding to the first request message is greater than 0, the polling host can repeatedly read the real-time data and write the new real-time data into the byte array so as to calculate the actual byte number of the new read real-time data. After the polling host computer repeatedly reads the real-time data, the repeated reading times corresponding to the request message can be subtracted by one, so that the remaining repeated reading times of the first request message currently being requested in the current polling period can be updated. The polling host may return to performing the step of parsing the real-time data, determining the number of bytes of the first data segment and the number of expected bytes, and subsequent steps, to update the number of expected bytes corresponding to the real-time data. The polling host may repeatedly perform the step of reading the real-time data until the first request message satisfies the reading stop condition or the message stop condition. The reading stop condition is that the repeated reading times corresponding to the first request message is less than or equal to 0. The message stop condition is that the expected byte number of the real-time data is less than or equal to the actual byte number.
When the polling host judges that the first request message meets the reading stop condition or the message stop condition, the polling host can stop reading the real-time data and generate a receipt message according to the read real-time data. The polling host can check whether the currently generated receipt message is legal. If the polling host judges that the current receipt message is legal, the polling host can determine that the current receipt message is the receipt message returned by the slave based on the first request message, and the polling host can analyze the currently acquired receipt message and update the request state corresponding to the first request message in the message list to be a successful return state. If the receipt message is illegal, the polling host can discard the acquired receipt message and update the request state corresponding to the first request message in the message list to the error state of the last receipt message.
In this embodiment, since the response time required by the slave is unstable when the slave replies to the request message sent by the polling master, that is, the time required by the slave to respond to the request of the master is actually an interval. Therefore, after waiting based on experience waiting time and acquiring real-time data, the slave reporter needs to calculate the expected byte number and the actual byte number corresponding to the real-time data and judge whether the expected byte number is larger than the actual byte number. The polling host can determine whether the read real-time data is a complete receipt message returned by the slave based on the first request message by judging whether the expected byte number is greater than the actual byte number. If the polling host determines that the desired number of bytes is greater than the actual number of bytes, the polling host may repeatedly read the real-time data. Therefore, by the method provided by the embodiment of the application, the receipt message acquired by the polling host can be ensured to be the complete receipt message returned by the slave based on the first request message, so that the accuracy of the polling host in reading the receipt message is improved.
Fig. 7 shows a flowchart of a specific implementation of a polling method S102 according to a fourth embodiment of the present application. Referring to fig. 7, compared to the embodiment described in fig. 1, in a polling method provided in this embodiment, S102 includes: s701 to S703 are specifically described below:
s701, sending a second request message to the slave machine, recording the sending time of the second request message, and executing repeated reading operation for a plurality of times; the second request message is any request message; and the repeated reading operation is used for reading a plurality of real-time data returned by the slave machine based on the second request message based on a preset reading interval.
In this embodiment, after the polling host acquires the second request packet from the packet list, the polling host may send the second request packet to the slave and record the sending time corresponding to the second request packet. After the polling host transmits a second request message to the slave, the polling host executes repeated reading operation for a plurality of times. The repeated reading operation of the polling host may be that a plurality of pre-reading messages returned by the slave based on the second request message are read according to a preset reading interval of a user. The second request message sent by the polling host may be any request message in the message list.
In one possible implementation, after the polling host obtains the request message from the message list in response to the polling command, it may be determined whether the request message includes an experience waiting time. If the polling host determines that the request message includes experience waiting time, the polling host may determine that the current request message is the first request message. The polling host may perform polling according to a polling method corresponding to the first request packet, where the polling method corresponding to the first request packet may refer to the content in the second embodiment and the third embodiment of the present application, and will not be described herein. If the polling host determines that the request message does not include the experience waiting time, the polling host may determine that the current request message is the second request message.
S702, if the current repeated reading operation does not read the real-time data, determining a receipt message corresponding to the second request message based on the read plurality of real-time data, and recording the execution time of the current repeated reading operation.
In this embodiment, after the polling host performs the repeated reading operation each time, it may be determined whether the current reading operation has read the real-time data. If the polling host determines that the current repeated reading operation does not read the real-time data returned by the slave based on the second request message, the polling host can stop executing the repeated reading operation. The polling host can determine the receipt message corresponding to the second request message according to the plurality of real-time data read by the previous repeated reading operation. The polling host may also record the execution time of the current repeated read operation.
In one possible implementation, since the slave machine returns the receipt message in response to the second request message, the slave machine sequentially generates and returns each data segment according to the return order of each data segment in the receipt message. Therefore, after the host is polled for each time of reading operation, whether the current reading operation reads real-time data can be determined by judging whether the number of the bytes read is 0. If the polling time determines that the number of bytes of the currently read data is not 0, the polling host may determine that the current read operation has read real-time data. If the polling time determines that the number of bytes of the currently read data is 0, the polling host may determine that the current read operation did not read real-time data.
S703, generating experience waiting time corresponding to the second request message based on the sending time, the executing time and the reading interval, and writing the experience waiting time into the second request message, so that when the next polling instruction is responded, the reading time of the receipt message corresponding to the second request message is determined based on the experience waiting time in the second request message.
In this embodiment, after determining the execution time of the last repeated reading operation, the polling host may generate the experience waiting time corresponding to the second request message according to the sending time of the second request message, the execution time of the last repeated reading operation, and the reading interval preset by the user. The polling host may write the experience latency into the second request message. After responding to the next polling instruction initiated by the user, the polling host can send a second request message containing experience waiting time to the slave, and determine the reading time of a receipt message corresponding to the second request message according to experience waiting time.
In one possible implementation, referring to fig. 8, a schematic flow chart of generating experience waiting time is shown. As shown in fig. 8, when the polling host generates a request message, the polling host may set the generated request message to an unpolled state, and write the request message and its corresponding request state into the message list. When the polling host responds to the polling command and acquires the request message from the message list, if the request message does not contain experience waiting time and the message state corresponding to the request message is in a non-polling state, the polling host can determine that the current request message is a second request message, and the polling host can acquire a preset reading interval of a user. Specifically, the reading interval may be 10 ms, which is not specifically limited in the embodiment of the present application, and one skilled in the art may set the reading interval according to the performance data of the slave and the content of the request message. The polling master may then send a second request message to the slave and wait at the read interval and update the wait time. After the host is polled to update the waiting time, whether the current waiting time exceeds a waiting threshold preset by a user or not can be judged.
If the polling host judges that the current waiting time exceeds the waiting threshold preset by the user, the polling host can discard the acquired receipt message and update the request state corresponding to the first request message in the message list to a timeout receipt-free state.
If the polling host judges that the current waiting time does not exceed the waiting threshold preset by the user, the polling host can read the data returned by the slave from the preset serial port. The polling host may then determine whether the number of bytes read by this read operation is 0. If the polling host determines that the number of bytes read by the read operation is not 0, the polling host may write the data read by the read operation into the byte array, and return to execute the step of waiting and updating the waiting time according to the preset read interval and the subsequent steps. If the polling host determines that the number of bytes read by the read operation is 0, the polling host may determine whether there is any content in the current byte array. If the polling host determines that the current byte array has no content, the polling host may return to executing the step of waiting at a preset read interval and updating the waiting time and subsequent steps. If the polling host determines that the current byte array has content, the polling host can record the obtained waiting time, sending time and reading interval and calculate the experience waiting time of the second request message. Where the empirical wait time may be equal to the wait time minus the transmit time minus the read interval.
The polling host can generate a receipt message according to all real-time data contained in the byte array, and judge whether the receipt message is legal or not. If the polling host judges that the receipt message is legal, the polling host can determine that the current receipt message is the receipt message returned by the slave based on the first request message, and the polling host can analyze the currently acquired receipt message and update the request state corresponding to the first request message in the message list to be a successful return state. If the receipt message is illegal, the polling host can discard the receipt message and update the request state corresponding to the first request message in the message list to the error state of the last receipt message.
In this embodiment, when the request packet does not include the experience waiting time, the polling master may read, according to a preset reading interval, a plurality of real-time data returned by the slave based on the second request packet. The polling host can determine a receipt message corresponding to the second request message according to the read real-time data, and determine experience waiting time corresponding to the second request message according to execution time corresponding to the last repeated reading operation, sending time and reading interval of the second request message. By the method provided by the embodiment, the polling host can quickly and accurately acquire the receipt message corresponding to the second request message under the condition of no experience waiting time, and generate the experience waiting time corresponding to the second request message. The method provided by the present embodiment thus improves the availability of polling hosts and ensures accuracy of experience latency.
Fig. 9 shows a flowchart of a specific implementation of a polling method S101 according to a fifth embodiment of the present application. Referring to fig. 9, compared to the embodiment described in fig. 1, in a polling method provided in this embodiment, S101 includes: s1011 to S1013, the details are as follows:
s1011, dividing a plurality of control instructions in a message configuration list into a plurality of request subgroups based on the function code, and sequentially acquiring a first control instruction in any request subgroup; the first control instruction is one of the control instructions in the any request group.
In this embodiment, after the polling host acquires the message configuration list corresponding to the slave, the polling host may divide a plurality of control instructions in the message configuration list into a plurality of request subgroups according to the function codes corresponding to the control instructions. After the polling host generates a plurality of request subgroups, the polling host can sequentially package the control instructions with the same function code and continuous register addresses into the same request message according to the control instructions in each request subgroup. The polling host may obtain the first control instruction in any of the request subgroups. Wherein each request team may contain at least one control command, and the first control command may be one of the control commands in the request team. As shown in fig. 2, the function codes corresponding to the temperature detection command, the voltage 1 detection command, the voltage 2 detection command, the current 1 detection command and the current 2 detection command are Ox03 and Ox04. Thus, the polling host may divide the temperature detect command, the voltage 1 detect command, the voltage 2 detect command, the current 1 detect command, and the current 2 detect command into the same request team.
In one possible implementation, after generating the plurality of request subgroups, the polling host may sort the first control instructions in the same request subgroup in descending order according to the register addresses of the first control instructions in the request subgroup. After the sequencing is finished, the polling host can sequentially acquire each first control instruction in the same request group.
S1012, aiming at any request subgroup, if a first control instruction in the request subgroup meets a preset continuous request condition, writing the first control instruction into a continuous request list, and judging whether other control instructions in the request subgroup meet the continuous request condition.
In this embodiment, after generating a plurality of request subgroups, the polling host may determine, for any request subgroup, whether the acquired first control instruction satisfies a continuous request condition preset by a user after acquiring the first control instruction in the current request subgroup. If the polling host determines that the acquired first control instruction meets the continuous request condition preset by the user, the polling host can write the first control instruction into the continuous request list and sequentially acquire other control instructions in the same request group.
In one possible implementation manner, if the polling host determines that the acquired first control instruction does not meet the continuous request condition preset by the user, the polling host may generate an independent request message according to the current control instruction. The polling host can acquire the next control instruction in the request group and judge whether the next control instruction meets the continuous request condition preset by the user
And S1013, writing the other control instructions meeting the continuous request condition into the continuous request list, continuously acquiring the other control instructions in the request group for judgment until any one of the other control instructions does not meet the continuous request condition or all the control instructions in the request group have judged the continuous request condition, and generating a request message based on all the control instructions in the continuous request list.
In this embodiment, the polling host may determine whether the acquired control instruction satisfies the continuous request condition preset by the user after acquiring other control instructions each time. If the polling host determines that the current other control instruction satisfies the continuous request condition, the polling host may write the other control instruction into the continuous request list. The polling host may continue to obtain each other control instruction in the current request group to make a determination until either one of the other control instructions does not satisfy the continuous request condition or all of the control instructions in the current request group have made a determination of the continuous request condition.
In one possible implementation, if the polling host determines that any other control instruction does not satisfy the continuous request condition, the polling host may generate a request message according to all control instructions in the continuous request list. Then, the polling host can empty the continuous request list and acquire the next other control instruction to judge the continuous request condition. The polling host may write a control instruction that satisfies the continuous request condition into the continuous request list.
In one possible implementation, when the polling host generates the request message through all the control instructions in the continuous request list, the polling host may generate the check segment in the request message according to the checksum calculation method preset by the user and through all the control instructions in the continuous request list. The polling host may further determine the number of continuous requests corresponding to the request packet according to a start register address corresponding to the control instruction of the first write-in continuous request list and an end register address corresponding to the control instruction of the last write-in continuous request list. The polling host can generate a request message according to the slave label, the check segment and the continuous request number corresponding to the message configuration list. The checksum calculation method may be modulo two division or any checksum calculation method commonly used by those skilled in the art, and the embodiment of the present application does not specifically limit the checksum calculation method.
By the method provided by the embodiment, a plurality of control instructions encapsulated in the same request message by the polling host can be ensured to meet continuous request conditions, so that the request message generated by the polling host can be used for continuously requesting a plurality of registers in the slave, and the availability of the request message is ensured.
Fig. 10 shows a flowchart of a specific implementation of a polling method S1013 provided by a sixth embodiment of the present application. Referring to fig. 10, compared to the embodiment shown in fig. 9, in a polling method provided in this embodiment, S1013 includes: s1001 to S1003 are specifically described as follows:
s1001, writing an ith control instruction meeting all the continuous conditions into a continuous request list; and i is a positive integer greater than or equal to 1.
In this embodiment, the polling host may traverse each request subgroup in turn after generating a plurality of request subgroups. When the polling host traverses any request subgroup, the polling host can acquire an ith control instruction in the current request subgroup according to the traversing cursor i. The polling host may determine whether the ith control instruction satisfies the continuous request list. Wherein i is a positive integer greater than or equal to 1. Wherein, in an embodiment of the present application, the continuous request condition includes a plurality of continuous conditions. The address continuation condition is one of a plurality of continuation conditions. The message configuration list may further include a register address corresponding to each control instruction. The register address of each control instruction may include a start register address corresponding to the control instruction and an end register address corresponding to the control instruction.
In one possible implementation, the data type condition is also one of a plurality of consecutive conditions. When there is no control instruction in the continuous request list, the polling host may determine whether the ith control instruction satisfies the continuous request condition according to the data type of the ith control instruction. If the data type of the ith control instruction meets the data type condition preset by the user, the polling host can judge that the ith control instruction meets the continuous request condition, and the polling host can write the ith control instruction into the continuous request list as the first control instruction in the continuous request list.
In one possible implementation, when the control instruction is already present in the continuous request list, the polling host may determine whether the ith control instruction satisfies the continuous request condition by determining an address relationship between the ith control instruction and the ith-1 control instruction. The specific judging process is identical to the judging process of the address relationship between the ith control instruction and the (i+1) th control instruction in the sixth embodiment of the present application, and will not be described herein.
In one possible implementation, when a control instruction already exists in the continuous request list, the polling host may further determine whether the ith control instruction satisfies the continuous request condition by the number of pre-requests in the continuous request list. The specific judging process is referred to in the seventh embodiment of the present application, and will not be described herein.
S1002, if the i is smaller than the number of instructions corresponding to the request group, acquiring an i+1th control instruction in the request group.
In this embodiment, after the polling host writes the ith control instruction into the continuous request list, it may be determined whether i is smaller than the number of instructions corresponding to the request group. If the polling host determines that i is less than the number of instructions corresponding to the request group, the polling host may acquire the i+1th control instruction in the current request group.
S1003, if the address relation between the ith end register address corresponding to the ith control instruction and the (i+1) th start register address corresponding to the (i+1) th control instruction does not meet the address continuous condition, generating the request message based on all control instructions in the continuous request list.
In this embodiment, after the polling host acquires the i+1th control instruction, it may be determined whether the address relationship between the i-th end register address corresponding to the i-th control instruction and the i+1th start register address corresponding to the i+1th control instruction satisfies the address continuation condition set in advance by the user. If the polling host determines that the address relationship between the ith end register address corresponding to the ith control instruction and the ith+1 start register address corresponding to the ith+1 control instruction does not meet the address continuous condition, the polling host may generate the request message based on all the control instructions in the continuous request list, and delete all the control instructions in the continuous request list, so as to store a plurality of control instructions meeting the continuous request condition through the continuous request list.
Fig. 11 is a schematic flow chart of a request message generation according to an embodiment of the present application. Referring to fig. 11, after the polling host acquires the message configuration list corresponding to the slave, all the control instructions in the message configuration list may be grouped according to the function codes corresponding to the control instructions in the message configuration list. After generating a plurality of request subgroups, the polling host can determine the number of instructions corresponding to each request subgroup and traverse each request subgroup in turn. The polling host may first define the traversal cursor i of the control instruction and define i as 1 when it starts traversing any of the request subgroups. The polling host can obtain the individual control instructions in the request team from traversing cursor i. The polling host may first determine whether i is less than the number of instructions corresponding to the currently traversed request team. If i is greater than or equal to the number of instructions corresponding to the currently traversed request group, the polling host may generate a request message according to all control instructions in the continuous request list, and begin traversing the next request group. If i is smaller than the number of instructions corresponding to the currently traversed request group, the polling host can acquire the ith control instruction and judge whether the ith control instruction meets the continuous request condition. If the ith control instruction meets the continuous request condition, the polling host can write the ith control instruction into the continuous request list and judge whether i+1 is smaller than the number of instructions corresponding to the currently traversed request group.
If i+1 is greater than or equal to the number of instructions corresponding to the currently traversed request subgroup, the polling host may generate a request message according to all control instructions in the continuous request list, and start traversing the next request subgroup. If i+1 is smaller than the number of instructions corresponding to the currently traversed request group, the polling host can acquire the i+1-th starting register address of the i+1-th control instruction and the i-th ending register address corresponding to the i-th control instruction in the current request group. The polling host may determine whether the i+1th start register address minus the i-th end register address is greater than 1. If the i+1th start register address minus the i+1th end register address is greater than 1, the polling host may determine that the address relationship between the i-th control instruction and the i+1th control instruction does not satisfy the address continuation condition. The polling host may generate a request message according to all control instructions in the continuous request list, and let i equal i plus 2. The polling host may return to executing the step of determining whether i is less than the number of instructions corresponding to the currently traversed request group and subsequent steps. If the i+1th start register address minus the i+1th end register address is less than or equal to 1, the polling host may determine that the address relationship between the i-th control instruction and the i+1th control instruction satisfies the address continuation condition. The polling host may write the i+1th control instruction to the continuous request list. Then, the polling host may make i equal to i plus 2, and return to executing the step of determining whether i is less than the number of instructions corresponding to the currently traversed request group and subsequent steps.
By the method provided by the embodiment, the register addresses of a plurality of control instructions encapsulated in the same request message by the polling host can be ensured to be continuous and the function codes are the same, so that the usability of the request message generated by the polling host is ensured.
Fig. 12 is a flowchart showing a specific implementation of a polling method S1002 according to a seventh embodiment of the present application. Referring to fig. 12, compared to the embodiment shown in fig. 10, after S1002, the polling method provided in this embodiment further includes: s1201 to S1202 are specifically described as follows:
s1201, determining the number of pre-requests based on the (i+1) th end register address corresponding to the (i+1) th control instruction and the start address in the continuous request list; the starting address is a starting register address corresponding to a control instruction written into the continuous request list first.
In this embodiment, a number of conditions may be included in the plurality of continuous conditions. After the polling host obtains the (i+1) th control instruction, the polling host can determine the pre-request quantity according to the (i+1) th end register address corresponding to the (i+1) th control instruction and the start address in the continuous request list. The start address in the continuous request list may be a start register address corresponding to the control instruction written in the continuous request list.
S1202, if the number of the pre-requests does not meet the number condition, generating the request message based on all control instructions in the continuous request list.
In this embodiment, after determining the number of pre-requests in the continuous request list, the polling host may determine whether the number of pre-requests satisfies the number condition. If the polling host determines that the number of pre-requests does not meet the number condition, the polling host may generate the request message based on all control instructions in the current continuous request list. If the polling host determines that the number of pre-requests satisfies the number condition, the polling host may write the i+1th control instruction into the continuous request list.
In one possible implementation, the polling host may determine whether the number of pre-requests satisfies the number condition by determining whether the number of pre-requests is less than a continuous request threshold set by a user. Fig. 13 is a schematic flow chart of a request message generation according to an embodiment of the present application. The step of acquiring the i+1 control command in fig. 13 and all the previous steps are identical to those in fig. 11, and the specific process is referred to in the description about fig. 11, and is not repeated here.
Referring to fig. 13, after the polling host acquires the i+1 control instruction, the polling host may calculate the number of pre-requests corresponding to the continuous request list after writing the i+1 control instruction by subtracting the start address from the i+1 end register address corresponding to the i+1 control instruction. If the number of pre-requests is greater than the continuous request threshold, the polling host may generate a request message based on all control instructions that are already in the continuous request list.
In this embodiment, since the polling host may determine the number of pre-requests corresponding to the continuous request list through the i+1th end register address and the start address, and generate the request packet according to all the control instructions existing in the continuous request list when the number of pre-requests does not satisfy the number condition. Therefore, by the method provided by the embodiment, the number of registers of continuous requests in the request message generated by the polling host can be ensured to be within the continuous request threshold value which can be responded by the slave. Thereby ensuring the high availability of the request message generated by the embodiment of the application.
Fig. 14 shows a flowchart of a specific implementation of a polling method S1002 according to a seventh embodiment of the present application. Referring to fig. 14, compared to the embodiment shown in fig. 10, after S1002, the polling method provided in this embodiment further includes: s1401, detailed below:
S1401, if the data type corresponding to the (i+1) th control instruction does not meet the data type condition, generating the continuous request message based on all the control instructions in the continuous request list, and generating the independent request message based on the (i+1) th control instruction.
In this embodiment, the plurality of continuous conditions further includes a data type condition. The request messages generated by the polling host may also include continuous request messages and independent request messages. The continuous request message may encapsulate a plurality of control instructions with the same function code and continuous register addresses. The polling master can continuously read the contents of a plurality of registers in the slave through continuous request messages. The independent request message can be encapsulated with a control instruction which can only be read independently. The polling master can read the content of one register in the slave through an independent request message. After the polling host acquires the (i+1) th control instruction, the polling host can also judge whether the (i+1) th control instruction meets the continuous request condition through the data type corresponding to the (i+1) th control instruction. The polling host may determine whether the data type corresponding to the i+1th control instruction satisfies a data type condition. If the data type corresponding to the (i+1) th control instruction does not meet the data type condition, the host machine can generate a continuous request message according to all the control instructions in the continuous request list based on the polling. The polling host can also generate the independent request message according to the (i+1) th control instruction.
In one possible implementation manner, after the polling host obtains the (i+1) th control instruction, the polling host may determine whether the data type corresponding to the (i+1) th control instruction is a string type. The register corresponding to the control instruction of the character string type cannot be continuously read by the request message, namely the registers corresponding to the control instruction of the character string type are read one by the independent request message. Therefore, if the data type corresponding to the i+1th control instruction is a character string type, the polling host may determine that the data type corresponding to the i+1th control instruction does not satisfy the data type condition. If the data type corresponding to the i+1th control instruction does not belong to the character string type, the polling host can determine that the data type corresponding to the i+1th control instruction meets the data type condition.
In this embodiment, the polling host may determine whether each control instruction satisfies the continuous request condition according to the data type of each control instruction. Therefore, by the method provided by the embodiment, the register of a plurality of control instructions encapsulated in the same request message by the polling host can be ensured to be continuously requested by the polling host through the request message, so that the availability of the request message generated by the polling host is ensured.
In the practical application of the present scheme, when a researcher takes a total of 65 register contents as a subject with a polling host. Researchers found that if polling generated a separate request message per register content according to the prior art, the polling period required to poll 65 registers was greater than 6500 milliseconds. However, the polling period required to poll the host by the method provided by the embodiment of the application is only 800 milliseconds. In addition, because the method provided by the embodiment of the application can greatly reduce the total time required by a single polling period, compared with the method provided by the embodiment of the application in the prior art, a single polling host can poll more slaves, and the single polling host can also be connected with more slaves through a serial port, thereby achieving the effect of reducing the system cost.
It should be noted that, the sequence number of each step in the above embodiment does not mean the sequence of execution sequence, and the execution sequence of each process should be determined by its function and internal logic, and should not limit the implementation process of the embodiment of the present application in any way.
Referring to fig. 15, a schematic diagram of a polling device according to an embodiment of the present application may specifically include a request message generating module 1501 and a polling module 1502, where:
A request message generating module 1501, configured to encapsulate control instructions with the same function code and continuous register addresses into the same request message according to a message configuration list corresponding to a slave, so as to generate a plurality of request messages corresponding to the slave; the message configuration list records the register address corresponding to each control instruction in the slave;
a polling module 1502, configured to respond to a polling instruction, and sequentially send each request message to the slave based on a sending timing of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine.
The polling module may be further configured to send the first request packet to the slave based on a sending timing of the first request packet; and reading a receipt message returned by the slave machine based on the first request message based on the experience waiting time.
The polling module is also used for reading real-time data returned by the slave machine in the experience waiting time; if the real-time data comprises a first data segment, determining a first expected byte number corresponding to the real-time data according to the byte number of the first data segment; if the actual byte number of the real-time data is smaller than the first expected byte number, reading the real-time data returned by the slave machine based on a preset interval waiting time interval, and updating the repeated reading times corresponding to the first request message until the real-time data meets a preset message stopping condition or the repeated reading times meet a preset reading stopping condition; the message stopping condition is that the actual byte number of the real-time data is larger than or equal to the second expected byte number; the reading stop condition is that the repeated reading times are larger than or equal to a preset repeated reading threshold value.
The polling module is further configured to send a second request packet to the slave, record a sending time of the second request packet, and perform repeated reading operations for multiple times; the second request message is any request message; the repeated reading operation is used for reading a plurality of real-time data returned by the slave machine based on the second request message based on a preset reading interval; if the current repeated reading operation does not read the real-time data, determining a receipt message corresponding to the second request message based on a plurality of read real-time data, and recording the execution time of the current reading operation; and generating experience waiting time corresponding to the second request message based on the sending time, the executing time and the reading interval, and writing the experience waiting time into the second request message, so that when a next polling instruction is responded, the reading time of the receipt message corresponding to the second request message is determined based on the experience waiting time in the second request message.
The request message generating module is further configured to divide the plurality of control instructions in the message configuration list into a plurality of request subgroups based on the function code, and sequentially obtain a first control instruction in any request subgroup; the first control instruction is one of the control instructions in the any request group; for any request subgroup, if a first control instruction in the request subgroup meets a preset continuous request condition, writing the first control instruction into a continuous request list, and judging whether other control instructions in the request subgroup meet the continuous request condition; writing the other control instructions meeting the continuous request condition into the continuous request list, continuously acquiring the other control instructions in the request group for judgment until any one of the other control instructions does not meet the continuous request condition or all control instructions in the request group have judged the continuous request condition, and generating a request message based on all control instructions in the continuous request list.
The request message generating module is further configured to write an ith control instruction meeting all the continuous conditions into a continuous request list; the i is a positive integer greater than or equal to 1; if the i is smaller than the number of the instructions corresponding to the request group, acquiring an (i+1) th control instruction in the request group; and if the address relation between the ith end register address corresponding to the ith control instruction and the (i+1) th start register address corresponding to the (i+1) th control instruction does not meet the address continuous condition, generating the request message based on all control instructions in the continuous request list.
The request message generating module is further configured to determine a pre-request number based on an i+1th end register address corresponding to the i+1th control instruction and a start address in the continuous request list; the initial address is the initial register address corresponding to the control instruction written into the continuous request list; and if the number of the pre-requests does not meet the number condition, generating the request message based on all control instructions in the continuous request list.
The request message generating module may be further configured to generate the continuous request message based on all control instructions in the continuous request list if the data type corresponding to the i+1th control instruction does not meet the data type condition, and generate the independent request message based on the i+1th control instruction.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference should be made to the description of the method embodiments.
Referring to fig. 16, a schematic diagram of an electronic device according to an embodiment of the present application is shown. As shown in fig. 16, an electronic device 1600 in an embodiment of the present application includes: a processor 1610, a memory 1620, and a computer program 1621 stored in the memory 1620 and executable on the processor 1610. The processor 1610, when executing the computer program 1621, implements the steps of the various embodiments of the polling method described above, such as steps S101 to S102 shown in fig. 1. Alternatively, the processor 1610 may implement the functions of the modules/units in the above-described device embodiments when executing the computer program 1621, for example, the functions of the modules 1501 to 1502 shown in fig. 15.
By way of example, the computer program 1621 may be partitioned into one or more modules/units that are stored in the memory 1620 and executed by the processor 1610 to perform the present application. The one or more modules/units may be a series of computer program instruction segments capable of performing particular functions, which may be used to describe the execution of the computer program 1621 in the electronic device 400. For example, the computer program 1621 may be divided into a request message generation module and a polling module, each of which functions as follows:
The request message generating module is used for packaging control instructions with continuous register addresses and the same function code into the same request message according to a message configuration list corresponding to the slave machine so as to generate a plurality of request messages corresponding to the slave machine; the message configuration list records the register address corresponding to each control instruction in the slave;
the polling module is used for responding to a polling instruction and sequentially sending each request message to the slave machine based on the sending time of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine.
The polling module may be further configured to send the first request packet to the slave based on a sending timing of the first request packet; and reading a receipt message returned by the slave machine based on the first request message based on the experience waiting time.
The electronic device 1600 may be the polling host in the foregoing embodiments, where the polling host may be a computing device such as a desktop computer, a cloud server, or the like. The electronic device 1600 may include, but is not limited to, a processor 1610, a memory 1620. It will be appreciated by those skilled in the art that fig. 16 is merely an example of an electronic device 1600 and is not intended to be limiting of the electronic device 1600, and may include more or fewer components than shown, or may combine certain components, or different components, e.g., the electronic device 1600 may also include input and output devices, network access devices, buses, etc.
The processor 1610 may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 1620 may be an internal storage unit of the electronic device 1600, such as a hard disk or a memory of the electronic device 1600. The memory 1620 may also be an external storage device of the electronic device 1600, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the electronic device 1600. Further, the memory 1620 may also include both internal and external memory units of the electronic device 1600. The memory 1620 is used to store the computer program 1621 and other programs and data required by the electronic device 1600. The memory 1620 may also be used to temporarily store data that has been output or is to be output.
The embodiment of the application also discloses an electronic device, which comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the polling method described in the previous embodiments is realized when the processor executes the computer program.
The embodiments of the present application also disclose a computer readable storage medium storing a computer program which, when executed by a processor, implements the polling method described in the previous embodiments.
The embodiment of the application also discloses a computer program product which, when running on a computer, causes the computer to execute the polling method described in the previous embodiments.
The above embodiments are only for illustrating the technical solution of the present application, and are not limited thereto. Although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (11)

1. A method of polling applied to a polling host, comprising:
according to a message configuration list corresponding to a slave, packaging control instructions with continuous register addresses and the same function code into the same request message to generate a plurality of request messages corresponding to the slave; the message configuration list records the register address corresponding to each control instruction in the slave;
responding to a polling instruction, and sequentially transmitting each request message to the slave machine based on the transmission time of each request message; the (n+1) th sending time is that after reading a receipt message returned by the slave machine based on a last request message, a next request message is sent to the slave machine; and N is a positive integer greater than or equal to 1.
2. The method of claim 1 wherein the first request message includes an experience latency; the first request message is any request message; the response to the polling instruction, based on the sending time of each request message, sends each request message to the slave in turn, including:
transmitting the first request message to the slave machine based on the transmission time of the first request message;
And reading a receipt message returned by the slave machine based on the first request message based on the experience waiting time.
3. The method of claim 2, wherein the response piece messages are returned by the slave to the polling master sequentially based on a return order of the respective data segments, the reading the response piece messages returned by the slave based on the first request message based on the empirical waiting time, further comprising:
reading real-time data returned by the slave machine at the experience waiting time;
if the real-time data comprises a first data segment, determining a first expected byte number corresponding to the real-time data according to the byte number of the first data segment;
if the actual byte number of the real-time data is smaller than the first expected byte number, reading the real-time data returned by the slave machine based on a preset interval waiting time interval, and updating the repeated reading times corresponding to the first request message until the real-time data meets a preset message stopping condition or the repeated reading times meet a preset reading stopping condition; the message stopping condition is that the actual byte number of the real-time data is larger than or equal to the second expected byte number; the reading stop condition is that the repeated reading times are larger than or equal to a preset repeated reading threshold value.
4. The method according to claim 1, wherein the sequentially transmitting each request message to the slave based on a transmission timing of each request message in response to a polling instruction includes:
sending a second request message to the slave machine, recording the sending time of the second request message, and executing repeated reading operation for a plurality of times; the second request message is any request message; the repeated reading operation is used for reading a plurality of real-time data returned by the slave machine based on the second request message based on a preset reading interval;
if the current repeated reading operation does not read the real-time data, determining a receipt message corresponding to the second request message based on the read plurality of real-time data, and recording the execution time of the current repeated reading operation;
and generating experience waiting time corresponding to the second request message based on the sending time, the executing time and the reading interval, and writing the experience waiting time into the second request message, so that when a next polling instruction is responded, the reading time of the receipt message corresponding to the second request message is determined based on the experience waiting time in the second request message.
5. The method according to any one of claims 1-4, wherein the message configuration list further records the function codes corresponding to the control instructions, and the encapsulating the control instructions with the same function code and consecutive register addresses into the same request message according to the message configuration list corresponding to the slave machine to generate a plurality of request messages corresponding to the slave machine includes:
dividing a plurality of control instructions in a message configuration list into a plurality of request subgroups based on the function code, and sequentially acquiring a first control instruction in any request subgroup; the first control instruction is one of the control instructions in the any request group;
for any request subgroup, if a first control instruction in the request subgroup meets a preset continuous request condition, writing the first control instruction into a continuous request list, and judging whether other control instructions in the request subgroup meet the continuous request condition;
writing the other control instructions meeting the continuous request condition into the continuous request list, continuously acquiring the other control instructions in the request group for judgment until any one of the other control instructions does not meet the continuous request condition or all control instructions in the request group have judged the continuous request condition, and generating a request message based on all control instructions in the continuous request list.
6. The method of claim 5, wherein the continuous request condition comprises a plurality of continuous conditions, the plurality of continuous conditions comprising an address continuous condition, the register address comprising a start register address and an end register address, the writing the other control instructions satisfying the continuous request condition into the continuous request list, and continuously acquiring the other control instructions in the request group to make a determination until either the other control instructions do not satisfy the continuous request condition or all control instructions in the request group have made a determination of a continuous request condition, generating a request message based on all control instructions in the continuous request list, comprising:
writing an ith control instruction meeting all the continuous conditions into a continuous request list; the i is a positive integer greater than or equal to 1;
if the i is smaller than the number of the instructions corresponding to the request group, acquiring an (i+1) th control instruction in the request group;
and if the address relation between the ith end register address corresponding to the ith control instruction and the (i+1) th start register address corresponding to the (i+1) th control instruction does not meet the address continuous condition, generating the request message based on all control instructions in the continuous request list.
7. The method of claim 6, wherein the plurality of consecutive conditions includes a number condition, and wherein if the i is less than the number of instructions corresponding to the request group, after the (i+1) th control instruction in the request group is obtained, further comprising:
determining the number of pre-requests based on the (i+1) th end register address corresponding to the (i+1) th control instruction and the start address in the continuous request list; the initial address is the initial register address corresponding to the control instruction written into the continuous request list;
and if the number of the pre-requests does not meet the number condition, generating the request message based on all control instructions in the continuous request list.
8. The method of claim 6, wherein the plurality of continuous conditions further includes a data type condition, the request message includes a continuous request message and an independent request message, and the step of acquiring the i+1 control instruction in the request group if the i is smaller than the number of instructions corresponding to the request group further includes:
and if the data type corresponding to the (i+1) th control instruction does not meet the data type condition, generating the continuous request message based on all the control instructions in the continuous request list, and generating the independent request message based on the (i+1) th control instruction.
9. A polling device, for use with a polling host, comprising:
the request message generating module is used for packaging control instructions with continuous register addresses and the same function code into the same request message according to a message configuration list corresponding to the slave machine so as to generate a plurality of request messages corresponding to the slave machine; the message configuration list records the register address corresponding to each control instruction in the slave;
the polling module is used for responding to a polling instruction and sequentially sending each request message to the slave machine based on the sending time of each request message; and the sending time is that after the receipt message returned by the slave machine based on the last request message is read, the next request message is sent to the slave machine.
10. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the polling method of any of claims 1-8 when executing the computer program.
11. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the polling method of any of claims 1-8.
CN202310923775.5A 2023-07-25 2023-07-25 Polling method, polling device, electronic equipment and storage medium Pending CN117061275A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310923775.5A CN117061275A (en) 2023-07-25 2023-07-25 Polling method, polling device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310923775.5A CN117061275A (en) 2023-07-25 2023-07-25 Polling method, polling device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117061275A true CN117061275A (en) 2023-11-14

Family

ID=88663639

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310923775.5A Pending CN117061275A (en) 2023-07-25 2023-07-25 Polling method, polling device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117061275A (en)

Similar Documents

Publication Publication Date Title
US11169938B2 (en) Non-volatile memory (NVM) express (NVMe) data processing method and system
CN102866971B (en) Device, the system and method for transmission data
CN113254368B (en) Data writing method and data reading method from AXI bus to OPB bus
CN109558344B (en) DMA transmission method and DMA controller suitable for network transmission
CN106487896B (en) Method and apparatus for handling remote direct memory access request
CN105556930A (en) NVM EXPRESS controller for remote memory access
CN110109626B (en) NVMe SSD command processing method based on FPGA
CN107590099A (en) A kind of more main frames access method, expanding unit and the storage medium of slave
CN109564502B (en) Processing method and device applied to access request in storage device
CN110688333A (en) PCIE (peripheral component interface express) -based DMA (direct memory Access) data transmission system and method
CN110941582B (en) USB bus structure of BMC chip and communication method thereof
CN113590512A (en) Self-starting DMA device capable of directly connecting peripheral equipment and application
CN115827524A (en) Data transmission method and device
JP2009502072A (en) FlexRay communication module, FlexRay communication control device, and method for transmitting a message between a FlexRay communication connection and a FlexRay subscriber device
CN116225992A (en) NVMe verification platform and method supporting virtualized simulation equipment
US8671230B2 (en) Data transfer device and data transfer method
CN117061275A (en) Polling method, polling device, electronic equipment and storage medium
CN102420749A (en) Device and method for realizing network card issuing function
CN111371799B (en) Method, device and equipment for controlling data receiving and transmitting of MCTP (Multi-channel media Port) controller
CN114610231A (en) Control method, system, equipment and medium for large-bit-width data bus segmented storage
CN112825024A (en) Command fusion and split method and NVMe controller
CN112732176B (en) SSD (solid State disk) access method and device based on FPGA (field programmable Gate array), storage system and storage medium
CN111625486B (en) Universal serial bus device and data transmission method thereof
CN112835823B (en) Storage controller response sending method
CN113934671B (en) Interface control chip and network equipment

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