A serial port server data forwarding method based on dual-port quality comparison
By employing a dual-port quality comparison method in the serial port server, synchronously receiving and calculating quality scores, and selecting the best high-quality data frames for forwarding, the problem of receiving erroneous data in redundant scenarios by the serial port server is solved, thereby improving the reliability and trustworthiness of data transmission.
Patent Information
- Application Number
- CN202611193856.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-11-17
AI Technical Summary
In dual-port redundancy scenarios, existing serial servers are affected by electromagnetic interference and cable quality deterioration. Although the data frames can be received completely, there are field errors in the content. This causes the upper-level system to receive erroneous data without being able to detect it, which in turn leads to misjudgment or control abnormalities.
A serial server data selection and forwarding method based on dual-port quality comparison is adopted. The first and second serial ports are connected in parallel to the same RS485 bus for synchronous reception and buffering. Integrity verification is performed separately, quality scores are calculated according to preset quality quantification rules, and high-quality data frames are selected for forwarding.
It enables the effective identification and filtering of silent erroneous data frames without relying on external monitoring methods, ensuring that high-quality data frames are forwarded first, improving the reliability and trustworthiness of data transmission, and avoiding frequent switching problems caused by minor fluctuations in scores.
Smart Images

Figure CN123114882A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial communication technology, and in particular to a serial port server data forwarding method based on dual-port quality comparison. Background Technology
[0002] Serial port servers are widely deployed communication devices in industrial fields, responsible for acquiring data from field devices on the RS485 bus and forwarding it to the upper-level system. In practical engineering projects in industries such as power, water, and building automation, to ensure the reliability of field communication links, a redundant networking method is usually adopted, where two serial ports are connected in parallel to the same RS485 bus. This allows the serial port server to receive data from the same bus simultaneously through two serial ports and then forward it to the upper-level system, thus mitigating the risk of communication interruption caused by hardware aging, poor contact, or other reasons related to a single serial port.
[0003] In existing technologies, serial port servers in dual-port redundancy scenarios generally adopt a "first-come, first-served" strategy, meaning that the data received first from the port is forwarded directly to the host system, while data from the other port is discarded. However, in actual industrial settings, due to factors such as electromagnetic interference and cable quality deterioration, data frames may be received completely but contain field errors, known as "silent error" frames. These frames are forwarded to the host system indistinguishably from normal frames under the "first-come, first-served" strategy, while higher-quality data frames received from the other port are discarded. This results in the host system receiving erroneous data without being aware of it, potentially leading to misjudgments or control anomalies. Summary of the Invention
[0004] In view of this, the present invention proposes a serial port server data preferential forwarding method based on dual-port quality comparison. This method solves the problem that in actual industrial sites, existing data forwarding methods are affected by factors such as electromagnetic interference and cable quality deterioration. Although the data frame can be received completely, its content may contain field errors. However, under the "first-come, first-served" strategy, it is forwarded to the upper system indistinguishably from the normal frame, while the higher-quality data frame received by the other port is discarded. This results in the upper system receiving erroneous data but being unable to detect it, which in turn leads to misjudgment or control abnormalities.
[0005] The technical solution of this invention is implemented as follows: This invention provides a serial port server data preferential forwarding method based on dual-port quality comparison, including the following steps: S1, connect the first serial port and the second serial port in parallel to the same RS485 bus, and perform synchronous reception and buffering processing on the bus data frames on the RS485 bus to obtain the first received data frame and the second received data frame. S2, perform integrity verification processing on the first received data frame and the second received data frame respectively to obtain the first integrity verification result and the second integrity verification result; S3, according to the preset quality quantization rules, the first integrity verification result and the second integrity verification result are numerically processed to obtain the first quality score corresponding to the first received data frame and the second quality score corresponding to the second received data frame. S4. Based on the preset comparison rules, the first quality score and the second quality score are compared. The receiving data frame with the higher quality score is selected from the first received data frame and the second received data frame as the target uplink data frame. When the first quality score and the second quality score are the same, one of them is selected in a preset order to obtain the target uplink data frame. S5, the target uplink data frame is sent through the uplink communication interface to obtain the uplink communication data frame.
[0006] In some embodiments, step S3 includes: S31, perform quality information parsing on the first integrity check result and the second integrity check result respectively, and extract multi-dimensional quality evaluation data; S32, according to the preset quality quantification rules, perform score mapping processing on the multidimensional quality evaluation data respectively to obtain multiple quality sub-scores; S33, the multiple quality sub-scores are weighted and synthesized to obtain the first quality score and the second quality score.
[0007] In some embodiments, step S31 includes: When parsing the quality information of the first integrity check result and the second integrity check result, the multidimensional quality evaluation data includes frame integrity status, error type identifier and error quantity index. The frame integrity status is used to distinguish between check pass and check fail, the error type identifier is used to distinguish between length error, address error and check field error, and the error quantity index is used to characterize the number of fields judged as errors in the same received data frame.
[0008] In some embodiments, step S32 includes: When performing score mapping processing on multidimensional quality evaluation data according to preset quality quantification rules, discrete scoring tables are preset for frame integrity status, error type identifier, and error quantity index respectively. The values of frame integrity status, error type identifier, and error quantity index are used to index and look up the corresponding discrete scoring tables to obtain the quality sub-scores that correspond one-to-one with the quality evaluation data of each dimension.
[0009] In some embodiments, step S33 includes: When performing weighted synthesis of quality sub-scores, weight factors are preset for frame integrity status, error type identifier, and error quantity index respectively. The quality sub-scores corresponding to frame integrity status, error type identifier, and error quantity index are weighted and summed according to the corresponding weight factors to obtain the first quality score and the second quality score. The weighted summation result is then limited to a preset score range.
[0010] In some embodiments, step S4 includes: S41, compare the first quality score and the second quality score to generate a quality comparison identifier. The quality comparison identifier is used to distinguish between the state where the first quality score is greater than the second quality score, the state where the first quality score is equal to the second quality score, and the state where the first quality score is less than the second quality score. S42, according to the quality comparison identifier, a set of candidate received data frames is determined from the first received data frame and the second received data frame. When the quality comparison identifier indicates that the first quality score is greater than the second quality score or the first quality score is less than the second quality score, the received data frame with the higher quality score is taken as the candidate received data frame. When the quality comparison identifier indicates that the first quality score is equal to the second quality score, the first received data frame and the second received data frame are taken as candidate received data frames at the same time. S43, select a receiving data frame from the candidate receiving data frame set in a preset order to obtain the target uplink data frame.
[0011] In some embodiments, step S41 includes: When generating a quality comparison identifier, the difference between the first quality score and the second quality score is compared with a preset comparison threshold. When the difference is greater than the preset comparison threshold, the quality comparison identifier is set to a state where there is a quality advantage port. When the difference is less than or equal to the preset comparison threshold, the quality comparison identifier is set to a state where the quality scores are equal, and the state where the quality scores are equal corresponds to the state where the first quality score is equal to the second quality score.
[0012] In some embodiments, step S42 includes: When determining the candidate received data frame set based on the quality comparison indicator, if the quality comparison indicator indicates that the first quality score is greater than the second quality score, the candidate received data frame set is set to include only the first received data frame; if the quality comparison indicator indicates that the first quality score is less than the second quality score, the candidate received data frame set is set to include only the second received data frame; if the quality comparison indicator indicates that the first quality score is equal to the second quality score, the candidate received data frame set is set to include both the first and second received data frames.
[0013] In some embodiments, step S43 includes: When selecting a received data frame as the target uplink data frame from the candidate received data frame set according to a preset order, if the candidate received data frame set includes both a first received data frame and a second received data frame, the preset order is rotated based on the source of the target uplink data frame in the previous communication cycle. Specifically, if the target uplink data frame in the previous communication cycle is the first received data frame, the second received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle; if the target uplink data frame in the previous communication cycle is the second received data frame, the first received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle.
[0014] In some embodiments, step S5 includes: The target uplink data frame is encapsulated using an uplink communication protocol, and a protocol header field and a protocol trailer field are added to obtain an uplink communication data frame. The uplink communication data frame is written into the transmission buffer of the uplink communication interface, and the uplink communication interface is controlled to output the uplink communication data frame according to a preset transmission sequence.
[0015] The serial port server data optimization forwarding method based on dual-port quality comparison of the present invention has the following advantages over the prior art: (1) By connecting the first serial port and the second serial port in parallel to the same RS485 bus, the same bus data frames are collected in parallel in the dual-port synchronous reception mode. Multi-dimensional integrity verification processing containing frame length, slave address and check field is performed on the two received data frames respectively. The verification results are converted into a quantifiable and comparable quality score according to the preset quality quantification rules. Then, the data frame with higher quality score is selected from the two received data frames by score comparison as the target uplink data frame for forwarding. Thus, without relying on external monitoring means, the effective identification and filtering of data frames that do not cause communication interruption but actually carry erroneous content is realized. (2) By parsing the integrity verification results, the frame integrity status, error type identification and error quantity index are extracted as three independent dimensions of quality evaluation data. For each dimension, a corresponding discrete scoring table is preset and the mapping from quality evaluation data to quality sub-scoring is completed by index lookup. Then, weight factors are configured for each dimension to perform weighted summation and the results are constrained within the preset scoring range. Thus, the integrity verification results are transformed into a comprehensive quality score with clear structure, clear dimensions and controllable numerical range. This makes the contribution of different error types and error severity to the final score quantifiable and distinguishable, providing accurate and stable numerical basis for the comparison and selection of dual-port quality scores. (3) By introducing a quality comparison identifier, the comparison results of the dual-port quality scores are expressed in a structured manner. The scoring relationship is divided into two states: one with a quality advantage and the other with equal quality scores, by comparing the difference with a preset comparison threshold. This avoids the problem of frequent switching of forwarding ports due to small fluctuations in scores. When determining the candidate set of received data frames, the three branch logics are precisely distinguished according to the quality comparison identifier to ensure that the port data with superior quality is selected first. When the quality scores of the two ports are equal, the selection is carried out in rotation according to the source of the target uplink data frame in the previous communication cycle, so that the forwarding opportunities of the two serial ports are alternately allocated. This transforms the result of the dual-port quality score comparison into a clear data frame selection decision, realizing the deterministic and unambiguous selection of the target uplink data frame in the dual serial port redundancy scenario. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of a serial port server data optimization forwarding method based on dual-port quality comparison according to the present invention. Figure 2 This is a schematic diagram of the application architecture of a serial port server based on dual-port quality comparison in an RS485 fieldbus system according to an embodiment of the present invention. Figure 3 This is a schematic diagram of the serial port server data selection and forwarding method based on dual-port quality comparison according to an embodiment of the present invention. Figure 4 This is a schematic diagram of the decision process for dual-port quality comparison and silent error detection in an embodiment of the present invention; Figure 5 This is a schematic diagram of the serial port server port health diagnosis and alarm processing flow according to an embodiment of the present invention; Figure 6 This is a schematic diagram of the serial port server functional modules and data flow based on dual-port quality comparison in an embodiment of the present invention. Figure 7 This is a schematic diagram of the integrated alarm processing flow of dual-port quality scoring and port health diagnosis in an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0019] To facilitate understanding of the method provided by this invention, the relevant application scenarios will be further explained before introducing specific embodiments. In typical fieldbus applications such as industrial automation and building control, the RS485 bus is usually connected to the host computer system through a serial port server. To improve the reliability of field communication, redundant access methods are often adopted in engineering, with two serial ports connected in parallel to the same RS485 bus, enabling the serial port server to simultaneously listen to the same bus data frames through two physical ports. However, existing serial port servers in dual-port redundancy scenarios mostly adopt a simple forwarding strategy of "first-come, first-served" or fixed port priority, selecting uplink data frames only based on the order of reception or fixed configuration. They lack quantitative comparison of the quality of the two received data streams, making it difficult to identify silent error data frames that only exhibit content errors but do not cause link interruption in a timely manner.
[0020] Please see Figure 1 This invention provides a method for preferential forwarding of serial port server data based on dual-port quality comparison, comprising the following steps: S1, connect the first serial port and the second serial port in parallel to the same RS485 bus, and perform synchronous reception and buffering processing on the bus data frames on the RS485 bus to obtain the first received data frame and the second received data frame.
[0021] It is understood that in step S1, the serial server configures both the first and second serial ports as RS485 slave receiving ports and sets the same baud rate, data bits, parity bits, and stop bit parameters, enabling the two serial ports to listen for bus data frames on the same physical bus. When a bus data frame arrives on the RS485 bus, the first and second serial ports sequentially buffer the received byte streams and extract the complete frame data from the buffers according to the frame start / end flags or frame length information, respectively generating the corresponding first and second received data frames, providing a parallel raw data foundation for integrity verification and quality comparison.
[0022] S2, perform integrity verification processing on the first received data frame and the second received data frame respectively to obtain the first integrity verification result and the second integrity verification result.
[0023] It is understood that in step S2, the serial port server parses the frame format of the first and second received data frames respectively, identifies the frame start position and frame end position, and extracts key field information such as frame length field, slave address field and check field; then, it performs consistency judgment on the frame length field, slave address field and frame content except check field according to preset check rules, records the length mismatch, address mismatch or check failure as the corresponding error type and error number, and generates the first integrity check result and the second integrity check result accordingly, so that each received data frame corresponds to a check result reflecting the frame integrity status and error status.
[0024] S3, according to the preset quality quantification rules, the first integrity verification result and the second integrity verification result are numerically processed to obtain the first quality score corresponding to the first received data frame and the second quality score corresponding to the second received data frame.
[0025] It is understood that in step S3, the serial port server parses the quality information of the first integrity verification result and the second integrity verification result according to the preset quality quantification rules, extracts multi-dimensional quality evaluation data such as frame integrity status, error type identifier, and error quantity index, and obtains the corresponding quality sub-scores by looking up tables for each dimension of quality evaluation data; then, preset weighting factors are assigned to the quality sub-scores of different dimensions, and the sub-scores are weighted and synthesized, and the weighted result is limited to a preset score range, so as to obtain the first quality score corresponding to the first received data frame and the second quality score corresponding to the second received data frame, so that the quality of the two data frames can be directly compared with a unified numerical scale.
[0026] S4. Based on the preset comparison rules, the first quality score and the second quality score are compared. The receiving data frame with the higher quality score is selected from the first received data frame and the second received data frame as the target uplink data frame. When the first quality score and the second quality score are the same, one of them is selected in a preset order to obtain the target uplink data frame.
[0027] It is understood that in step S4, the serial port server first compares the first quality score and the second quality score, and generates a quality comparison identifier to distinguish between "the first quality score is greater than the second quality score", "the first quality score is equal to the second quality score", and "the first quality score is less than the second quality score". On the side with a quality advantage, the receiving data frame with the higher quality score is directly used as a candidate data frame. When the two quality scores are equal, the first receiving data frame and the second receiving data frame are included in the candidate receiving data frame set, and one of them is selected from the candidate receiving data frame set according to a preset order rule (e.g., rotating according to the source of the target uplink data frame in the previous communication cycle) to determine the final target uplink data frame. This allows for priority selection of high-quality data when there is a significant quality difference, and avoids long-term fixed bias of the port when the quality scores are equal.
[0028] S5, the target uplink data frame is sent through the uplink communication interface to obtain the uplink communication data frame.
[0029] It is understood that in step S5, the serial port server encapsulates the determined target uplink data frame according to the format requirements of the uplink communication protocol. For example, it adds uplink protocol headers, protocol trailers, and necessary control fields before and after the target uplink data frame to generate an uplink communication data frame that meets the requirements of the host computer interface. Subsequently, the uplink communication data frame is written into the corresponding transmission buffer and output to the host system or monitoring center through Ethernet port, serial port, or other types of uplink communication interfaces according to the preset transmission sequence, so that the host system can receive the data frame that has been quality compared and selected without changing the existing communication protocol.
[0030] In summary, this embodiment achieves synchronous reception and buffering processing of the first and second serial ports on the same RS485 bus. By combining integrity verification, quality score calculation, and selection based on score comparison of the two received data frames, the data quality information in the dual-port redundant access process is explicitly quantified and participates in forwarding decisions. While ensuring compatibility with the bus protocol, it effectively filters silent erroneous data frames and prioritizes the forwarding of high-quality data frames, thereby improving the data transmission reliability and uplink data trustworthiness of the serial server in dual-port redundant scenarios.
[0031] In some embodiments, based on the above embodiments, step S1 includes: Configure the first and second serial ports as RS485 slave receiving ports, and set the baud rate, data bits, parity bits, and stop bits of the first and second serial ports to the same communication parameters. After the first and second serial ports are connected in parallel to the same RS485 bus, the bus data frames on the RS485 bus are received in parallel in listening mode. The bus data frames received through the first serial port are sequentially buffered and read out to obtain the first received data frame. The bus data frames received through the second serial port are sequentially buffered and read out to obtain the second received data frame.
[0032] Understandably, in the above steps, firstly, in the configuration interface or initialization program of the serial port server, the RS485 working mode is set for the first and second serial ports respectively, and the baud rate, data bits, parity bits, and stop bits are uniformly set to parameter values consistent with the field RS485 bus, so that the two serial ports use the same encoding format and timing constraints when parsing the same bus data frame; then, after the first and second serial ports are connected in parallel, the serial port server puts both serial ports into a listening state of receiving only and not transmitting, and reads the incoming byte stream from their respective hardware receive buffers through interrupt response or periodic polling, and processes them in the order of arrival. The data is sequentially written to the corresponding software buffer queues. During the buffering process, the start and end points of a data frame are determined according to the predefined frame start flag, the length value indicated by the frame length field, or other frame boundary conditions specified by the bus protocol. When a complete data frame is detected, a continuous byte sequence is extracted from the corresponding buffer queue as a complete bus data frame for output. The complete data frame extracted from the first serial port buffer queue is recorded as the first received data frame, and the complete data frame extracted from the second serial port buffer queue is recorded as the second received data frame. This ensures that the two received data streams form a synchronous frame data that can be processed later under the premise that the physical layer and link layer conditions are consistent.
[0033] In one specific embodiment, in step S1, the serial port server receives data frames from the RS485 bus in parallel through the first serial port and the second serial port, and stores them in the corresponding first receive buffer FIFO_A and second receive buffer FIFO_B, respectively. When each received data frame is written to the receive buffer, metadata information such as the receive timestamp, source port number, and data frame length is recorded. The receive timestamp is used to identify the specific arrival time of the data frame in the current polling cycle, the source port number is used to distinguish whether the data frame is received by the first serial port or the second serial port, and the data frame length is used to provide basic parameters for subsequent frame length verification and quality scoring. By completing the above metadata marking in the receiving stage, the subsequent integrity verification, quality scoring calculation, and dual-port data comparison can accurately associate and compare the two received data frames based on a unified time scale and port identifier.
[0034] By supplementing the specific implementation of step S1 above, this embodiment fully describes the implementation process of dual-port parallel access and synchronous frame extraction from multiple aspects such as serial port mode configuration, communication parameter unification, listening and receiving mechanism, and frame boundary identification in the buffer queue. This enables those skilled in the art to reproduce the entire process of dual-port parallel reception and generation of the first received data frame and the second received data frame under a given hardware platform and RS485 protocol.
[0035] In some embodiments, based on the above embodiments, step S2 includes: The first received data frame is parsed to determine the frame start position and frame end position. The frame length field, slave address field and check field are extracted. The frame length field, slave address field and frame content excluding the check field are checked and judged. The first integrity check result is generated based on the check and judgment result.
[0036] It is understandable that the frame format parsing of the first received data frame is completed by the pre-configured protocol parsing module in the serial port server. This protocol parsing module searches for the start flag or specific synchronization byte used to identify the start of the frame from the byte sequence in the receive buffer according to the frame structure defined by the RS485 bus communication protocol used at the target site, and determines the end position of the frame by combining the value of the frame length field or the end flag. After accurately locating the frame boundary, the parsing module reads key fields such as the frame length field, slave address field, and check field in sequence, and judges whether the frame length field is consistent with the actual number of valid data bytes received, whether the slave address field falls within the allowed address range, and whether the check result calculated by the check algorithm for the frame content is consistent with the value carried in the check field, according to the length range, address validity set, and check calculation rules specified by the protocol. Each type of abnormality is recorded as the corresponding error type and error quantity. Finally, after processing, these judgment conclusions are summarized and organized into the first integrity check result and associated with the first received data frame, thereby providing input data containing structured error information for quality quantification.
[0037] The second received data frame is parsed to determine the frame start and end positions, and the frame length field, slave address field, and check field are extracted. The frame length field, slave address field, and frame content excluding the check field are checked and judged. A second integrity check result is generated based on the check and judgment results.
[0038] For example, the processing flow for the second received data frame is consistent with that for the first received data frame. The serial port server also calls the protocol parsing module to identify the boundaries of the buffered byte stream in the second received data frame according to the same frame start flag, end flag, or frame length field, avoiding additional deviations due to inconsistent processing logic between the two ports. After the frame boundaries are determined, the system extracts the frame length field, slave address field, and check field from the second received data frame in the same field order, and performs legality and consistency checks on the field values according to the same check rules as the first received data frame. The system categorizes and counts the occurrences of length anomalies, address anomalies, and check failures, forming an error record set for the second received data frame. Based on this, a second integrity check result is generated and saved one-to-one with the second received data frame, so that the two received data have a unified judgment standard and output format in the integrity check stage, which facilitates parallel processing and comparative analysis in the quality quantification and comparison stages.
[0039] The first integrity verification result and the second integrity verification result include frame integrity status, error type identifier and error quantity index.
[0040] In this implementation, the frame integrity status is used to provide an overall judgment conclusion for the received data frame under the current verification rules. For example, it records internally whether the frame passes all verification items or whether any key field is abnormal, in the form of binary or multi-valued flags, so that the status can be directly mapped to a higher or lower basic quality score during quality quantization. The error type identifier is used to distinguish the error categories triggered by different verification items. For example, an error caused by a mismatch in the frame length field is marked as a length error, an error caused by the slave address field being outside the allowed range is marked as an address error, and an error caused by the inconsistency between the frame content and the verification field is marked as a verification field error. By pre-assigning fixed encoding values to various types of errors, the corresponding quality reduction can be found based on the error type encoding during the numerical processing stage. The error quantity index is used to count the number of fields judged as errors or the number of times errors occur in the same received data frame. After completing the verification of each field, the parsing module accumulates all abnormal events to obtain a value representing the degree of error accumulation, so that the error quantity and the severity of a single error type can be considered together during quality quantization to form a multi-dimensional quality evaluation data input.
[0041] In some embodiments, in step S2, the serial port server performs three integrity checks on the first and second received data frames, respectively. These three integrity checks include Cyclic Redundancy Check (CRC16), frame length check, and slave address check. In the CRC16 check, the system takes the entire frame data (excluding the CRC field at the end of the frame) as input, calculates the check value according to the CRC16 MODBUS algorithm specified in the Modbus RTU specification, and compares it with the CRC field value carried at the end of the data frame. If the calculated check value is completely consistent with the frame end field, the check result is marked as passed; otherwise, it is marked as failed. In the frame length check, the system performs checks according to Modbus... The RTU protocol defines the frame format, pre-limiting the allowed frame length range to be from three bytes to 256 bytes. When the actual length of the received data frame falls within this range and meets the field quantity requirements corresponding to the current function code, the length verification result is marked as passed; otherwise, it is marked as failed. This is used to identify truncated and stuck frames caused by bus interference or lost bytes. In slave address verification, the system reads the slave address value from the address field of the received data frame and compares this value with the list of valid slave addresses configured in this serial port server. Only when the address is within the valid range of one to two hundred and forty-seven as defined by the protocol and completely matches a slave address in the configuration table, is the slave address verification result marked as passed; otherwise, it is considered an invalid address or inconsistent with the system configuration and is marked as failed. Through the combined output of the above three integrity verifications, this embodiment generates integrity status information for each received data frame, including CRC verification result, length verification result, and slave address verification result, providing a clear and quantifiable protocol constraint basis for quality score calculation and dual-port data comparison.
[0042] Through the above supplementary explanation of the specific implementation method of step S2, this embodiment provides a detailed description of the generation process of the first integrity verification result and the second integrity verification result from aspects such as frame boundary identification, key field extraction, verification rule configuration, and structured output of error information. This enables those skilled in the art to realize consistency verification and error classification statistics of received data frames based on existing RS485 protocol specifications and serial port server hardware and software resources, thereby providing a clear, stable, and easily expandable basic data structure for the design of quality quantification rules and quality scoring comparison in subsequent steps.
[0043] In some embodiments, based on the above embodiments, step S3 includes: S31, perform quality information parsing on the first integrity check result and the second integrity check result respectively, and extract multi-dimensional quality evaluation data.
[0044] It is understood that in this implementation, the serial port server is equipped with a quality information parsing module. This module takes the first integrity verification result and the second integrity verification result output in step S2 as input, and decomposes the frame integrity status, error category, error quantity and other information in the verification result into multiple quality evaluation dimensions with clear physical meaning and value range according to the pre-designed field meanings. It organizes these dimensions into a multi-dimensional quality evaluation data vector in a structured manner, so that quantification and weighting processing can be performed under a unified data structure, avoiding ambiguity caused by directly performing calculations on the original text description or mixed flags.
[0045] S32, according to the preset quality quantification rules, perform score mapping processing on the multidimensional quality evaluation data to obtain multiple quality sub-scores.
[0046] For example, the quality quantification rule consists of multiple discrete scoring tables and corresponding mapping logic. During the operation phase, the system uses the values of each dimension in the multidimensional quality evaluation data as index inputs, and searches for entries in the pre-established scoring tables that match the values to obtain the quality sub-scores for each dimension. During the research and development and deployment phases, the quality quantification rule can be configured and optimized by combining historical communication data. By collecting a large number of integrity verification samples with manually or automatically labeled quality levels, the scoring entries corresponding to different error types and error quantities are adjusted so that the quality sub-scores calculated based on the discrete scoring tables are generally consistent with the actual data quality level. S33, the multiple quality sub-scores are weighted and synthesized to obtain the first quality score and the second quality score.
[0047] It is understood that in this implementation, the system assigns a weight factor to each dimension in the multidimensional quality evaluation data, and linearly weights and sums the quality sub-scores obtained by mapping the aforementioned scores according to the weight factors to obtain the comprehensive quality score of the corresponding received data frame. The comprehensive score corresponding to the first received data frame is recorded as the first quality score, and the comprehensive score corresponding to the second received data frame is recorded as the second quality score. The setting of the weight factors can be completed during the development stage through repeated experiments and data statistics. For example, based on the statistical results of the impact of different error dimensions on the actual communication reliability, the weight of each dimension can be gradually adjusted so that the quality score obtained by weighted synthesis is more in line with the real quality differences reflected in engineering experience and historical operation records.
[0048] In some embodiments, based on the above embodiments, step S31 includes: When parsing the quality information of the first integrity check result and the second integrity check result, the multidimensional quality evaluation data includes frame integrity status, error type identifier and error quantity index. The frame integrity status is used to distinguish between check pass and check fail, the error type identifier is used to distinguish between length error, address error and check field error, and the error quantity index is used to characterize the number of fields judged as errors in the same received data frame.
[0049] For example, in this embodiment, the quality information parsing module first reads the frame integrity status, which represents the overall verification conclusion, from the integrity verification result and organizes it into a status flag with a clear value. This flag is used to directly distinguish between frames that have passed the verification completely and frames with any errors during score mapping. Subsequently, an error type identifier is generated based on the error classification result recorded in step S2. By defining three basic error types—length error, address error, and check field error—and assigning them fixed codes, different scoring entries can be found for different error types during score mapping. At the same time, the quality information parsing module accumulates and counts various error events that occur within the same received data frame to obtain the numerical dimension of the error quantity index. This allows the magnitude of the error quantity to reflect the degree of error accumulation during the quantification stage. Thus, the verification information, which was originally scattered across multiple fields and flags, is summarized into multi-dimensional quality evaluation data with three core dimensions: frame integrity status, error type identifier, and error quantity index.
[0050] In some embodiments, in step S31, when parsing the quality information of the integrity verification result, three binary judgment information items are extracted for the CRC verification result, frame length verification result, and slave address verification result, respectively, denoted as whether the CRC verification passed or failed, whether the length verification passed or failed, and whether the address verification passed or failed. These three judgment information items are used as inputs for subsequent score mapping to distinguish whether the corresponding verification item is in a passed state or a failed state.
[0051] In some embodiments, based on the above embodiments, step S32 includes: When performing score mapping processing on multidimensional quality evaluation data according to preset quality quantification rules, discrete scoring tables are preset for frame integrity status, error type identifier, and error quantity index respectively. The values of frame integrity status, error type identifier, and error quantity index are used to index and look up the corresponding discrete scoring tables to obtain the quality sub-scores that correspond one-to-one with the quality evaluation data of each dimension.
[0052] For example, regarding the frame integrity status dimension, the system constructs a dedicated discrete scoring table, providing basic quality scores for both verification pass and verification fail states, so that the difference between passing and failing integrity verification can be directly reflected in the quality score. Regarding the error type identification dimension, the system establishes a scoring table indexed by error type codes, configuring different deduction intensities for length errors, address errors, and check field errors to reflect the different impacts of different error types on communication reliability. Regarding the error quantity index dimension, the system divides the possible error quantity range into several discrete segments and configures a corresponding score value or deduction gradient for each segment, so that the sub-scores gradually decrease as the number of errors increases. During runtime, the score mapping module inputs the three values of the multi-dimensional quality evaluation data into their respective discrete scoring tables for index lookup, obtaining three independent but jointly weighted quality sub-scores, thereby realizing the mapping from symbolic and count-type quality features to numerical scoring space.
[0053] In some embodiments, in step S32, according to a preset quality quantification rule, the above three judgment information items are mapped to corresponding single quality sub-scores, wherein, for a certain received data frame, the first... CRC checksum score of each data frame Recorded as: ; No. Frame length checksum score for each data frame Recorded as: ; No. Slave address checksum score for each data frame Recorded as: ; Among them, CRC checksum score The maximum score is 40, used to reflect the dominant role of CRC check in ensuring data integrity, and the frame length check sub-score. The maximum score is 30, used to reflect the constraint relationship between frame length and protocol format legality, and is used for station address verification sub-scoring. The maximum score is 30, which is used to reflect the impact of address legality and system configuration matching degree on data availability. The sum of the maximum scores of the three sub-scores is 100, which corresponds to the maximum score level of the quality score Q.
[0054] In some embodiments, based on the above embodiments, step S33 includes: When performing weighted synthesis of quality sub-scores, weight factors are preset for frame integrity status, error type identifier, and error quantity index respectively. The quality sub-scores corresponding to frame integrity status, error type identifier, and error quantity index are weighted and summed according to the corresponding weight factors to obtain the first quality score and the second quality score. The weighted summation result is then limited to a preset score range.
[0055] For example, based on engineering experience and historical operational data analysis, the system configures different weighting factors for the frame integrity status sub-score, error type sub-score, and error quantity sub-score. For instance, the weight corresponding to frame integrity status can be set relatively large to ensure that verification pass rate dominates the overall score. The weights for error type and error quantity are set as auxiliary adjustment items to refine the quality differences under different error scenarios. When calculating the overall score, each of the three sub-scores is multiplied by its corresponding weighting factor and then summed to obtain an original quality score value. To avoid difficulties in comparison due to excessively large or small scores, the system further limits this original score to a preset score range through linear scaling or truncation, such as between a fixed minimum and maximum value. This ensures that the value ranges of the first and second quality scores are stable and consistent, facilitating horizontal comparisons between different communication cycles and different ports. The weighting factors and score range boundaries can be adjusted before system deployment using multiple rounds of simulation and field trial operation data to ensure that the calculated quality score more closely reflects actual communication quality performance.
[0056] In some embodiments, when weighting and synthesizing the three quality sub-scores in step S33, the following linear summation formula is used to calculate the first... Overall quality score of each received data frame : ; because , and The three sub-scores range from 0 to 40, 0 to 30, and 0 to 30, respectively. The theoretical value range is 0 to 100, when all three integrity checks pass. The value is equal to 100. When any one or more checks fail, the corresponding sub-score is set to 0, thus reducing the overall score. For scores below the maximum, this weighted synthesis method maps the integrity verification results of the three protocol layers to a unified numerical scoring space, providing a clear calculation formula and parameter basis for the definition of the first quality score and the second quality score.
[0057] By providing supplementary explanations of step S3 and its sub-steps S31, S32, and S33, this embodiment comprehensively presents the composition and parameter setting ideas of the quality quantification model from three aspects: the input-output structure of quality information parsing, the mapping rules from multi-dimensional quality evaluation data to quality sub-scores, and the construction process of comprehensive quality scores based on weight factors. This enables those skilled in the art to configure or optimize discrete scoring tables and weight factors according to specific application needs, based on historical communication data and field experience. This allows for the reproduction and adjustment of the calculation process of the first and second quality scores in different engineering scenarios, providing an achievable and verifiable technical foundation for quality comparison and optimal data forwarding.
[0058] In some embodiments, based on the above embodiments, step S4 includes: S41, compare the first quality score and the second quality score to generate a quality comparison identifier. The quality comparison identifier is used to distinguish between the state where the first quality score is greater than the second quality score, the state where the first quality score is equal to the second quality score, and the state where the first quality score is less than the second quality score.
[0059] It is understood that in this embodiment, the serial port server is equipped with a quality comparison module. The first quality score and the second quality score are taken as inputs, and the numerical calculation unit performs a comparison between the two. Based on the comparison result, a state code is selected from a predefined finite set of states as a quality comparison identifier output. This identifier at least distinguishes between states where the first quality score is greater than the second quality score, states where the two are equal, and states where the first quality score is less than the second quality score. This maps continuous quality score values into discrete state quantities that are easy to use for logical judgment, simplifying the judgment logic of quality relationship in subsequent steps.
[0060] S42, according to the quality comparison identifier, a set of candidate received data frames is determined from the first received data frame and the second received data frame. When the quality comparison identifier indicates that the first quality score is greater than the second quality score or the first quality score is less than the second quality score, the received data frame with the higher quality score is taken as the candidate received data frame. When the quality comparison identifier indicates that the first quality score is equal to the second quality score, the first received data frame and the second received data frame are taken as candidate received data frames at the same time.
[0061] For example, the candidate set determination module uses a quality comparison flag as a control signal and filters between the first and second received data frames according to the status indicated by the flag. When the comparison result shows a clear relationship between high and low quality, the received data frame with the higher quality score is added separately to the candidate received data frame set, thus directly reflecting the selection principle when there is a quality advantage. When the comparison result shows that the two quality scores are equal, the first and second received data frames are added together to the candidate received data frame set, reserving space for port rotation and load balancing through a sequential strategy when the two quality scores are comparable, so that the construction of the candidate set follows both quality priority and port balance.
[0062] S43, select a receiving data frame from the candidate receiving data frame set in a preset order to obtain the target uplink data frame.
[0063] It is understood that in this implementation, the target frame selection module traverses or indexes the already constructed set of candidate received data frames, and selects one of the received data frames from the set as the target uplink data frame corresponding to the current communication cycle according to the pre-set order rules in the system. When the candidate set contains only one received data frame, the module directly selects that data frame as the output. When the candidate set contains multiple received data frames, the selection is performed according to the preset order strategy to ensure that the decision-making process in the case of multiple candidates is deterministic and repeatable. By indexing or recording the members in the candidate set, the target uplink data frame can be tracked and referenced in the subsequent encapsulation and transmission steps.
[0064] In some embodiments, in step S4, the serial port server bases the first quality score on... Second quality score The system performs a quality score-based decision-making process for forwarding data frames received by both ports during the current polling cycle. and The value range is from 0 to 100, with 60 points as the minimum quality threshold for allowed forwarding, 100 points as the maximum quality level, and 0 points as a completely invalid level. and The size relationship and the existence of valid received frames are combined to determine the total number of possible input scenarios.
[0065] In some embodiments, based on the above embodiments, step S41 includes: When generating a quality comparison identifier, the difference between the first quality score and the second quality score is compared with a preset comparison threshold. When the difference is greater than the preset comparison threshold, the quality comparison identifier is set to a state where there is a quality advantage port. When the difference is less than or equal to the preset comparison threshold, the quality comparison identifier is set to a state where the quality scores are equal, and the state where the quality scores are equal corresponds to the state where the first quality score is equal to the second quality score.
[0066] For example, in this embodiment, the quality comparison module first calculates the difference between the first quality score and the second quality score, and takes the absolute value or signed value of the difference as the judgment basis. Then, the difference is compared with a pre-configured comparison threshold. When the difference is greater than the comparison threshold, it is considered that there is a sufficiently obvious difference in the quality score between the two data frames, and it can be determined that there is a quality advantage port state. At this time, the quality comparison identifier not only indicates the existence of quality advantage, but also implies the direction of the advantage port, which is used to retain only the higher quality received data frames in the candidate set in the future. When the difference is less than or equal to the comparison threshold, it is considered that the quality scores of the two data frames are in a basically equivalent range. The quality comparison identifier is set to the quality score equal state, and logically this state is equivalent to the case where the first quality score is equal to the second quality score. In this way, the threshold buffer suppresses frequent port switching caused by small fluctuations in the score, making the quality comparison result smoother.
[0067] In some embodiments, in step S41, the serial port server first classifies the reception status of the current polling period into three cases based on the presence or absence of the first received data frame and the second received data frame: frames only on the first port, frames only on the second port, and no frames on either port. The corresponding quality judgment conditions and processing rules are as follows: Scenario 1: Only the first received data frame has a corresponding quality score. ; When satisfied When the first received data frame is received, the serial port server forwards it to the host computer as the target uplink data frame; when If the frame quality is deemed insufficient to support reliable forwarding, the data frame is discarded and the abnormal collection information is reported to the host computer.
[0068] Scenario 2: Only the second received data frame has a corresponding quality score. ; When satisfied When the serial port server receives the second received data frame, it forwards it to the host computer as the target uplink data frame; when If the frame is deemed to be of insufficient quality, it is discarded and the abnormal acquisition information is reported to the host computer.
[0069] Scenario 3: Neither the first nor the second received data frame exists; In this situation, it is considered that the slave station has no response or the response exceeds the waiting time in this polling cycle; the host computer has no available data frames, the serial port server generates a timeout exception response as specified by the Modbus protocol, reports it to the host computer, and records the timeout event log.
[0070] By introducing a quality threshold of 60 points in step S41, quantitative forwarding and dropping boundary conditions are given for scenarios where only a single port has data.
[0071] In some embodiments, based on the above embodiments, step S42 includes: When determining the candidate received data frame set based on the quality comparison indicator, if the quality comparison indicator indicates that the first quality score is greater than the second quality score, the candidate received data frame set is set to include only the first received data frame; if the quality comparison indicator indicates that the first quality score is less than the second quality score, the candidate received data frame set is set to include only the second received data frame; if the quality comparison indicator indicates that the first quality score is equal to the second quality score, the candidate received data frame set is set to include both the first and second received data frames.
[0072] For example, after receiving the quality comparison identifier, the candidate set determination module first determines the quality relationship type indicated in the identifier. When the identifier indicates that the first quality score is greater than the second quality score, the module only writes the first received data frame into the candidate set and removes the entries related to the second received data frame from the set, so that target selection can only be performed on the first received data frame with higher quality. When the identifier indicates that the first quality score is less than the second quality score, the module performs the opposite operation and only retains the second received data frame as a candidate. When the identifier indicates that the quality score is equal to or within the threshold tolerance range, the module adds the first received data frame and the second received data frame to the candidate set at the same time, and adds a port source identifier or index information to each member, so as to distinguish candidate frames from different sources in the rotation rule based on a preset order, thereby ensuring that the candidate set has a definite composition under different quality comparison states.
[0073] In some embodiments, in step S42, when the first received data frame and the second received data frame exist simultaneously, that is, when both ports receive data frames, the serial port server determines the quality score. and Based on the numerical relationship, the following decision rules are used to select the target uplink data frame or proceed to the subsequent depth comparison process.
[0074] Scenario 4: Both ports receive and ; At this point, the first received data frame with the higher quality score is selected as the target uplink data frame, and this frame is forwarded to the host computer, while the second received data frame is discarded.
[0075] Scenario 5: Both ports receive and ; At this point, the second received data frame with the higher quality score is selected as the target uplink data frame, and this frame is forwarded to the host computer, while the first received data frame is discarded.
[0076] Scenario 6: Both ports receive and ; At this point, both frames are considered to be at the full quality level. The serial port server selects one of the two frames as the target uplink data frame according to preset rules. The preset rules may include selecting the frame that arrives first by default, selecting the frame corresponding to the main port by default, or comparing the CRC check values of the two frames when necessary and selecting the frame with the better CRC check value. After the selection is completed, the target frame is forwarded to the host computer, and the log records that the two frames have the same quality score and are both full marks, as well as the actual selection strategy used.
[0077] Scenario 7: Both ports receive and , ; At this point, the two frames have equal quality scores but neither is perfect. To further improve reliability, the serial port server does not make a selection based directly on the Q value, but instead enters the deep comparison process described in step S43, which completes the selection by comparing the data payload content of the two frames byte by byte and making additional rule judgments.
[0078] Scenario 8: Both ports receive and ; At this point, it can be determined that both frames have failed the three integrity checks or are in a completely invalid state. The serial port server discards both frames simultaneously, does not forward any data to the host computer, and reports the abnormal information of this round of data acquisition failure.
[0079] Based on the above step S42 and The multi-scenario decision rules defined by the comparison relationship can ensure that the system has clear and predictable behavior under all possible combinations of data on both ends.
[0080] In some embodiments, based on the above embodiments, step S43 includes: When selecting a received data frame as the target uplink data frame from the candidate received data frame set according to a preset order, if the candidate received data frame set includes both a first received data frame and a second received data frame, the preset order is rotated based on the source of the target uplink data frame in the previous communication cycle. Specifically, if the target uplink data frame in the previous communication cycle is the first received data frame, the second received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle; if the target uplink data frame in the previous communication cycle is the second received data frame, the first received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle.
[0081] For example, when the candidate set contains only one received data frame, the target frame selection module directly outputs that data frame as the target uplink data frame. When it detects that both the first and second received data frames exist in the candidate set, it reads the source information of the target uplink data frame from the previous communication cycle stored in the status register unit. Based on this information, it determines the port that was selected in the previous cycle and prioritizes selecting the received data frame corresponding to the other port as the target uplink data frame in the current cycle. This achieves the rotation between the first and second serial ports under the premise of equal quality scores. At the same time, after completing the target selection in the current cycle, the module updates the source record in the status register unit so that the rotation logic can continue in subsequent cycles. This cross-cycle sequential control mechanism ensures that under long-term operating conditions, the two ports obtain roughly equal uplink opportunities when the quality is comparable, thus avoiding port resource idleness and not breaking the basic principle of quality priority.
[0082] In some embodiments, in step S43, when the condition is met... , At that time, the serial port server performs further content-level determination on the two frames according to the depth comparison process, which includes the following sub-steps: 1. Extract data load: Extract the data payload (excluding the CRC checksum) from each of the two frames and use it as input for content comparison.
[0083] 2. Byte-by-byte content comparison: Perform a byte-by-byte comparison on the data payloads of the two frames, and classify the content relationship into two cases based on the comparison results: completely identical or differing. When the data loads of the two frames are exactly the same and simultaneously satisfy the following conditions Select one frame as the target uplink data frame and forward it to the host computer system. Record in the log that this round is a two-frame consistent scenario and that the quality scores of both frames are not lower than the quality lower limit threshold of 60 points. When two frames of data have exactly the same load, but simultaneously satisfy... At this time, either frame can still be selected as the target uplink data frame for forwarding, but the log will record that this round is a scenario where both frames are at a low quality level, which is convenient for statistical analysis and diagnosis of link quality. When the data loads of the two frames differ and simultaneously satisfy the following conditions If a silent error scenario occurs where two frames pass CRC checks but have inconsistent content, the serial port server triggers a silent error alarm to alert maintenance personnel to pay attention to the slave station or port link. At the same time, in terms of forwarding strategy, if the Q value is the same, the frame with the better CRC check value can be selected, or the frame received by the master port can be selected as the target uplink data frame according to the system configuration.
[0084] 3. When there is a difference in data load between two frames and at least one frame has a quality score lower than the lower quality threshold, the condition is met. When a frame with a higher quality score is selected as the target uplink data frame, the event that a low-quality frame has been filtered is recorded in the log.
[0085] By introducing the aforementioned deep comparison and silent error detection rules based on a quality score threshold of 60 and score comparison relationships in step S43, this invention can still quantitatively distinguish whether the content of two frames is consistent, even in special scenarios where the quality scores of both ports are equal but not full. Furthermore, when inconsistencies are detected but CRC checks pass, a clear alarm and optimal forwarding strategy are provided, and each decision is recorded in the log. and The specific values and the judgment branches used are provided to facilitate subsequent auditing and port health diagnosis.
[0086] By providing supplementary explanations of step S4 and its sub-steps S41, S42, and S43, this embodiment systematically presents a complete decision-making process for deriving the target uplink data frame from the first and second quality scores, covering three aspects: the calculation rules for the quality score difference and comparison threshold, the construction method of the candidate received data frame set, and the rotation order control based on the source information of the previous communication cycle. This enables those skilled in the art to implement the optimal forwarding logic after dual-port quality comparison within a clear framework of state coding, set operation, and sequence control. In engineering applications, this ensures that high-quality data frames are prioritized when there are significant quality differences, while port rotation improves system resource utilization and overall communication link stability when quality scores are similar.
[0087] In some embodiments, based on the above embodiments, step S5 includes: The target uplink data frame is encapsulated using an uplink communication protocol, and a protocol header field and a protocol trailer field are added to obtain an uplink communication data frame. The uplink communication data frame is written into the transmission buffer of the uplink communication interface, and the uplink communication interface is controlled to output the uplink communication data frame according to a preset transmission sequence.
[0088] It is understood that in this implementation, the serial port server is internally configured with an uplink communication protocol encapsulation module. This module adds a protocol header field and a protocol trailer field to the beginning and end of the target uplink data frame, respectively, according to the communication protocol format used by the host computer or monitoring system. The protocol header field may contain uplink message type identifier, source port identifier, length information, and uplink address information, while the protocol trailer field may contain an end marker and a checksum field for verifying the integrity of the uplink message. This encapsulates the original target uplink data frame into a structurally complete uplink communication data frame that conforms to the uplink interface specification. After encapsulation is complete... Subsequently, the transmission control module writes the uplink communication data frame into the transmission buffer corresponding to the uplink communication interface. This transmission buffer can be a hardware transmission buffer unit provided by the network controller or serial port controller, or it can be a transmission queue maintained by software. According to the preset transmission timing parameters set during the system initialization phase, the module controls the transmission enable, transmission interval, and retransmission strategy of the uplink communication interface to ensure that the uplink communication data frame is output to the host system in a manner that meets the bandwidth and real-time requirements. At the same time, the module monitors the transmission results and abnormal conditions through the interface driver status feedback mechanism so that retransmission or alarm processing can be performed when necessary.
[0089] In some embodiments, in step S5, the serial port server maintains several rolling statistical indicators for the first and second serial ports respectively, which are used to quantify the long-term communication quality of the ports and generate health diagnosis reports periodically. The statistical indicators include CRC error rate, frame loss rate, number of data inconsistency occurrences, average quality score, and quality score trend, etc., and the meanings and calculation methods of the parameters are as follows: In some embodiments, for a certain port, the total number of received frames within the most recent 100 frames is denoted as . The number of frames that failed CRC check was Then the CRC error rate of this port Defined as: ; in, The value ranges from 0 to 100 and is used to reflect the bus signal quality of this port within the last one hundred frames. When the value continues to rise and exceeds the preset threshold, it can be considered that there is a significant risk of interference in the link where the port is located.
[0090] In some embodiments, for a certain port, the total number of requests in the most recent one hundred host computer requests is denoted as . The number of requests for which no response data frames were received was The frame loss rate of that port is... Defined as: ; in, The value ranges from 0 to 100 and is used to reflect the reachability of the station in the last one hundred requests. When A significant increase within the statistical window indicates that the slave device or link may experience intermittent disconnections or abnormal responses.
[0091] In some embodiments, in step S5, the number of silent error events detected in the most recent hour through steps S4 and S43 is recorded as... ,Will This metric serves as an indicator of the frequency of data inconsistency events. It does not require normalization, is a non-negative integer, and reflects the frequency of dual-frame content inconsistency events occurring on this port within the past hour. When the preset threshold is exceeded, a corresponding port health alarm is triggered.
[0092] In some embodiments, for a certain port, among the most recent 100 frames of valid received data, the [number]th [frame] is recorded as [number]. The frame quality score is The total number of valid frames is Then the average quality score of that port Defined as: ; Among them, the quality score of each frame The value ranges from 0 to 100, therefore the average quality score It also falls between 0 and 100, used to reflect the overall communication quality level of the port within the statistical window.
[0093] In some embodiments, to characterize the trend of port quality changes over a longer time scale, the quality score time series of a certain port over the most recent 24 hours is treated as a function of time. A linear fit is performed on this time series, and the slope of the resulting linear function is denoted as the quality score trend index of that port. .when When the value is close to zero, it indicates that the overall port quality is stable; when... When the value is negative and the absolute value is large, it indicates that the port quality is showing a continuous downward trend, which can prompt maintenance personnel to check for potential problems in advance.
[0094] In some embodiments, in step S5, the serial port server further configures the generation cycle parameter of the diagnostic report, denoted as... . The default value is ten minutes, which can be configured within a range of one to sixty minutes. At the end of each cycle, the system updates and calculates the above statistical indicators and generates a port health diagnostic report based on the latest results. The report cycle parameter... Used to control the temporal resolution of diagnostic reporting.
[0095] In some embodiments, to introduce quantitative alarm conditions into the port health diagnostic report, threshold parameters are configured for some statistical indicators in step S5. The alarm threshold for the CRC error rate is denoted as... The default value is 10%. When a certain port meets the requirement... When this occurs, the system will issue an alarm flag for the CRC error rate of that port in the diagnostic report. The alarm threshold for the number of times data inconsistency occurs is denoted as... The default value is five times per hour. This is determined when a port meets the requirement within the last hour. At that time, the system will issue an alarm in the diagnostic report indicating that the port has frequent silent errors. This can be mitigated by introducing... and Configurable threshold parameters can provide clear numerical criteria for quantitative assessment and automatic alarm of port health status without changing the quality score calculation and optimal forwarding logic.
[0096] By supplementing step S5, this embodiment provides a detailed description of the conversion process and physical transmission process of the target uplink data frame to the uplink communication data frame from three aspects: the functional division of the protocol encapsulation module, the typical content composition of the protocol header field and protocol trailer field, and the timing control strategy of the transmission buffer and uplink interface. This enables those skilled in the art to reproduce the implementation path of encapsulation and transmission under existing uplink communication protocols and hardware interfaces, ensuring that the target uplink data frame obtained through quality comparison and screening can be stably and reliably transmitted to the host system, thereby completely closing the processing link of the entire data preferential forwarding method.
[0097] In one specific embodiment, please refer to Figure 2 This is a schematic diagram of the application architecture of a serial port server based on dual-port quality comparison in an RS485 fieldbus system according to an embodiment of the present invention. Figure 2As shown, the serial port server of this invention is deployed between the RS485 fieldbus and the host computer system. It is connected to the RS485 fieldbus below via an RS485 serial port driver. Multiple field instruments at the slave device layer, including pH meters, turbidity meters, dissolved oxygen meters, and flow meters, are connected to the RS485 bus to collect various process measurement data. Inside the serial port server layer, an RS485 serial port driver, a health diagnosis module for CRC statistics and trend analysis, a preferred forwarding engine for quality scoring and silent error detection, and a TCP server module for multi-connection management are sequentially configured to achieve quality assessment and preferred forwarding of data from the dual-port access of the fieldbus. In the uplink direction, the serial port server connects to the industrial Ethernet via the Ethernet communication layer and communicates with the Modbus TCP client or SCADA data acquisition system at the host computer layer according to uplink protocols such as Modbus TCP. Thus, while maintaining the existing network and protocol system, the data after quality comparison and health diagnosis processing is reliably transmitted to the host monitoring system.
[0098] In one specific embodiment, please refer to Figure 3 This is a schematic diagram of the serial port server data selection and forwarding method based on dual-port quality comparison according to an embodiment of the present invention, as shown below. Figure 3 As shown, the method of this invention begins with system startup and initialization of the RS485 port and Ethernet interface. After detecting a polling request from the host computer based on Modbus TCP, the serial server parses the request data and sends an access command to the corresponding slave device via the RS485 fieldbus. Subsequently, the process enters the slave computer response and reception stage. The serial server acquires the response data from the RS485 bus through a dual-port parallel reception method, performs CRC check, quality scoring, and silent error detection on the two received data frames, performs CRC statistics and trend analysis in the health diagnosis module, and generates a health alarm or silent error alarm when an anomaly is detected. Based on this, the optimal forwarding engine selects the target uplink data frame according to the quality comparison result, completes the uplink protocol encapsulation, and returns it to the host computer via the Ethernet interface. When the host computer initiates the next round of polling, the process returns to the aforementioned request processing stage, realizing a complete closed-loop data acquisition and quality control process.
[0099] In one specific embodiment, please refer to Figure 4 This is a schematic diagram of the decision process for dual-port quality comparison and silent error detection in an embodiment of the present invention, as shown below. Figure 4As shown, after receiving a data frame from the dual-port buffer, the present invention first extracts a frame of data to be judged from the respective receive FIFOs of port A and port B, and determines whether both ports currently have valid data frames. When only one port has a data frame, the system performs CRC check, length check, and address check on the data frame, generates a quality feature vector composed of the CRC result, length status, and address status, calculates the corresponding quality score, and if the score is higher than a preset threshold, the data frame of that port is used as an uplink candidate and enters the subsequent forwarding process; otherwise, it is considered a low-quality frame and is not sent up. When both ports have data frames, the system performs the same integrity check and quality feature extraction on both data frames respectively, obtains the quality scores of port A and port B, and classifies them into three cases based on the relationship between the score size and whether the threshold is exceeded: only one score is qualified, both scores are unqualified, and both scores are qualified. In the case where both scores are qualified, the system further compares whether the content of the two frames is consistent. If the content is inconsistent, it is marked as a suspected silent error and an alarm is triggered. If the content is consistent, the system selects the target uplink data frame by combining the quality score result and the predetermined strategy, thereby realizing data quality optimization and silent error detection in dual-port scenarios.
[0100] In one specific embodiment, please refer to Figure 5 This is a schematic diagram of the serial port server port health diagnosis and alarm processing flow according to an embodiment of the present invention, as shown below. Figure 5 As shown, this invention periodically performs statistical and trend analysis on the CRC check error rate of each RS485 port during long-term operation. When the CRC error count within the sampling window exceeds the preset threshold or the error rate shows a continuous upward trend, it is considered that the port health status does not meet the normal operating conditions, and the port anomaly diagnosis branch is entered. The abnormal port is marked and the current error statistics and time information are recorded. After the port health status is determined, the system encapsulates the abnormal information into corresponding alarm messages according to the alarm reporting method configuration, and sends or stores them through different channels such as Modbus TCP extended register, SNMP Trap or local log file, so that the host computer or maintenance personnel can be informed of the potential degradation or failure of the port in a timely manner, thereby realizing online monitoring and preventive maintenance of the dual-port operating status without interrupting fieldbus communication.
[0101] In one specific embodiment, please refer to Figure 6 This is a schematic diagram of the serial port server functional modules and data flow based on dual-port quality comparison according to an embodiment of the present invention, as shown below. Figure 6As shown, the overall structure of the serial port server of this invention, from right to left, includes an RS485 physical interface and UART receive buffer, a background data processing module, and a host computer communication module. The lower layer is the field acquisition data stream, and the upper layer is the diagnostic and alarm data stream: The RS485 interface sends the bus data acquired by the two ports to the data receiving and buffering module through the UART receive FIFO. The frame extraction and integrity verification unit generates multi-dimensional features such as length, address, and CRC. Then, the quality assessment and silent error detection module calculates the quality score and determines whether there is a silent error. At the same time, the CRC statistical results and error features are sent to the health diagnosis module for long-term statistical and trend analysis. In the optimal forwarding module, the target uplink data frame is selected according to the quality score and the judgment result, and handed over to the uplink protocol encapsulation and Modbus TCP server module to be sent to the host computer. The health diagnosis module reports the port health status and alarm information to the operation and maintenance system or the host computer through a dedicated channel, thereby realizing the collaborative work of data acquisition, quality control, health diagnosis and uplink communication under a unified architecture.
[0102] In one specific embodiment, please refer to Figure 7 This is a schematic diagram of the integrated alarm processing flow of dual-port quality scoring and port health diagnosis according to an embodiment of the present invention, as shown below. Figure 7 As shown, during operation, this invention periodically acquires the CRC check statistics and historical quality score sequences of each RS485 port. Simultaneously, after the silent error detection module outputs a suspected abnormal event, the above information is aggregated to the comprehensive judgment unit. This unit performs joint analysis of the port's current quality score, score fluctuations, and CRC error rate, and classifies the port's operating status into different levels such as normal, quality degradation, and severe anomaly according to preset rules. For ports judged as quality degradation or severe anomaly, the system records detailed statistical data and judgment results while triggering an alarm processing flow. Depending on the configuration, the system reports or stores the port's health status and silent error information via Modbus TCP extended registers, SNMP Trap, or local log files. The judgment results can also be fed back to the optimal forwarding engine for subsequent weight adjustments or port degradation, thus achieving collaborative processing of quality scoring, health diagnosis, and alarm reporting within a unified process.
[0103] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for forwarding data of a serial server based on a two-port quality ratio, characterized in that, Includes the following steps: S1, connect the first serial port and the second serial port in parallel to the same RS485 bus, and perform synchronous reception and buffering processing on the bus data frames on the RS485 bus to obtain the first received data frame and the second received data frame. S2, perform integrity verification processing on the first received data frame and the second received data frame respectively to obtain the first integrity verification result and the second integrity verification result; S3, according to the preset quality quantization rules, the first integrity verification result and the second integrity verification result are numerically processed to obtain the first quality score corresponding to the first received data frame and the second quality score corresponding to the second received data frame. S4. Based on the preset comparison rules, the first quality score and the second quality score are compared. The receiving data frame with the higher quality score is selected from the first received data frame and the second received data frame as the target uplink data frame. When the first quality score and the second quality score are the same, one of them is selected in a preset order to obtain the target uplink data frame. S5, the target uplink data frame is sent through the uplink communication interface to obtain the uplink communication data frame.
2. The method of claim 1, wherein the method further comprises: Step S3 includes: S31, perform quality information parsing on the first integrity check result and the second integrity check result respectively, and extract multi-dimensional quality evaluation data; S32, according to the preset quality quantification rules, perform score mapping processing on the multidimensional quality evaluation data respectively to obtain multiple quality sub-scores; S33, the multiple quality sub-scores are weighted and synthesized to obtain the first quality score and the second quality score.
3. The method of claim 2, wherein the method further comprises: Step S31 includes: When parsing the quality information of the first integrity check result and the second integrity check result, the multidimensional quality evaluation data includes frame integrity status, error type identifier and error quantity index. The frame integrity status is used to distinguish between check pass and check fail, the error type identifier is used to distinguish between length error, address error and check field error, and the error quantity index is used to characterize the number of fields judged as errors in the same received data frame.
4. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 2, characterized in that, Step S32 includes: When performing score mapping processing on multidimensional quality evaluation data according to preset quality quantification rules, discrete scoring tables are preset for frame integrity status, error type identifier, and error quantity index respectively. The values of frame integrity status, error type identifier, and error quantity index are used to index and look up the corresponding discrete scoring tables to obtain the quality sub-scores that correspond one-to-one with the quality evaluation data of each dimension.
5. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 2, characterized in that, Step S33 includes: When performing weighted synthesis of quality sub-scores, weight factors are preset for frame integrity status, error type identifier, and error quantity index respectively. The quality sub-scores corresponding to frame integrity status, error type identifier, and error quantity index are weighted and summed according to the corresponding weight factors to obtain the first quality score and the second quality score. The weighted summation result is then limited to a preset score range.
6. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 1, characterized in that, Step S4 includes: S41, compare the first quality score and the second quality score to generate a quality comparison identifier. The quality comparison identifier is used to distinguish between the state where the first quality score is greater than the second quality score, the state where the first quality score is equal to the second quality score, and the state where the first quality score is less than the second quality score. S42, according to the quality comparison identifier, a set of candidate received data frames is determined from the first received data frame and the second received data frame. When the quality comparison identifier indicates that the first quality score is greater than the second quality score or the first quality score is less than the second quality score, the received data frame with the higher quality score is taken as the candidate received data frame. When the quality comparison identifier indicates that the first quality score is equal to the second quality score, the first received data frame and the second received data frame are taken as candidate received data frames at the same time. S43, select a receiving data frame from the candidate receiving data frame set in a preset order to obtain the target uplink data frame.
7. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 6, characterized in that, Step S41 includes: When generating a quality comparison identifier, the difference between the first quality score and the second quality score is compared with a preset comparison threshold. When the difference is greater than the preset comparison threshold, the quality comparison identifier is set to a state where there is a quality advantage port. When the difference is less than or equal to the preset comparison threshold, the quality comparison identifier is set to a state where the quality scores are equal, and the state where the quality scores are equal corresponds to the state where the first quality score is equal to the second quality score.
8. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 6, characterized in that, Step S42 includes: When determining the candidate received data frame set based on the quality comparison indicator, if the quality comparison indicator indicates that the first quality score is greater than the second quality score, the candidate received data frame set is set to include only the first received data frame; if the quality comparison indicator indicates that the first quality score is less than the second quality score, the candidate received data frame set is set to include only the second received data frame; if the quality comparison indicator indicates that the first quality score is equal to the second quality score, the candidate received data frame set is set to include both the first and second received data frames.
9. A serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 6, characterized in that, Step S43 includes: When selecting a received data frame as the target uplink data frame from the candidate received data frame set according to a preset order, if the candidate received data frame set includes both a first received data frame and a second received data frame, the preset order is rotated based on the source of the target uplink data frame in the previous communication cycle. Specifically, if the target uplink data frame in the previous communication cycle is the first received data frame, the second received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle; if the target uplink data frame in the previous communication cycle is the second received data frame, the first received data frame is selected as the target uplink data frame from the candidate received data frame set in this cycle.
10. The serial port server data preferential forwarding method based on dual-port quality comparison as described in claim 1, characterized in that, Step S5 includes: The target uplink data frame is encapsulated using an uplink communication protocol, and a protocol header field and a protocol trailer field are added to obtain an uplink communication data frame. The uplink communication data frame is written into the transmission buffer of the uplink communication interface, and the uplink communication interface is controlled to output the uplink communication data frame according to a preset transmission sequence.
