Serial port baud rate adaptive adjustment method and device of HDLC protocol

By detecting changes in the edges of received data, the actual sampling point position is determined and the baud rate is adjusted. This solves the data latching error problem caused by baud rate deviation in the HDLC protocol, realizes simple and easy baud rate adaptation, and ensures the accuracy and stability of communication.

CN117914643BActive Publication Date: 2026-07-31TRAFFIC CONTROL TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TRAFFIC CONTROL TECH CO LTD
Filing Date
2023-12-22
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In existing HDLC protocol serial communication, baud rate deviation causes sampling points to deviate from the midpoint, which is difficult to correct in time, leading to data latching errors. Furthermore, existing baud rate adaptive methods are complex and difficult to implement.

Method used

By detecting edge changes in the received data, the actual sampling point position of the current bit is determined, and the baud rate of the receiving end is adjusted according to the comparison result. The sampling point position is calculated by using a counter to record the number of oscillations of the synchronization clock, thus achieving adaptive adjustment of the baud rate.

Benefits of technology

Without modifying existing hardware and the HDLC protocol, baud rate adaptation was easily implemented, ensuring the accuracy and stability of HDLC protocol serial communication and reducing costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117914643B_ABST
    Figure CN117914643B_ABST
Patent Text Reader

Abstract

This application provides an adaptive baud rate adjustment method and apparatus for HDLC protocol serial ports, relating to the field of serial communication technology. The method includes: detecting whether there is an edge change in the received data; determining the position of the actual sampling point of the current bit when an edge change is detected; comparing the position of the actual sampling point of the current bit with the theoretical midpoint of the current bit to obtain a comparison result; and adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result. The adaptive baud rate adjustment method and apparatus for HDLC protocol serial ports provided in this application are simple to implement and can reduce costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of serial communication technology, and in particular to a method and apparatus for adaptive adjustment of HDLC protocol serial port baud rate. Background Technology

[0002] High-Level Data Link Control (HDLC) is a bit-oriented link layer protocol. Its key characteristic is that it does not require data to adhere to a specific character set, enabling transparent transmission of any bit stream. HDLC communication requires both the sender and receiver to agree on and maintain a consistent baud rate. Generally, the receiver samples at the midpoint of each bit when receiving serial data, as this position provides the most stable waveform. However, due to hardware differences and transmission distance, the baud rates of the sender and receiver often deviate. Since HDLC requires the continuous transmission of hundreds of bytes, and each byte lacks start and stop bits like those in Universal Asynchronous Receiver / Transmitter (UART) protocols, the deviation of the sampling point from the midpoint of each bit caused by baud rate discrepancies cannot be corrected promptly. Furthermore, as each bit of data is transmitted, the deviation accumulates, inevitably leading to data latching errors (such as...). Figure 1 (As shown). However, current methods for adaptive baud rate in serial communication are quite complex and difficult to implement. Therefore, there is an urgent need to propose a new method for adaptive adjustment of serial port baud rate. Summary of the Invention

[0003] This application provides a method and apparatus for adaptive baud rate adjustment of HDLC protocol serial ports, which solves the problem that current methods for adaptive baud rate adjustment in serial communication are complex and difficult to implement. The HDLC protocol serial port baud rate adaptive adjustment method provided in this application is simple and easy to implement, and can reduce costs.

[0004] In a first aspect, embodiments of this application provide a method for adaptive adjustment of the baud rate of an HDLC protocol serial port, including:

[0005] Detect whether there are edge changes in the received data;

[0006] When an edge change is detected in the received data, the position of the actual sampling point of the current bit is determined;

[0007] Compare the actual sampling point position of the current bit with the theoretical midpoint position corresponding to the current bit to obtain the comparison result;

[0008] The HDLC protocol serial port baud rate is adjusted by the receiving end when receiving subsequent bits based on the comparison result.

[0009] In one embodiment, determining the position of the actual sampling point of the current bit upon detecting an edge change in the received data includes:

[0010] If an edge change is detected in the received data, a second counter is started to record the number of oscillations of the receiving end synchronization clock from the start time of the second counter.

[0011] When the first counter restarts, the second counter is stopped, and the latch value of the second counter is recorded; the first counter is used to calculate the theoretical intermediate position corresponding to each bit.

[0012] The position of the actual sampling point of the current bit is determined based on the latch value.

[0013] In one embodiment, the width from the actual sampling point of the current bit to the starting position of the current bit is (Z-1) / Y;

[0014] Where Z is the latch value and Y is the frequency of the receiving end synchronization clock.

[0015] In one embodiment, the method further includes:

[0016] Upon determining the moment the start frame is received, the first counter is started to record the number of oscillations of the receiving end's synchronization clock from the moment the first counter is started.

[0017] The first counter is stopped, cleared, and restarted each time it counts to (Y / X)-1.

[0018] Where Y is the frequency of the receiving end's synchronization clock, and X is the initial baud rate agreed upon by the transmitting end and the receiving end.

[0019] In one embodiment, adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result includes:

[0020] In the case that (1 / 2X)-a<(Z-1) / Y<(1 / 2X)+a, the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits is determined to be X;

[0021] Where (Z-1) / Y is the width from the actual sampling point of the current bit to the starting position of the current bit, 1 / 2X is the width from the theoretical middle position of the current bit to the starting position of the current bit, and a is the first preset constant.

[0022] In one embodiment, adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result includes:

[0023] When (Z - 1) / Y > (1 / X) - b, determine to increase the HDLC protocol serial port baud rate of the receiving end to X1 when receiving subsequent bits;

[0024] Among them, (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the starting position of the current bit, 1 / X is the width from the theoretical termination position corresponding to the current bit to the starting position of the current bit, and b is a second preset constant.

[0025] In one embodiment, adjusting the HDLC protocol serial port baud rate of the receiving end according to the comparison result includes:

[0026] When (Z - 1) / Y < b, determine to decrease the HDLC protocol serial port baud rate of the receiving end to X2 when receiving subsequent bits;

[0027] Among them, (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the starting position of the current bit, and b is a second preset constant.

[0028] In a second aspect, an embodiment of the present application provides an HDLC protocol serial port baud rate adaptive adjustment device, including:

[0029] A detection module, configured to detect whether there is an edge change in the received data;

[0030] A determination module, configured to determine the position of the actual sampling point of the current bit when it is detected that there is an edge change in the received data;

[0031] A comparison module, configured to compare the relationship between the position of the actual sampling point of the current bit and the theoretical middle position corresponding to the current bit, and obtain a comparison result;

[0032] An adjustment module, configured to adjust the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result.

[0033] In a third aspect, the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the method described in the first aspect is implemented.

[0034] In a fourth aspect, the present application further provides a non - transient computer - readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in the first aspect is implemented.

[0035] In a fifth aspect, the present application further provides a computer program product, including a computer program. When the computer program is executed by a processor, the method described in the first aspect is implemented.

[0036] The HDLC protocol serial port baud rate adaptive adjustment method and apparatus provided in this application determine the actual sampling point position of the current bit when the edge changes, and adjusts the serial port baud rate based on the comparison result between the actual sampling point position of the current bit and the theoretical midpoint position corresponding to the current bit. This method requires no modification to existing serial communication hardware, nor does it require adding check bytes to the HDLC protocol. It can be directly deployed on hardware interfaces such as RS-485, is simple and easy to implement, and can ensure the accuracy and stability of HDLC protocol serial communication while reducing costs. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 This is a diagram illustrating the baud rate deviation provided in this application;

[0039] Figure 2 This is a flowchart illustrating the HDLC protocol serial port baud rate adaptive adjustment method provided in this application;

[0040] Figure 3 This is a schematic diagram illustrating the overall steps of the HDLC protocol serial port baud rate adaptive adjustment method provided in this application;

[0041] Figure 4 This is a schematic diagram of the adjustment process of the HDLC protocol serial port baud rate adaptive adjustment method provided in this application;

[0042] Figure 5 This is a schematic diagram of the HDLC protocol serial port baud rate adaptive adjustment device provided in this application;

[0043] Figure 6 This is a schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation

[0044] The HDLC protocol is widely used in rail transit projects such as subways, high-speed railways, and light rail in my country, ensuring accurate and reliable data communication between train equipment and control consoles. Currently, baud rate adaptation methods used in serial communication generally include PROFIBUS-DP, using higher frequencies and more stable crystal oscillators, etc., but these methods are often difficult to implement and require higher costs. This application provides a software-based method for implementing baud rate adaptation, which is easy to implement and can reduce costs.

[0045] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0046] Figure 2 This is a flowchart illustrating the HDLC protocol serial port baud rate adaptive adjustment method provided in an embodiment of this application. (Refer to...) Figure 2 This application provides an HDLC protocol serial port baud rate adaptive adjustment method, the execution subject of which can be an electronic device, such as a controller. The method may include:

[0047] Step 210: Detect whether there are edge changes in the received data;

[0048] Step 220: If an edge change is detected in the received data, determine the position of the actual sampling point of the current bit;

[0049] Step 230: Compare the actual sampling point position of the current bit with the theoretical intermediate position corresponding to the current bit to obtain the comparison result;

[0050] Step 240: Adjust the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result.

[0051] Figure 3 This is a schematic diagram illustrating the specific steps of the HDLC protocol serial port baud rate adaptive adjustment method provided in this application, which can be compared with... Figure 2 They correspond to each other.

[0052] In step 210, the controller can perform edge detection (detecting both rising and falling edges) during the data reception process of serial communication and obtain the result of whether there is an edge change in the received data.

[0053] In step 220, when the controller detects an edge change in the received data, it can determine the position of the actual sampling point of the current bit based on the edge change.

[0054] In step 230, the controller can also obtain the theoretical intermediate position corresponding to the current bit, and obtain a comparison result by comparing the position of the actual sampling point of the current bit with the theoretical intermediate position corresponding to the current bit. The comparison result can reflect the deviation between the position of the actual sampling point of the current bit and the theoretical intermediate position corresponding to the current bit.

[0055] In step 240, the controller can adjust the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the deviation between the actual sampling point position of the current bit reflected by the comparison result and the theoretical midpoint position corresponding to the current bit.

[0056] The HDLC protocol serial port baud rate adaptive adjustment method provided in this application determines the actual sampling point position of the current bit when the edge changes, and adjusts the serial port baud rate based on the comparison result between the actual sampling point position of the current bit and the theoretical midpoint position corresponding to the current bit. This method requires no modification to existing serial communication hardware, nor does it require adding check bytes to the HDLC protocol. It can be directly deployed on hardware interfaces such as RS-485, is simple and easy to implement, and can ensure the accuracy and stability of HDLC protocol serial communication while reducing costs.

[0057] In one embodiment, determining the position of the actual sampling point of the current bit upon detecting an edge change in the received data includes:

[0058] If an edge change is detected in the received data, the second counter is started to record the number of oscillations of the receiver's synchronization clock from the start time of the second counter.

[0059] When the first counter restarts, the second counter is stopped, and the latch value of the second counter is recorded; the first counter is used to calculate the theoretical intermediate position corresponding to each bit.

[0060] The position of the actual sampling point of the current bit is determined based on the latch value.

[0061] The counter can count the number of oscillations of the synchronization clock. When the controller detects an edge change in the received data of the serial communication, it can start a second counter to record the number of oscillations of the receiver's synchronization clock from the moment the second counter is started.

[0062] To calculate the width from the actual sampling point of the current bit to the start position of the current bit, the controller can stop the second counter when the first counter restarts, latch the count value, record the latched value of the second counter, and then clear the second counter. The latched value of the second counter reflects the width from the actual sampling point of the current bit to the start position of the current bit. The controller can control the counting of the first counter, and the count value of the first counter can be used to calculate the theoretical intermediate position for each bit. In this way, the position of the actual sampling point of the current bit can be determined whenever an edge change occurs.

[0063] The controller can determine the position of the actual sampling point of the current bit based on the latch value of the second counter.

[0064] The HDLC protocol serial port baud rate adaptive adjustment method provided in this application obtains the latch value of the second counter by controlling the counting of the second counter. The latch value can be used to determine the position of the actual sampling point of the current bit, and the position of the actual sampling point of the current bit can be used to adjust the HDLC protocol serial port baud rate. This embodiment provides the necessary data preparation for baud rate adaptive adjustment, which helps to ensure the accuracy and stability of HDLC protocol serial communication.

[0065] In one embodiment, the width from the actual sampling point of the current bit to the starting position of the current bit is (Z-1) / Y;

[0066] Where Z is the latch value and Y is the frequency of the receiver's synchronization clock.

[0067] The controller can calculate the width from the actual sampling point of the current bit to the starting position of the current bit based on the latch value of the second counter. Specifically, when the latch value of the second counter is Z and the frequency of the receiving end synchronization clock is Y (unit: Hz), the width from the actual sampling point of the current bit to the starting position of the current bit is (Z-1) / Y.

[0068] The HDLC protocol serial port baud rate adaptive adjustment method provided in this application determines the width from the actual sampling point of the current bit to the starting position of the current bit based on the latch value of the second counter. This width can be used to adjust the HDLC protocol serial port baud rate. This embodiment provides the necessary data preparation for baud rate adaptive adjustment, which helps to further ensure the accuracy and stability of HDLC protocol serial communication.

[0069] In one embodiment, the HDLC protocol serial port baud rate adaptive adjustment method further includes:

[0070] Upon determining the moment the start frame is received, start the first counter and record the number of oscillations of the receiver's synchronization clock from the moment the first counter is started;

[0071] The first counter is stopped, cleared, and restarted every time it counts to (Y / X)-1.

[0072] Where Y is the frequency of the receiver's synchronization clock, and X is the initial baud rate agreed upon by the transmitter and receiver.

[0073] Assuming the initial baud rate agreed upon by the serial communication transmitter and receiver is X (in bps), the baud rate period is 1 / X (in seconds). Assuming the receiver's synchronization clock frequency is Y (in Hz), calculating one baud rate period requires counting Y / X times. When there is no data transmission or reception, the receive data line is high, and the HDLC protocol frame header is 7E (b01111110). When the receiver detects a falling edge of the data, the first counter starts counting. If the count reaches (Y / 2X)-1, and the data remains low throughout, it indicates that the start frame has been received.

[0074] Upon receiving the start frame, the controller can start the first counter to record the number of oscillations of the receiver's synchronization clock from the start of the first counter. Every time the first counter counts to (Y / X)-1, a sample is taken, and simultaneously, the first counter stops, resets to zero, and restarts to continue counting. Initially, the first counter's sampling point is located at the midpoint of each bit of data, and if there is no baud rate deviation, the sampling point will always be located at the midpoint of each bit of data.

[0075] The HDLC protocol serial port baud rate adaptive adjustment method provided in this application determines the theoretical intermediate position corresponding to the current bit by controlling a first counter. This theoretical intermediate position can be used to adjust the HDLC protocol serial port baud rate. This embodiment provides the necessary data preparation for adaptive baud rate adjustment, which helps to further ensure the accuracy and stability of HDLC protocol serial communication.

[0076] In one embodiment, adjusting the HDLC protocol serial port baud rate at the receiving end when receiving subsequent bits based on the comparison result includes:

[0077] Given that (1 / 2X)-a<(Z-1) / Y<(1 / 2X)+a, the HDLC protocol serial port baud rate at the receiving end is still X when receiving subsequent bits;

[0078] Where (Z-1) / Y is the width from the actual sampling point of the current bit to the starting position of the current bit, 1 / 2X is the width from the theoretical middle position of the current bit to the starting position of the current bit, and a is the first preset constant.

[0079] The controller can determine the width (Z-1) / Y) from the actual sampling point of the current bit to the starting position of the current bit based on the latch value Z of the second counter and the frequency Y of the receiving end's synchronization clock. The controller can also determine the width (1 / 2X) from the theoretical middle position of the current bit to the starting position of the current bit based on the initial baud rate agreed upon by the serial communication transmitter and receiver.

[0080] like Figure 4As shown, when (1 / 2X)-a<(Z-1) / Y<(1 / 2X)+a (a is the first preset constant, which can be set according to actual needs), that is, when the actual sampling point of the current bit is within a range of 2a before and after the theoretical midpoint of the current bit, it can be considered that the actual sampling point is kept near the midpoint, the controller does not need to adjust the receiving baud rate, and it can be determined that the HDLC protocol serial port baud rate of the receiving end is still X when receiving subsequent bits.

[0081] The HDLC protocol serial port baud rate adaptive adjustment method provided in this application determines that the subsequent baud rate remains unchanged when the actual sampling point of the current bit is near the theoretical middle position corresponding to the current bit. This method requires no modification to existing serial communication hardware and does not require adding check bytes to the HDLC protocol. It can be directly deployed on hardware interfaces such as RS-485, is simple and easy to implement, and can ensure the accuracy and stability of HDLC protocol serial communication while reducing costs.

[0082] In one embodiment, adjusting the HDLC protocol serial port baud rate at the receiving end when receiving subsequent bits based on the comparison result includes:

[0083] Given that (Z-1) / Y>(1 / X)-b, determine to increase the HDLC protocol serial port baud rate of the receiving end to X1 when receiving subsequent bits;

[0084] Where (Z-1) / Y is the width from the actual sampling point of the current bit to the starting position of the current bit, 1 / X is the width from the theoretical termination position of the current bit to the starting position of the current bit, and b is the second preset constant.

[0085] The controller can determine the width (Z-1) / Y) from the actual sampling point of the current bit to the start position of the current bit based on the latch value Z of the second counter and the frequency Y of the receiving end's synchronization clock. The controller can also determine the width (1 / X) from the theoretical termination position of the current bit to the start position of the current bit based on the initial baud rate agreed upon by the serial communication transmitter and receiver.

[0086] like Figure 4 As shown, when (Z-1) / Y>(1 / X)-b (b is the second preset constant, which can be set according to actual needs), that is, when the distance between the actual sampling point of the current bit and the end position of the bit is less than b, it indicates that the receiving baud rate is less than the transmitting baud rate, the sampling point moves backward, and the controller can appropriately increase the receiving baud rate to make the sampling point move forward back to the position near the midpoint. The increased receiving end has an HDLC protocol serial port baud rate of X1 when receiving subsequent bits.

[0087] The baud rate deviation magnitude n can be calculated by taking the absolute value of the difference between the width (Z - 1) / Y from the position of the actual sampling point of the current bit to the starting position of the current bit and the width 1 / 2X from the theoretical middle position corresponding to the current bit to the starting position of the current bit, and then taking the derivative.

[0088] For the HDLC protocol data frame transmitted in the form of Non Return Zero Inverted Code (NRZI) (level change is 0, no change is 1), according to the protocol specification, only the situation of 7 consecutive bits without level change is allowed. When there is no level change, since there is no rising edge / falling edge, the method of the embodiment of the present application cannot be used to calculate the sampling point position. Thus, the constraint relationship of the X1 parameter can be obtained:

[0089] 1 / X - 1 / X1 < [(1 / X) - b] / 7

[0090] After simplification, it can be obtained that: X1 < 7X / (6 + bX)

[0091] And at the same time, X1 satisfies: X + n < X1

[0092] Finally, it can be obtained that: X < X + n < X1 < 7X / (6 + bX)

[0093] The HDLC protocol serial port baud rate adaptive adjustment method provided by the embodiment of the present application increases the subsequent baud rate when comparing the shift of the position of the actual sampling point of the current bit, so as to perform the adaptive adjustment of the serial port baud rate. This method neither requires any modification to the existing serial communication hardware, nor requires adding check bytes to the HDLC protocol. Instead, it realizes the baud rate adaptive function by changing the baud rate of the receiving end, avoids the influence of baud rate deviation on data reception, can be directly deployed on hardware interfaces such as RS - 485, is simple and easy to implement, and can ensure the accuracy and stability of the HDLC protocol serial communication while reducing costs.

[0094] In one embodiment, adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result includes:

[0095] In the case where (Z - 1) / Y < b, it is determined to reduce the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits to X2;

[0096] Among them, (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the starting position of the current bit, and b is the second preset constant.

[0097] The controller can determine that the width from the position of the actual sampling point of the current bit to the starting position of the current bit is (Z - 1) / Y based on the latch value Z of the second counter and the frequency Y of the receiving end synchronization clock.

[0098] As Figure 4 shown, when (Z - 1) / Y < b (b is the second preset constant, which can be set according to actual needs), when the distance of the actual sampling point of the current bit from the starting position of the bit is less than b, it indicates that the received baud rate is greater than the transmitted baud rate, and the sampling point moves forward. The controller can appropriately reduce the received baud rate to move the sampling point backward to a position near the midpoint. The HDLC protocol serial port baud rate of the receiving end after reduction is X2 when receiving subsequent bits.

[0099] The magnitude n of the baud rate deviation can be calculated by taking the absolute value of the difference between the width (Z - 1) / Y from the position of the actual sampling point of the current bit to the starting position of the current bit and the width 1 / 2X from the theoretical midpoint corresponding to the current bit to the starting position of the current bit and then taking the derivative.

[0100] For the HDLC protocol data frame transmitted in the form of Non Return Zero Inverted Code (NRZI) (level change is 0, no change is 1), according to the protocol specification, only the situation of 7 consecutive bits without level change is allowed. When there is no level change, since there is no rising edge / falling edge, the method of this application embodiment cannot be used to calculate the sampling point position. Thus, the constraint relationship of the X2 parameter can be obtained:

[0101] 1 / X2 - 1 / X < [(1 / X) - b] / 7

[0102] After simplification, it can be obtained that: X2 > 7X / (8 - bX)

[0103] And at the same time, X2 satisfies: X2 < X - n

[0104] Finally, it can be obtained that: 7X / (8 - bX) < X2 < X - n < X

[0105] The HDLC protocol serial port baud rate adaptive adjustment method provided by the embodiment of this application reduces the subsequent baud rate when comparing the forward movement of the position of the actual sampling point of the current bit, thereby realizing the adaptive adjustment of the serial port baud rate. This method neither requires any modification to the existing serial communication hardware nor requires adding check bytes to the HDLC protocol. Instead, it realizes the baud rate adaptive function by changing the receiving end baud rate, avoiding the influence of baud rate deviation on data reception. It can be directly deployed on hardware interfaces such as RS - 485, is simple and easy to implement, and can ensure the accuracy and stability of HDLC protocol serial communication while reducing costs.

[0106] The HDLC protocol serial port baud rate adaptive adjustment device provided in this application is described below. The HDLC protocol serial port baud rate adaptive adjustment device described below can be referred to in correspondence with the HDLC protocol serial port baud rate adaptive adjustment method described above.

[0107] Figure 5 This is a schematic diagram of the HDLC protocol serial port baud rate adaptive adjustment device provided in an embodiment of this application. (Refer to...) Figure 5 The HDLC protocol serial port baud rate adaptive adjustment device provided in this application embodiment may include:

[0108] The detection module 510 is used to detect whether there are edge changes in the received data;

[0109] The determination module 520 is used to determine the position of the actual sampling point of the current bit when an edge change is detected in the received data;

[0110] Comparison module 530 is used to compare the actual sampling point position of the current bit with the theoretical intermediate position corresponding to the current bit, and obtain the comparison result;

[0111] The adjustment module 540 is used to adjust the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result.

[0112] The HDLC protocol serial port baud rate adaptive adjustment device provided in this application determines the actual sampling point position of the current bit when the edge changes, and adjusts the serial port baud rate based on the comparison result between the actual sampling point position of the current bit and the theoretical midpoint position corresponding to the current bit. This method requires no modification to existing serial communication hardware, nor does it require adding check bytes to the HDLC protocol. It can be directly deployed on hardware interfaces such as RS-485, is simple and easy to implement, and can ensure the accuracy and stability of HDLC protocol serial communication while reducing costs.

[0113] Specifically, the HDLC protocol serial port baud rate adaptive adjustment device provided in this application embodiment can implement all the method steps implemented by the method embodiment with the controller as the execution subject, and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiment and the beneficial effects will not be described in detail.

[0114] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630, and a communication bus 640. The processor 610, communication interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions from the memory 630 to execute an HDLC protocol serial port baud rate adaptive adjustment method, such as:

[0115] Detect whether there are edge changes in the received data;

[0116] When an edge change is detected in the received data, the position of the actual sampling point of the current bit is determined;

[0117] Compare the actual sampling point position of the current bit with the theoretical midpoint position corresponding to the current bit to obtain the comparison result;

[0118] The HDLC protocol serial port baud rate is adjusted by the receiving end when receiving subsequent bits based on the comparison result.

[0119] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0120] On the other hand, this application also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the HDLC protocol serial port baud rate adaptive adjustment method provided by the above methods, for example including:

[0121] Detect whether there are edge changes in the received data;

[0122] When an edge change is detected in the received data, the position of the actual sampling point of the current bit is determined;

[0123] Compare the actual sampling point position of the current bit with the theoretical midpoint position corresponding to the current bit to obtain the comparison result;

[0124] The HDLC protocol serial port baud rate is adjusted by the receiving end when receiving subsequent bits based on the comparison result.

[0125] Furthermore, this application also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to perform the steps of the HDLC protocol serial port baud rate adaptive adjustment method provided by the above methods, for example including:

[0126] Detect whether there are edge changes in the received data;

[0127] When an edge change is detected in the received data, the position of the actual sampling point of the current bit is determined;

[0128] Compare the actual sampling point position of the current bit with the theoretical midpoint position corresponding to the current bit to obtain the comparison result;

[0129] The HDLC protocol serial port baud rate is adjusted by the receiving end when receiving subsequent bits based on the comparison result.

[0130] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0131] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0132] It should also be noted that the terms "first," "second," etc., used in the embodiments of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first" and "second" are generally of the same class, and the number of objects is not limited. For example, the first object can be one or more.

[0133] In the embodiments of this application, the term "and / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following associated objects have an "or" relationship.

[0134] In this application's embodiments, "determine B based on A" means that factor A must be considered when determining B. It is not limited to "B can be determined based solely on A," but should also include: "determine B based on A and C," "determine B based on A, C, and E," "determine C based on A, and further determine B based on C," etc. Additionally, it can include using A as a condition for determining B, for example, "when A meets the first condition, determine B using the first method"; another example, "when A meets the second condition, determine B," etc.; another example, "when A meets the third condition, determine B based on the first parameter," etc. Of course, it can also be a condition where A is a factor in determining B, for example, "when A meets the first condition, determine C using the first method, and further determine B based on C," etc.

[0135] In the embodiments of this application, the term "multiple" refers to two or more, and other quantifiers are similar.

[0136] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for adaptive adjustment of HDLC protocol serial port baud rate, characterized in that, including: detecting whether there is an edge change in the received data; when detecting an edge change in the received data, determining the position of the actual sampling point of the current bit; comparing the relationship between the position of the actual sampling point of the current bit and the theoretical middle position corresponding to the current bit to obtain a comparison result; adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result; when detecting an edge change in the received data, determining the position of the actual sampling point of the current bit, including: when detecting an edge change in the received data, starting a second counter to record the number of oscillations of the synchronization clock of the receiving end since the start time of the second counter; stopping the second counter when the first counter is restarted, and recording the latched value of the second counter; the first counter is used to calculate the theoretical middle position corresponding to each bit; determining the position of the actual sampling point of the current bit according to the latched value; the width from the position of the actual sampling point of the current bit to the start position of the current bit is (Z - 1) / Y; where Z is the latched value and Y is the frequency of the synchronization clock of the receiving end; the method further includes: when determining the moment of receiving the start frame, starting a first counter to record the number of oscillations of the synchronization clock of the receiving end since the start time of the first counter; when the first counter counts to (Y / X) - 1 each time, stopping, clearing and restarting the first counter; where Y is the frequency of the synchronization clock of the receiving end and X is the initial baud rate agreed upon by the sending end and the receiving end; adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result, including: when (1 / 2X) - a < (Z - 1) / Y < (1 / 2X) + a, determining that the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits remains X; where (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the start position of the current bit, 1 / 2X is the width from the theoretical middle position corresponding to the current bit to the start position of the current bit, and a is a first preset constant; adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result, including: when (Z - 1) / Y > (1 / X) - b, determining to increase the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits to X1; where (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the start position of the current bit, 1 / X is the width from the theoretical end position corresponding to the current bit to the start position of the current bit, and b is a second preset constant; adjusting the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits according to the comparison result, including: when (Z - 1) / Y < b, determining to decrease the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits to X2; where (Z - 1) / Y is the width from the position of the actual sampling point of the current bit to the start position of the current bit, and b is a second preset constant.

2. An HDLC protocol serial port baud rate adaptive adjustment device applying the HDLC protocol serial port baud rate adaptive adjustment method as described in claim 1, characterized in that, including: The detection module is used to detect whether there are edge changes in the received data; The determination module is used to determine the position of the actual sampling point of the current bit when an edge change is detected in the received data; The comparison module is used to compare the actual sampling point position of the current bit with the theoretical middle position corresponding to the current bit, and obtain the comparison result. The adjustment module is used to adjust the HDLC protocol serial port baud rate of the receiving end when receiving subsequent bits based on the comparison result.

3. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the HDLC protocol serial port baud rate adaptive adjustment method as described in claim 1.

4. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the HDLC protocol serial port baud rate adaptive adjustment method as described in claim 1.