Data communication method and device, equipment, storage medium and program product

By obtaining and processing data frames in the serial port ring queue, and using timeout time to judge the normality of the data frame, combined with the producer and consumer strategy mode, the data loss problem caused by interruption of microcontrollers is solved, and the real-time data processing is improved Sex and accuracy.

CN119003427APending Publication Date: 2024-11-22BEIJING HORIBA METRON INSTR
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411051816.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

In the prior art, the MODBUS slave framework causes low-probability data loss due to interruption of the microcontroller, which affects the effectiveness of communication data.

Method used

Obtain data frames in the serial port ring queue, and judge the normality of the data frame by timeout time. If it is normal, it will be parsed and stored in the sending frame buffer. The producer and consumer strategy mode is used to process the serial port data to avoid interruption and interruption.

Benefits of technology

Improve the real-time nature of data processing, reduce the number of error frames in MODBUS communication frames, and ensure that data is not lost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003427A_ABST
    Figure CN119003427A_ABST
Patent Text Reader

Abstract

The invention provides a data communication method and device, equipment, a storage medium and a program product, and is applied to the technical field of data communication. The method comprises the steps that under the condition that it is determined that data exists in a serial port annular queue, a first data frame is obtained from the serial port annular queue, and the serial port annular queue is used for storing data frames received from a bus; storing the first data frame into a receiving frame buffer area; if the time for receiving the first data frame exceeds the inter-frame timeout time, judging whether the first data frame is a normal data frame or not; and if yes, determining a target instruction according to the first data frame and a preset key value table, and storing the target instruction into a sending frame buffer area.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] Serial interface is abbreviated as serial port, also known as serial communication interface or serial communication interface. It is an expansion interface using serial communication. In actual industrial networks, serial communication is an indispensable means to realize process control, real-time monitoring and other functions. In the actual production process, industrial serial networks usually use MODBUS protocol, which is an application layer protocol based on serial interface and is a commonly used connection method between industrial electronic equipment.

[0003] In the prior art, the MODBUS slave framework will faithfully write the data from the bus into the variable of the corresponding address. However, the traditional interrupt and data cache mode cannot maintain the validity of the communication data. At the same time, the communication data will be interrupted by the interrupt of the microcontroller, which will cause a small probability of data loss. Summary of the invention

[0004] The present invention provides a data communication method, device, equipment, storage medium and program product, which are used to solve the problem of data loss with a small probability caused by the interruption of a single-chip microcomputer in the prior art.

[0005] The present invention provides a data communication method, comprising: when it is determined that there is data in a serial port ring queue, obtaining a first data frame from the serial port ring queue, the serial port ring queue being used to store data frames received from a bus; storing the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds an inter-frame timeout time, determining whether the first data frame is a normal data frame; if so, determining a target instruction according to the first data frame and a preset key value table, and storing the target instruction in a sending frame buffer.

[0006] According to a data communication method provided by the present invention, if the time for receiving the first data frame exceeds the inter-frame timeout time, then determining whether the first data frame is a normal data frame includes: if the adjacent character interval of the first data frame does not exceed the inter-character timeout time, then determining that the first data frame is a normal data frame; if the adjacent character interval of the first data frame exceeds the inter-character timeout time, then determining that the first data frame is an abnormal data frame.

[0007] According to a data communication method provided by the present invention, if so, then determining the target instruction according to the first data frame and the preset key value table, and storing the target instruction in the sending frame buffer, including: if so, determining the key value information by parsing the first data frame; determining the corresponding target instruction in the preset key value table with the key value information as the index.

[0008] According to a data communication method provided by the present invention, the key value information is a register address or a coil address.

[0009] According to a data communication method provided by the present invention, the preset key value table includes a read-register table, a write-register table, a read-coil table, and a write-coil table.

[0010] According to a data communication method provided by the present invention, before acquiring the first data frame from the serial port ring queue, the method further includes: When the interrupt is triggered, the first data frame is received, and the first data frame is sequentially stored in the serial port ring queue according to the receiving order.

[0011] The present invention also provides a data communication device, comprising the following modules: an acquisition module and a processing module; the acquisition module is used to acquire a first data frame from a serial port ring queue when it is determined that there is data in the serial port ring queue, and the serial port ring queue is used to store data frames received from a bus; the processing module is used to store the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds the inter-frame timeout time, it is determined whether the first data frame is a normal data frame; if so, the target instruction is determined according to the first data frame and a preset key value table, and the target instruction is stored in a sending frame buffer.

[0012] According to a data communication device provided by the present invention, the processing module is used to determine that the first data frame is a normal data frame if the adjacent character interval of the first data frame does not exceed the inter-character timeout period; if the adjacent character interval of the first data frame exceeds the inter-character timeout period, determine that the first data frame is an abnormal data frame.

[0013] According to a data communication device provided by the present invention, the processing module is used to determine the key value information by parsing the first data frame if yes; and determine the corresponding target instruction in the preset key value table using the key value information as an index.

[0014] According to a data communication device provided by the present invention, the key value information is a register address or a coil address.

[0015] According to a data communication device provided by the present invention, the preset key value table includes a read-register table, a write-register table, a read-coil table, and a write-coil table.

[0016] According to a data communication device provided by the present invention, the processing module is used to receive the first data frame when an interrupt is triggered, and store the first data frame in the serial port ring queue in sequence according to the receiving order.

[0017] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned data communication methods is implemented.

[0018] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data communication method described in any one of the above is implemented.

[0019] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned data communication methods.

[0020] The data communication method, device, equipment, storage medium and program product provided by the present invention can obtain the first data frame from the serial port circular queue when it is determined that there is data in the serial port circular queue, and the serial port circular queue is used to store the data frames received from the bus; store the first data frame in the receiving frame buffer; if the time to receive the first data frame exceeds the inter-frame timeout time, determine whether the first data frame is a normal data frame; if so, determine the target instruction according to the first data frame and the preset key value table, and store the target instruction in the sending frame buffer. Through this scheme, since the newly added serial port circular queue can store the data frames received from the bus, and the implementation of processing serial port data adopts the producer and consumer strategy mode, it avoids the interruption of the single-chip microcomputer in the traditional technology, and can improve the real-time performance of data processing and reduce the number of error frames in the MODBUS communication frame under the premise of ensuring that data is not lost. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0022] Figure 1 It is a flow chart of the data communication method provided by the present invention; Figure 2 It is a schematic diagram of a flow chart of storing data into a serial port ring queue provided by the present invention; Figure 3 It is a structural schematic diagram of a data communication device provided by the present invention; Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0024] It should be noted that, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0025] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0026] In order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second", etc. are used to distinguish the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first", "second", etc. are not limiting the quantity and execution order.

[0027] The embodiments of the present application describe some exemplary embodiments for the purpose of explanation. It should be understood that the present application can be implemented in other ways that are not specifically shown in the drawings.

[0028] like Figure 1 As shown, an embodiment of the present application provides a data communication method, which can be applied to a data communication device. The data communication method may include S101-S104: S101: When determining that there is data in a serial port ring queue, the data communication device obtains a first data frame from the serial port ring queue.

[0029] The serial port ring queue is used to store data frames received from the bus.

[0030] Specifically, since the serial port ring queue can be used to store data frames received from the bus, when it is determined that there is data in the serial port ring queue, the data communication device can directly obtain the first data frame from the serial port ring queue.

[0031] Optionally, the data frames stored in the serial port ring queue may include MODBUS normal data frames, MODBUS abnormal data frames, and non-MODBUS data frames.

[0032] Optionally, before acquiring the first data frame from the serial port ring queue, the data communication device may receive the first data frame when an interrupt is triggered, and store the first data frame in the serial port ring queue in sequence according to a receiving order.

[0033] Specifically, Figure 2 As shown, after the single-chip microcomputer platform is powered on, the hardware can be initialized first, that is, the serial port ring queue, inter-frame timeout, inter-character timeout, receiving frame buffer, sending frame buffer, frame state and preset key value table are initialized. Then, if the MODBUS frame needs to be consumed, if N characters are obtained on the bus of the single-chip microcomputer platform, an interrupt will be triggered. In the interrupt processing stage, the data communication device can push the N characters obtained from the bus into the serial port ring queue in sequence according to the receiving order. It should be noted that the above-mentioned first data frame includes the N characters.

[0034] It should be noted that the above-mentioned inter-frame timeout period can be used to determine whether a MODBUS frame on the bus has ended, and the above-mentioned inter-character timeout period can be used to determine whether a current MODBUS frame has timed out.

[0035] S102: The data communication device stores the first data frame into a receiving frame buffer.

[0036] Optionally, the data communication device may switch the framework state machine from an idle state to a receiving state, and store the first data frame obtained from the serial port ring queue into a receiving frame buffer.

[0037] S103: If the time for receiving the first data frame exceeds the inter-frame timeout period, the data communication device determines whether the first data frame is a normal data frame.

[0038] Optionally, if the time for receiving the first data frame exceeds the inter-frame timeout period, the data communication device may first switch the framework state machine from the receiving state to the processing state, and then determine whether the first data frame is a normal data frame.

[0039] Optionally, if the interval between adjacent characters of the first data frame does not exceed the inter-character timeout period, the data communication device may determine that the first data frame is a normal data frame; if the interval between adjacent characters of the first data frame exceeds the inter-character timeout period, the data communication device may determine that the first data frame is an abnormal data frame.

[0040] S104: If yes, the data communication device determines a target instruction according to the first data frame and the preset key-value table, and stores the target instruction in a sending frame buffer.

[0041] Optionally, if so, the data communication device can determine the key value information by parsing the first data frame; and determine the corresponding target instruction in the preset key value table using the key value information as an index, wherein the key value information is a register address or a coil address.

[0042] Specifically, for a normal data frame, the data communication device can obtain data from a preset key value table through an access function according to the register address and number, fill the data into a sending frame buffer, and switch the frame state from a processing state to a sending state.

[0043] It should be noted that compared with the existing framework, this application adopts the form of a key-value table to store all actions and information of the coils and registers of the entire framework, which has better scalability, maintainability and data security, and at the same time has lower resource usage.

[0044] Optionally, the preset key value table includes a read-register table, a write-register table, a read-coil table, and a write-coil table.

[0045] Specifically, the data communication device can add corresponding addresses and access function pairs in the register table or coil table according to different devices and different requirements. When adding corresponding registers or coils, the table uses the register and coil addresses as keys and the corresponding functions as values, and reads and writes are separated. When accessing data from the register table or coil table, the read-register table, write-register table, read-coil table, and write-coil table can be accessed according to different instructions to perform different functions.

[0046] It should be noted that since the present application sets up a preset key value table, when it is necessary to add or delete modules, it is only necessary to add the corresponding address and access function pairs to the preset key value table, which makes modification convenient; at the same time, since the application layer processing and register / coil processing flow are separated, the modification of files and codes is reduced, the coupling is reduced, the direct modification of variables in the embedded microcontroller or processor is avoided, the data processing and data acquisition are separated, and the data security is ensured.

[0047] In the embodiment of the present application, since the newly added serial port ring queue can store data frames received from the bus, and the implementation of processing serial port data adopts the producer and consumer strategy model, it avoids the interruption disadvantages of the microcontroller in the traditional technology, and can improve the real-time performance of data processing while ensuring that data is not lost.

[0048] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiment disclosed herein, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0049] The data communication method provided in the embodiment of the present application can be executed by a data communication device or a control module for data communication in the data communication device. In the embodiment of the present application, the data communication device provided in the embodiment of the present application is described by taking the data communication device executing the data communication method as an example.

[0050] It should be noted that the embodiment of the present application can divide the functional modules of the data communication device according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. Optionally, the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0051] like Figure 3 As shown, an embodiment of the present application provides a data communication device 300. The data communication device 300 includes: an acquisition module 301 and a processing module 302. The acquisition module 301 is used to acquire a first data frame from the serial port circular queue when it is determined that there is data in the serial port circular queue, and the serial port circular queue is used to store data frames received from the bus; the processing module 302 is used to store the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds the inter-frame timeout time, it is determined whether the first data frame is a normal data frame; if so, the target instruction is determined according to the first data frame and the preset key value table, and the target instruction is stored in the sending frame buffer.

[0052] Optionally, the processing module 302 is used to determine that the first data frame is a normal data frame if the interval between adjacent characters of the first data frame does not exceed the inter-character timeout period; if the interval between adjacent characters of the first data frame exceeds the inter-character timeout period, determine that the first data frame is an abnormal data frame.

[0053] Optionally, the processing module 302 is configured to determine key value information by parsing the first data frame; and determine a corresponding target instruction in the preset key value table using the key value information as an index.

[0054] Optionally, the key value information is a register address or a coil address.

[0055] Optionally, the preset key value table includes a read-register table, a write-register table, a read-coil table, and a write-coil table.

[0056] Optionally, the processing module 302 is used to receive the first data frame when an interrupt is triggered, and store the first data frame in the serial port ring queue in sequence according to a receiving order.

[0057] In the embodiment of the present application, since the newly added serial port ring queue can store data frames received from the bus, and the implementation of processing serial port data adopts the producer and consumer strategy model, it avoids the interruption disadvantages of the microcontroller in the traditional technology, and can improve the real-time performance of data processing while ensuring that data is not lost.

[0058] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the data communication method, which includes: when it is determined that there is data in the serial port circular queue, obtaining a first data frame from the serial port circular queue, the serial port circular queue is used to store the data frame received from the bus; storing the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds the inter-frame timeout time, determining whether the first data frame is a normal data frame; if so, determining the target instruction according to the first data frame and the preset key value table, and storing the target instruction in the sending frame buffer.

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

[0060] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the data communication method provided by the above methods, and the method includes: when it is determined that there is data in the serial port ring queue, obtaining a first data frame from the serial port ring queue, and the serial port ring queue is used to store data frames received from the bus; storing the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds the inter-frame timeout time, determining whether the first data frame is a normal data frame; if so, determining the target instruction based on the first data frame and the preset key value table, and storing the target instruction in the sending frame buffer.

[0061] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the data communication method provided by the above-mentioned methods, the method comprising: when it is determined that there is data in the serial port ring queue, obtaining a first data frame from the serial port ring queue, the serial port ring queue being used to store data frames received from a bus; storing the first data frame in a receiving frame buffer; if the time for receiving the first data frame exceeds the inter-frame timeout time, determining whether the first data frame is a normal data frame; if so, determining a target instruction based on the first data frame and a preset key value table, and storing the target instruction in a sending frame buffer.

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

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

[0064] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data communication method, characterized in that: include: When it is determined that there is data in the serial port circular queue, obtaining a first data frame from the serial port circular queue, wherein the serial port circular queue is used to store data frames received from the bus; storing the first data frame into a receiving frame buffer; If the time for receiving the first data frame exceeds the inter-frame timeout period, determining whether the first data frame is a normal data frame; If yes, determine the target instruction according to the first data frame and the preset key value table, and store the target instruction in the sending frame buffer.

2. The data communication method according to claim 1, characterized in that: If the time of receiving the first data frame exceeds the inter-frame timeout period, determining whether the first data frame is a normal data frame includes: If the interval between adjacent characters of the first data frame does not exceed the inter-character timeout period, determining that the first data frame is a normal data frame; If the interval between adjacent characters of the first data frame exceeds the inter-character timeout period, the first data frame is determined to be an abnormal data frame.

3. The data communication method according to claim 1, characterized in that: If yes, determining a target instruction according to the first data frame and a preset key value table, and storing the target instruction in a sending frame buffer, including: If yes, determining the key value information by parsing the first data frame; The corresponding target instruction is determined in the preset key value table using the key value information as an index.

4. The data communication method according to claim 3, characterized in that: The key value information is a register address or a coil address.

5. The data communication method according to claim 4, characterized in that: The preset key value table includes a read-register table, a write-register table, a read-coil table, and a write-coil table.

6. The data communication method according to claim 1, characterized in that: Before acquiring the first data frame from the serial port ring queue, the method further includes: When the interrupt is triggered, the first data frame is received, and the first data frame is sequentially stored in the serial port ring queue according to the receiving order.

7. A data communication device, characterized in that: include: Acquisition module and processing module; The acquisition module is used to acquire a first data frame from the serial port circular queue when it is determined that there is data in the serial port circular queue, and the serial port circular queue is used to store data frames received from the bus; The processing module is used to store the first data frame into a receiving frame buffer; If the time for receiving the first data frame exceeds the inter-frame timeout period, determining whether the first data frame is a normal data frame; If yes, determine the target instruction according to the first data frame and the preset key value table, and store the target instruction in the sending frame buffer.

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

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

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