Data transmission method and device based on serial port aggregation transmission, equipment and medium
By setting up logical ports of multiple serial ports in the device, and conducting master-slave port competition and logical port confirmation, the problems of low serial port transmission rate and baud rate setting are solved, and efficient and reliable data transmission is achieved.
Patent Information
- Application Number
- CN202411704825.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-04-25
AI Technical Summary
The transmission rate of the serial port is low, which can easily lead to transmission bottlenecks and baud rate setting problems, resulting in communication failure.
By setting up logical ports in the device, each logical port contains multiple serial ports, master-slave port competition and logical port confirmation are performed to ensure the reliability and efficiency of data transmission, and baud rate negotiation if necessary.
Improves the speed and reliability of data transmission, avoids transmission bottlenecks and baud rate setting issues, and ensures reliable connections between devices.
Smart Images

Figure CN119892720A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a data transmission method, device, equipment and medium based on serial port aggregation transmission. Background Art
[0002] Serial communication is a communication method between computer hardware devices or between a computer and an external device, which allows data to be transmitted in a sequence (i.e., one bit after another) through a single communication line. Serial communication is widely used in computers, embedded systems, industrial control, telecommunications and many other fields.
[0003] Taking the railway interlocking system as an example, this system is a safety-related system with the highest safety level of SIL4, which requires that the systems that interface with it should adopt certain safety measures. Many relevant industry standards stipulate that the railway interlocking system must use serial ports for external data communication.
[0004] At present, the transmission rate of serial port data transmission is low. Using serial port on the channel with a large amount of data transmission in the system is more likely to cause transmission bottleneck, resulting in low transmission rate and easy blockage. The transmission baud rate of the serial port also needs to be set by the user, and there is no automatic adjustment function. Communication connection failure often occurs due to problems with the baud rate setting. Summary of the invention
[0005] In view of the above defects in the prior art, the present invention provides a data transmission method and device, equipment, and medium based on serial port aggregation transmission to solve the technical problem of low transmission efficiency.
[0006] To achieve the above-mentioned purpose and other related purposes, the present invention provides a data transmission method based on serial port aggregation transmission, which is applied to any device of two devices provided with logical ports, wherein the logical ports include at least one serial port; the data transmission method includes: initializing the logical port of the present device; performing a master-slave port competition on a first serial port in the logical port of the present device and a second serial port in the logical port of a corresponding connected opposite-end device to obtain a master-slave state of the first serial port; performing a logical port confirmation on the first serial port and the second serial port according to the master-slave state of the first serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent: if yes, using the first serial port and the second serial port to send and receive data; if not, re-performing a master-slave port competition and logical port confirmation.
[0007] In one embodiment of the present invention, initializing the logical port of the device includes: creating a logical port and setting a port number and a basic baud rate for the logical port; adding a serial port to the logical port and setting the state of the serial port to an initial state.
[0008] In one embodiment of the present invention, after the step of initializing the logical port of the present device, the step further includes: regularly traversing the unused serial ports of the present device, and adding them as first dynamic serial ports to the logical ports of the present device; performing master-slave port competition and logical port confirmation on the first dynamic serial port and the second dynamic serial port in the logical port of the corresponding connected opposite device to determine whether the port numbers of the logical ports to which the first dynamic serial port and the second dynamic serial port belong are consistent: if yes, using the first dynamic serial port and the second dynamic serial port to send and receive data; if not, removing the first dynamic serial port from the logical port of the present device.
[0009] In one embodiment of the present invention, a first serial port in the logical port of the present device and a second serial port in the logical port of the corresponding connected opposite device are subjected to master-slave port competition to obtain the master-slave state of the first serial port, including: controlling the first serial port to send a first message, the first message carrying a key value of the first serial port; receiving a first reply message responded by the second serial port, the first reply message carrying the key value of the local serial port, the key value of the opposite serial port and a master end mark, and determining the master-slave state of the first serial port according to the first reply message.
[0010] In one embodiment of the present invention, according to the master-slave state of the first serial port, logical port confirmation is performed on the first serial port and the second serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent, including: controlling the first serial port whose master-slave state is the master end to send a second message to the second serial port, and the second message carries the port number of the logical port to which the first serial port belongs; receiving a second reply message or a first error message responded by the second serial port, and the second reply message carries the port number of the logical port to which the first serial port belongs and the port number of the logical port to which the second serial port belongs; if the first error message is received, the port numbers of the logical ports are inconsistent; if the second reply message is received, a check is performed: if the check passes, the port numbers of the logical ports are consistent; if the check fails, the port numbers of the logical ports are inconsistent.
[0011] In one embodiment of the present invention, after the step of using the first serial port and the second serial port to send and receive data, the step also includes: checking the error rate of the sent and received data, and when the error rate is greater than a set threshold, performing baud rate negotiation to change the baud rate and re-perform master-slave port competition and logical port confirmation.
[0012] In one embodiment of the present invention, baud rate negotiation is performed, including: controlling the first serial port whose master-slave state is the master end to send a third message to the second serial port, wherein the third message carries a list of baud rates supported by the first serial port; receiving a third reply message responded by the second serial port, wherein the third reply message carries a list of commonly supported baud rates; controlling the first serial port that has received the third reply message to send a fourth message, wherein the fourth message carries the reset baud rate.
[0013] To achieve the above-mentioned purpose and other related purposes, the present invention also provides a data transmission device based on serial port aggregation transmission, including: an initialization module, used to initialize the logical port of the present device; a master-slave competition module, used to make a first serial port in the logical port of the present device and a second serial port in the logical port of the corresponding connected opposite device compete for a master-slave port to obtain the master-slave status of the first serial port; a logical port confirmation module, used to perform logical port confirmation on the first serial port and the second serial port according to the master-slave status of the first serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent; and a data transmission module, used to send and receive data using the first serial port and the second serial port.
[0014] To achieve the above-mentioned purpose and other related purposes, the present invention also provides an electronic device, including a processor, a memory and a communication bus; the communication bus is used to connect the processor and the memory; the processor is used to execute a computer program stored in the memory to implement a method provided in any one of the above embodiments.
[0015] To achieve the above-mentioned object and other related objects, the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is used to enable a computer to execute the method provided in any one of the above-mentioned embodiments.
[0016] Beneficial effects of the present invention: The present invention proposes a data transmission method and apparatus, device, and medium based on serial port aggregation transmission. The method sets logical ports, each of which has multiple serial ports. When data is transmitted, the transmission rate of the logical port based on multiple serial ports is increased exponentially compared to single serial port transmission. At the same time, when transmitting, through the steps in the method, master-slave port competition and logical port confirmation are first performed to ensure a reliable connection between the two devices. Since the connection between each pair of serial ports is independent and will not affect each other, the reliability of data transmission is guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 A schematic diagram of connecting two devices provided by an embodiment of the present invention;
[0019] Figure 2 A flowchart of a first data transmission method provided by an embodiment of the present invention;
[0020] Figure 3 A flowchart of initializing a logical port provided by an embodiment of the present invention;
[0021] Figure 4 A flowchart of master-slave port competition provided by an embodiment of the present invention;
[0022] Figure 5 A diagram of serial port message interaction when a master-slave port competes with each other provided by an embodiment of the present invention;
[0023] Figure 6 A diagram showing the state changes of the serial port when the master and slave ports compete with each other according to an embodiment of the present invention;
[0024] Figure 7 A flowchart of logical port confirmation provided by an embodiment of the present invention;
[0025] Figure 8 A diagram of serial port message interaction when a logical port is confirmed according to an embodiment of the present invention;
[0026] Fig. 9 A diagram showing changes in the state of the master end when the logical port is confirmed according to an embodiment of the present invention;
[0027] Fig.10 A diagram showing a slave end state change when a logical port is confirmed according to an embodiment of the present invention;
[0028] Fig.11 A flowchart of automatically adding a dynamic serial port provided by an embodiment of the present invention;
[0029] Fig.12 A flowchart of a second data transmission method provided by an embodiment of the present invention;
[0030] Fig.13 A flowchart of baud rate negotiation provided by an embodiment of the present invention;
[0031] Fig.14A diagram of message interaction during baud rate negotiation provided by an embodiment of the present invention;
[0032] Fig.15 A diagram showing changes in master end state when performing baud rate negotiation provided by an embodiment of the present invention;
[0033] Fig.16 A diagram showing a state change of a slave terminal when performing baud rate negotiation provided by an embodiment of the present invention;
[0034] Fig.17 A schematic diagram of data transmission and reception provided by an embodiment of the present invention;
[0035] Fig.18 A schematic diagram of a data transmission device provided by an embodiment of the present invention;
[0036] Fig.19 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0037] Description of reference numerals: 101, initialization module; 102, master-slave competition module; 103, logical port confirmation module; 104, data transmission module; 201, processor; 202, memory. DETAILED DESCRIPTION
[0038] The following describes the embodiments of the present invention through specific specific embodiments, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. It should be noted that the following embodiments and the features in the embodiments can be combined with each other without conflict. In addition to the specific methods, equipment, and materials used in the embodiments, according to the technical personnel in this technical field's grasp of the prior art and the records of the present invention, any methods, equipment, and materials of the prior art that are similar or equivalent to the methods, equipment, and materials described in the embodiments of the present invention can also be used to implement the present invention.
[0039] It should be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the scope of protection of the present invention. Unless otherwise defined, all technical and scientific terms used in the present invention have the same meaning as those generally understood by those skilled in the art.
[0040] The structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read, and are not used to limit the limiting conditions under which the present invention can be implemented, so they have no substantive technical significance. Any modification of the structure, change in the proportional relationship, or adjustment of the size should still fall within the scope of the technical content disclosed by the present invention without affecting the effects and purposes that can be achieved by the present invention. In addition, the drawings only show the components related to the present invention rather than the number, shape, and size of the components in actual implementation. The type, quantity, and proportion of each component in actual implementation can be changed arbitrarily, and the component layout type may also be more complicated.
[0041] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In some of the embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.
[0042] The flowchart and block diagram in the accompanying drawings illustrate the system architecture, functions and operations that may be implemented according to the methods and computer program products of various embodiments disclosed in the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a part of a code, and the module, the program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0043] See also Figure 1 and Figure 2 , Figure 2 A data transmission method based on serial port aggregation transmission is provided in one embodiment of the present invention. The data transmission method is applied to any device of two devices provided with logical ports, such as Figure 1In the device A or device B, the logical port includes at least one serial port. The following data transmission method is described based on a single-side device. It can be understood that when executing the data transmission method, at least two devices (i.e., the device and the opposite device) should be included, i.e., device A and device B, both of which use the data transmission method to transmit data. The data transmission method includes steps S100 to S300.
[0044] Step S100: Initialize the logical port of the device.
[0045] See also Figure 3 In a specific embodiment of the present invention, step S100 includes step S101 and step S102.
[0046] Step S101, create a logical port, and set the port number and basic baud rate for the logical port. The port number of the logical port is used to identify the logical port of the device and the logical port of the opposite device when communicating with the opposite device. The basic baud rate is a key parameter for setting the communication rate in serial communication, which directly affects the efficiency, accuracy and system compatibility of data transmission. In this embodiment, the basic baud rate can be set to 9600, for example.
[0047] Step S102, add a serial port to the logical port, and set the state of the serial port to an initial state. The initial state can be recorded as Ms_init, for example. The serial port in the initial state cannot perform data transmission, and data transmission can only be performed after subsequent master-slave port competition and logical port confirmation.
[0048] Step S200: The first serial port in the logical port of the device and the second serial port in the logical port of the corresponding opposite device are subjected to master-slave port competition to obtain the master-slave status of the first serial port. When this step is executed, the master-slave status of the second serial port corresponding to the first serial port can be obtained at the same time, that is, if the first serial port is the master serial port, then the second serial port corresponding to it is the slave serial port; conversely, when the first serial port is the slave serial port, the second serial port corresponding to it is the master serial port.
[0049] It should be noted that the master-slave port competition here and the logical port confirmation below are for a pair of serial ports. In fact, each pair of serial ports must perform these two steps, and only after confirmation can data be sent and received.
[0050] See also Figure 4In a specific embodiment of the present invention, step S200 includes: S201, controlling the first serial port to send a first message, the first message carrying the key value of the first serial port; S202, receiving a first reply message responded by the second serial port, the first reply message carrying the key value of the local serial port, the key value of the opposite serial port and the master end mark, and determining the master-slave state of the first serial port according to the first reply message. This is a master-slave port competition process described from the perspective of a single device end, and the process is described in more detail below in combination with two devices.
[0051] See also Figure 5 In a specific embodiment of the present invention, during the master-slave port competition phase, there are two messages involved:
[0052] Hello message (equivalent to the first message): carries the key value of the local serial port;
[0053] SelectMaster message (equivalent to the first reply message): carries the key value of the local serial port, the key value of the peer serial port, and the master tag.
[0054] Initially, the first serial port and the second serial port send Hello messages to each other. For example, the Hello message sent by end A to end B carries the serial port key value of the local end (i.e., the serial port key value of end A). When end B receives the Hello message from end A, it responds to end A with a SelectMaster message, carrying the serial port key value of the local end (i.e., the serial port key value of end B), the serial port key value of the other end (i.e., the serial port key value of end A), and the master end tag. Among them, the serial port key value is a generated random number, and the key value is used to determine the master end and the slave end. The larger serial port key value at both ends is compared with the master end. The master end tag indicates which key end is the master end.
[0055] See also Figure 6 In a specific embodiment of the present invention, in the master-slave port competition phase, there are four states involved:
[0056] Ms_init: the initial state of the master-slave competition process, the state after the serial port is opened;
[0057] Ms_r: The status of the master-slave competition process receiving the SelectMaster message;
[0058] Ms_s: The status of the master-slave competition process sending the SelectMaster message;
[0059] Ms_finished: The status of the master-slave competition process being completed.
[0060] The state change process of the first or second serial port is as follows:
[0061] (1) In the Ms_init state, Hello messages are sent periodically;
[0062] (2) In Ms_s state, Hello messages are sent periodically;
[0063] (3) When in the Ms_init state, the SelectMaster message is received, the local and peer serial port key values and the master end mark carried in the message are recorded, and the state changes to Ms_r;
[0064] (4) When the Hello message is received from the other party in the Ms_r state, check whether the local serial port key value in the message (the local serial port key value in the message is the serial port key value of the other end relative to the receiving end) is consistent with the recorded serial port key value of the other end; if they are consistent, compare the serial port key values of both ends, the larger key value is the serial port key of the master end, send a SelectMaster message, carry the local and the serial port key values of the other end, and the master end mark, the master end mark is recorded locally, the state enters Ms_finished, and the master-slave competition is completed; if they are inconsistent, see (5); if the key values of both ends are the same, the local end regenerates the serial port key value and sends a Hello message;
[0065] (5) When in the Ms_r state, the local end receives a Hello message from the other end and checks whether the local end serial port key value in the message is consistent with the recorded serial port key value; if they are inconsistent, after sending a SelectMaster message, the state enters Ms_s and the serial port key value of the other end is recorded; if they are consistent, see (4);
[0066] (6) In the Ms_init state, the client receives a Hello message and sends a SelectMaster message, recording the serial port key value and master tag of the peer end.
[0067] (7) The Ms_s state receives the SelectMaster message and checks the serial port key values of the local and remote ends in the message. If they are consistent with the local records, the state enters the Ms_finished state and the master-slave competition is completed; if they are inconsistent, the state remains unchanged.
[0068] Step S300: According to the master-slave status of the first serial port, the first serial port and the second serial port are logically confirmed to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent: if yes, the first serial port and the second serial port are used to send and receive data; if no, the master-slave port competition and logical port confirmation are performed again. The port number of the logical port here may also be referred to as the logical port number below.
[0069] See also Figure 7In a specific embodiment of the present invention, according to the master-slave state of the first serial port, logical port confirmation is performed on the first serial port and the second serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent, including: S301, controlling the first serial port whose master-slave state is the master to send a second message to the second serial port, and the second message carries the port number of the logical port to which the first serial port belongs; S302, receiving a second reply message or a first error message responded by the second serial port, and the second reply message carries the port number of the logical port to which the first serial port belongs and the port number of the logical port to which the second serial port belongs; S303, if the first error message is received, the port numbers of the logical ports are inconsistent; S304, if the second reply message is received, a check is performed: if the check passes, the port numbers of the logical ports are consistent; if the check fails, the port numbers of the logical ports are inconsistent.
[0070] The logical port confirmation is initiated by the master serial port. To further illustrate the process, the message interaction and state changes between the master serial port and the slave serial port are described in detail below.
[0071] See also Figure 8 In a specific embodiment of the present invention, during the logical port confirmation phase, there are three messages involved:
[0072] LogicPortNotifyRequest message (equivalent to the second message): a logical port confirmation process notification logical port request message, sent by the master serial port, carrying the port number of the logical port to which the master serial port belongs.
[0073] LogicPortNotifyReply message (equivalent to the second reply message): the logical port confirmation process notifies the logical port response message, which is sent from the serial port and carries the port number of the logical port to which the serial port belongs.
[0074] LogicPortNotifyError message (equivalent to the first error message): a logical port confirmation process error message, carrying the port number of the logical port to which the serial ports at both ends belong.
[0075] After the master-slave competition is completed, the master serial port actively sends a LogicPortNotifyRequest message, carrying the master's logical port number. After the slave serial port receives the LogicPortNotifyRequest message, if the check passes, it responds with a LogicPortNotifyReply message, carrying the master's logical port number and the slave's logical port number; if the check fails, it responds with a LogicPortNotifyError message. After the master receives the LogicPortNotifyReply message sent by the slave, if the check fails, it sends a LogicPortNotiryError message.
[0076] See also Fig. 9 and Fig.10 In a specific embodiment of the present invention, during the logical port confirmation phase, there are two serial port states involved:
[0077] Error: error status;
[0078] Com_normal: The state in which service data can be sent and received normally.
[0079] See also Fig. 9 , the status change process of the master serial port is as follows:
[0080] (1) When the master serial port is in the Ms_finished state, it periodically sends a LogicPortNotifyRequest message carrying the logical port number of the master;
[0081] (2) The master serial port receives the LogicPortNotifyReply message sent by the slave in the Ms_finished state. The message carries the logical port number of the master and the logical port number of the slave. The master port number and the slave port number in the message are compared with the locally set master port number and the slave port number to see if they are consistent. If they are consistent, the master serial port enters the Com_normal state. If not, the master serial port enters (3).
[0082] (3) The master serial port Ms_finished state receives the LogicPortNotifyReply message sent by the slave, and checks it in the same way as in (2). If they are inconsistent, the master serial port state enters Error, and sends a LogicPortNotifyError message to the slave serial port.
[0083] (4) The master serial port Ms_finished state receives the LogicPortNotifyError message sent by the slave serial port, and the state enters Error;
[0084] (5) The master serial port is in Error state. After a period of time, the master serial port is reopened using the basic baud rate and enters Ms_init to perform the master-slave competition process.
[0085] (6) The master serial port receives the LogicPortNotifyError message when it is in Com_normal state, and then enters Error state.
[0086] See also Fig.10 , the status change process of the slave serial port is as follows:
[0087] (1) The slave serial port receives the LogicPortNotifyRequest message in the Ms_finised state and checks whether the remote logical port number is consistent with the setting. If not, a LogicPortNotifyError message is sent to the master serial port, and the slave serial port enters the Error state. If they are consistent, see (2).
[0088] (2) The slave serial port receives the LogicPortNotifyRequest message in the Ms_finised state and checks whether the remote logical port number is consistent with the setting. If they are consistent, it sends a LogicPortNotifyReply message to the master serial port, carrying the master logical port number and the slave logical port number, and the slave serial port state enters Com_normal;
[0089] (3) The slave serial port receives a LogicPortNotifyError message in the Ms_finished state, and the state enters Error;
[0090] (4) The slave serial port receives a LogicPortNotifyError message in Com_normal state, and the state changes to Error;
[0091] (5) The slave serial port is in Error state. After a period of time, the slave serial port is reopened using the basic baud rate and enters Ms_init to carry out the master-slave competition process.
[0092] The process of steps S100 to S300 has been fully introduced above. By setting logical ports, each logical port has multiple serial ports. When data is transmitted, the transmission rate of the logical port based on multiple serial ports is doubled compared to the single serial port transmission. At the same time, when transmitting, through the steps in this method, master-slave port competition and logical port confirmation are first performed to ensure a reliable connection between the two devices. Since the connection between each pair of serial ports is independent and will not affect each other, the reliability of data transmission is guaranteed.
[0093] See also Fig.11 In a specific embodiment of the present invention, step S100 further includes step S401 and step S402. These two steps are aimed at the situation that the serial port is re-added during normal communication.
[0094] Step S401: Regularly traverse the unused serial ports of the device and add them as the first dynamic serial ports to the logical ports of the device.
[0095] Step S402: Perform master-slave port competition and logical port confirmation on the first dynamic serial port and the second dynamic serial port in the logical port of the corresponding connected opposite device to determine whether the port numbers of the logical ports to which the first dynamic serial port and the second dynamic serial port belong are consistent: if yes, use the first dynamic serial port and the second dynamic serial port to send and receive data; if not, remove the first dynamic serial port from the logical port of the current device.
[0096] When a dynamic serial port is added to the logical port, the master-slave port competition and logical port confirmation process also needs to be executed to ensure that the pair of dynamic serial ports can send and receive data. Different from step S300, in step S402, if the logical port confirmation is inconsistent, the dynamic serial port needs to be removed from the logical port of the device.
[0097] See also Fig.12 In a specific embodiment of the present invention, after the step of using the first serial port and the second serial port to transmit and receive data, the following step is further performed: S500, checking the error rate of the transmitted and received data, and when the error rate is greater than the set threshold, performing baud rate negotiation to change the baud rate and re-perform the master-slave port competition and logical port confirmation. During serial port communication, a higher baud rate means a faster transmission speed, but the error rate during communication will increase accordingly. In the present invention, the baud rate negotiation is performed by checking the error rate of the transmitted and received data, thereby realizing automatic adjustment of the baud rate.
[0098] After the two connected serial ports can send and receive data, they will send and receive data at the basic baud rate due to the setting of the basic baud rate. In order to ensure the establishment of a reliable connection between the two serial ports, the basic baud rate is generally not set too high, so if the data is transmitted at the basic baud rate, the speed is average. In a specific embodiment of the present invention, before sending and receiving data, the baud rate negotiation process is automatically entered to select the highest baud rate for data transmission to increase the transmission speed; and then the above step S500 is executed to continue to adjust to the appropriate baud rate.
[0099] See also Fig.13 In a specific embodiment of the present invention, baud rate negotiation is performed, including: S501, controlling the master-slave state to allow the first serial port of the master end to send a third message to the second serial port, the third message carrying a baud rate list supported by the first serial port; S502, receiving a third reply message from the second serial port, the third reply message carrying a baud rate list supported by both; S503, controlling the first serial port that receives the third reply message to send a fourth message, the fourth message carrying the reset baud rate.
[0100] See also Fig.14 In a specific embodiment of the present invention, when performing baud rate negotiation, there are three messages involved:
[0101] AdjustBandList message (equivalent to the third message): a message for negotiating baud rate, sent by the master serial port, carrying a list of baud rates supported by the master serial port;
[0102] AdjustBandListReply message (equivalent to the third reply message): a message for negotiating baud rate, sent from the serial port of the end, carrying a list of baud rates supported by both ends;
[0103] AdjustBandSet message (equivalent to the fourth message): a baud rate negotiation message, sent by the master serial port, carrying the baud rate determined by the master.
[0104] The master serial port sends the AdjustBandList message, which carries the baud rate list supported by the master. After receiving the AdjustBandList message, the slave responds with AdjustBandListReply, which carries the baud rate list supported by both. After receiving the AdjustBandListReply, the master sends the AdjustBandSet message, which carries the set baud rate.
[0105] See also Fig.15 and Fig.16 When negotiating the baud rate, there are three serial port states involved:
[0106] AB_init: initial state of baud rate negotiation process;
[0107] AB_starting: baud rate negotiation in progress;
[0108] AB_finished: baud rate negotiation process completed status.
[0109] See also Fig.15 When negotiating the baud rate, the status of the master serial port changes as follows:
[0110] (1) The status is AB_finished during normal operation, and changes to AB_init when baud rate negotiation is started;
[0111] (2) When the master serial port status is AB_init, it sends an AdjustBandList message carrying a list of baud rates supported by the master.
[0112] (3) When the master serial port state is AB_init, it receives the AdjustBandListReply message, which carries the maximum baud rate supported by both parties. The master serial port checks whether the commonly supported baud rate is the only baud rate currently used. If so, see (4); if not, the state enters AB_starting;
[0113] (4) When the master serial port state is AB_init, it receives the AdjustBandListReply message, which carries the maximum baud rate supported by both parties. The master serial port checks whether the commonly supported baud rate is the baud rate you are currently using. If so, the state changes to AB_finished; if not, see (3);
[0114] (5) When the master serial port status is AB_starting, it sends an AdjustBandSet message carrying the baud rate selected by the master. Then it sets the status to AB_finished, reopens the serial port with the selected baud rate, and performs master-slave competition and other processes. When the serial port communication status changes to Ms_finished, baud rate negotiation is automatically performed.
[0115] (6) The master serial port status is AB_finished. Check the data transmission and reception status and whether the error rate exceeds the limit. If it cannot meet normal communication requirements, mark the current baud rate as unavailable and will not be used during the next baud rate negotiation. Re-negotiate the baud rate.
[0116] See also Fig.16 When negotiating the baud rate, the status of the slave serial port changes as follows:
[0117] (1) When the slave serial port is in the AB_finished state, it receives the AdjustBandList message, checks the baud rate list in the message, and responds with an AdjustBandListReply message containing the baud rates supported by both parties;
[0118] (2) The slave serial port receives the AdjustBandSet message in the AB_finished state. The message carries the baud rate used, records the baud rate, and changes the state to AB_starting.
[0119] (3) When the serial port is in the AB_starting state, the serial port is reopened using the recorded new baud rate to perform the master-slave competition process. When the serial port communication state changes to Ms_finished, the baud rate negotiation is automatically performed; the baud rate negotiation state is set to AB_finished;
[0120] (4) The serial port status is AB_finished. Check the data transmission and reception status and whether the error rate exceeds the limit. If normal communication cannot be achieved, mark the current baud rate as unavailable and will not be used in the next baud rate negotiation. Re-negotiate the baud rate.
[0121] See also Fig.17In a specific embodiment of the present invention, when two serial ports can send and receive data, the two can send data to each other. The data sender can continuously send Data messages carrying service data and data sequence numbers; the data receiver responds by sending Data messages carrying data sequence numbers of all other party's Data messages.
[0122] In a specific embodiment of the present invention, the process of data transmission and reception is as follows:
[0123] (1) The logical port has a data queue to be sent. Each data to be sent has a data sequence number. After receiving the data, the logical port segments the data, assigns a data sequence number, and adds the data to the data queue to be sent.
[0124] (2) The logical port cyclically selects the serial port in the Com_normal state to send data, and moves the data from the logical port's send data list to the serial port's sent data list;
[0125] (3) The logical port has a receiving data buffer pool, and the serial port has a list of data sequence numbers to be responded to. After receiving the data, the other end serial port puts the data into the receiving data buffer pool and puts the data sequence number into the list of data sequence numbers to be responded to;
[0126] (4) When the local serial port has data to send to the peer serial port, the serial port sends the serial port's data sequence number to be responded to to the peer through a Data message; when there is no data to send to the peer, the serial port sends the data sequence number to be responded to to the peer through an empty Data message at regular intervals;
[0127] (5) The data sending serial port receives the Data message from the other end and deletes the data from the sent data list of the serial port according to the response data sequence number in the message;
[0128] (6) The data sending serial port periodically checks the sent data list of the serial port, and moves the data that has not received a response data sequence number due to timeout from the serial port sent data list to the head of the waiting-to-send data list of the logical port. The logical port will use other serial ports to send the data;
[0129] (7) The logical port checks the received data buffer pool, concatenates the data with consecutive data sequence numbers, and submits them to the upper-layer application for use.
[0130] (8) During data transmission, the transmission error rate of valid data is counted to facilitate the subsequent automatic adjustment of the baud rate.
[0131] It should be noted that the step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they contain the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0132] See also Fig.18 , Fig.18 A data transmission device based on serial port aggregation transmission provided in one embodiment of the present invention includes an initialization module 101, a master-slave competition module 102, a logical port confirmation module 103 and a data transmission module 104. The initialization module 101 is used to initialize the logical port of the device; the master-slave competition module 102 is used to make the first serial port in the logical port of the device and the second serial port in the logical port of the corresponding connected opposite device compete for the master-slave port to obtain the master-slave status of the first serial port; the logical port confirmation module 103 is used to perform logical port confirmation on the first serial port and the second serial port according to the master-slave status of the first serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent; the data transmission module 104 is used to use the first serial port and the second serial port to send and receive data.
[0133] It should be noted that the data transmission device of this embodiment is a device corresponding to the above-mentioned data transmission method, and the functional modules in the data transmission device may correspond to the corresponding steps in the data transmission method. The data transmission device of this embodiment can be implemented in conjunction with the data transmission method, that is, in the absence of conflict, the relevant technical details mentioned in the data transmission method of the above-mentioned embodiment can also be applied to the data transmission device of this embodiment.
[0134] See also Fig.19 , Fig.19 An electronic device provided for one embodiment of the present invention includes a processor 201, a memory 202 and a communication bus; the communication bus is used to connect the processor 201 and the memory 202; the processor 201 is used to execute a computer program stored in the memory 202 to implement the above-mentioned data transmission method.
[0135] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. The computer program is used to enable a computer to execute the above data transmission method.
[0136] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A data transmission method based on serial port aggregation transmission, characterized in that: Applicable to any one of two devices provided with a logical port, wherein the logical port includes at least one serial port; the data transmission method comprises: Initialize the logical port of this device; Performing a master-slave port competition on a first serial port in the logical port of the device and a second serial port in the logical port of the corresponding opposite device to obtain a master-slave state of the first serial port; According to the master-slave status of the first serial port, logical port confirmation is performed on the first serial port and the second serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent: If yes, use the first serial port and the second serial port to send and receive data; If not, re-perform master-slave port competition and logical port confirmation.
2. The data transmission method based on serial port aggregation transmission according to claim 1, characterized in that: Initialize the logical port of this device, including: Create a logical port, and set a port number and a basic baud rate for the logical port; A serial port is added to the logical port, and the state of the serial port is set to an initial state.
3. The data transmission method based on serial port aggregation transmission according to claim 1, characterized in that: The steps of initializing the logical port of the device also include: Regularly traverse the unused serial ports of the device, and add the unused serial ports as the first dynamic serial ports to the logical ports of the device; The first dynamic serial port and the second dynamic serial port in the logical port of the corresponding connected opposite-end device are subjected to master-slave port competition and logical port confirmation to determine whether the port numbers of the logical ports to which the first dynamic serial port and the second dynamic serial port belong are consistent: If yes, use the first dynamic serial port and the second dynamic serial port to send and receive data; If not, remove the first dynamic serial port from the logical port of the local device.
4. The data transmission method based on serial port aggregation transmission according to claim 1, characterized in that: The first serial port in the logical port of the device and the second serial port in the logical port of the corresponding opposite device are subjected to master-slave port competition to obtain the master-slave state of the first serial port, including: Control the first serial port to send a first message, where the first message carries a key value of the first serial port; A first reply message responded by the second serial port is received, wherein the first reply message carries a key value of the local serial port, a key value of the opposite serial port, and a master end mark, and a master-slave state of the first serial port is determined according to the first reply message.
5. The data transmission method based on serial port aggregation transmission according to claim 1, characterized in that: According to the master-slave state of the first serial port, performing logical port confirmation on the first serial port and the second serial port to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent, including: Control the master-slave state to be the master end, and the first serial port sends a second message to the second serial port, wherein the second message carries the port number of the logical port to which the first serial port belongs; receiving a second reply message or a first error message responded by the second serial port, wherein the second reply message carries the port number of the logical port to which the first serial port belongs and the port number of the logical port to which the second serial port belongs; If the first error message is received, the port numbers of the logical ports are inconsistent; If the second reply message is received, check: If the check passes, the port numbers of the logical ports are consistent; If the check fails, the port numbers of the logical ports are inconsistent.
6. The data transmission method based on serial port aggregation transmission according to claim 1, characterized in that: After the step of using the first serial port and the second serial port to send and receive data, the method further includes: The error rate of the received and sent data is checked, and when the error rate is greater than a set threshold, baud rate negotiation is performed to change the baud rate and to re-perform master-slave port competition and logic port confirmation.
7. The data transmission method based on serial port aggregation transmission according to claim 6, characterized in that: Perform baud rate negotiation, including: Control the master-slave state so that the first serial port at the master end sends a third message to the second serial port, wherein the third message carries a baud rate list supported by the first serial port; receiving a third reply message responded by the second serial port, wherein the third reply message carries a list of commonly supported baud rates; The first serial port that has received the third reply message is controlled to send a fourth message, wherein the fourth message carries the reset baud rate.
8. A data transmission device based on serial port aggregation transmission, characterized in that: include: An initialization module, used to initialize the logical port of this device; A master-slave competition module, used for performing a master-slave port competition between a first serial port in the logical port of the device and a second serial port in the logical port of the corresponding connected opposite-end device, to obtain a master-slave state of the first serial port; a logical port confirmation module, configured to perform logical port confirmation on the first serial port and the second serial port according to the master-slave state of the first serial port, so as to determine whether the port numbers of the logical ports to which the first serial port and the second serial port belong are consistent; as well as The data transmission module is used to send and receive data using the first serial port and the second serial port.
9. An electronic device, characterized in that: The system comprises a processor, a memory and a communication bus; the communication bus is used to connect the processor and the memory; the processor is used to execute a computer program stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is used to make a computer execute the method according to any one of claims 1 to 7.