CN112463706B - Data transmitting and receiving method and communication terminal - Google Patents

Data transmitting and receiving method and communication terminal Download PDF

Info

Publication number
CN112463706B
CN112463706B CN202011431250.2A CN202011431250A CN112463706B CN 112463706 B CN112463706 B CN 112463706B CN 202011431250 A CN202011431250 A CN 202011431250A CN 112463706 B CN112463706 B CN 112463706B
Authority
CN
China
Prior art keywords
data
byte
type
frame
data frame
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.)
Active
Application number
CN202011431250.2A
Other languages
Chinese (zh)
Other versions
CN112463706A (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

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 the first data frame; converting the data contained in each data segment into data in byte format supported by serial communication protocol according to conversion rule between data type and byte format; and encapsulating the converted data into a second data frame in a byte format supported by the serial communication protocol, and transmitting the encapsulated second data frame. In the receiving method, receiving communication parameters input by a user, and acquiring byte arrays in a byte format in a second data frame according to the communication parameters; 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 transmitting 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 and receiving method and a communication terminal.
Background
The essence and the core of the industrial Internet are that equipment, production lines, factories, suppliers, products and clients are tightly fused together through an industrial Internet platform, so that the manufacturing industry is helped to lengthen an industrial chain, and interconnection and intercommunication among equipment, systems, factories and areas are formed, thereby improving the industrial efficiency, promoting the intellectualization of the whole manufacturing service system, being beneficial to promoting the melting development of the manufacturing industry, realizing the crossing development between the manufacturing industry and the service industry, and enabling various element resources of the industrial economy to be shared with high efficiency.
The industrial internet generally uses serial communication protocols to transmit data, wherein various serial communication interfaces such as RS-232, RS-422, and RS-485 can be used. Because of the different number of bytes of different types of data, it is necessary to convert the data to a data type that matches the number of bytes occupied by the capacity of the transmitting 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 people. The mode of manually specifying the data types and then converting the data is simple and quick, but 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, as the master-slave station communication program among different devices is different, when the same transmitting end device is communicated 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 person needs to manually calculate a conversion result according to the conversion relation among different data types and input or output the result, thereby influencing the transmission speed of data frames containing different data types and the speed of storing the converted data in an artificial intelligent database.
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 data in byte format supported by serial communication protocol according to conversion rule between data type and byte format;
And encapsulating the converted data into a second data frame in a byte format supported by the serial communication protocol, and transmitting the encapsulated second data frame.
According to the embodiment of the application, each data in the first data frame is segmented 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 subjected to type conversion independently, so that the conversion efficiency is improved; the method realizes the transmission of different types of data in one data frame, does not influence the conversion of the types in other data segments when the types of the data in each data segment are changed, and improves the flexibility of data conversion; in the type conversion process, manual calculation is not needed, so that 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 alternatively
Sequentially integrating the converted data into a byte array according to the sequence of the data;
And encapsulating the integrated byte array into a second data frame in 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 can be integrated into one byte array and then packaged, wherein the accuracy of data packaging can be improved by integrating each data into the byte array and then packaging.
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 the serial communication protocol, adding a start code to the head end of the converted first data and adding an end code to the tail end of the converted last data;
encapsulating the integrated byte array into a second data frame in a byte format supported by a serial communication protocol, comprising:
According to the serial communication protocol, a start code is added to the head of the integrated byte array, and an end code is added to the tail of the byte array.
In the embodiment of the application, a start code is added to the head end of the first data after conversion according to the serial communication protocol, an end code is added to the tail end of the last data after conversion, or a start code is added to the head end of the byte array after integration, and an end code is added to the tail end of the byte array, so that the second data frame after encapsulation accords with 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 terminal equipment can accurately receive the data frame.
In a second aspect, an embodiment of the present application provides a data receiving method, including:
receiving communication parameters input by a user, and receiving a second data frame in a byte format supported by a serial communication protocol according to the communication parameters to obtain a byte array 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 array 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 array in the second data frame is obtained, the data type corresponding to each byte in the byte array is determined 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 is reversely utilized to convert each byte into the corresponding data type, so that manual calculation is not needed, the conversion speed is improved, and the user workload is reduced.
In some embodiments of the present application, converting each byte in a byte array 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 types, wherein the data types corresponding to the bytes in each data segment are the same and the node addresses are continuous, and each data segment comprises at least one data;
And converting bytes contained in each data segment 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 byte array is divided according to the data types to obtain at least one data segment, and each data segment can be used for independently converting the data types, so that the conversion efficiency is improved.
In some embodiments of the present application, receiving a second data frame in a byte format supported by a serial communication protocol according to a communication parameter, to obtain a byte array in the byte format in the second data frame, including:
acquiring a return value of a start code and a return value of an end code of the second data frame;
and eliminating 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 byte sequence of 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 array, so that the subsequent conversion of each byte in the byte array is convenient.
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 data in a byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
And the packaging module is used for packaging the converted data into a second data frame in a byte format supported by the serial communication protocol and sending the packaged 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 in a byte format supported by the serial communication protocol according to the communication parameters, and obtaining a byte array in 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 a method of embodiments of the present application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it will be obvious that the drawings in the following description are some embodiments of the present application, and that other drawings can be obtained according to these drawings without inventive effort to a person skilled in the art.
Fig. 1 schematically illustrates an application scenario provided by an embodiment of the present application;
fig. 2 is a schematic diagram schematically illustrating a structure of a data frame according to an embodiment of the present application;
Fig. 3 is a flowchart schematically illustrating a data transmission method according to an embodiment of the present application;
fig. 4 is a flowchart schematically illustrating a data receiving method according to an embodiment of the present application;
fig. 5 is a flowchart schematically illustrating a data transceiving method according to an embodiment of the present application;
FIG. 6 illustrates a data transceiver user interface provided by an embodiment of the present application;
Fig. 7 is a schematic diagram of a data transceiver system according to an embodiment of the present application;
Fig. 8 is a diagram schematically showing a structure of a communication terminal provided by an embodiment of the present application;
fig. 9 is a diagram schematically showing a structure of another communication terminal according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described in further detail below with reference to the accompanying drawings, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
All other embodiments, which can be made by a person skilled in the art without inventive effort, based on the exemplary embodiments shown in the present application are intended to fall within the scope of the present application. Furthermore, while the present disclosure has been described in terms of an exemplary embodiment or embodiments, it should be understood that each aspect of the disclosure may be separately implemented as a complete solution.
It should be understood that the terms first, second, and the like in the description and in the claims and in the above-described figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate, such as where appropriate, for example, implementations other than those illustrated or described in connection with the embodiments of the application.
Furthermore, the terms "comprise" and "have," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or apparatus that comprises a list of elements is not necessarily limited to those elements expressly listed, but may include other elements not expressly listed or inherent to such product or apparatus.
The term "module" as used in this disclosure 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 function associated with that element.
Modbus is a typical master/slave serial communication protocol, and is widely used in the industrial Internet. As a serial communication protocol, the Modbus RTU specification does not allow for duplicate node addresses, nor does the standard protocol have broadcast and multicast functionality. The transmission node in the communication protocol is 2 bytes, i.e. every two bytes corresponds to a node address. Because the address capacity of each transmission node is 2 bytes, when the master node transmits a data frame with more than 2 bytes, the data of the first two bytes are transmitted to the address of the starting node specified by the user, and the following bytes are sequentially transmitted according to the address number. For example, the master node transmits 4 bytes of data (e.g., 4556) to the slave node with an address of 6, and after the transmission is completed, the slave node starts storing 45 data registers with an address of 6, and the data registers with an address of 7 store 56 data registers.
Since the data transmitted in the Modbus protocol can only be written into the register in the form of 2 bytes, the data can only be exported in the form of 2 bytes, so that when the data in the form of non-2 bytes is transmitted by using the Modbus protocol, data type conversion is required, for example, when data transmission is performed, 4 bytes of float type data are required to be converted into two 2 bytes of ushort type data to be transmitted; in data reception, it is also necessary to convert two data of ushort types of 2 bytes into one data of a float type of 4 bytes for reception.
In the current serial communication process, the type of the transmission data is preset, whether the type of the transmission data is matched with the set data type is determined, and if the type of the transmission data is matched with the set data type, a data frame with the byte more than 2 is artificially converted into a data frame with the set type and then is transmitted. The mode of manually converting the data types is simple and quick, but the flexibility of data transmission is poor, and because of the compatibility problem between communication software of different devices, different communication software still needs to be installed when different devices communicate, or the data types are manually converted, so that the communication speed is low.
Based on the above problems, the embodiment of the application provides a data sending and receiving method and a communication terminal. The method comprises the steps of carrying out data type conversion on data in each segment independently in a mode of segmenting a data frame sent or received by a serial communication protocol, and then packaging the converted data into a complete data frame to be sent or received; on one hand, the method provided by the embodiment of the application can simultaneously send or receive the data frames with different data types by using an application program or a debugging assistant without manually converting the data types, thereby improving the flexibility of data receiving and transmitting and the speed of data conversion; on the other hand, different software is not required to be developed for different receiving end devices or data conversion is not required to be manually carried out, so that the speed of transmitting data frames from the same transmitting end device to different receiving end devices is improved, and the cost and time of data transmission are saved.
It should be noted that the method provided by the embodiment of the application is not only applicable to Modbus protocols, but also applicable to other serial communication protocols, such as RS-232 protocols, HART protocols, MPI protocols and the like.
Embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 schematically illustrates an application scenario provided by an embodiment of the present application. As shown in fig. 1, the same transmitting end device 101 may transmit data frames to one or more receiving end devices simultaneously. In fig. 1, three receiving end devices 102-104 are taken as an example, where the sending end device 101 and the receiving end devices 101-104 use a Modbus network (but may also be other networks, and the application is not limited thereto), and the receiving end devices 101-104 may use different data types to receive the same data frame sent by the sending end device 101. Wherein the transmitting-end device and the receiving-end device are collectively called a communication terminal.
Fig. 2 is a schematic diagram of a structure 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 the data 1 and the data 2 shown in fig. 2 are different.
It should be noted that the structure of the data frames transmitted by different serial communication protocols may be different, and the embodiment of the present application does not require a limitation on the structure of the data frames on the basis of not changing the essential content provided by the embodiment 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 can be implemented in a software manner, and mainly includes the following steps:
S301: at least one data segment is determined 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, the first data frame is an original data frame to be transmitted, the first data frame is segmented according to the data type of each data in the first data frame, at least one data segment is obtained, a dashed line box in fig. 2 represents a data segment, 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 can be the same or different.
S302: and converting the data contained in each data segment into data in a 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 set in advance. For example, the data segment 1 includes data 1 with a data type of shaping (int), and the conversion rule between the data type int and the byte format (ushort) supported by the serial communication protocol is that one 4-byte int type data is converted into two 2-byte format (ushort) data, and one 4-byte data 1 is converted into two 2-byte format data according to the conversion rule; the data type of the two data 2 included in the data segment 2 is floating point (float), the conversion rule between the data type float and the byte format (ushort) supported by the serial communication protocol is that the data of one 4-byte float type is converted into the data of two 2-byte formats (ushort), and the two 4-byte data 2 is converted into the data of four 2-byte formats according to the conversion rule.
It should be noted that, the data types in the embodiment of the present application may be existing conventional data types, such as short (ushort), int16 (uint 16), int32, long, float, double, and the like, or user-defined data types, such as a piece of data with a custom int type and a piece of data with a float type, which form a piece of 8 bytes of data, that is, the custom data type is formed by the int type and the float type.
S303: and encapsulating the converted data into a second data frame in a byte format supported by the serial communication protocol, and transmitting the encapsulated second data frame.
In S301 and S302, the types of the plurality of data in the first data frame are converted, and the data frames need to be packaged into a complete data frame to be sent after conversion. In S303, the converted data are directly encapsulated into a second data frame in a byte format supported by the serial communication protocol in the order of the data in the first data frame. In particular, according to the serial communication protocol, a start code is added to the head end of the first data after conversion, and an end code is added to the tail end of the last data after conversion.
For example, the first data frame includes two data segments, the 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 are obtained after conversion, which are sequentially the first sub-data and the second sub-data; the two data 2 in the data segment 2 are sequentially second data and third data in the first data frame, the data type of the data 2 is float, the two data in the 2 byte format obtained after the second data conversion are sequentially third sub-data and fourth sub-data, the two data in the 2 byte format obtained after the third data conversion are sequentially fifth sub-data and sixth sub-data, a start code is added at the head end of the first sub-data and an end code is added at the tail end of the sixth sub-data, and all the sub-data fields are sequentially packaged to obtain the second data frame in the 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 packaged second data frame according to the communication parameters. In some embodiments, the master station further transmits a function code to the receiving end device, and allocates node addresses for the receiving end device sequentially from the start address of the second data frame for data transmission. The communication parameters include an identification of the receiving device (e.g., station number, ID number, etc.), an address of the originating node, and the communication parameters are used to indicate which receiving device starts receiving the second data frame from which node address.
In an alternative implementation manner, the communication parameters further include the length of the data to be transmitted, so that the transmitting device cannot continue to transmit after transmitting the data with the length, transmission of redundant data is avoided, and resource overhead is saved.
Wherein the data length may be determined by:
Let the byte number of single data be N, the address capacity of the transmission node be x bytes, then the node number M occupied by single data is:
the data length of the X data is x×m.
In some embodiments, when the converted data is packaged, the data may be integrated first, and then the integrated byte array is packaged. Sequentially integrating the converted data into a byte array according to the sequence of the data; and encapsulating the integrated byte array into a second data frame in a byte format supported by the serial communication protocol. In particular, according to the serial communication protocol, a start code is added to the head of the integrated byte array, and an end code is added to the tail of the byte array.
Based on the example of S303, after the first sub data to the sixth sub data are obtained, the first sub data to the sixth sub data are sequentially integrated into a byte array, a start code is added to the head end of the integrated byte array, and an end code is added to the tail end of the byte array, 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, and each data segment includes at least one data with the same data type, so that the data in each data segment can be simultaneously and individually subjected to type conversion, thereby improving the conversion efficiency; the method realizes the transmission of different types of data in one data frame, does not influence the conversion of the types in other data segments when the types of the data in each data segment are changed, and improves the flexibility of data conversion; in the type conversion process, manual calculation is not needed, so that 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 schematically illustrating a data receiving method according to an embodiment of the present application. As shown in fig. 4, the process may be implemented in a software manner, and mainly includes the following steps:
S401: and receiving the communication parameters input by the user, and receiving a second data frame in a byte format supported by the serial communication protocol according to the communication parameters to obtain a byte array in the byte format in the second data frame.
In this step, the communication parameter includes an identification of the transmitting device (such as a station number, an ID number, etc.), an address of the originating node, and the communication parameter is used to indicate which transmitting device is to receive data transmitted from which node address. Optionally, the communication parameters further include a length of data to be received, so that the receiving device stops receiving after receiving the data with the length, thereby avoiding receiving redundant data and saving resource overhead.
In specific implementation, a second data frame in a byte format supported by a serial communication protocol is received according to communication parameters of user data, a return value of a start code and a return value of an 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, so that a byte array in the byte format in the second data frame is obtained. Wherein, the node address of each byte in the byte array corresponds to the corresponding data type one by one.
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 to 4 th bytes in the byte array is float, the 1 st to 4 th bytes in the byte array is determined to correspond to the float data type.
S403: and 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.
Dividing the byte array into at least one data segment according to the data types corresponding to each byte in the byte array, wherein the data types corresponding to each byte in each data segment are the same and the node addresses are continuous, and each data segment comprises at least one data; for example, the data type corresponding to the1 st to 4th bytes in the byte array is float, the data type corresponding to the 5 th to 12 th bytes is int, the byte array is divided into 2 data segments according to the data type, the first data segment comprises the1 st to 4th bytes of the continuous float type, and the second data segment comprises the 5 th to 12 th bytes of the continuous int type. In S302, each data in each data segment is converted into data in byte format according to the conversion rule between the data type and the byte format, and in S403, the bytes included in each data segment are converted into data of corresponding data type by reversely utilizing the conversion rule between the data type and the byte format; for example, converting the1 st-4 th byte of a first data segment containing consecutive float types to a 4th byte of float type data, converting the 5 th-8 th byte of a second data segment containing consecutive int types to a 4th byte of int type data and converting the 8 th-12 th byte of consecutive int types to a 4th byte of int type data. Wherein the first data segment contains a 4-byte stream type of data and the second data segment contains two 4-byte int types of data.
In the above embodiment of the present application, after receiving the complete second data frame, the start code and the end code in the second data frame are removed to obtain the complete byte array, and the byte array is divided according to the data types, so that each data segment can independently perform data type conversion, thereby improving the conversion efficiency; and node addresses of all bytes in each byte array are in one-to-one correspondence with corresponding data types, and the bytes in all data segments are converted into the corresponding data types by reversely utilizing the conversion rules 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 complete flow of the data transceiving method provided by the embodiment of the application is described in detail below by taking a master station and a slave station as examples.
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 a communication connection.
In this step, the master station acts as a transmitting-end device, the slave station acts 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 Modbus protocol).
S502: the primary station receives a first communication parameter entered by a user.
In the step, the first communication parameter is a communication parameter input in the process of transmitting data, and the first communication parameter comprises a station number of a slave station node and an address of a starting node, and the length of the data to be transmitted. A user may enter communication parameters to the master station via the user interface of fig. 6. In the process of transmitting data, a user inputs the station number of the slave station node and the address of the starting node at the corresponding position in the transmitting operation module, and the length of the data to be transmitted is determined.
S502: and the master 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 input box of the corresponding data type in the image interface shown in fig. 6, e.g., the user enters a first data segment n1 into an input box of data type int16, a second data segment n2 into an input box of data type float, and so on.
S503: and converting the data contained in each data segment into data in a byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format.
A detailed description of this step is referred to S302 and is not repeated here.
S504: and encapsulating each converted data into a second data frame in a byte format supported by the serial communication protocol.
A detailed description of this step is referred to S303 and is not repeated here.
S505: the master station transmits the encapsulated second data frame to the slave station.
In this step, it is known to which secondary station the second data frame is transmitted, from which start address the secondary station starts to receive data of a specified data length, based on the user input communication parameters at the user interface of fig. 6 in S502.
It should be noted that the transmitting operation module further provides a function of "data clearing", and the master station responds to an operation instruction of clicking a "data clearing" function key by a user to clear data in an input frame of a station number, a start address, a length and a data type so as to transmit a data frame to another slave station.
S506: the master station receives the second communication parameters input by the user.
In the step, the second communication parameter is a communication parameter input in the process of receiving data, and the second communication parameter comprises a station number of the slave station node and an address of the starting node, and is the length of the data to be received. A user may enter communication parameters to the master station via the user interface of fig. 6. In the process of receiving data, a user inputs the station number of the slave station node and the address of the starting node at the corresponding position in the receiving operation module, and the length of the data to be received is determined.
S506: the master station receives the second data frame in byte format transmitted by the slave station in accordance with the communication parameters.
S507: the master station obtains the return value of the start code and the return value of the end code of the second data frame, and eliminates 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 a byte array in a byte format in the second data frame.
S508: the master station segments the byte array according to the data type to obtain at least one data segment.
The relevant descriptions of S506 to S508 are referred to S401 to S403 and are not repeated here.
S509: bytes in each data segment are converted into data of a 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 being float, every two bytes in the first data segment are converted into data with one float type, the second data segment n2 is input into the input box with the data type being int, every two bytes in the second data segment are converted into data with one int type, and so on.
It should be noted that the receiving operation module further provides a function of "data clearing", and the master station responds to an operation instruction of clicking a "data clearing" function key by a user to clear data in an input frame of a station number, a start address, a length and a data type so as to receive another slave station to send a data frame.
S510: the master station displays waveforms corresponding to the converted data on a waveform control 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 intuitively compared through the waveform diagrams of the data, for example, n1 to n4 are respectively data segments of four sensors, the waveform diagrams of the data in the data segments n1 to n4 are drawn at the same time, the relation among the data of the four sensors can be determined, for example, the waveform diagrams of the data in the data segments n10 and n11 sent by the force sensor and the speed sensor are drawn at the same time, and the relation between the two sensors can be determined.
The user can also click on the function key of saving the image to send a saving control instruction to the master station, and save the waveform image displayed by the waveform display window according to the saving control instruction. When the file is stored, the file can be stored to a default path by default file names, and the file can also be stored to a position appointed by a user by popup storage windows.
The user can click a 'clear data' function key to send a clear control instruction to the master station, and the waveform image displayed by the waveform display window is cleared according to the clear control instruction.
In some embodiments of the application, the master station may only present waveform images of the data in a portion of the data segment. The user selects the waveform of the data in the data segment to be displayed by checking the corresponding check box in the user interface 'real-time data' module in fig. 6, after the selection, 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 checks the check box of n1 only in the "real-time data" module, the waveform display window displays only the waveform diagram of the data in the data segment n 1.
In some embodiments of the present application, the setting column of fig. 6 may also set some parameters of the communication protocol, such as parameters of serial port, baud rate, data bit, check bit, stop bit, and timing data transceiving.
According to the data receiving and transmitting method provided by the embodiment of the application, due to the fact that the number of bytes occupied by different data types is different, part of data occupies a plurality of node addresses, for example, the data of the int type occupies two node addresses. In the serial communication protocol, limited bytes of data are transmitted according to the capacity of the node address, for example, only two bytes of data can be transmitted according to the capacity of one node address in the Modbus protocol, so that the transmitted data can be segmented according to the data type, and each segment can be converted into bytes independently. In the process of sending data, a user can select the data type of each data segment in a data frame to be transmitted at any time in a self-defining mode, convert bytes and data according to a preset conversion rule between the data type and a byte format, and package each converted data into a complete data frame to be sent; in the process of receiving data, after determining the data type to be received, according to the corresponding relation between the node address of each byte in the byte array and the corresponding data type, segmenting the byte array according to the data type, and reversely converting each byte in each data segment into the corresponding data type in a relatively independent mode by utilizing the conversion rule between the data type and the byte format. On the one hand, when data is transmitted and received, the slave node addresses are automatically distributed to the data in the data frames according to the sequence according to the byte number occupied by the data type and the starting address of the transmission data (comprising a first data frame and a second data frame), 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 emptying, waveform image storage and the like are included.
In the foregoing embodiment, the master station is used as a transmitting end device in a data transmission process and is used as a receiving end device in a data receiving process. Based on the above technical concept, an embodiment of the present application provides a data transceiving system, as shown in fig. 7, where the system includes a communication terminal 1 and a communication terminal 2, where the communication terminal 1 and the communication terminal 2 are connected by a serial port line, and the communication terminal 1 includes a serial port interface 1, a receiving module, a data analyzing module, a packaging module, a sending module, and an application module, where 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 the received and transmitted data frame.
Based on the same technical concept, the embodiment of the application provides a communication terminal, which 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 a packaging 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 a byte format;
And the encapsulating module 803 is 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 alternatively
Sequentially integrating the converted data into a byte array according to the sequence of the data;
And encapsulating the integrated byte array into a second data frame in 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 the serial communication protocol, adding a start code to the head end of the converted first data and adding an end code to the tail end of the converted last data; or alternatively
According to the serial communication protocol, a start code is added to the head of the integrated byte array, and an end code is added to the tail of the byte array.
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 transmitting module, configured to transmit the encapsulated second data frame according to the communication parameter.
It should be noted that, the above communication terminal provided by the embodiment of the present application can implement the steps of the data transmission method implemented by the embodiment of the method, and can achieve the same technical effects, and the same parts and beneficial effects as those of the embodiment of the method in the embodiment are not described in detail herein.
Based on the same technical concept, the embodiment of the application provides a communication terminal, which 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.
The receiving module 901 is 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, so as to obtain a byte array 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 corresponding relationship between a node address of each node in the byte array and a corresponding data type;
The conversion module 903 is configured to convert 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 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 types, wherein the data types corresponding to the bytes in each data segment are the same and the node addresses are continuous, and each data segment comprises at least one data;
And converting bytes contained in each data segment 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 receiving module 901 is specifically configured to:
acquiring a return value of a start code and a return value of an end code of the second data frame;
and eliminating 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 byte sequence of byte format in the second data frame.
It should be noted that, the above communication terminal provided by the embodiment of the present application can implement the steps of the data receiving method implemented by the embodiment of the method, and can achieve the same technical effects, and the same parts and beneficial effects as those of the embodiment of the method in the embodiment are not described in detail herein.
The embodiment of the application also provides a computer-readable storage medium, which stores computer-executable instructions for causing a computer to perform the method in the above embodiment.
The embodiment of the application also provides a computer program product for storing a computer program for executing the method of the previous embodiment.
It will be appreciated by those skilled in the art that 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 flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations 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 modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (9)

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 data in byte format supported by serial communication protocol according to conversion rule between data type and byte format;
And encapsulating the converted data into a second data frame in a byte format supported by the serial communication protocol, and transmitting the encapsulated second data frame.
2. The method of claim 1, wherein encapsulating the 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 in a byte format supported by the serial communication protocol; or alternatively
Sequentially integrating the converted data into a byte array according to the sequence of the data;
And packaging the integrated byte sequence into a second data frame in 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 to the head end of the converted first data and adding an end code to the tail end of the converted last data;
The encapsulating the integrated byte array into a second data frame in a byte format supported by the serial communication protocol includes:
According to the serial communication protocol, a start code is added to the head end of the integrated byte sequence, and an end code is added to 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 packaged second data frame according to the communication parameters.
5. A data receiving method, comprising:
Receiving communication parameters input by a user, and 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;
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;
dividing the byte sequence into at least one data segment according to the data types, wherein the data types corresponding to the bytes in each data segment are the same and the node addresses are continuous, and each data segment comprises at least one data;
And converting bytes contained in each data segment 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 receiving a second data frame in a byte format supported by a serial communication protocol according to the communication parameters, obtaining a byte array 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 eliminating 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 a byte sequence in a byte format in the second data frame.
7. 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 data in a byte format supported by the serial communication protocol according to the conversion rule between the data type and the byte format;
And the packaging module is used for packaging the converted data into a second data frame in a byte format supported by the serial communication protocol and sending the packaged second data frame.
8. A communication terminal, comprising:
The receiving module is used for receiving communication parameters input by a user, receiving a second data frame in a byte format supported by a serial communication protocol according to the communication parameters, and obtaining a byte array in 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 sequence according to the corresponding relation between the node address of each node in the byte sequence and the corresponding data type;
The conversion module is used for dividing the byte sequence into at least one data segment according to the data type, and converting bytes contained in each data segment into data of a corresponding data type according to a conversion rule between the data type and a byte format; the data types corresponding to the bytes in each data segment are the same and the node addresses are continuous, and each data segment comprises at least one data.
9. A computer readable storage medium storing computer executable instructions for causing a computer to perform the method of any one of claims 1-6.
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 CN112463706A (en) 2021-03-09
CN112463706B true 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)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA3235209A1 (en) * 2021-11-12 2023-05-19 Alpha Sanatorium Technologies 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

Citations (8)

* 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
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

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103067269B (en) * 2012-12-31 2016-04-06 飞天诚信科技股份有限公司 A kind of method and system of on-line communication
US9996058B2 (en) * 2013-12-19 2018-06-12 General Electric Company Systems and methods for dynamic mapping for end devices of control systems

Patent Citations (8)

* 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
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
地震数据存储技术研究;文领章;《中国优秀硕士学位论文全文数据库 信息科技辑》;20111015(第10期);I137-27 *

Also Published As

Publication number Publication date
CN112463706A (en) 2021-03-09

Similar Documents

Publication Publication Date Title
CN110430219B (en) Method and system for self-adapting of multi-protocol Internet of things equipment
CN112463706B (en) Data transmitting and receiving method and communication terminal
CN107919947B (en) Coding method for long message transmission of CAN bus
CN107707447A (en) A kind of slave station system and control method based on EtherCAT
CN109840155B (en) Method and device for realizing remote procedure call
US9575920B2 (en) Method for transmitting a process map via a gateway device
JP7030797B2 (en) Network management information receiving method, receiving device and storage medium
CN105187283A (en) Industrial control network slave station communication method and device based on EtherCAT protocol
CN102196002A (en) Data-stream-communication-based network control system
WO2021238741A1 (en) Message forwarding method, system, device, node device, and storage medium
CN103532998A (en) Protocol/data conversion device and method
CN106130824B (en) Integration of three networks broadband access priority polling control method and system
US20230353425A1 (en) Method, program, medium, and device for interconnecting primary network domain with secondary network domain through gateway device
CN113923265A (en) System and method for converting end computing gateway protocol
CN108809949A (en) The method converted and dispatched between profinet, FF H1, CAN and profibus agreements
Zhong et al. Industrial wireless communication protocol WIA-PA and its interoperation with foundation fieldbus
CN113328926B (en) FC-AE-1553 and FC-AE-ASM hybrid network system
CN110430110B (en) On-site bus gateway and protocol conversion method thereof
CN114915515B (en) CAN communication method and system based on SOC
CN103346943A (en) Method and system of data transmission
Lin et al. Gigabit Modbus user datagram protocol fieldbus network integrated with industrial vision communication
CN115333943A (en) Deterministic network resource configuration system, method, device and storage medium
CN107342920A (en) Things-internet gateway access device and its data interactive method
CN115396368B (en) Efficient composite network data transmission method based on node addressing and data encapsulation
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