CN112463706A - Data sending and receiving method and communication terminal - Google Patents

Data sending and receiving method and communication terminal Download PDF

Info

Publication number
CN112463706A
CN112463706A CN202011431250.2A CN202011431250A CN112463706A CN 112463706 A CN112463706 A CN 112463706A CN 202011431250 A CN202011431250 A CN 202011431250A CN 112463706 A CN112463706 A CN 112463706A
Authority
CN
China
Prior art keywords
data
byte
type
data frame
sequence
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.)
Granted
Application number
CN202011431250.2A
Other languages
Chinese (zh)
Other versions
CN112463706B (en
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.)
Shanghai Electric Group Corp
Original Assignee
Shanghai Electric Group Corp
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 Shanghai Electric Group Corp filed Critical Shanghai Electric Group Corp
Priority to CN202011431250.2A priority Critical patent/CN112463706B/en
Publication of CN112463706A publication Critical patent/CN112463706A/en
Application granted granted Critical
Publication of CN112463706B publication Critical patent/CN112463706B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Communication Control (AREA)

Abstract

The application relates to the technical field of communication, and provides a data sending and receiving method and a communication terminal. In the sending method, at least one data segment is determined according to the data type of each data in a first data frame; converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format; and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol, and sending the encapsulated second data frame. In the receiving method, a communication parameter input by a user is received, and a byte sequence in a byte format in a second data frame is obtained according to the communication parameter; and converting each byte in the byte array into data of the corresponding data type according to the corresponding relation between the node address of each byte in the byte array and the corresponding data type and the conversion rule between the data type and the byte format. The conversion process does not need manual calculation, and the flexibility of data receiving and transmitting is improved.

Description

Data sending and receiving method and communication terminal
Technical Field
The present application relates to the field of communications technologies, and in particular, to a data sending method, a data receiving method, and a communication terminal.
Background
The essence and core of the industrial internet are that equipment, production lines, factories, suppliers, products and customers are tightly fused together through an industrial internet platform, the manufacturing industry is helped to elongate an industrial chain, and cross-equipment, cross-system, cross-factory and cross-region interconnection and intercommunication are formed, so that the industrial efficiency is improved, the intelligence of the whole manufacturing service system is promoted, the melting development of the manufacturing industry is promoted, the cross-development between the manufacturing industry and the service industry is realized, and various element resources of the industrial economy can be efficiently shared.
The industrial internet generally uses a serial communication protocol to transmit data, wherein a plurality of serial communication interfaces such as RS-232, RS-422 and RS-485 can be used. Since the number of bytes of different types of data is different, the data needs to be converted into a data type matching the number of bytes occupied by the capacity of the transfer node. Currently, in the process of communication using a serial communication protocol, the type of transmission data is mainly converted according to a rule set by a human. Although the method for converting data by manually specifying data types is simple and rapid, the flexibility of data transmission is poor, and the compatibility between communication software of different devices is poor, so that although the same serial communication protocol is used, because communication programs of master and slave stations of different devices are different, when the same sending-end device communicates with different types of receiving-end devices using the same serial communication protocol, different communication software still needs to be installed, or a data acquisition worker needs to manually calculate conversion results according to conversion relations between different data types and input or export the conversion results, so that the transmission speed of data frames containing different data types is influenced, and the speed of storing the converted data in an artificial intelligent database is also influenced.
Disclosure of Invention
The embodiment of the application provides a data sending and receiving method and a communication terminal, which are used for improving the flexibility of data receiving and sending and the speed of data conversion.
In a first aspect, an embodiment of the present application provides a data sending method, including:
determining at least one data segment according to the data type of each data in the first data frame, wherein each data segment comprises at least one data with the same data type;
converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol, and sending the encapsulated second data frame.
The embodiment of the application segments each data in the first data frame according to the data type, each data segment comprises at least one data with the same data type, and the data in each data segment can be simultaneously and independently subjected to type conversion, so that the conversion efficiency is improved; the data of different types are transmitted in one data frame, and when the type of each data in each data segment changes, the type conversion of other data segments is not influenced, so that the flexibility of data conversion is improved; in the type conversion process, manual calculation is not needed, the conversion speed is improved, and the workload of a user is reduced.
In some embodiments of the present application, encapsulating each converted data into a second data frame in a byte format supported by a serial communication protocol includes:
according to the sequence of each data, directly packaging each converted data into a second data frame in a byte format supported by a serial communication protocol; or
Integrating the converted data into a byte array in sequence according to the sequence of the data;
and packaging the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol.
In the embodiment of the application, each data can be directly packaged according to the sequence of each data, or each data can be integrated into a byte sequence and then packaged, wherein the data can be packaged after being integrated into the byte sequence, so that the accuracy of data packaging can be improved.
In some embodiments of the present application, directly encapsulating each converted data into a second data frame in a byte format supported by a serial communication protocol includes:
according to a serial communication protocol, adding a start code at the head end of the first converted data and adding an end code at the tail end of the last converted data;
encapsulating the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol, including:
according to the serial communication protocol, a start code is added to the head of the integrated byte sequence, and an end code is added to the end of the byte sequence.
In the embodiment of the application, a start code is added to the head end of the first converted data according to the serial communication protocol, and an end code is added to the tail end of the last converted data, or the start code is added to the head end of the byte number sequence after integration, and the end code is added to the tail end of the byte number sequence, so that the second encapsulated data frame conforms to the transmission rule of the serial communication protocol.
In some embodiments of the present application, sending the encapsulated second data frame includes:
and receiving the communication parameters input by the user, and sending the encapsulated second data frame according to the communication parameters.
According to the embodiment of the application, the data frame is sent according to the received communication parameters, so that the corresponding receiving end equipment can accurately receive the data frame.
In a second aspect, an embodiment of the present application provides a data receiving method, including:
receiving a communication parameter input by a user, and receiving a second data frame in a byte format supported by a serial communication protocol according to the communication parameter to obtain a byte sequence in the byte format in the second data frame;
determining the data type corresponding to each byte in the byte sequence according to the corresponding relation between the node address of each byte in the byte sequence and the corresponding data type;
and converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format.
According to the embodiment of the application, the second data frame is received according to the parameters input by the user, the byte number sequence in the second data frame is obtained, the data type corresponding to each byte in the byte number sequence is determined according to the corresponding relation between the node address of each byte in the byte number sequence and the corresponding data type, the conversion rule between the data type and the byte format is reversely utilized, each byte is converted into the corresponding data type, manual calculation is not needed, the conversion speed is improved, and the workload of the user is reduced.
In some embodiments of the present application, converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format includes:
dividing the byte sequence into at least one data segment according to the data type, wherein the data type corresponding to each byte in each data segment is the same and the node addresses are continuous, and each data segment comprises at least one datum;
and converting the bytes contained in each data segment into the data of the corresponding data type according to a conversion rule between the data type and the byte format.
According to the embodiment of the application, the byte array is segmented according to the data type to obtain at least one data segment, and each data segment can independently convert the data type, so that the conversion efficiency is improved.
In some embodiments of the present application, receiving, according to the communication parameter, a second data frame in a byte format supported by the serial communication protocol, and obtaining a byte sequence in the byte format in the second data frame includes:
acquiring a return value of a start code and a return value of an end code of a second data frame;
and according to the return value of the start code and the return value of the end code, eliminating the start code and the end code of the second data frame to obtain the byte sequence of the byte format in the second data frame.
In the embodiment of the application, the start code and the end code of the second data frame are removed to obtain a complete byte sequence, so that the subsequent conversion of each byte in the byte sequence is facilitated.
In a third aspect, an embodiment of the present application provides a communication terminal, including:
the segmentation module is used for determining at least one data segment according to the data type of each data in the first data frame, wherein each data segment comprises at least one data with the same data type;
the conversion module is used for converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
and the encapsulation module is used for encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol and sending the encapsulated second data frame.
In a fourth aspect, an embodiment of the present application provides a communication terminal, including:
the receiving module is used for receiving the communication parameters input by the user, receiving a second data frame of a byte format supported by the serial communication protocol according to the communication parameters, and obtaining a byte sequence of the byte format in the second data frame;
the data type determining module is used for determining the data type corresponding to each node in the byte array according to the corresponding relation between the node address of each node in the byte array and the corresponding data type;
and the conversion module is used for converting each byte in the byte array into data of a corresponding data type according to a conversion rule between the data type and the byte format.
In a fifth aspect, embodiments of the present application provide a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the method of the embodiments of the present application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to these drawings without inventive exercise.
Fig. 1 schematically illustrates an application scenario provided by an embodiment of the present application;
fig. 2 schematically shows a structure diagram of a data frame provided by an embodiment of the present application;
fig. 3 is a flowchart illustrating a data transmission method provided by an embodiment of the present application;
fig. 4 is a flowchart illustrating a data receiving method provided by an embodiment of the present application;
fig. 5 is a flowchart illustrating a data transceiving method provided by an embodiment of the present application;
FIG. 6 is a diagram illustrating an exemplary data transceiving user interface provided by an embodiment of the present application;
fig. 7 is a diagram schematically illustrating a structure of a data transceiving system according to an embodiment of the present application;
fig. 8 is a block diagram schematically illustrating a communication terminal provided in an embodiment of the present application;
fig. 9 is a block diagram schematically illustrating another communication terminal provided in an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
All other embodiments, which can be derived by a person skilled in the art from the exemplary embodiments shown in the present application without inventive effort, shall fall within the scope of protection of the present application. Moreover, while the disclosure herein has been presented in terms of exemplary one or more examples, it is to be understood that each aspect of the disclosure can be utilized independently and separately from other aspects of the disclosure to provide a complete disclosure.
It should be understood that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used are interchangeable under appropriate circumstances and can be implemented in sequences other than those illustrated or otherwise described herein with respect to the embodiments of the application, for example.
Furthermore, the terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or device that comprises a list of elements is not necessarily limited to those elements explicitly listed, but may include other elements not expressly listed or inherent to such product or device.
The term "module," as used herein, refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and/or software code that is capable of performing the functionality associated with that element.
Modbus is a serial communication protocol of a typical master-slave (master/slave) architecture, and is widely applied to the industrial Internet. As a serial communication protocol, the Modbus RTU specification does not allow duplicate node addresses, nor does the standard protocol have broadcast and multicast functionality. The transmission node in the communication protocol is 2 bytes, that is, every two bytes correspond to a node address. Since the address capacity of each transfer node is 2 bytes, when the master node transfers a data frame larger than 2 bytes during data transfer, the first two bytes of data are transferred to the address of the start node specified by the user, and the following bytes are sequentially transferred according to the address number. For example, the master node transfers 4 bytes of data (e.g. 4556) to the slave node with the starting node address of 6, the data register with the starting node address of 6 stores 45 after the transfer is completed, and the data register with the node address of 7 stores 56.
Since the transmission data in the Modbus protocol can only be written into the register in a form of 2 bytes, and thus can only be exported in a form of 2 bytes, data type conversion is required when the Modbus protocol is used to transmit data in a non-2-byte form, for example, when data is transmitted, data in a float type of 4 bytes needs to be converted into data in a ushort type of two 2 bytes for transmission; in data reception, two 2 bytes of ushort type data need to be converted into one 4 byte float type data for reception.
In the current serial communication process, the type of transmission data is preset, whether the type of the transmission data is matched with the set data type or not is determined, and if the type of the transmission data is matched with the set data type, the data frame with the size larger than 2 bytes is artificially converted into the data frame with the set type and then is transmitted. Although the mode of manually converting the data type is simple and quick, the flexibility of data transmission is poor, and due to the compatibility problem among communication software of different devices, different communication software still needs to be installed during communication among different devices, or the data type needs to be manually converted, so that the communication speed is slow.
Based on the above problems, embodiments of the present application provide a data sending method, a data receiving method, and a communication terminal. The data in each segment is independently converted into data types by segmenting the data frames sent or received by the serial communication protocol, and then the converted data is encapsulated into complete data frames for sending or receiving; on one hand, the method provided by the embodiment of the application can simultaneously send or receive data frames of different data types by using an application program or a debugging assistant without manually converting the data types, so that the flexibility of data receiving and sending and the speed of data conversion are improved; on the other hand, different software does not need to be developed for different receiving end devices or data conversion is carried out manually, so that the speed of data frame transmission from the same sending end device to different receiving end devices is increased, and the cost and time of data transmission are saved.
It should be noted that the method provided by the embodiment of the present application is not only applicable to the Modbus protocol, but also applicable to other serial communication protocols, such as the RS-232 protocol, the HART protocol, the MPI protocol, and the like.
Embodiments of the present application are described in detail below with reference to the drawings.
Fig. 1 schematically illustrates an application scenario provided in an embodiment of the present application. As shown in fig. 1, the same transmitting device 101 may transmit data frames to one or more receiving devices at the same time. Fig. 1 illustrates three receiving end devices 102 and 104 as an example, the sending end device 101 and the receiving end device 101 and 104 use a Modbus network (which may also be other networks, and this application does not make a limiting requirement) for communication, and the receiving end device 101 and 104 can use different data types to receive the same data frame sent by the sending end device 101. The sending end device and the receiving end device are collectively called a communication terminal.
Fig. 2 is a schematic structural diagram of a data frame according to an embodiment of the present application. As shown in fig. 2, a data frame includes a start code, n data (n is an integer greater than or equal to 1), and an end code, where the start code sequentially includes a start bit, a function code, a start address, and data length information, and the end code sequentially includes a check code and a stop bit. The data types of the data may be the same or different, for example, the data types of data 1 and data 2 shown in fig. 2 are different.
It should be noted that the structures of the data frames transmitted by different serial communication protocols may be different, and the structure of the data frame is not required to be limited in the embodiments of the present application on the basis of not changing the essence provided by the embodiments of the present application.
Fig. 3 is a flowchart illustrating a data transmission method according to an embodiment of the present application. As shown in fig. 3, the process may be implemented by software, and mainly includes the following steps:
s301: and determining at least one data segment according to the data type of each data in the first data frame, wherein each data segment contains at least one data with the same data type.
In this step, a first data frame is an original data frame to be transmitted, and the first data frame is segmented according to a data type of each data in the first data frame to obtain at least one data segment, where a dashed box in fig. 2 represents one data segment, where each data segment contains at least one data with the same data type, as shown in fig. 2, the data segment 1 contains one data 1, the data segment 2 contains two data 2 with the same data type, the data segment 3 contains one data 3, the data types of the data 1 and the data 2 are different, the data types of the data and the data 3 are different, and the data types of the data 1 and the data 3 may be the same or different.
S302: and converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format.
In this step, the conversion rule between the data type and the byte format may be preset. For example, the data type of the data 1 contained in the data segment 1 is the shaping (int), the conversion rule between the data type int and the byte format (ushert) supported by the serial communication protocol is that data of the int type of 4 bytes is converted into data of two byte formats (ushert) of 2 bytes, and according to the conversion rule, the data 1 of one 4 bytes is converted into data of two byte formats (ushert); the data type of the two data 2 included in the data segment 2 is floating point type (float), the conversion rule between the data type float and the byte format (ushort) supported by the serial communication protocol is that one 4-byte float type data is converted into two 2-byte format (ushort) data, and according to the conversion rule, the two 4-byte data 2 are converted into four 2-byte format data.
It should be noted that the data type in the embodiment of the present application may be an existing conventional data type, such as short (ushort), int16 (agent 16), int (int32), long, float, double, and the like, and may also be a user-defined data type, for example, a piece of data of int type and a piece of data of float type are defined to form an 8-byte data, that is, the defined data type is formed by int type and float type.
S303: and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol, and sending the encapsulated second data frame.
In S301 and S302, the types of the multiple data in the first data frame are converted, and after the conversion, the multiple data frames need to be encapsulated into complete data frames for transmission. In S303, each converted data is directly encapsulated into a second data frame in a byte format supported by the serial communication protocol according to the sequence of each data in the first data frame. In specific implementation, according to the serial communication protocol, a start code is added at the head end of the first converted data, and an end code is added at the tail end of the last converted data.
For example, the first data frame includes two data segments, data 1 in the data segment 1 is the first data in the first data frame, the data type of the data 1 is int, and two 2-byte formats obtained after conversion are sequentially the first sub data and the second sub data; two data 2 in the data segment 2 are sequentially the second data and the third data in the first data frame, the data type of the data 2 is float, two data in 2-byte format obtained after the second data conversion are sequentially the third sub data and the fourth sub data, two data in 2-byte format obtained after the third data conversion are sequentially the fifth sub data and the sixth sub data, according to the Modbus protocol, a start code is added at the head end of the first sub data, an end code is added at the tail end of the sixth sub data, and sub data fields are sequentially packaged to obtain a second data frame in byte format supported by the Modbus protocol.
And after the second data frame is obtained, receiving the communication parameters input by the user, and sending the encapsulated second data frame according to the communication parameters. In some embodiments, the master station further sends the function code to the sink device, and sequentially allocates node addresses to the sink device from the start address of the second data frame for data transmission. The communication parameters include an identification of the receiving device (such as a station number, an ID number, etc.), an address of the originating node, and are used to indicate which receiving device receives the second data frame from which node address.
In an optional implementation manner, the communication parameter further includes a length of the data to be sent, so that the sending device does not continue sending the data with the length after sending the data with the length, transmission of redundant data is avoided, and resource overhead is saved.
Wherein, the data length can be determined by the following method:
if the byte number of a single data is N and the address capacity of a transmission node is x bytes, the number M of nodes occupied by the single data is:
Figure BDA0002820735160000101
the data length of the X data is X × M.
In some embodiments, when the converted data is encapsulated, the data may be integrated first, and then the integrated byte sequence may be encapsulated. Integrating the converted data into a byte array in sequence according to the sequence of the data; and packaging the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol. In a specific implementation, according to the serial communication protocol, a start code is added to the head of the integrated byte sequence, and an end code is added to the tail of the byte sequence.
Based on the example of S303, after the first to sixth sub-data are obtained, the first to sixth sub-data are sequentially integrated into a byte sequence, a start code is added to the head of the integrated byte sequence, and an end code is added to the tail of the byte sequence, so as to obtain a complete second data frame.
In the above embodiment of the present application, each data in the first data frame is segmented according to the data type, each data segment includes at least one data with the same data type, and the data in each data segment can be simultaneously and independently subjected to type conversion, so that the conversion efficiency is improved; the data of different types are transmitted in one data frame, and when the type of each data in each data segment changes, the type conversion of other data segments is not influenced, so that the flexibility of data conversion is improved; in the type conversion process, manual calculation is not needed, the conversion speed is improved, and the workload of a user is reduced.
The embodiment of the application also provides a data receiving method, which receives a second data frame according to the parameters input by the user, reversely converts the byte sequence in the second data frame, and converts each byte in the byte sequence into data of a corresponding data type.
Fig. 4 is a flowchart illustrating a data receiving method provided by an embodiment of the present application. As shown in fig. 4, the process may be implemented in software, and mainly includes the following steps:
s401: receiving a communication parameter input by a user, receiving a second data frame of a byte format supported by a serial communication protocol according to the communication parameter, and obtaining a byte sequence of the byte format in the second data frame.
In this step, the communication parameters include the identification (such as station number, ID number, etc.) of the transmitting device, the address of the originating node, and the communication parameters are used to indicate which transmitting device has started transmitting data from which node address. Optionally, the communication parameter further includes a length of data to be received, so that the receiving device stops receiving the data of the length after receiving the data of the length, thereby avoiding receiving redundant data and saving resource overhead.
During specific implementation, a second data frame in a byte format supported by the serial communication protocol is received according to the communication parameters of the user data, the return value of the start code and the return value of the end code of the second data frame are obtained, and the start code and the end code of the second data frame are removed according to the return value of the start code and the return value of the end code to obtain a byte sequence in the byte format in the second data frame. Wherein, the node address of each byte in the byte array is in one-to-one correspondence with the corresponding data type.
S402: and determining the data type corresponding to each byte in the byte sequence according to the corresponding relation between the node address of each byte in the byte sequence and the corresponding data type.
For example, if the data type corresponding to the node address of the 1 st byte to the 4 th byte in the byte array is float, the 1 st byte to the 4 th byte in the byte array is determined to correspond to the float data type.
S403: and converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format.
Dividing the byte sequence into at least one data segment according to the data type corresponding to each byte in the byte sequence, wherein the data type corresponding to each byte in each data segment is the same and the node addresses are continuous, and each data segment comprises at least one data; for example, the data type corresponding to the 1 st to 4 th bytes in the byte number sequence is float, the data type corresponding to the 5 th to 12 th bytes is int, and the byte number sequence is divided into 2 data segments according to the data type, wherein the first data segment contains the 1 st to 4 th bytes of the continuous float type, and the second data segment contains the 5 th to 12 th bytes of the continuous int type. In S302, converting each data in each data segment into data in a byte format according to a conversion rule between the data type and the byte format, and in S403, converting bytes contained in each data segment into data in a corresponding data type by reversely using the conversion rule between the data type and the byte format; for example, a first data segment containing consecutive bytes 1-4 of float type is converted into a 4-byte data of float type, and a second data segment containing consecutive bytes 5-8 of int type is converted into a 4-byte data of int type and consecutive bytes 8-12 of int type are converted into a 4-byte data of int type. Wherein the first data segment contains one 4 byte float type data and the second data segment contains two 4 byte int type data.
In the embodiment of the application, after the complete second data frame is received, the start code and the end code in the second data frame are removed to obtain the complete byte sequence, the byte sequence is segmented according to the data type, and each data segment can independently perform data type conversion, so that the conversion efficiency is improved; and the node address of each byte in each byte sequence corresponds to the corresponding data type one by one, and the bytes in each data segment are converted into the corresponding data types by reversely utilizing the conversion rule between the data types and the byte formats, so that manual calculation is not needed, the conversion speed is improved, and the workload of a user is reduced.
The following describes in detail a complete flow of the data transceiving method provided in the embodiment of the present application, taking the master station and the slave station as an example.
Fig. 5 illustrates a complete flow chart of data transceiving provided by an embodiment of the present application. The process can be realized in a software mode, and mainly comprises the following steps:
s501: the master station and the slave station establish communication connection.
In this step, the master station serves as a sending end device, the slave station serves as a receiving end device, and the master station and the slave station establish a serial communication connection through a serial communication protocol (such as a Modbus protocol).
S502: the master station receives a first communication parameter input by a user.
In this step, the first communication parameter is a communication parameter input in the process of sending data, and the first communication parameter includes the station number of the slave station node, the address of the start node, and the length of data to be sent. The user may input communication parameters to the master station through the user interface of fig. 6. In the process of sending data, a user inputs the station number of the slave station node, the address of the starting node and the length of data to be sent at corresponding positions in the sending operation module.
S502: the primary station determines at least one data segment according to the data type of each data in the first data frame, and receives the corresponding data segment in the data frame of the data type.
In this step, the specific segmentation process is referred to as S301, and is not repeated here. The user may enter each data segment into an entry box for the corresponding data type in the graphical interface shown in FIG. 6, e.g., the user enters the first data segment n1 into an entry box for data type int16, the second data segment n2 into an entry box for data type float, and so on.
S503: and converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format.
The detailed description of this step is referred to S302 and will not be repeated here.
S504: and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol.
The detailed description of this step is referred to S303 and will not be repeated here.
S505: and the master station transmits the encapsulated second data frame to the slave station.
In this step, it is known to which slave station the second data frame is transmitted, and from which start address the slave station receives data of a specified data length, based on the communication parameters input by the user in the user interface of fig. 6 in S502.
It should be noted that the sending operation module also provides a function of "clearing data", and the master station responds to an operation instruction of clicking a "clear data" function key by a user, and clears data in the input boxes of the station number, the start address, the length and the data type, so as to send a data frame to another slave station.
S506: the master station receives the second communication parameters input by the user.
In this step, the second communication parameter is a communication parameter input in the process of receiving data, and the second communication parameter includes a station number of the slave station node, an address of the start node, and a length of data to be received. The user may input communication parameters to the master station through the user interface of fig. 6. In the process of receiving data, a user inputs the station number of the slave station node, the address of the starting node and the length of data to be received at corresponding positions in the receiving operation module.
S506: and the master station receives the second data frame in the byte format sent by the slave station according to the communication parameters.
S507: and the master station acquires the return value of the start code and the return value of the end code of the second data frame, and rejects the start code and the end code of the second data frame according to the return value of the start code and the return value of the end code to obtain the byte sequence in the byte format in the second data frame.
S508: the master station segments the byte sequence according to the data type to obtain at least one data segment.
The relevant description of S506-S508 is referred to S401-S403 and will not be repeated here.
S509: the bytes in each data segment are converted to data of the corresponding data type.
In this step, the user may input each data segment into the input box corresponding to the corresponding data type through the user interface of fig. 6, for example, the user inputs the first data segment n1 into the input box with the data type float, every two bytes in the first data segment are converted into data of the float type, the second data segment n2 is input into the input box with the data type int, every two bytes in the second data segment are converted into data of the int type, and so on.
It should be noted that the receiving operation module also provides a function of "clearing data", and the master station responds to an operation instruction of clicking a "clear data" function key by a user, and clears data in the input boxes of the station number, the start address, the length and the data type so as to receive a data frame sent by another slave station.
S510: and the master station displays the waveform corresponding to the converted data on a waveform console.
In the step, after data conversion, a drawing control instruction sent by a user by clicking a 'drawing start' function key is received, and the waveform of the data in each converted data segment is displayed in a waveform display window in a continuous (series) line segment mode according to the drawing control instruction. The change of different data can be visually compared through the waveform diagrams of the data, for example, n1 to n4 are data segments of four sensors respectively, the waveform diagrams of the data in the data segments of n1 to n4 are drawn at the same time, the relation between the data of the four sensors can be determined, and for example, the relationship between the two sensors can be determined by drawing the waveform diagrams of the data in the data segments n10 and n11 sent by the force sensor and the speed sensor at the same time.
The user can click the function key of 'save image' to send a save control instruction to the master station, and the waveform image displayed on the waveform display window is saved according to the save control instruction. In the saving process, the file may be saved to a default path by a default file name, or may pop up a save window and save to a position designated by the user.
The user can also click the 'clear data' function key to send a clear control instruction to the master station, and the waveform image displayed on the waveform display window is cleared according to the clear control instruction.
In some embodiments of the application, the master station may only show waveform images of the data in a portion of the data segments. The user selects the waveform of the data in the data segment to be displayed by checking the corresponding check box through the real-time data module in the user interface in fig. 6, and after the selection is finished, the user clicks the 'start drawing' function key to send a drawing control instruction to the master station, and the master station only displays the waveform image of the data in the data segment checked by the user according to the drawing control instruction. For example, if the user only checks the check box of n1 in the "real-time data" block, the waveform display window only displays the waveform map of the data in data segment n 1.
In some embodiments of the present application, as shown in the setting column of fig. 6, part of parameters in the communication protocol may also be set, such as parameters used for serial port, baud rate, data bit, check bit, stop bit, and timing transceiving data.
In the data transceiving method provided by the above embodiment of the present application, since the number of bytes occupied by different data types is different, part of the data occupies multiple node addresses, for example, int-type data occupies two node addresses. In the serial communication protocol, limited bytes of data are transmitted according to the capacity of a node address, for example, only two bytes are transmitted in one node address capacity in the Modbus protocol, so that the transmitted data can be segmented according to the data type, and each segment is independently subjected to byte conversion. In the data sending process, a user can select the data type of each data segment in a data frame to be transmitted at any time in a user-defined mode, carry out byte-to-data conversion according to a preset conversion rule between the data type and the byte format, and package each converted data into a complete data frame to be sent; in the process of receiving data, after the data type to be received is determined, segmenting the byte sequence according to the data type according to the corresponding relation between the node address of each byte in the byte sequence and the corresponding data type, and reversely converting each byte in each data segment into the corresponding data type in a relatively independent mode by using a conversion rule between the data type and the byte format. On one hand, when data is received and sent, slave node addresses are automatically allocated to the data in the data frames according to the number of bytes occupied by the data types and the initial addresses of the transmission data (including the first data frame and the second data frame) in sequence, so that the flexibility of data conversion is improved; on the other hand, the unified management and control of each data segment is realized, and the functions of data conversion, data clearing, waveform image storage and the like are included.
In the foregoing embodiment, the master station serves as a sending-end device during data sending, and serves as a receiving-end device during data receiving. Based on the above technical concept, an embodiment of the present application provides a data transceiving system, as shown in fig. 7, the system includes a communication terminal 1 and a communication terminal 2, the communication terminal 1 and the communication terminal 2 are connected by a serial port line, the communication terminal 1 includes a serial port interface 1, a receiving module, a data parsing module, a packaging module, a sending module, and an application module, and the application module is configured to provide each module to implement the data transceiving method provided by the embodiment of the present application. The data parsing module may include sub-modules, such as a segmentation module, a conversion module, a data type determination module, and the like. The communication terminal 2 includes a serial interface 2 and a data register for storing a data frame to be transmitted and received.
Based on the same technical concept, the embodiment of the application provides a communication terminal, and the communication terminal can realize the data transmission method in the embodiment.
Referring to fig. 8, the charging apparatus includes a segmentation module 801, a conversion module 802, and an encapsulation module 803.
A segmentation module 801, configured to determine at least one data segment according to a data type of each data in the first data frame, where each data segment includes at least one data with the same data type;
a conversion module 802, configured to convert data included in each data segment into data in a byte format supported by a serial communication protocol according to a conversion rule between a data type and the byte format;
an encapsulating module 803, configured to encapsulate each converted data into a second data frame in a byte format supported by the serial communication protocol, and send the encapsulated second data frame.
In some embodiments of the present application, the encapsulation module 803 is specifically configured to:
according to the sequence of each data, directly packaging each converted data into a second data frame in a byte format supported by a serial communication protocol; or
Integrating the converted data into a byte array in sequence according to the sequence of the data;
and packaging the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol.
In some embodiments of the present application, the encapsulation module 803 is specifically configured to:
according to a serial communication protocol, adding a start code at the head end of the first converted data and adding an end code at the tail end of the last converted data; or
According to the serial communication protocol, a start code is added to the head of the integrated byte sequence, and an end code is added to the end of the byte sequence.
In some embodiments of the present application, the communication terminal further includes a receiving module, configured to receive a communication parameter input by a user, and a sending module, configured to send the encapsulated second data frame according to the communication parameter.
It should be noted that, the communication terminal provided in the embodiment of the present application can implement the steps of the data transmission method implemented by the method embodiment, and can achieve the same technical effect, and detailed descriptions of the same parts and beneficial effects as those of the method embodiment in this embodiment are not repeated herein.
Based on the same technical concept, the embodiment of the application provides a communication terminal, and the communication terminal can realize the data transmission method in the embodiment.
Referring to fig. 9, the charging apparatus includes a receiving module 901, a data type determining module 902, and a converting module 903.
A receiving module 901, configured to receive a communication parameter input by a user, and receive a second data frame in a byte format supported by a serial communication protocol according to the communication parameter, to obtain a byte sequence in the byte format in the second data frame;
a data type determining module 902, configured to determine a data type corresponding to each node in the byte array according to a correspondence between a node address of each node in the byte array and a corresponding data type;
a conversion module 903, configured to convert each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format.
In some embodiments of the present application, the conversion module 903 is specifically configured to:
dividing the byte sequence into at least one data segment according to the data type, wherein the data type corresponding to each byte in each data segment is the same and the node addresses are continuous, and each data segment comprises at least one datum;
and converting the bytes contained in each data segment into the data of the corresponding data type according to a conversion rule between the data type and the byte format.
In some embodiments of the present application, the receiving module 901 is specifically configured to:
acquiring a return value of a start code and a return value of an end code of a second data frame;
and according to the return value of the start code and the return value of the end code, eliminating the start code and the end code of the second data frame to obtain the byte sequence of the byte format in the second data frame.
It should be noted that, the communication terminal provided in this embodiment of the present application can implement the steps of the data receiving method implemented in the foregoing embodiment of the method, and can achieve the same technical effect, and details of the same parts and beneficial effects as those of the embodiment of the method are not described herein again.
The embodiment of the present application further provides a computer-readable storage medium, where computer-executable instructions are stored, and the computer-executable instructions are used to enable a computer to execute the method in the foregoing embodiment.
The embodiments of the present application also provide a computer program product for storing a computer program, where the computer program is used to execute the method of the foregoing embodiments.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A data transmission method, comprising:
determining at least one data segment according to the data type of each data in the first data frame, wherein each data segment comprises at least one data with the same data type;
converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol, and sending the encapsulated second data frame.
2. The method of claim 1, wherein encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol comprises:
according to the sequence of each data, directly packaging each converted data into a second data frame of a byte format supported by the serial communication protocol; or
Integrating the converted data into a byte array in sequence according to the sequence of the data;
and packaging the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol.
3. The method of claim 2, wherein said directly encapsulating each converted data into a second data frame in a byte format supported by said serial communication protocol comprises:
according to the serial communication protocol, adding a start code at the head end of the first converted data and adding an end code at the tail end of the last converted data;
the encapsulating the integrated byte sequence into a second data frame of a byte format supported by the serial communication protocol includes:
according to the serial communication protocol, a start code is added at the head end of the byte sequence after integration, and an end code is added at the tail end of the byte sequence.
4. The method of claim 1, wherein the sending the encapsulated second data frame comprises:
and receiving the communication parameters input by the user, and sending the encapsulated second data frame according to the communication parameters.
5. A data receiving method, comprising:
receiving a communication parameter input by a user, and receiving a second data frame of a byte format supported by a serial communication protocol according to the communication parameter to obtain a byte sequence of the byte format in the second data frame;
determining the data type corresponding to each byte in the byte sequence according to the corresponding relation between the node address of each byte in the byte sequence and the corresponding data type;
and converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format.
6. The method of claim 5, wherein converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format comprises:
dividing the byte sequence into at least one data segment according to the data type, wherein the data type corresponding to each byte in each data segment is the same and the node addresses are continuous, and each data segment comprises at least one datum;
and converting the bytes contained in each data segment into the data of the corresponding data type according to a conversion rule between the data type and the byte format.
7. The method of claim 5, wherein receiving a second data frame in a byte format supported by a serial communication protocol according to the communication parameters to obtain a byte sequence in the byte format in the second data frame comprises:
acquiring a return value of a start code and a return value of an end code of the second data frame;
and according to the return value of the start code and the return value of the end code, eliminating the start code and the end code of the second data frame to obtain a byte sequence in a byte format in the second data frame.
8. A communication terminal, comprising:
the segmentation module is used for determining at least one data segment according to the data type of each data in the first data frame, wherein each data segment comprises at least one data with the same data type;
the conversion module is used for converting the data contained in each data segment into the data in the byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
and the encapsulation module is used for encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol and sending the encapsulated second data frame.
9. A communication terminal, comprising:
the receiving module is used for receiving communication parameters input by a user, receiving a second data frame of a byte format supported by a serial communication protocol according to the communication parameters, and obtaining a byte sequence of the byte format in the second data frame;
the data type determining module is used for determining the data type corresponding to each node in the byte array according to the corresponding relation between the node address of each node in the byte array and the corresponding data type;
and the conversion module is used for converting each byte in the byte sequence into data of a corresponding data type according to a conversion rule between the data type and the byte format.
10. A computer-readable storage medium having computer-executable instructions stored thereon for causing a computer to perform the method of any one of claims 1-7.
CN202011431250.2A 2020-12-07 2020-12-07 Data transmitting and receiving method and communication terminal Active CN112463706B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011431250.2A CN112463706B (en) 2020-12-07 2020-12-07 Data transmitting and receiving method and communication terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011431250.2A CN112463706B (en) 2020-12-07 2020-12-07 Data transmitting and receiving method and communication terminal

Publications (2)

Publication Number Publication Date
CN112463706A true CN112463706A (en) 2021-03-09
CN112463706B CN112463706B (en) 2024-05-31

Family

ID=74801965

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011431250.2A Active CN112463706B (en) 2020-12-07 2020-12-07 Data transmitting and receiving method and communication terminal

Country Status (1)

Country Link
CN (1) CN112463706B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114422604A (en) * 2021-12-27 2022-04-29 中国电信股份有限公司 Data sending and receiving method and device
WO2023084418A3 (en) * 2021-11-12 2023-07-13 Alpha Sanatorium Technologies Inc. Method and system for optimizing transmission of serialized data using dynamic, adaptive slicing and reduction of serialized data

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101008890A (en) * 2007-01-30 2007-08-01 金蝶软件(中国)有限公司 Compression and uncompression method of integral data and device thereof
CN101267448A (en) * 2008-05-09 2008-09-17 东北大学 An intelligent protocol conversion device and method based on embedded QNX operating system
CN101588370A (en) * 2009-07-02 2009-11-25 浙江大学 Analytic method of multirate communication data stream format
CN102281152A (en) * 2011-06-08 2011-12-14 烽火通信科技股份有限公司 Distributed communication system, implementation method, marshalling and unmarshalling method of remote API (Application Program Interface)
KR101191547B1 (en) * 2011-06-27 2012-10-15 엘에스산전 주식회사 A way to convert can and modbus communication and a gateway for can and modbus communication
US20150177708A1 (en) * 2013-12-19 2015-06-25 General Electric Company Systems and methods for dynamic mapping for end devices of control systems
US20150296398A1 (en) * 2012-12-31 2015-10-15 Feitian Technologies Co., Ltd. Method and system for online communication
CN105187332A (en) * 2015-08-05 2015-12-23 武汉森岩科技有限公司 Multi-source data transmission method based on Zigbee network
CN107147657A (en) * 2017-05-31 2017-09-08 飞智控(天津)科技有限公司 Suitable for the communication protocol of multimachine reliable communication, decoding method and communication apparatus
CN112035401A (en) * 2019-06-03 2020-12-04 北京京东尚科信息技术有限公司 Model data processing method and device, electronic equipment and readable medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101008890A (en) * 2007-01-30 2007-08-01 金蝶软件(中国)有限公司 Compression and uncompression method of integral data and device thereof
CN101267448A (en) * 2008-05-09 2008-09-17 东北大学 An intelligent protocol conversion device and method based on embedded QNX operating system
CN101588370A (en) * 2009-07-02 2009-11-25 浙江大学 Analytic method of multirate communication data stream format
CN102281152A (en) * 2011-06-08 2011-12-14 烽火通信科技股份有限公司 Distributed communication system, implementation method, marshalling and unmarshalling method of remote API (Application Program Interface)
KR101191547B1 (en) * 2011-06-27 2012-10-15 엘에스산전 주식회사 A way to convert can and modbus communication and a gateway for can and modbus communication
US20150296398A1 (en) * 2012-12-31 2015-10-15 Feitian Technologies Co., Ltd. Method and system for online communication
US20150177708A1 (en) * 2013-12-19 2015-06-25 General Electric Company Systems and methods for dynamic mapping for end devices of control systems
CN105187332A (en) * 2015-08-05 2015-12-23 武汉森岩科技有限公司 Multi-source data transmission method based on Zigbee network
CN107147657A (en) * 2017-05-31 2017-09-08 飞智控(天津)科技有限公司 Suitable for the communication protocol of multimachine reliable communication, decoding method and communication apparatus
CN112035401A (en) * 2019-06-03 2020-12-04 北京京东尚科信息技术有限公司 Model data processing method and device, electronic equipment and readable medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
文领章: "地震数据存储技术研究", 《中国优秀硕士学位论文全文数据库 信息科技辑》, no. 10, 15 October 2011 (2011-10-15), pages 137 - 27 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023084418A3 (en) * 2021-11-12 2023-07-13 Alpha Sanatorium Technologies Inc. Method and system for optimizing transmission of serialized data using dynamic, adaptive slicing and reduction of serialized data
GB2627090A (en) * 2021-11-12 2024-08-14 Alpha Sanatorium Tech Inc Method and system for optimizing transmission of serialized data using dynamic, adaptive slicing and reduction of serialized data
CN114422604A (en) * 2021-12-27 2022-04-29 中国电信股份有限公司 Data sending and receiving method and device

Also Published As

Publication number Publication date
CN112463706B (en) 2024-05-31

Similar Documents

Publication Publication Date Title
US4888726A (en) Distributed processing in a cluster of industrial controls linked by a communications network
CN107919947B (en) Coding method for long message transmission of CAN bus
CN111049752B (en) Load balancing method and device for multiple transmission lines
CN112463706B (en) Data transmitting and receiving method and communication terminal
CN107707447A (en) A kind of slave station system and control method based on EtherCAT
JP7030797B2 (en) Network management information receiving method, receiving device and storage medium
CN103827760B (en) For being carried out the method and system of transmitting procedure reflection by gateway device
CN107819659B (en) Intelligent cascade communication network based on SPI
CN106789258A (en) The collocation method of EPA
CN103546354A (en) Communicating method being based on Internet of Things electric temperature measurement equipment and enabling RS485 bus and CAN bus to be compatible
CN101882975B (en) Method for transmitting data by using preamble of Ethernet frame
CN104866399B (en) UM-BUS bus run Failure Detection Controller and detection method
CN108809949A (en) The method converted and dispatched between profinet, FF H1, CAN and profibus agreements
CN106059964B (en) Message forwarding method and device
JPH06318945A (en) Mutual connection device between networks
Zhong et al. Industrial wireless communication protocol WIA-PA and its interoperation with foundation fieldbus
CN104753899B (en) A kind of open bus structures with multi-tier structure
CN103346943A (en) Method and system of data transmission
CN114915515B (en) CAN communication method and system based on SOC
CN109831768A (en) A kind of LoRa multinode big data method for transmission processing, apparatus and system
CN101895560A (en) Fieldbus DP-NET with open two-stage topological structure
CN107342920A (en) Things-internet gateway access device and its data interactive method
CN112994998A (en) Communication node, communication method, communication device and electronic equipment
US6295280B1 (en) Method for network node recognition
CN104579878A (en) Flexible general MVB (Multifunctional Vehicle Bus) network modeling method based on OMNeT++

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
GR01 Patent grant
GR01 Patent grant