Serial port data processing component and device based on XML (Extensible Markup Language)
The XML-based serial port data processing component addresses the inefficiencies in industrial control software by providing comprehensive data handling for RS422 and RS232 interfaces, reducing development cycles and enhancing reliability through data verification and framing.
Patent Information
- Application Number
- CN202411291934.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-27
AI Technical Summary
Existing industrial control software for non-standard equipment requires repetitive work and long development cycles due to the need for customized software development, particularly in full-duplex and half-duplex communication modes, and lacks comprehensive data parsing and validity judgment methods for serial port data processing.
A serial port data processing component and device based on XML, comprising four components: protocol loading, data verification, data parsing, and data framing, which handle RS422 and RS232 interfaces, enabling efficient data processing and communication by configuring serial port data parsing and framing rules, and verifying data integrity.
Reduces software development and maintenance workload, improves efficiency, and enhances communication reliability by addressing data frame anomalies and supporting various communication modes.
Smart Images

Figure CN119201053A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial software design and development, and in particular to an XML-based serial port data processing component and device. Background Art
[0002] Industrial control software is one of the indispensable and important components in modern industrial manufacturing. With the development of modern instrumentation, most of the current instruments are digital instruments, which provide RS422 interface, RS485 interface and RS232 interface. For special non-standard equipment, customized software development is required, which leads to a large amount of repetitive work and a long development cycle. Therefore, some common components need to be developed to reduce repetitive work.
[0003] At present, the industry mostly adopts XML-based software development methods to implement software parameter configuration item modifications to improve the versatility and maintainability of the software. For example, CN201910140665.5 discloses an XML-based configuration method and device for a rocket test, launch and control system, and CN202111218220.8 discloses an XML-based protocol dynamic packaging and parsing method.
[0004] CN201910140665.5 discloses a configuration method and device for a rocket test, launch and control system based on XML. This patent defines various dedicated software interfaces and data parsing rules and software interface data display rules through XML, which improves the versatility of the software to a certain extent and reduces the workload of software development with similar functions. However, this patent can only configure the receiving data parsing rules, which belongs to the simplex communication mode. It cannot be universal for data in the half-duplex communication mode and the full-duplex communication mode. At the same time, this patent only defines data parsing, and does not define the acquisition and validity judgment methods of data frames. In actual work, most of the use of serial ports by non-standard equipment is in full-duplex communication mode. Therefore, this patent has certain limitations.
[0005] CN202111218220.8 discloses a method for dynamic protocol packaging and parsing based on XML. The method defines the protocol format and business actions through keywords in the XML file of the protocol template, and realizes protocol process interaction by parsing the XML keywords, that is, dynamic protocol packaging and parsing; the basic functions and business functions called by keywords and operations; the targeted field is the field of information technology, so the application field of this patent is different. Summary of the invention
[0006] The purpose of the present invention is to provide a component and a device for solving the large workload of serial port data processing software development based on the analysis of serial port usage scenarios in the industrial field in order to solve the above-mentioned problem. The component and the device comprehensively consider the RS422 interface and RS232 interface protocol contents commonly used in non-standard special equipment, and configure the serial port data parsing content and rules, data framing rules, etc. through the protocol, thereby reducing the software duplication design and software maintenance workload caused by changes in serial port protocols, reducing software maintenance costs and improving software development efficiency.
[0007] The present invention achieves the above-mentioned purpose through the following technical solutions:
[0008] The invention provides a serial port data processing component and device based on XML, comprising four components, namely, a serial port protocol loading component, a serial port data verification component, a serial port data parsing component and a serial port data framing component.
[0009] As a preferred embodiment of the present invention, the serial port protocol loading component reads the XML configuration file and generates a serial port information class according to the file content. The serial port information class includes two types of data: serial port basic information and protocol content, both of which are obtained by the serial port information class in an inheritance manner;
[0010] As a preferred embodiment of the present invention, according to the basic information of the serial port, the serial port is opened, and the data received in the serial port buffer area is read by using an event interrupt triggering method; the serial port data verification component is called, the serial port data verification component caches the data, and the frame header, data length, and check bit of the cached data are verified to obtain valid serial port data, and invalid data is removed at the same time to obtain a data frame that meets the protocol data content;
[0011] As a preferred embodiment of the present invention, in the serial port data verification component, the serial port verification component stores the input serial port data into a cache array, determines whether the received data length meets the data length requirement of the protocol content (receiving class), and if so, searches for the frame header from the first byte. If the frame header is found, all the data before the frame header are removed; if the frame header is not found, all the data are removed; after finding the frame header, determines whether the remaining data length meets the data length requirement, and if so, calculates the check digit according to the protocol content and compares them; if not, saves the data, exits this data verification, and restarts verification after the next set of data enters; after the check digit comparison is completed, if the check digit is correct, takes out the complete serial port byte data and feeds back; if the check digit is incorrect, removes the frame header data, searches for the frame header again from the first byte after the frame header, and repeats the above steps.
[0012] As a preferred embodiment of the present invention, in the serial port parsing component, the corresponding data is taken out from the serial port byte data in the order of the protocol content, and calculated according to the resolution algorithm to obtain the actual value, with the serial port ID as the data header, and the data part consisting of the data name + actual value is sent to the message list 1.
[0013] As a preferred embodiment of the present invention, the serial port data framing component reads the data in the message list 2 in real time. This part of the data is the data sent to the serial port. The data uses the serial port ID as the data header and the data name + data value as the data part. The serial port data framing component reads the message data, selects the protocol data content to frame the message data according to the serial port ID, and sends the framed serial port data frame to the serial port data sending buffer, and the serial port data buffer sends the data.
[0014] As a preferred embodiment of the present invention, the serial port used is an RS422 interface and an RS232 interface.
[0015] As a preferred embodiment of the present invention, the XML configuration file consists of two first-level nodes: serial port basic information and protocol content, wherein the protocol content contains no less than one second-level node, the second-level node contains multiple subordinate nodes, and the total number of XML configuration file nodes is no more than 5 levels.
[0016] As a preferred embodiment of the present invention, the serial port data is transmitted in hexadecimal.
[0017] The beneficial effects of the present invention are:
[0018] 1. The XML-based serial port data processing component and device provided by the present invention is an effective measure to reduce the workload of industrial control software development and maintenance. Based on the characteristics of XML files, the needs of serial port data processing in different scenarios can be met by changing XML, reducing the workload of repeated software development and shortening the software development cycle.
[0019] 2. The XML-based serial port data processing component and device provided by the present invention comprehensively considers the RS422 interface and RS232 interface protocol contents used by the serial port, constructs two first-level nodes (serial port basic information and protocol contents) of the XML file, realizes protocol conversion through protocol configuration of serial port data parsing contents and rules, data framing rules, etc., verifies the serial port received data in a variety of ways, effectively avoids the problem that the serial port cannot parse data due to data frame anomalies such as half-cut data frames, and improves the reliability of serial port communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 The present invention discloses an XML-based serial port data processing component and a device serial port data processing flow chart.
[0021] Figure 2 It is a schematic diagram of the XML file structure in the present invention.
[0022] Figure 3 It is a data verification flow chart of the data verification component in the present invention;
[0023] Figure 4 It is the use case view of the measurement and control software of a certain type of engine test bench for implementing the use case.
[0024] Figure 5 This is a diagram of the XML file of a certain type of engine test bench measurement and control software for the implementation use case. DETAILED DESCRIPTION
[0025] In order to make the objectives, technical solutions and advantages of the present invention clearer, the implementation method of the present invention will be described in detail below in conjunction with the accompanying drawings and embodiments, so that the implementation process of how the present invention applies technical means to solve technical problems and achieve technical effects can be fully understood and implemented accordingly.
[0026] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.
[0027] Example 1
[0028] like Figure 1 As shown, a serial port data processing component and device based on XML includes four components: a serial port protocol loading component, a serial port data verification component, a serial port data parsing component, and a serial port data framing component. The serial port protocol loading component reads the XML configuration file, and the XML configuration file structure is as follows: Figure 2 As shown, according to the file content, a serial port information class is generated, which includes two types of data: basic serial port information and protocol content. According to the basic serial port information, the serial port is opened, and the data received in the serial port buffer is read using the event interrupt triggering method. The serial port data verification component is called. Figure 3The verification process shown in the figure caches the data, verifies the frame header, data length and check bit of the cached data, obtains valid serial port data, removes invalid data and obtains data frames that meet the protocol data content; the serial port parsing component obtains the complete data frame, takes out the corresponding data from the serial port byte data in the order of the protocol content, and calculates according to the solution algorithm to obtain the actual value, takes the serial port ID as the data header, and sends the data part consisting of the data name + the actual value to the message list 1; the serial port data framing component reads the data in the message list 2 in real time. This part of the data is the data sent to the serial port. The data uses the serial port ID as the data header and the data name + data value as the data part. The serial port data framing component reads the message data, selects the protocol data content according to the serial port ID to frame the message data, and sends the framed data to the serial port.
[0029] Example 2
[0030] One embodiment of the present invention is a certain type of engine test bench measurement and control software, which is mainly used to communicate with the engine electronic controller, receive data such as engine speed and engine exhaust temperature fed back by the engine electronic controller, and send test driver control instructions to the engine electronic controller. Figure 4 A certain type of engine measurement and control software mainly includes serial port, serial port protocol loading component, serial port data verification component, serial port data parsing component, software interface display module, software interface control module, and the Config.xml configuration file information is as follows: Figure 5 shown.
[0031] The specific implementation steps of a certain type of engine measurement and control software are as follows:
[0032] The test driver runs a certain type of engine measurement and control software, and the serial port protocol loading component loads the Config.xml file in the software. According to the serial port information, the serial port is opened (serial port name: COM1, baud rate is 115200bps, odd parity, 8 data bits, 1 stop bit, no flow control), and a serial port 1 variable is created at the same time, including the data receiving class ReceivedData and the data sending class SendData; the data in the Receive structure in Config.xml is read and assigned to the ReceivedData class, and the data in the Send structure in Config.xml is read and assigned to the SendData class, completing the data initialization of the entire variable;
[0033] Serial port 1 open event interrupt;
[0034] The serial port 1 event interrupt is triggered, and all the data sent by the electric controller to the serial port 1 are taken out and put into the buffer area Buffer[] array;
[0035] Real-time judgment of the data in the Buffer[] array, if there is a number, asynchronously call the serial port verification component, assign the data in the Buffer to the serial port verification component interface function, and the serial port verification component follows Figure 3 Process, check the frame header (0x55AA) and data length (8) according to the BasicInformation information in the ReceivedData class. If the requirements are met, calculate the checksum to determine whether the checksum of the last two digits of the data is consistent with the received data;
[0036] Real-time judgment of the data in the RealBuffer[] array. If there is data, the serial port parsing component is asynchronously called to parse the data in sequence according to the Data information in the ReceivedData class. After the data is parsed, it is sent to message queue 1 in the format of "COMID:1001; engine speed: 0; engine exhaust temperature: 0";
[0037] The software interface display module reads the message with COMID "1001" from the message queue 1, and displays the engine speed and engine exhaust temperature on the software interface according to the format;
[0038] The test driver clicks the button in the software interface control module as needed (the relevant button is dynamically created and loaded according to the Data information in the SendData class). The button response event will be sent in the format of serial port ID + data content. Click the [Flight Speed] setting button and set the value to 0.1Ma. The [Flight Speed] button response event will send the message "COMID: 1001; Flight Speed: 0.1" to message queue 2.
[0039] The serial port data framing component reads the message with COMID "1001" from message queue 2, calculates the value of "flight speed" as 10 according to the Data information in the SendData class, assigns it to the sending array SendBuffer[], recalculates the checksum, and calls the serial port COM1 sending interface function (assigns SendBuffer[] to the sending interface function) to send data to the electronic controller.
[0040] Although the present invention is described herein with reference to the illustrative embodiments of the present invention, the above embodiments are only preferred embodiments of the present invention, and the embodiments of the present invention are not limited to the above embodiments. It should be understood that those skilled in the art can design many other modifications and embodiments, which will fall within the scope and spirit of the principles disclosed in this application.
Claims
1. A serial port data processing method based on XML, characterized in that: The steps include: Step S01: The software starts and calls the serial port protocol loading component. The serial port protocol loading component reads the XML configuration file and generates a serial port information class according to the file content. The serial port information class includes two types of data: serial port basic information and protocol content. Both are obtained by the serial port information class in an inheritance manner. Step S02: according to the basic information of the serial port, the serial port is opened, and the data received in the serial port buffer area is read by using an event interrupt triggering method; Call the serial port data verification component, which caches the data, verifies the frame header, data length, and check bit of the cached data, obtains valid serial port data, removes invalid data, and obtains a data frame that meets the protocol data content; Step S03: calling the serial port parsing component to parse the data frame. After parsing, the data uses the serial port ID as the data header and the data name + data value as the data part, and is sent to the message list 1; Step S04: The serial port data framing component reads the data in the message list 2 in real time. This part of the data is the data sent to the serial port. The data uses the serial port ID as the data header and the data name + data value as the data part. The serial port data framing component reads the message data, selects the protocol data content to frame the message data according to the serial port ID, and sends the framed serial port data frame to the serial port data sending buffer, which sends the data.
2. The XML-based serial port data processing method according to claim 1, characterized in that: The specific steps of "serial port data verification" in step S02 are: using a circular queue method to search for data frame headers one by one, verifying the data length and the check bit, and only taking out the complete data after the verification passes, otherwise continue to search and remove invalid data.
3. A serial port data processing device based on XML, characterized in that: Including serial port protocol loading component, serial port data verification component, serial port data parsing component and serial port data framing component; The serial port protocol loading component reads the XML configuration file; The serial port data verification component caches and verifies the data; The serial port parsing component calculates the data and sends it to the message list 1; The serial port data framing component reads the data in the message list 2 and frames the data according to the protocol data content selected by the serial port ID, and sends the framed serial port data frame to the serial port data sending buffer area.
4. The XML-based serial port data processing device according to claim 3, characterized in that: The serial ports are RS422 and RS232.
5. The XML-based serial port data processing device according to claim 3, characterized in that: The XML configuration file is composed of two first-level nodes, namely, basic serial port information and protocol content, wherein the protocol content contains no less than one second-level node, and the second-level node contains multiple subordinate nodes.
6. The XML-based serial port data processing device according to claim 3, characterized in that: The total number of nodes is no more than 5 levels.
7. The XML-based serial port data processing device according to claim 3, characterized in that: The serial port data is transmitted in hexadecimal.
Citation Information
Patent Citations
Configuration method and device of rocket test launch control system based on XML
CN109857452A
Dynamic protocol packing and analyzing method based on XML (Extensible Markup Language)
CN113887173A