CN113612760A - Control method and control device applied to serial port communication protocol of upper and lower computers - Google Patents

Control method and control device applied to serial port communication protocol of upper and lower computers Download PDF

Info

Publication number
CN113612760A
CN113612760A CN202110865880.9A CN202110865880A CN113612760A CN 113612760 A CN113612760 A CN 113612760A CN 202110865880 A CN202110865880 A CN 202110865880A CN 113612760 A CN113612760 A CN 113612760A
Authority
CN
China
Prior art keywords
data
segment
serial port
byte
length
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
CN202110865880.9A
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.)
Shenzhen Jiecheng Technology Service Co ltd
Original Assignee
Shenzhen Jiecheng Technology Service 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 Shenzhen Jiecheng Technology Service Co ltd filed Critical Shenzhen Jiecheng Technology Service Co ltd
Priority to CN202110865880.9A priority Critical patent/CN113612760A/en
Publication of CN113612760A publication Critical patent/CN113612760A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/03Protocol definition or specification 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/06Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Communication Control (AREA)

Abstract

The invention provides a control method applied to a serial port communication protocol of an upper computer and a lower computer, which is applied to a sending end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and is characterized by comprising the following steps: labeling the element data according to different element types in the data to be sent to generate labeled data, wherein any element data corresponds to a label; combining all tagged data to form a data field; forming a serial port protocol packet according to the data header, the command word, the data length, the data field, the end character and the check bit; and sending the serial port protocol packet to a receiving end.

Description

Control method and control device applied to serial port communication protocol of upper and lower computers
Technical Field
The invention relates to the technical field of serial communication protocols, in particular to a control method and a control device applied to a serial communication protocol of an upper computer and a lower computer.
Background
Serial communication is generally used for data transmission between devices, and is widely used in various fields. The DATA stream transmitted in the communication process is packaged by a protocol format agreed by an upper computer and a lower computer in advance, and the existing serial port DATA protocol format is usually (DATA header (STX) + command word (CMD) + DATA Length (LEN) + DATA field (DATA) + end symbol (EXT) + check bit (LRC)). Since the "DATA field (DATA)" is composed of different elements in the actual DATA interaction, when there are multiple elements to be transmitted simultaneously, in order to solve this problem, the currently used method is to adopt a mode of fixed length area and fixed arrangement sequence of each element, or a mode of interacting in multiple times, each protocol packet only contains one element.
However, the existing method has the following problems: the data format is solidified, the expandability is poor, the protocol maintenance is not friendly, the time cost is increased by adopting a multi-interaction mode, and the response speed is influenced. Therefore, a control method and a control device applied to a serial port communication protocol of an upper computer and a lower computer, which can meet the requirement of simultaneously transmitting a plurality of elements and avoid the problems, are needed.
Disclosure of Invention
The invention provides a control method and a control device applied to a serial port communication protocol of an upper computer and a lower computer, and aims to solve the technical problems in the background art.
The invention provides a control method applied to a serial port communication protocol of an upper computer and a lower computer, which is applied to a sending end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and the control method comprises the following steps:
labeling the element data according to different element types in the data to be sent to generate labeled data, wherein any element data corresponds to a label;
combining all tagged data to form a data field;
forming a serial port protocol packet according to the data header, the command word, the data length, the data field, the end character and the check bit;
and sending the serial port protocol packet to a receiving end.
Further, the "tagging the element data according to different element types in the data to be transmitted to generate tagged data" specifically includes:
generating a label segment corresponding to the element type according to the element type, wherein the attribute of the label segment is bit and is represented by a 16-system, and the number of bytes is fixed to two;
generating a data length section corresponding to the information of the number of bytes occupied by the element data according to the information of the number of bytes occupied by the element data;
and combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment comprises the information of the number of bytes occupied by the data segment, and the data segment is element data in the data to be sent.
Further, the attribute of the data length segment is bit, and the control method includes:
when the byte occupied by the data length segment is 1 byte, the leftmost bit of the leftmost byte of the data length segment is 0, and the remaining 7 bits of the byte are the number of bytes occupied by the data segment;
when the byte occupied by the data length segment is more than 1 byte, the leftmost bit of the leftmost byte of the data length segment is 1, the remaining 7 bits of the leftmost byte are the number of bytes occupied by the data length segment, and at this time, the other bytes except the leftmost byte in the data length segment are the number of bytes occupied by the data segment.
The invention also provides a control method applied to the serial port communication protocol of the upper computer and the lower computer, which is applied to a receiving end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and the control method comprises the following steps:
receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by a sending end;
acquiring a data field in the serial port protocol packet;
dividing the data into a plurality of tagged data according to tags;
and analyzing the tagged data into corresponding element data.
Further, the "acquiring the data field in the serial protocol packet" specifically includes:
and extracting the data domain according to a preset serial port communication protocol.
Further, the tagged data includes a tag segment, a data length segment and a data segment, where the data length segment includes information about the number of bytes occupied by the data segment, an attribute of the data length segment is bit, and the data segment is one element data in the data to be sent, where "parsing the tagged data into corresponding element data" specifically includes:
identifying the tag segment;
judging whether the leftmost bit of the first byte after the label segment is 0 or not;
if the bit length is 0, identifying the value corresponding to the remaining 7 bits of the byte, and reading a data segment with the corresponding length according to the value;
if the bit number is 1, identifying the value corresponding to the remaining 7 bits of the byte, intercepting the bytes of the corresponding number backwards of the byte according to the value, and reading the data segment of the corresponding length according to the intercepted value corresponding to the byte.
The invention also provides a control device, which is applied to a control method of a serial port communication protocol of an upper computer and a lower computer and applied to a sending end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and the control device comprises:
the labeling module is used for labeling the element data according to different element types in the data to be sent so as to generate labeled data, wherein any element data corresponds to a label;
the data domain generating module is used for combining all the tagged data to form a data domain;
a serial port protocol packet generating module, configured to form a serial port protocol packet according to the data header, the command word, the data length, the data field, the end symbol, and the check bit;
and the sending module is used for sending the serial port protocol packet to a receiving end.
Further, the labeling module specifically includes:
the tag segment generation module is used for generating a tag segment corresponding to the element type according to the element type, wherein the attribute of the tag segment is bit and is represented by a 16-system, and the number of bytes is fixed to two;
the data length segment generating module is used for generating a data length segment corresponding to the information according to the number of bytes occupied by the element data;
and the integration module is used for combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment contains information of the number of bytes occupied by the data segment, and the data segment is element data in the data to be sent.
The invention also provides a control device, which is applied to a control method of a serial port communication protocol of an upper computer and a lower computer and applied to a receiving end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and the control device comprises:
the receiving module is used for receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by the sending end;
the extraction module is used for acquiring a data field in the serial port protocol packet;
the tag identification module is used for dividing the data into a plurality of tagged data according to tags;
and the analysis module is used for analyzing the tagged data into corresponding element data.
Further, the tagged data includes a tag segment, a data length segment and a data segment, the data length segment includes information of the number of bytes occupied by the data segment, an attribute of the data length segment is bit, the data segment is element data in the data to be sent, and the tag identification module specifically includes:
an identification module for identifying the tag segment;
the judging module is used for judging whether the leftmost bit of the first byte after the label segment is 0 or not;
the first execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 0, and reading the data segment with the corresponding length according to the value;
and the second execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 1, intercepting the corresponding number of bytes of the byte backwards according to the value, and reading the data segment with the corresponding length according to the intercepted value corresponding to the byte.
The element data is coded through a labeling coding rule, and different elements are distinguished through different labels. If a plurality of element data need to be transmitted in one interactive protocol, the data field is composed of a plurality of tagged data, and the ordering is not limited. Therefore, when the equipment is interacted through the serial port, the data encoder and the data analyzer are integrated in the interactive equipment, and the transmission element data can be rapidly encoded and analyzed.
On one hand, the method can simplify the organization difficulty of data, and particularly, when one data packet needs to contain a plurality of different element data, the advantages are more obvious by labeling different elements; on the other hand, the tagging mode can increase the flexibility of the protocol, and when the transmitted data needs to be added or deleted, the tags are directly added or deleted without modifying the protocol format again. The tagging mode can improve the maintainability of the protocol, and the content represented by the elements can be clearly known through element tagging, so that the protocol is more friendly to maintain. The labeling mode can improve the coding efficiency and the running efficiency of a program, unify the data characteristics, integrate a unified data encoder and a unified data decoder and quickly perform coding and decoding operations on data.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
Fig. 1 is a flowchart of steps of a control method applied to a serial port communication protocol of an upper computer and a lower computer at a sending end according to an embodiment of the present invention.
FIG. 2 is a block diagram of a control apparatus applying a serial communication protocol of an upper computer and a lower computer applied to a transmitting end according to an embodiment of the present invention
Fig. 3 is a flowchart of steps of a control method applied to a serial port communication protocol of an upper computer and a lower computer at a receiving end according to an embodiment of the present invention.
FIG. 4 is a block diagram of a control device applying a serial port communication protocol of an upper computer and a lower computer applied to a receiving end according to an embodiment of the present invention
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are illustrative only and should not be construed as limiting the invention.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, or operations, but do not preclude the presence or addition of one or more other features, integers, steps, operations, or groups thereof.
It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
It will be appreciated by those skilled in the art that the terms "application," "application program," "application software," and the like, as used herein, are intended to refer to a computer software product electronically-adapted to be electronically-constructed, from a collection of computer instructions and associated data resources, in accordance with the principles of the present invention. Unless otherwise specified, such nomenclature is not itself limited by the programming language class, level, or operating system or platform upon which it depends. Of course, such concepts are not limited to any type of terminal.
Referring to fig. 1, the present invention provides a control method applied to a serial communication protocol of an upper computer and a lower computer, which is applied to a sending end, wherein a serial protocol packet is composed of a data header, a command word, a data length, a data field, an end symbol and a check bit, and the control method comprises the following steps:
and S101, labeling the element data according to different element types in the data to be sent to generate labeled data, wherein any element data corresponds to a label.
And S102, combining all the tagged data to form a data field.
And S103, forming a serial port protocol packet according to the data header, the command word, the data length, the data field, the end character and the check bit.
The serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, wherein the data length, the data field, the end symbol and the check bit are arranged in the serial port protocol packet.
And S104, sending the serial port protocol packet to a receiving end.
After the serial port protocol packet is formed, the sending end sends the serial port protocol packet to the receiving end to complete data interaction based on the serial port communication protocol of the upper computer and the lower computer.
In an embodiment of the present invention, the step S101 specifically includes:
and S101a, generating a corresponding label segment according to the element type, wherein the attribute of the label segment is bit and is expressed by a 16-system, and the number of bytes is fixed to two.
In this embodiment, a sending end first tags each element in data to be sent, and each element allocates a specific Tag segment Tag according to a TLV rule, where one Tag corresponds to one element. For example, one element in an interaction is a card number, and the element of the card number may be assigned a Tag field Tag of "FF 01". And the number of bytes is fixed so as to be convenient for accurately identifying the label segment, thereby avoiding reading difficulty caused by data chaos.
And S101b, generating a data length segment corresponding to the element data according to the information of the number of bytes occupied by the element data.
The information of the number of bytes occupied by the element data is converted into the data length section, and the information of the number of bytes occupied by the element data is stored by using the data length section, so that the element data information corresponding to the label can be accurately identified, and the information confusion caused by misreading is avoided.
S101c, combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment comprises the information of the number of bytes occupied by the data segment, and the data segment is an element data in the data to be sent.
In this embodiment, a TLV (tag-length-value) format is used, that is, each sub-field is composed of a tag label segment (T), a data length segment (L) and a data segment (V), and the data field is composed of a plurality of sub-fields.
Specifically, in an embodiment of the present invention, an attribute of the data length segment is bit, and the control method further includes:
when the byte occupied by the data length segment is 1 byte, the leftmost bit of the leftmost byte of the data length segment is 0, and the remaining 7 bits of the byte are the number of bytes occupied by the data segment;
when the byte occupied by the data length segment is more than 1 byte, the leftmost bit of the leftmost byte of the data length segment is 1, the remaining 7 bits of the leftmost byte are the number of bytes occupied by the data length segment, and at this time, the other bytes except the leftmost byte in the data length segment are the number of bytes occupied by the data segment.
In this embodiment, when the leftmost bit (i.e., bit8) of the leftmost byte of the data length segment is 0, it indicates that the data length segment occupies one byte, and its subsequent 7 bits (i.e., bit7 to bit1) indicate the length of the data segment, and binary numbers are used to indicate the decimal number of the data length segment. For example, if a certain data segment occupies 3 bytes, its corresponding data length segment is denoted as "00000011". It can be known that if the length of the subfield value is between 1 and 127 bytes, the data length segment itself only occupies one byte.
When the leftmost bit (i.e., bit8) of the leftmost byte of the data length segment is 1, indicating that the data length segment occupies more than one byte, it occupies as few bytes as indicated by the decimal value of the next 7 bits (i.e., bit 7-bit 1) of the leftmost byte. For example, if the leftmost byte of the data length segment is 10000010, it indicates that the data length segment has two bytes after the leftmost byte, and then the decimal value corresponding to the subsequent byte indicates the length of the value taken by the subfield. For example, if the data length segment is represented as "1000000111111111," it indicates that the data length segment takes 255 bytes. Therefore, if the length of the data segment is 127-255 bytes, the data length segment itself needs to occupy two bytes.
In an embodiment of the present invention, the data segment is represented by 16, and every two bits are a byte, for example, the data segment is "6226888899990000", and the data segment is converted into "36323236383838383939393930303030" (0x36, 0x320x320x360x380x380x380x380x390x390x390x390x300x300x 30) in 16.
In this embodiment, each element is allocated with a specific Tag segment according to TLV rules, and the element and the data are bound by a TLV encoder, assuming that one element in a certain interaction is a card number, the length of the card number is 16, and the content of the card number is 6226888899990000, we can allocate Tag to the element of the card number as "FF 01", and form tagged data by using the TLV rules, and encode the data of the element of the card number as "FF 011036323236383838383838393939393930303030" (the above encoding is 16-system data), and write the tagged data as a part of a data field, and finally form a data packet to be sent according to a serial port protocol.
In one embodiment, the present invention further provides a control apparatus 100, which is applied to a control method of a serial communication protocol of an upper computer and a lower computer, and is applied to a transmitting end, wherein a serial protocol packet is composed of a data header, a command word, a data length, a data field, an end symbol, and a check bit, the apparatus 100 stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the control method applied to the serial communication protocol of the upper computer and the lower computer, and the control apparatus includes:
and S101, labeling the element data according to different element types in the data to be sent to generate labeled data, wherein any element data corresponds to a label.
And S102, combining all the tagged data to form a data field.
And S103, forming a serial port protocol packet according to the data header, the command word, the data length, the data field, the end character and the check bit.
And S104, sending the serial port protocol packet to a receiving end.
For convenience of description, the apparatus 100 is split into a functional module architecture, as shown in fig. 2, including:
the tagging module 101 is configured to tag the element data according to different element types in the data to be sent to generate tagged data, where any element data corresponds to a tag.
And a data field generation module 102, configured to combine all tagged data to form a data field.
A serial protocol packet generating module 103, configured to form a serial protocol packet according to the data header, the command word, the data length, the data field, the end symbol, and the check bit.
And the sending module 104 is configured to send the serial port protocol packet to a receiving end.
Further, the labeling module 101 specifically includes:
and the label segment generation module is used for generating a label segment corresponding to the element type according to the element type, wherein the attribute of the label segment is bit and is represented by a 16-system, and the number of bytes is fixed to two.
And the data length segment generating module is used for generating the corresponding data length segment according to the information of the number of bytes occupied by the element data.
And the integration module is used for combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment contains information of the number of bytes occupied by the data segment, and the data segment is element data in the data to be sent.
Referring to fig. 3, the present invention further provides a control method applied to a serial communication protocol of an upper computer and a lower computer, which is applied to a receiving end, wherein a serial protocol packet is composed of a data header, a command word, a data length, a data field, an end symbol and a check bit, and the control method includes the following steps:
s201, receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by the sending end.
S202, acquiring a data field in the serial port protocol packet.
And S203, dividing the data into a plurality of tagged data according to the tags.
And S204, analyzing the tagged data into corresponding element data.
Specifically, in an embodiment of the present invention, the step S202 specifically includes:
and extracting the data domain according to a preset serial port communication protocol.
In this embodiment, the serial communication protocol is preset, and the serial communication protocol includes a data header, a command word, a data length, a data field, an end symbol, and a check bit.
Specifically, in an embodiment of the present invention, the tagged data includes a tag segment, a data length segment and a data segment, where the data length segment includes information about the number of bytes occupied by the data segment, an attribute of the data length segment is bit, and the data segment is an element data in the data to be sent, where "parsing the tagged data into corresponding element data" specifically includes:
the tag segment is identified.
And judging whether the leftmost bit of the first byte after the label segment is 0 or not.
If the bit length is 0, identifying the value corresponding to the remaining 7 bits of the byte, and reading the data segment with the corresponding length according to the value.
If the bit number is 1, identifying the value corresponding to the remaining 7 bits of the byte, intercepting the bytes of the corresponding number backwards of the byte according to the value, and reading the data segment of the corresponding length according to the intercepted value corresponding to the byte.
In this embodiment, because the sending end sends the preset tagging rule, the receiving end analyzes the rule direction to obtain the element data. Assuming that a single tagged data received by a receiving terminal is "FF 01103632323638383838383839393930303030", after the parsing by the parser, the Tag segment Tag is "FF 01", the data Length segment Length is 16(0x10), and the data segment Value is 6226888899990000(0x36, 0x320x320x360x380x380x380x380x390x390x390x 300x300x30), so that the element type and the element data content represented by the piece of data can be clearly known, and when the receiving terminal receives a plurality of elements, the parsing is performed in the same manner, so that the data transmission is completed.
The invention also provides a control device 200, which is applied to a control method of the serial port communication protocol of the upper computer and the lower computer and applied to a receiving end, wherein a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, the device 200 stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the control method applied to the serial port communication protocol of the upper computer and the lower computer, and comprise the following steps:
s201, receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by the sending end.
S202, acquiring a data field in the serial port protocol packet.
And S203, dividing the data into a plurality of tagged data according to the tags.
And S204, analyzing the tagged data into corresponding element data.
For convenience of description, the apparatus 200 is split into a functional module architecture, as shown in fig. 4, including:
the receiving module 201 is configured to receive a serial protocol packet, where the serial protocol packet is sent from a sending end to a receiving end.
And the extracting module 202 is configured to obtain a data field in the serial port protocol packet.
And the tag identification module 203 is used for dividing the data into a plurality of tagged data according to the tags.
And the analyzing module 204 is configured to analyze the tagged data into corresponding element data.
Further, the tagged data includes a tag segment, a data length segment and a data segment, where the data length segment includes information of the number of bytes occupied by the data segment, an attribute of the data length segment is bit, the data segment is an element data in the data to be sent, and the tag identification module 203 specifically includes:
an identification module to identify the tag segment.
And the judging module is used for judging whether the leftmost bit of the first byte after the label segment is 0 or not.
And the first execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 0, and reading the data segment with the corresponding length according to the value.
And the second execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 1, intercepting the corresponding number of bytes of the byte backwards according to the value, and reading the data segment with the corresponding length according to the intercepted value corresponding to the byte.
The element data is coded through a labeling coding rule, and different elements are distinguished through different labels. If a plurality of element data need to be transmitted in one interactive protocol, the data field is composed of a plurality of tagged data, and the ordering is not limited. Therefore, when the equipment is interacted through the serial port, the data encoder and the data analyzer are integrated in the interactive equipment, and the transmission element data can be rapidly encoded and analyzed.
On one hand, the method can simplify the organization difficulty of data, and particularly, when one data packet needs to contain a plurality of different element data, the advantages are more obvious by labeling different elements; on the other hand, the tagging mode can increase the flexibility of the protocol, and when the transmitted data needs to be added or deleted, the tags are directly added or deleted without modifying the protocol format again. The tagging mode can improve the maintainability of the protocol, and the content represented by the elements can be clearly known through element tagging, so that the protocol is more friendly to maintain. The labeling mode can improve the coding efficiency and the running efficiency of a program, unify the data characteristics, integrate a unified data encoder and a unified data decoder and quickly perform coding and decoding operations on data.
The electronic device integrated module/unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the application program multi-open method described in the above embodiments of the present invention may also be implemented by referring to related hardware through a computer program, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the steps of the control method applied to the serial port communication protocol of the upper and lower computers described in the above embodiments of the method may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
Throughout the description and claims of this application, the words "comprise/comprises" and the words "have/includes" and variations of these are used to specify the presence of stated features, values, steps or components but do not preclude the presence or addition of one or more other features, values, steps, components or groups thereof.
Some features of the invention, which are, for clarity, described in the context of separate embodiments, may also be provided in combination in a single embodiment. Conversely, certain features of the invention, which are, for brevity, described in the context of a single embodiment, may also be provided separately or in any suitable combination in different embodiments.
The above description specifically describes each embodiment of the control method and apparatus applied to the serial port communication protocol of the upper and lower computers of the present invention. Finally, it should be noted that the above embodiments are only used for illustrating the technical solutions of the present invention and not for limiting the same. Although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.

Claims (10)

1. A control method applied to a serial port communication protocol of an upper computer and a lower computer is applied to a sending end, and a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and is characterized by comprising the following steps:
labeling the element data according to different element types in the data to be sent to generate labeled data, wherein any element data corresponds to a label;
combining all tagged data to form a data field;
forming a serial port protocol packet according to the data header, the command word, the data length, the data field, the end character and the check bit;
and sending the serial port protocol packet to a receiving end.
2. The control method according to claim 1, wherein the "tagging element data according to different element types in data to be transmitted to generate tagged data" specifically includes:
generating a label segment corresponding to the element type according to the element type, wherein the attribute of the label segment is bit and is represented by a 16-system, and the number of bytes is fixed to two;
generating a data length section corresponding to the information of the number of bytes occupied by the element data according to the information of the number of bytes occupied by the element data;
and combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment comprises the information of the number of bytes occupied by the data segment, and the data segment is element data in the data to be sent.
3. The control method according to claim 2, wherein the attribute of the data length segment is bit, and the control method comprises:
when the byte occupied by the data length segment is 1 byte, the leftmost bit of the leftmost byte of the data length segment is 0, and the remaining 7 bits of the byte are the number of bytes occupied by the data segment;
when the byte occupied by the data length segment is more than 1 byte, the leftmost bit of the leftmost byte of the data length segment is 1, the remaining 7 bits of the leftmost byte are the number of bytes occupied by the data length segment, and at this time, the other bytes except the leftmost byte in the data length segment are the number of bytes occupied by the data segment.
4. A control method applied to a serial port communication protocol of an upper computer and a lower computer is applied to a receiving end, and a serial port protocol packet consists of a data header, a command word, a data length, a data field, an end symbol and a check bit, and is characterized by comprising the following steps:
receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by a sending end;
acquiring a data field in the serial port protocol packet;
dividing the data into a plurality of tagged data according to tags;
and analyzing the tagged data into corresponding element data.
5. The control method according to claim 4, wherein the acquiring the data field in the serial protocol packet specifically comprises:
and extracting the data domain according to a preset serial port communication protocol.
6. The control method according to claim 4, wherein the tagged data includes a tag segment, a data length segment, and a data segment, the data length segment includes information about the number of bytes occupied by the data segment, the attribute of the data length segment is bit, the data segment is an element data in the data to be transmitted, and the "parsing the tagged data into corresponding element data" specifically includes:
identifying the tag segment;
judging whether the leftmost bit of the first byte after the label segment is 0 or not;
if the bit length is 0, identifying the value corresponding to the remaining 7 bits of the byte, and reading a data segment with the corresponding length according to the value;
if the bit number is 1, identifying the value corresponding to the remaining 7 bits of the byte, intercepting the bytes of the corresponding number backwards of the byte according to the value, and reading the data segment of the corresponding length according to the intercepted value corresponding to the byte.
7. A control device is applied to a control method of a serial port communication protocol of an upper computer and a lower computer, applied to a sending end, and a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and is characterized in that the control device comprises:
the labeling module is used for labeling the element data according to different element types in the data to be sent so as to generate labeled data, wherein any element data corresponds to a label;
the data domain generating module is used for combining all the tagged data to form a data domain;
a serial port protocol packet generating module, configured to form a serial port protocol packet according to the data header, the command word, the data length, the data field, the end symbol, and the check bit;
and the sending module is used for sending the serial port protocol packet to a receiving end.
8. The control device according to claim 7, wherein the labeling module specifically comprises:
the tag segment generation module is used for generating a tag segment corresponding to the element type according to the element type, wherein the attribute of the tag segment is bit and is represented by a 16-system, and the number of bytes is fixed to two;
the data length segment generating module is used for generating a data length segment corresponding to the information according to the number of bytes occupied by the element data;
and the integration module is used for combining the label segment, the data length segment and the data segment to form labeled data, wherein the labeled data comprises the label segment, the data length segment and the data segment, the data length segment contains information of the number of bytes occupied by the data segment, and the data segment is element data in the data to be sent.
9. A control device is applied to a control method of a serial port communication protocol of an upper computer and a lower computer, is applied to a receiving end, and a serial port protocol packet consists of a data head, a command word, a data length, a data field, an end symbol and a check bit, and is characterized in that the control device comprises:
the receiving module is used for receiving a serial port protocol packet, wherein the serial port protocol packet is sent to the receiving end by the sending end;
the extraction module is used for acquiring a data field in the serial port protocol packet;
the tag identification module is used for dividing the data into a plurality of tagged data according to tags;
and the analysis module is used for analyzing the tagged data into corresponding element data.
10. The control device according to claim 9, wherein the tagged data includes a tag segment, a data length segment, and a data segment, the data length segment includes information about the number of bytes occupied by the data segment, an attribute of the data length segment is bit, the data segment is an element data in the data to be sent, and the tag identification module specifically includes:
an identification module for identifying the tag segment;
the judging module is used for judging whether the leftmost bit of the first byte after the label segment is 0 or not;
the first execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 0, and reading the data segment with the corresponding length according to the value;
and the second execution module is used for identifying the value corresponding to the remaining 7 bits of the byte when the leftmost bit of the first byte after the label segment is 1, intercepting the corresponding number of bytes of the byte backwards according to the value, and reading the data segment with the corresponding length according to the intercepted value corresponding to the byte.
CN202110865880.9A 2021-07-29 2021-07-29 Control method and control device applied to serial port communication protocol of upper and lower computers Pending CN113612760A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110865880.9A CN113612760A (en) 2021-07-29 2021-07-29 Control method and control device applied to serial port communication protocol of upper and lower computers

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110865880.9A CN113612760A (en) 2021-07-29 2021-07-29 Control method and control device applied to serial port communication protocol of upper and lower computers

Publications (1)

Publication Number Publication Date
CN113612760A true CN113612760A (en) 2021-11-05

Family

ID=78306023

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110865880.9A Pending CN113612760A (en) 2021-07-29 2021-07-29 Control method and control device applied to serial port communication protocol of upper and lower computers

Country Status (1)

Country Link
CN (1) CN113612760A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140376405A1 (en) * 2013-06-25 2014-12-25 Nest Labs, Inc. Efficient Communication for Devices of a Home Network
CN107995206A (en) * 2017-12-13 2018-05-04 大唐融合通信股份有限公司 Realization device and method for the TLV communications protocol formats of industrial big data
CN109981651A (en) * 2019-03-27 2019-07-05 努比亚技术有限公司 Data transmission method, device, mobile terminal and readable storage medium storing program for executing
CN110324222A (en) * 2019-07-05 2019-10-11 厦门金龙联合汽车工业有限公司 A kind of vehicle CAN bus data interactive system and its exchange method
CN111740960A (en) * 2020-05-25 2020-10-02 杭州涂鸦信息技术有限公司 Communication method of Internet of things equipment, Internet of things equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140376405A1 (en) * 2013-06-25 2014-12-25 Nest Labs, Inc. Efficient Communication for Devices of a Home Network
CN107995206A (en) * 2017-12-13 2018-05-04 大唐融合通信股份有限公司 Realization device and method for the TLV communications protocol formats of industrial big data
CN109981651A (en) * 2019-03-27 2019-07-05 努比亚技术有限公司 Data transmission method, device, mobile terminal and readable storage medium storing program for executing
CN110324222A (en) * 2019-07-05 2019-10-11 厦门金龙联合汽车工业有限公司 A kind of vehicle CAN bus data interactive system and its exchange method
CN111740960A (en) * 2020-05-25 2020-10-02 杭州涂鸦信息技术有限公司 Communication method of Internet of things equipment, Internet of things equipment and storage medium

Similar Documents

Publication Publication Date Title
US7770091B2 (en) Data compression for use in communication systems
CN109086199A (en) A kind of automation generates the method for test script, terminal and can storage medium
CN110166463B (en) Message transmission conversion method and device
US10635957B2 (en) System and method for collecting and analyzing multi-fields two-dimensional code
CN101526963A (en) Method for identifying web page coding, device and terminal equipment
CN111131403A (en) Message coding and decoding method and device for Internet of things equipment
CN111402570A (en) Infrared remote control signal receiving method, receiving system, receiving device and storage medium
CN103036641A (en) Method and system of data exchange and deserialization method
CN106033551A (en) Data parsing method, apparatus and system thereof
CN108021540B (en) Hadoop-oriented general text format analysis method and tool
CN113612760A (en) Control method and control device applied to serial port communication protocol of upper and lower computers
CN113742294A (en) Method, system, device and medium for decoding ASN.1-PER signaling message
CN110347567B (en) Binary data log analysis method and system based on protocol matching
CN111967274B (en) Label conversion processing method and device, electronic equipment and readable storage medium
CN113676290A (en) Data transmission method based on fund system and related equipment
CN116150119A (en) Log processing method, system, electronic equipment and computer readable storage medium
CN112486885B (en) Data frame generation method, storage medium and computer equipment
CN104036210A (en) Test method of identifying multi-tag performance by UHF reader
US5793984A (en) Method of computer representation of data
CN110110073B (en) Character display method and device
US10915547B2 (en) Optimizing data conversion using pattern frequency
CN110489121B (en) Skin package file generation method and system
US20030204638A1 (en) Scripting language for processing typed structured data
CN113691532B (en) Parallel analysis method and device for tera-megaphone communication data based on FAST protocol
CN110378457A (en) A kind of yard of target generation method and device

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20211105

RJ01 Rejection of invention patent application after publication