Method and device for detecting serial port communication baud rate of acquisition terminal
By acquiring the serial communication time domain data of the acquisition terminal for edge detection and interval calculation, the communication baud rate is calculated, and the problems of poor measurement accuracy and low efficiency in the prior art are solved, and efficient and accurate baud rate detection is achieved.
Patent Information
- Application Number
- CN202510431493.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-07-11
AI Technical Summary
The existing baud rate detection method for serial communication of acquisition terminals has the problem of poor measurement accuracy and relatively low efficiency.
By obtaining the original sampling data in the serial communication time domain between the acquisition terminal and other devices, performing edge detection, calculating the sampling intervals of adjacent edges and the number of times each sampling interval occurs, and using edge information to calculate the communication baud rate and support rate to realize automated baud rate detection.
It improves the accuracy and efficiency of detection, can make full use of signal sampling data, balances the contradiction between detection speed and accuracy, and obtains more accurate and reliable detection results.
Smart Images

Figure CN120301535A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a baud rate detection method in the field of power system detection, in particular to a baud rate detection method for serial port communication of a collection terminal, and also relates to a baud rate detection device for serial port communication of a collection terminal. Background Art
[0002] Serial port communication based on the RS-485 protocol is an important communication method for collection terminals and intelligent electric energy meters, and has been widely used in multiple links such as the research, testing, and production of terminals and electric energy meters. Currently, the communication baud rates of such power information collection devices are mostly adjustable, and relevant standards have specified several typical values for them. For power equipment with an unknown communication baud rate, typical values close to the communication baud rate can be determined by polling and other methods. However, the result of the polling method is only a judgment on whether communication can be carried out at a certain communication baud rate, rather than the accurate communication baud rate.
[0003] As a relay device between the master station and the intelligent electric energy meter, the collection terminal's correct communication baud rate with the intelligent electric energy meter directly affects the power information collection result. Therefore, in practical applications, the collection terminal has a high sensitivity to the communication baud rate of the intelligent electric energy meter. The serial port communication baud rate is mostly manually measured by testers using an oscilloscope to measure the signal waveform edges and calculate. There is still a lack of relatively mature and available automated baud rate detection methods for serial port communication of collection terminals. Limited by the huge amount of data generated at high sampling rates, the existing baud rate detection methods for serial port communication of collection terminals have problems of poor measurement accuracy and relatively low efficiency. Summary of the Invention
[0004] To solve the technical problems of poor measurement accuracy and relatively low efficiency existing in the existing baud rate detection methods for serial port communication of collection terminals, the present invention provides a baud rate detection method and device for serial port communication of a collection terminal.
[0005] The present invention is implemented by the following technical solutions: A baud rate detection method for serial port communication of a collection terminal, which includes the following steps:
[0006] S1: Obtain the original sampling data in the time domain of the serial port communication between the collection terminal and other devices;
[0007] S2: According to the preset edge type and preset edge determination condition, extract the edge information of the original sampling data and perform edge detection to obtain an edge detection result;
[0008] S3: According to the edge detection result, calculate the sampling intervals between adjacent edges and the number of occurrences of each sampling interval;
[0009] S4: Through the collection terminal, calculate the number of supporters of each sampling interval in all sampling intervals in turn;
[0010] S5: Perform data conversion on the sampling interval and the number of supporters to obtain the corresponding communication baud rate and support rate, which are used as the communication baud rate detection result.
[0011] In the present invention, by first acquiring the sampling data of the communication signal between the acquisition terminal and other devices, then performing edge detection on the sampling signal, transmitting the extracted edge information to the acquisition terminal, calculating the number of interval sampling points between adjacent edges to obtain the sampling interval, and by analyzing the proportional relationship between the number of interval sampling points with different intervals, inferring the most likely actual baud rate of the communication signal, the detection of the communication baud rate and support rate is realized, avoiding the disadvantages such as insufficient data utilization and unstable measurement deviation in the process of manually measuring the communication baud rate, being able to make more full use of the signal sampling data, converting the processing of the original sampling data to the detection and processing of edges, balancing the contradiction between detection speed and accuracy, having a relatively high detection efficiency, and also making it possible to estimate the baud rate based on the acquisition terminal platform, solving the technical problems of poor measurement accuracy and relatively low efficiency existing in the existing serial communication baud rate detection method of the acquisition terminal, and obtaining a more accurate and reliable detection result.
[0012] As a further improvement of the above solution, in step S2, the method for edge detection includes the following steps:
[0013] S21: Input the sampling rate F of the original sampling data s and the sampling signal vector s for storing the sampling results, and arrange them in the order of sampling time; wherein, the sampling signal vector s is a row vector or a column vector, and each element represents the sampling value of the signal at a moment, and N s identifies the number of elements of the vector s;
[0014] S22: Set the edge midpoint voltage v c ;
[0015] S23: Initialize the edge start position vector p, the number of edges N e and the index index; wherein, the vector p stores the sampling point indices of the sampling amplitudes before passing through the voltage v c in all the subsequent detected edges, the number of edges N e is the record of the number of elements in the vector p, and the index index identifies the sampling point sequence number and is used for subsequent traversal of the sampling signal vector s;
[0016] S24: Perform edge judgment: According to the comparison results of the current sampling signal amplitude s[index] and the next sampling signal amplitude s[index + 1] with the voltage v c respectively, judge whether the adjacent signals form an edge. If so, execute step S25; otherwise, execute step S26;
[0017] S25: Add the index that satisfies the preset edge determination condition to the vector p, and at the same time set N e = N e + 1, indicating that the number of detected edges increases by 1, and execute step S26;
[0018] S26: After determining whether one of the indexes is the starting point of an edge and performing corresponding processing, first set index = index + 1, and then determine whether index < N s holds. If it holds, execute step S24; otherwise, execute step S27;
[0019] S27: Output the edge detection information including the vector p and the number of edges N e to the acquisition terminal for processing.
[0020] Further, the preset edge determination condition includes:
[0021] For the rising edge, the edge determination formula is:
[0022] s[index] ≤ v c and s[index + 1]> v c
[0023] For the falling edge, the edge determination formula is:
[0024] s[index] ≥ v c and s[index + 1]< v c .
[0025] Still further, in step S3, perform interval calculation:
[0026] S31: Input the vector p and the number of edges N e ;
[0027] S32: Initialize the sampling interval - occurrence count key - value pair set x and the index index;
[0028] S33: Determine whether the sampling interval p[index + 1] - p[index] is a key in the set x. If it is, execute step S35; otherwise, execute step S34; where p[index + 1] is the position of the next edge starting point, and p[index] is the position of the current edge starting point;
[0029] S34: First add the key - value pair <p[index + 1] - p[index], 1> to the set x, and then set N x = N x + 1; N x represents the number of elements in the set x;
[0030] S35: Increment the value corresponding to the key p[index + 1] - p[index] in the set x by 1;
[0031] S36: First, set index = index + 1, and then determine whether index < N e holds. If it holds, execute step S33; otherwise, execute step S37;
[0032] S37: Use the set x as the sampling interval statistical result of the adjacent edge.
[0033] Furthermore, in step S4, perform baud rate estimation:
[0034] S41: Input the sampling rate F s , the set x, and the number of elements N x ;
[0035] S42: Initialize the sampling interval - support number key - value pair set y and the index i, and set the allowable sampling deviation b;
[0036] S43: Determine whether i ≤ N x holds. If it holds, execute step S44; otherwise, execute step S410;
[0037] S44: Add the key - value <x[i].key, 0> to the set y, and then initialize the index j; where the sampling interval x[i].key is the key of the i - th key - value pair in the set x;
[0038] S45: Determine whether j ≤ N x holds. If it holds, execute step S47; otherwise, execute step S46;
[0039] S46: Set i = i + 1, and execute step S43;
[0040] S47: Determine whether the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b. If it is, execute step S48; otherwise, execute step S49; where the sampling interval x[j].key is the key of the j - th key - value pair in the set x;
[0041] S48: Increment the value corresponding to the key x[i].key in the set y by x[j].value, and execute step S49;
[0042] S49: Set j = j + 1, and execute step S45;
[0043] S410: Output the set y as the baud rate estimation result.
[0044] Further, in step S47, the supporter determination method includes the following steps:
[0045] Let n = round(x[j].key / h) represent the length of the bits of the signal contained in x[j].key, where the function round() means rounding the element in the parentheses to the nearest integer; when jointly detecting without using the rising edge and the falling edge, the length corresponding to a 1-bit signal is represented by h = x[i].key / 2; when jointly detecting using the rising edge and the falling edge, the length corresponding to a 1-bit signal is h = x[i].key;
[0046] Judge the following condition: whether abs(x[j].key - n·h) ≤ n·b holds. If it holds, it is determined that the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b; otherwise, it is determined that the sampling interval x[j].key is not a supporter of x[i].key within the allowable sampling deviation b; where the function abs() means taking the absolute value of the element in the parentheses.
[0047] Further, in step S5, the conversion formula between the sampling interval and the corresponding communication baud rate is:
[0048] r = F s / h
[0049] In the formula, r is the communication baud rate.
[0050] As a further improvement of the above solution, in step S1, first monitor the communication serial port of the acquisition terminal and the smart electricity meter, and then perform uniform sampling in the time domain to obtain the original sampling data of the communication signal; in step S2, also transfer the edge information to the acquisition terminal for processing; in step S3, according to the position information of each edge in the edge detection result, calculate the number of sampling points between adjacent edges as the sampling interval; in step S4, define each sampling interval as the minimum distance that can be generated at a corresponding communication baud rate, and calculate the number of all distances that can be generated by the same baud rate as the sampling interval as the number of supporters; in step S5, also save the communication baud rate detection result in the acquisition terminal or output it to other devices.
[0051] As a further improvement of the above solution, in step S3, the edge detection object is the rising edge or / and the falling edge, and it runs on the platform of the acquisition terminal; the platform stores the sampling interval and the occurrence times of each sampling interval in the form of a set of key-value pairs of sampling interval - occurrence times.
[0052] The present invention also provides a device for detecting the communication baud rate of the serial port of an acquisition terminal, which includes:
[0053] A sampling module for obtaining original sampling data in the time domain of the serial port communication between the acquisition terminal and other devices;
[0054] An edge detection module for extracting edge information of the original sampling data and performing edge detection according to a preset edge type and a preset edge determination condition to obtain an edge detection result;
[0055] An interval calculation module for calculating the sampling interval between adjacent edges and the number of occurrences of each sampling interval according to the edge detection result;
[0056] A baud rate estimation module for sequentially calculating the number of supporters of each sampling interval in all sampling intervals through the acquisition terminal;
[0057] A data conversion module for performing data conversion on the sampling interval and the number of supporters to obtain a corresponding communication baud rate and support rate as a communication baud rate detection result.
[0058] Compared with the existing methods for detecting the serial port communication baud rate of acquisition terminals, the method and device for detecting the serial port communication baud rate of the acquisition terminal of the present invention have the following beneficial effects:
[0059] 1. The method for detecting the serial port communication baud rate of the acquisition terminal first obtains the sampling data of the communication signal between the acquisition terminal and other devices, then performs edge detection on the sampling signal, transmits the extracted edge information to the acquisition terminal, calculates the number of sampling points in the interval between adjacent edges to obtain the sampling interval, and estimates the most likely actual baud rate of the communication signal by analyzing the proportional relationship between different numbers of sampling points in the interval, so as to realize the detection of the communication baud rate and support rate. It avoids the disadvantages such as insufficient data utilization and unstable measurement deviation in the process of manual measurement of the communication baud rate, can make more full use of the signal sampling data, converts the processing of the original sampling data to the detection and processing of edges, balances the contradiction between detection speed and accuracy, has relatively high detection efficiency, and also makes it possible to estimate the baud rate based on the acquisition terminal platform, solves the technical problems of poor measurement accuracy and relatively low efficiency existing in the existing methods for detecting the serial port communication baud rate of acquisition terminals, and obtains more accurate and reliable detection results.
[0060] 2. In the method for detecting the serial port communication baud rate of the acquisition terminal, at a high sampling rate, the number of edges is at least three orders of magnitude lower than the number of original sampling points, and by converting the processing and analysis of the original sampling data into the detection of edges and the processing and analysis of the distance between adjacent edges, the amount of data to be processed is significantly reduced, the detection time is shortened, and while obtaining a reliable baud rate, the efficiency, accuracy and reliability of the communication baud rate detection are improved, which can assist in the research and development, detection, operation and maintenance and other links of related products. Description of the Drawings
[0061] Figure 1 This is the flowchart of the serial port communication baud rate detection method for the acquisition terminal in Embodiment 1 of the present invention;
[0062] Figure 2 is Figure 1 The time-domain diagram of the signal recovered from the first sampling result in step S1 data acquisition of the serial port communication baud rate detection method for the acquisition terminal in
[0063] Figure 3 is Figure 1 The specific flowchart of step S2 of the serial port communication baud rate detection method for the acquisition terminal in
[0064] Figure 4 is Figure 1 The specific flowchart of step S3 of the serial port communication baud rate detection method for the acquisition terminal in
[0065] Figure 5 is Figure 1 The specific flowchart of step S4 of the serial port communication baud rate detection method for the acquisition terminal in
[0066] Figure 6 is Figure 1 The baud rate support rate diagram of a single detection given in step S5 of the serial port communication baud rate detection method for the acquisition terminal in Detailed implementation manner
[0067] In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0068] Embodiment 1
[0069] Please refer to Figures 1 to 6 , this embodiment provides a serial port communication baud rate detection method for an acquisition terminal. This detection method is a method for processing the sampled data of the serial port communication signal of the acquisition terminal, performing edge detection, and then transmitting the data to the acquisition terminal to complete the serial port communication baud rate detection on the acquisition terminal. This detection method mainly performs steps such as data acquisition, edge detection, interval calculation, baud rate estimation, and result output and storage, specifically including steps S1 - S5.
[0070] Step S1: Obtain the original sampling data in the time domain of the serial port communication between the acquisition terminal and other devices. In this embodiment, first use instruments such as an oscilloscope and a sampling module to monitor the communication serial port between the acquisition terminal and the smart electricity meter, and then perform uniform sampling in the time domain to obtain the original sampling data of the communication signal. In this embodiment, various parts of the sampling data are considered, which helps to obtain more real and reliable results. Here, not only can the sampling data in CSV format be processed, but for sampling data stored in other file formats, as long as the sampling information required for the subsequent steps is stored therein, the baud rate can be estimated after simply adjusting the program.
[0071] In some embodiments, the sampling rate of the sampling device used should be high enough to depict the signal edge more finely and improve the accuracy of the detection result. The original sampling data obtained in this embodiment is stored in a CSV file, but for sampling data stored in other file formats, as long as the sampling information required for the subsequent steps is stored therein, the program designed in this embodiment can adapt to the original sampling data in other formats after simple modification.
[0072] As Figure 2 shown, the time-domain signal result of a single sampling drawn based on the original sampling data in step S1 is given. It can be seen that the signal contains rich edge information, which can provide data support for baud rate estimation; at the same time, it can also be seen that the waveform of the time-domain signal is complex, and simple manual testing requires a lot of effort. In addition, the amount of original sampling data is large, and it is difficult to directly perform communication baud rate detection on the acquisition terminal platform, and certain data screening needs to be carried out first.
[0073] Step S2: According to the preset edge type and preset edge determination condition, extract the edge information of the original sampling data and perform edge detection to obtain the edge detection result. In this embodiment, the edge information is also transmitted to the acquisition terminal for processing. Among them, the edge detection object is the rising edge or / and the falling edge, which significantly reduces the amount of data to be processed in the baud rate estimation process, and the edge judgment condition can be adjusted by setting the mid-edge voltage v c . The edge type can be the rising edge or the falling edge. Preliminary practice shows that the choice of the edge type will not have a significant impact on the detection result, but the corresponding edge determination condition needs to be set according to the edge type.
[0074] Please continue to refer to Figure 3 , in some embodiments including this embodiment, the method of edge detection includes the following steps (S21-27).
[0075] S21: Input the sampling rate F of the original sampling data sand store the sampled signal vector s of the sampling results, and arrange them in the order of sampling time; among them, the sampled signal vector s is a row vector or a column vector, and each element represents the sampled value of the signal at a moment, with N s identifying the number of elements of the vector s. In the case of uniform sampling, the sampling rate can be deduced from adjacent sampling moments and can be replaced by the available sampling time series.
[0076] S22: Set the edge midpoint voltage v c . The setting of the edge midpoint voltage directly affects the judgment of the signal edge. The necessary condition for determining the edge is that the signal amplitudes of two adjacent sampling points are greater than and less than v in sequence c (falling edge) or less than and greater than v in sequence c (rising edge).
[0077] S23: Initialize the edge start position vector p, the number of edges N e and the index index. Among them, the vector p is initialized as an empty vector, the number of edges N e is initialized to 0, and the index index is initialized to 1. The vector p stores the sampling point indexes of the sampling amplitudes before passing through the voltage v among all the subsequent detected edges, and the number of edges N c is the record of the number of elements in the vector p, and the index index identifies the sampling point number and is used for subsequent traversal of the sampled signal vector s. e
[0078] S24: Perform edge judgment: According to the comparison results of the current sampled signal amplitude s[index] and the next sampled signal amplitude s[index + 1] with the voltage v c respectively, judge whether the adjacent signals form an edge. If so, execute step S25; otherwise, execute step S26. The specific judgment condition depends on the set edge type. In the edge detection step, the rising edge or the falling edge is optional, and the results in both edge cases can also be integrated in the baud rate estimation and result output steps. The preset edge judgment conditions include:
[0079] For the rising edge, the edge judgment formula is:
[0080] s[index] ≤ v c and s[index + 1] > v c
[0081] For the falling edge, the edge judgment formula is:
[0082] s[index] ≥ v c and s[index + 1] < v c .
[0083] The above only gives two of the simplest judgment conditions. In actual operation, more sampling points can be incorporated into the edge judgment conditions; for the judgment of the equal sign situation, only duplication needs to be avoided and consistency maintained, and transferring it from the comparison of the magnitudes of s[index] and v c to the comparison of the magnitudes of s[index + 1] and v c will not significantly affect the result.
[0084] S25: For the index index that satisfies the preset edge determination condition, add it to the vector p, and at the same time set N e = N e + 1, and indicate that the number of detected edges increases by 1. After saving is completed, execute step S26.
[0085] S26: After determining whether one of the indexes index is the starting point of an edge and performing corresponding processing, first set index = index + 1, and then determine whether index < N s holds. If so, it means that there is still sampled data not processed, and return to execute step S24 to continue the edge judgment. Otherwise, it means that all the sampled data has been processed, and continue to execute step S27.
[0086] S27: Output the edge detection information including the vector p and the number of edges N e to the acquisition terminal for processing. Compared with the original sampled data, the edge detection result contains most of the information related to baud rate detection while the data volume is significantly reduced. Therefore, it can be transmitted to the acquisition terminal for processing. After executing step S27, step S2 is completed, and enter step S3.
[0087] Step S3: According to the edge detection result, calculate the sampling interval between adjacent edges and the number of occurrences of each sampling interval. In this embodiment, according to the position information of each edge in the edge detection result, calculate the number of sampling points between adjacent edges as the sampling interval. In the scenario considered in this embodiment, both the high level and the low level of the signal exist in the form of the length of a continuous number of integer bits. Therefore, the distance between adjacent rising edges corresponds to the length of the integer bit, and the baud rate of the signal can be deduced therefrom. Step S3 can run on the platform of the acquisition terminal, and some other steps can also be set on the platform as needed.
[0088] Please continue to refer to Figure 4 , in some embodiments including this embodiment, for interval calculation, the specific steps are as follows (S31 - S37).
[0089] S31: Input the vector p and the number of edges N e .
[0090] S32: Initialize the set x of sampling interval - occurrence count key - value pairs and the index index. The set x is initialized as an empty set, and the index index is initialized as 1, which is used to traverse each edge start point. The specific storage form of the set x can be determined according to the actual situation. It is necessary to store each sampling interval that appears and its corresponding occurrence count. The sampling interval is the key, and the occurrence count is the value, representing a key - value pair in the form of <key, value>. And operations such as finding and modifying corresponding values or key - value pairs can be performed based on the key.
[0091] S33: Determine whether the sampling interval p[index + 1]-p[index] is a key in the set x. If it is, execute step S35; otherwise, execute step S34. Here, p[index + 1] is the next edge start point position, and p[index] is the current edge start point position. The difference between the two is the sampling interval. If it is a new value, it needs to be added to the set x first; otherwise, only the corresponding value needs to be incremented by 1.
[0092] S34: First, add the key - value pair <p[index + 1]-p[index], 1> to the set x, and then let N x = N x + 1, indicating that the number of key - value pairs in the set x increases by 1. Here, N x represents the number of elements in the set x.
[0093] S35: Increment the value corresponding to the key p[index + 1]-p[index] in the set x by 1. Since the currently processed sampling interval already exists in the set x, N x remains unchanged.
[0094] After processing the current sampling interval through step S34 or step S35, proceed to step S36.
[0095] S36: First, let index = index + 1, indicating that preparation is made to process the next set of adjacent edges. Then, determine whether index < N e holds. If it does, it means there is still data unprocessed, and return to execute step S33; otherwise, it means all data has been processed, and continue to execute step S37.
[0096] S37: Use the set x as the statistical result of the sampling interval of adjacent edges, and it can be output for subsequent programs to use. This step is only added to make the edge detection step complete. In actual operation, all steps use the same working area inside the acquisition terminal, and data is shared between steps without the need for special output. The purpose of adding the input and output steps is to make the functions and purposes of each program module clear, which can facilitate the modification and improvement of subsequent program modules. After executing step S37, step S3 is completed, and step S4 is entered.
[0097] Step S4: The acquisition terminal calculates the number of supporters of each sampling interval among all sampling intervals in sequence. In this embodiment, each sampling interval is defined as the minimum spacing that can be generated at a corresponding communication baud rate, and the number of all spacings that can be generated by the same baud rate as the sampling interval is calculated as the number of supporters. If the rising edge or falling edge is selected for analysis, the minimum spacing should be the length of 2 bits; if both the rising edge and falling edge are selected for analysis, the minimum spacing should be the length of 1 bit. It is necessary to note that theoretically, it is possible that the minimum spacing in a signal waveform does not meet the aforementioned analysis. However, this situation has not been encountered in practice in this embodiment, and this situation can be improved by analyzing the signal waveforms of different serial port messages.
[0098] Among them, the platform stores the sampling interval and the number of occurrences of each sampling interval in the form of a set of key-value pairs of sampling interval - number of occurrences, and provides it to the subsequent program for baud rate estimation. This embodiment uses the allowable sampling deviation b to balance the influence of random factors. Generally, the smaller b is, the greater the influence of random factors on the result. In practice, a unique highest support rate can be obtained under the condition of b ≤ 1 / 2. In this step, the communication baud rate detection results in two cases can be calculated according to different selected edge types, and there is consistency between the detection results of different edge types.
[0099] Please continue to refer to Figure 5 , in some embodiments including this embodiment, for baud rate estimation, the specific steps are as follows (S41 - 410).
[0100] S41: Input the sampling rate F s , the set x, and the number of elements N x , where the sampling rate is used to convert the sampling interval to the baud rate.
[0101] S42: Initialize the sampling interval - support a set of key-value pairs y and an index i, and set the allowable sampling deviation b. The set y is initialized as an empty set, and the index i is initialized as 1. The set y is similar to the set x, as long as it meets the function requirements without restricting its implementation method. The index i is used to traverse the set x; the allowable sampling deviation b is used to balance the influence of random factors such as the sampling deviation of the sampling device and signal fluctuations. b = 0 means no random deviation is allowed, and the resulting will be the most stringent estimation result. However, in this case, the result may be greatly affected by random factors. If b takes a large value, the estimation result may be ambiguous, and there may be multiple sampling intervals with a 100% support rate. In particular, in the preliminary practice of this embodiment, generally, a unique highest support rate can be obtained under the condition of b ≤ 1 / 2. However, for some baud rate scenarios, this limit needs to be more stringent. Therefore, it is recommended to gradually relax b from small to large.
[0102] S43: Determine whether i ≤ N x holds. If so, it means that there are still support counts of sampling intervals in the set x that have not been calculated, and step S44 is executed. Otherwise, it means that the support counts of all sampling intervals have been calculated, and step S410 is executed.
[0103] S44: Add the key-value <x[i].key, 0> to the set y, and then initialize the index j, which is initialized as 1. Among them, the sampling interval x[i].key is the key of the i-th key-value pair in the set x. Initially, the value in the key-value pair of the set y is 0, indicating that there are no supporters. It is necessary to explain that in some software and hardware scenarios, the set type may not support random reading by index, that is, x[i] cannot be directly obtained. For this situation, any non-repeating traversal operation can be used as a substitute. In particular, in practice, this embodiment uses a two-dimensional array to represent the conceptually set x and set y, so that it not only meets the aforementioned set characteristics but also allows random reading and writing.
[0104] S45: Determine whether j ≤ N x holds. If so, step S47 is executed; otherwise, step S46 is executed. If not, it means that the support count of the sampling interval x[i].key has been calculated, and the support count of the next sampling interval should be calculated, entering step S46. If so, it means that the support count of the sampling interval x[i].key has not been calculated yet, and it is necessary to determine whether x[j].key supports x[i].key, entering step S47.
[0105] S46: Let i = i + 1 and execute step S43. Increasing the index i by 1 means preparing to start calculating the support count of the next sampling interval.
[0106] S47: Determine whether the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b, if yes, execute step S48, otherwise execute step S49. The sampling interval x[j].key is the key of the jth key-value pair in the set x.
[0107] The supporter determination method includes the following two steps.
[0108] The bit length of the signal contained in x[j].key is represented by n=round(x[j].key / h), and the function round() represents rounding the elements in the brackets to the nearest integer; when the rising edge and falling edge are not used for joint detection, the length corresponding to a 1-bit signal is h=x[i].key / 2; when the rising edge and falling edge are used for joint detection, the length corresponding to a 1-bit signal is h=x[i].key.
[0109] Determine whether the following condition: abs(x[j].key-n·h)≤n·b holds. If so, determine that the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b. Otherwise, determine that the sampling interval x[j].key is not a supporter of x[i].key within the allowable sampling deviation b. Among them, the function abs() means taking the absolute value of the elements in the brackets. In particular, a value range can be specified for n, and the above judgment is performed for each positive integer value in the range. If n meets the condition at one value, the above judgment holds. This method is more suitable for scenarios with low sampling rates, but it is necessary to stop comparing the remaining values in the range after the judgment condition is met for the first time.
[0110] S48: Increase the value corresponding to the key x[i].key in the set y by x[j].value, that is, the number of supporters of the sampling interval x[i].key increases by x[j].value, and then execute step S49.
[0111] S49: Let j=j+1, and execute step S45. The index j increases by 1, indicating that it is ready to determine whether the next sampling interval is a supporter of the current sampling interval, and return to step S45.
[0112] S410: Output the set y as the baud rate estimation result to the subsequent program for use. At this point, step S4 is completed and the process proceeds to step S5.
[0113] Step S5: Perform data conversion on the sampling interval and the number of supporters to obtain the corresponding communication baud rate and support rate as the communication baud rate detection result. Figure 6 In this embodiment, the communication baud rate detection result is also saved in the acquisition terminal or output to other devices.
[0114] The conversion formula between the sampling interval and the corresponding communication baud rate is as follows:
[0115] r = F s / h
[0116] In the formula, r is the communication baud rate, F s is the sampling rate, and h is the length corresponding to 1-bit signal in the aforementioned step S47.
[0117] Obviously, two communication baud rate estimation results will be obtained by jointly detecting with and without rising edges and falling edges, but the two results should be similar or the same. By using the support number corresponding to each sampling interval calculated in step S4 and dividing it by the total number of sampling intervals, the support rate can be obtained. The baud rate corresponding to the sampling interval with the highest support rate is the most likely baud rate. Therefore, the baud rate corresponding to the sampling interval with the largest support number in set y can be regarded as the final detection result and saved in the acquisition terminal or output to other devices. To ensure the uniqueness of the final result, an appropriate b should be selected.
[0118] It should be noted here that in practical applications, the signal waveform of serial communication is not only determined by the baud rate, but also affected by settings such as the start bit, data bit, parity bit, and stop bit of the serial port, which brings difficulties to the automatic detection of the baud rate. In this embodiment, the sampling point spacing of all adjacent edges is used to estimate the communication baud rate. Theoretically, reliable baud rate estimation results can be obtained for any serial port settings except when the stop bit is set to 1.5, but for the case of stop bit 1.5, the estimation result is uncertain. Therefore, without loss of generality, it is assumed below that the serial port stop bit is not set to 1.5 which is rarely used in practical applications, and other serial port settings are not restricted.
[0119] In particular, the communication baud rate detection result of the acquisition terminal can be output to other devices, and the support situation of each baud rate can be plotted in a graphical manner. As Figure 6 shown, it is a baud rate support rate diagram given in step S5. The estimated baud rate corresponding to the highest support rate point in the figure is 9633.91, and the actually preset transmission baud rate is 9600, with a relative error of only 0.35%, which can meet the actual requirements.
[0120] Compared with the existing acquisition terminal serial port communication baud rate detection method, the acquisition terminal serial port communication baud rate detection method of this embodiment has the following beneficial effects:
[0121] 1. The serial communication baud rate detection method for the acquisition terminal first obtains the sampling data of the communication signal between the acquisition terminal and other devices, then performs edge detection on the sampling signal, transfers the extracted edge information to the acquisition terminal, calculates the number of interval sampling points between adjacent edges to obtain the sampling interval, and infers the most likely actual baud rate of the communication signal by analyzing the proportional relationship between different numbers of interval sampling points, so as to realize the detection of the communication baud rate and support rate. This method avoids the disadvantages of insufficient data utilization and unstable measurement deviation in the process of manual measurement of the communication baud rate, can make more full use of the signal sampling data, converts the processing of the original sampling data to the detection and processing of edges, balances the contradiction between detection speed and accuracy, has relatively high detection efficiency, and also makes it possible to estimate the baud rate based on the acquisition terminal platform, solving the technical problems of poor measurement accuracy and relatively low efficiency existing in the existing serial communication baud rate detection methods for acquisition terminals, and obtaining more accurate and reliable detection results.
[0122] 2. In the serial communication baud rate detection method for the acquisition terminal, at high sampling rates, the number of edges is at least three orders of magnitude lower than the number of original sampling points. Moreover, by converting the processing and analysis of the original sampling data into the detection of edges and the processing and analysis of the distance between adjacent edges, the amount of data to be processed is significantly reduced, the detection time is shortened, and while obtaining a reliable baud rate, the efficiency, accuracy, and reliability of the communication baud rate detection are improved, which can assist in the research and development, detection, operation and maintenance, etc. of related products.
[0123] Embodiment 2
[0124] This embodiment provides a serial communication baud rate detection device for an acquisition terminal. This device applies the detection method in Embodiment 1 and includes a sampling module, an edge detection module, an interval calculation module, a baud rate estimation module, and a data conversion module.
[0125] The sampling module is used to obtain the original sampling data in the time domain of the serial port communication between the acquisition terminal and other devices. The edge detection module is used to extract the edge information of the original sampling data and perform edge detection according to the preset edge type and preset edge determination condition to obtain the edge detection result. The interval calculation module is used to calculate the sampling interval between adjacent edges and the number of occurrences of each sampling interval according to the edge detection result. The baud rate estimation module is used to sequentially calculate the number of supporters of each sampling interval in all sampling intervals through the acquisition terminal. The data conversion module is used to perform data conversion on the sampling interval and the number of supporters to obtain the corresponding communication baud rate and support rate as the communication baud rate detection result.
[0126] The above modules can respectively implement steps S1 - S5 in Embodiment 1, and the beneficial effects obtained are similar to those in Embodiment 1, so they will not be elaborated here.
[0127] Example 3
[0128] This embodiment provides a computer terminal, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps of the serial port communication baud rate detection method of the acquisition terminal in Embodiment 1. It should be noted here that in some other embodiments, the baud rate detection method of Embodiment 1 can be implemented on the acquisition terminal. However, after the sampled data of the original signal is collected, the data can also be copied to other computer terminals, and the program can be run on them for baud rate estimation.
[0129] When the method of Embodiment 1 is applied, it can be applied in the form of software. For example, it can be designed as an independently running program and installed on a computer terminal. The computer terminal can be a computer, a smart phone, a control system, and other Internet of Things devices, etc. The method of Embodiment 1 can also be designed as an embedded running program and installed on a computer terminal, such as installed on a single-chip microcomputer.
[0130] Example 4
[0131] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the steps of the serial port communication baud rate detection method of the acquisition terminal in Embodiment 1.
[0132] When the method of Embodiment 1 is applied, it can be applied in the form of software. For example, it can be designed as an independently running program on a computer-readable storage medium. The computer-readable storage medium can be a USB flash drive, designed as a USB key, and a program for triggering the start of the entire method can be designed through the USB flash drive.
[0133] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for detecting the baud rate of serial port communication of a collection terminal, characterized in that, It includes the following steps: S1: Obtain the original sampling data in the time domain of the serial port communication between the acquisition terminal and other devices; S2: According to the preset edge type and preset edge determination condition, extract the edge information of the original sampling data and perform edge detection to obtain an edge detection result; S3: According to the edge detection result, calculate the sampling interval between adjacent edges and the number of occurrences of each sampling interval; S4: Sequentially calculate the number of supporters of each sampling interval among all sampling intervals through the acquisition terminal; S5: Perform data conversion on the sampling interval and the number of supporters to obtain the corresponding communication baud rate and support rate, which are used as the communication baud rate detection result.
2. The method for detecting the baud rate of the serial port communication of the acquisition terminal according to claim 1, wherein, In step S2, the method of edge detection includes the following steps: S21: Input the sampling rate F of the original sampling data s and the sampling signal vector s storing the sampling results, and arrange them in the order of sampling time; wherein, the sampling signal vector s is a row vector or a column vector, and each element represents the sampling value of the signal at a moment, with N s identifying the number of elements of the vector s S22: Set the edge midpoint voltage v c ; S23: Initialize the edge start position vector p, the number of edges N e and the index index; among them, the vector p stores the sampling point indexes of the sampling amplitudes in all the edges detected subsequently before passing through the voltage v c The number of edges N e is the record of the number of elements in the vector p, and the index index identifies the sampling point number and is used to traverse the sampling signal vector s subsequently; S24: Perform edge judgment: Based on the comparison results of the current sampling signal amplitude s[index] and the next sampling signal amplitude s[index + 1] with the voltage v c , determine whether adjacent signals form an edge. If so, execute step S25; otherwise, execute step S26; S25: Add the index that meets the preset edge determination condition to the vector p. At the same time, let N e = N e + 1, indicating that the number of detected edges increases by 1, and execute step S26; S26: After determining whether one of the indices index is an edge start point and performing corresponding processing, first set index = index + 1, and then determine whether index < N s holds. If it holds, execute step S24; otherwise, execute step S27; S27: Output the edge detection information including vector p and the number of edges N e to the acquisition terminal for processing.
3. The serial port communication baud rate detection method for the acquisition terminal according to claim 2, wherein The preset edge determination condition includes: For the rising edge, the edge determination formula is: s[index] ≤ v c and s[index + 1] > v c For the falling edge, the edge determination formula is: s[index]≥v c and s[index + 1]<v c .
4. The method for detecting the baud rate of the serial port communication of the acquisition terminal according to claim 2, wherein, In step S3, perform interval calculation: S31: Input vector p and the number of edges N e ; S32: Initialize the sampling interval - number of occurrences key - value pair set x and the index index; S33: Determine whether the sampling interval p[index + 1] - p[index] is a key in the set x. If so, execute step S35; otherwise, execute step S34; where p[index + 1] is the starting position of the next edge and p[index] is the starting position of the current edge; S34: First, add the key-value pair <p[index + 1] - p[index], 1> to the set x, and then let N x = N x + 1; N x represents the number of elements in the set x; S35: Increment the value corresponding to the key p[index + 1] - p[index] in the set x by 1; S36: Let index = index + 1 first, then determine whether index < N e holds. If it holds, execute step S33; otherwise, execute step S37; S37: Use the set x as the statistical result of the sampling intervals between adjacent edges.
5. The method for detecting the baud rate of the serial port communication of the acquisition terminal according to claim 4, wherein In step S4, perform baud rate estimation: S41: Input sampling rate F s , set x, and the number of elements N x ; S42: Initialize the sampling interval - number of supports key - value pair set y and the index i, and set the allowable sampling deviation b; S43: Determine whether i ≤ N x holds. If it does, execute step S44; otherwise, execute step S410; S44: Add the key - value pair <x[i].key, 0> to the set y, and then initialize the index j; where the sampling interval x[i].key is the key of the i - th key - value pair in the set x; S45: Determine whether j ≤ N x holds. If so, execute step S47; otherwise, execute step S46; S46: Let i = i + 1 and execute step S43; S47: Determine whether the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b. If so, execute step S48; otherwise, execute step S49; where the sampling interval x[j].key is the key of the j - th key - value pair in the set x; S48: Increment the value corresponding to the key x[i].key in the set y by x[j].value, and execute step S49; S49: Let j = j + 1 and execute step S45; S410: Output the set y as the baud rate estimation result.
6. The method for detecting the baud rate of the serial port communication of the acquisition terminal according to claim 5, wherein, In step S47, the method for determining supporters includes the following steps: Let n = round(x[j].key / h) represent the length of the bits of the signal contained in x[j].key, and the function round() represents rounding the element in the parentheses to the nearest integer; when not using the rising edge and the falling edge for joint detection, the length corresponding to 1 - bit signal is h = x[i].key / 2; when using the rising edge and the falling edge for joint detection, the length corresponding to 1 - bit signal is h = x[i].key; Judge whether the following condition holds: abs(x[j].key - n·h) ≤ n·b. If it holds, determine that the sampling interval x[j].key is a supporter of x[i].key within the allowable sampling deviation b; otherwise, determine that the sampling interval x[j].key is not a supporter of x[i].key within the allowable sampling deviation b; where the function abs() represents taking the absolute value of the element within the parentheses.
7. The serial port communication baud rate detection method of the acquisition terminal according to claim 6, wherein In the step S5, the conversion formula between the sampling interval and the corresponding communication baud rate is as follows: r = F s / n In the formula, r is the communication baud rate.
8. The serial port communication baud rate detection method of the acquisition terminal according to claim 1, wherein In the step S1, first listen to the communication serial port between the acquisition terminal and the smart energy meter, and then perform uniform sampling in the time domain to obtain the original sampling data of the communication signal; in the step S2, also transfer the edge information to the acquisition terminal for processing; in the step S3, according to the position information of each edge in the edge detection result, calculate the number of sampling points between adjacent edges as the sampling interval; in the step S4, define each sampling interval as the minimum distance that can be generated at a corresponding communication baud rate, and calculate the number of all distances that can be generated by the same baud rate as the sampling interval as the number of supporters; In the step S5, also save the communication baud rate detection result in the acquisition terminal or output it to other devices.
9. The serial port communication baud rate detection method for the acquisition terminal according to claim 1, wherein In the step S3, the edge detection object is the rising edge or / and the falling edge, and it runs on the platform of the acquisition terminal; the platform stores the sampling interval and the occurrence times of each sampling interval in the form of a set of key-value pairs of sampling interval - occurrence times.
10. A baud rate detection device for the serial port communication of a collection terminal, characterized in that, It includes: A sampling module, which is used to obtain the original sampling data in the time domain of the serial port communication between the acquisition terminal and other devices; An edge detection module, which is used to extract the edge information of the original sampling data and perform edge detection according to the preset edge type and preset edge determination condition to obtain an edge detection result; An interval calculation module, which is used to calculate the sampling interval between adjacent edges and the occurrence times of each sampling interval according to the edge detection result; A baud rate estimation module, which is used to sequentially calculate the number of supporters of each sampling interval among all sampling intervals through the acquisition terminal; A data conversion module, which is used to perform data conversion on the sampling interval and the number of supporters to obtain the corresponding communication baud rate and support rate as the communication baud rate detection result.