RS485 bus-based host extension method, apparatus and device, and storage medium

By configuring the RS485 bus host interface parameter and building a 5-level data stack structure, combined with the time slice-based task scheduling mechanism, the problem that multiple host devices cannot access RS485 bus communication at the same time is solved, and the functions of simultaneous monitoring and control of multiple hosts are realized, improving the scalability of the system and data transmission reliability.

CN119847967AActive Publication Date: 2025-04-18ZHONGJING KEXIN TECH CO LTD

Patent Information

Application Number
CN202510343265.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-04-18
Estimated Expiration
2045-03-21

AI Technical Summary

Technical Problem

In the existing RS485 bus network, multiple host devices cannot access the same bus at the same time for communication, which limits the scalability and flexibility of the system. The processing capacity of a single host is not enough to meet the needs of complex control systems, which easily leads to communication delays and data loss.

Method used

By configuring the RS485 bus host interface parameter, a 5-level data stack structure is built, the host data frame management unit is implemented, and a time slice-based task scheduling mechanism is adopted to support multiple hosts to monitor and control the slave devices at the same time.

Benefits of technology

It realizes that a single RS485 bus network supports multi-host access, improves the scalability and flexibility of the system, improves the accuracy and reliability of data transmission, and ensures the real-time and fairness of multi-host data interaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847967A_ABST
    Figure CN119847967A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of host extension, and discloses a host extension method, device and equipment based on an RS485 bus and a storage medium, and the method comprises the steps: carrying out the parameter configuration of an RS485 bus host interface, and obtaining an independently configured RS485 host interface group; constructing a five-level data stack structure for the RS485 host interface group to obtain a host data frame management unit; host interaction task processing is carried out on the host data frame management unit, and host data frames are stored in corresponding data frame cache regions; performing scheduling task processing on the host data frame in the host data frame management unit to obtain a data forwarding result; performing task scheduling time sequence processing based on the data forwarding result to obtain a task scheduling sequence; and the task scheduling sequence is input into the man-machine interaction task module for state monitoring to obtain a system operation state record, so that a plurality of host devices can monitor and control the slave devices at the same time, and the accuracy and reliability of data transmission are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of host expansion technology, and in particular to a host expansion method, device, equipment and storage medium based on RS485 bus. Background Art

[0002] RS485 bus is widely used in various control systems due to its strong anti-interference ability and long transmission distance. Traditional RS485 bus communication adopts master-slave mode, where one host controls multiple slave devices. This mode works well in simple control systems. However, with the expansion of system scale and the increase of control requirements, the processing capacity of a single host is gradually unable to meet the needs of complex control systems.

[0003] In the current RS485 bus network, multiple host devices cannot access the same bus for communication at the same time, which limits the scalability and flexibility of the system. In practical applications, multiple controllers are often required to monitor and control different slave devices at the same time, and the traditional single-host mode is difficult to achieve such complex control requirements. In addition, the processing power of a single host is limited, and when a large amount of data interaction needs to be processed, it is easy to cause communication delays and data loss. Summary of the invention

[0004] The present application provides a host expansion method, apparatus, device and storage medium based on RS485 bus, thereby enabling multiple host devices to monitor and control slave devices at the same time, thereby improving the accuracy and reliability of data transmission.

[0005] The first aspect of the present application provides a host expansion method based on RS485 bus, and the host expansion method based on RS485 bus includes:

[0006] The RS485 bus host interface is parameterized to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter;

[0007] The RS485 host interface group is constructed into a 5-level data stack structure, wherein each level of data stack comprises a data frame buffer, a data frame length counter and a data frame status register, and a host data frame management unit is obtained;

[0008] The host data frame management unit performs host interaction task processing, obtains the host data frame by monitoring the receiving flag of the RS485 bus host interface, and stores the host data frame in the corresponding data frame buffer area;

[0009] The host data frame in the host data frame management unit is subjected to scheduling task processing, and the data frame to be sent is sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, so as to obtain a data forwarding result;

[0010] Perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain a task scheduling sequence;

[0011] The task scheduling sequence is input into the human-computer interaction task module for status monitoring, and the number of online hosts, data stack usage rate, and data transmission success rate are recorded to obtain a system operation status record.

[0012] The second aspect of the present application provides a host expansion device based on an RS485 bus, and the host expansion device based on an RS485 bus includes:

[0013] The parameter configuration module is used for performing parameter configuration on the RS485 bus host interface to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter;

[0014] A construction module is used to construct a 5-level data stack structure for the RS485 host interface group, each level of the data stack includes a data frame buffer, a data frame length counter and a data frame status register, and obtain a host data frame management unit;

[0015] An interactive task processing module is used to perform host interactive task processing on the host data frame management unit, obtain host data frames by monitoring the receiving flag of the RS485 bus host interface, and store the host data frames in the corresponding data frame buffer area;

[0016] The scheduling task processing module is used to perform scheduling task processing on the host data frame in the host data frame management unit, and send the data frame to be sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, so as to obtain a data forwarding result;

[0017] A scheduling timing processing module, used to perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain a task scheduling sequence;

[0018] The status monitoring module is used to input the task scheduling sequence into the human-computer interaction task module for status monitoring, record the number of online hosts, data stack usage rate, data transmission success rate, and obtain system operation status records.

[0019] The third aspect of the present application provides an electronic device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the electronic device executes the above-mentioned host expansion method based on RS485 bus.

[0020] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned host expansion method based on the RS485 bus.

[0021] Compared with the prior art, the present application has the following beneficial effects: it realizes the function of supporting multi-host access in a single RS485 bus network, significantly improves the scalability and flexibility of the system, and enables multiple host devices to monitor and control slave devices at the same time. Through the design of a 5-level data stack structure, an independent data cache space is provided for each host interface, which effectively avoids data congestion and loss problems and improves the reliability of data interaction. A task scheduling mechanism based on time slices is adopted to reasonably allocate the communication resources of the host to ensure the real-time and fairness of multi-host data interaction. A complete data verification and protection mechanism is designed, including functions such as data frame integrity detection, checksum comparison and overflow protection, which significantly improves the accuracy and reliability of data transmission. A flexible parameter configuration function is realized, which supports independent configuration of the communication parameters of each RS485 interface to meet the communication requirements of different application scenarios. A comprehensive status monitoring function is provided to monitor the system operation status in real time, including indicators such as the host online status, data stack usage and transmission success rate, which is convenient for system maintenance and fault diagnosis. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0023] The structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with this technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantive technical significance. Any structural modification, change in proportion or adjustment of size, without affecting the effects and purposes that can be achieved by the present invention, should still fall within the scope of the technical contents disclosed by the present invention.

[0024] Figure 1It is a schematic flow chart of a host expansion method based on RS485 bus provided by an embodiment of the present invention;

[0025] Figure 2 It is a schematic block diagram of the structure of a host expansion device based on RS485 bus provided by an embodiment of the present invention;

[0026] Figure 3 It is a schematic block diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0029] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0030] It should be further understood that the term "and / or" used in the specification and appended claims of this application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations. Figure 1 In the embodiment of the present application, an embodiment of the host expansion method based on RS485 bus includes:

[0031] Step 100, RS485 bus host interface is carried out parameter configuration, obtains the RS485 host interface group of independent configuration, and the RS485 host interface group comprises baud rate parameter, data bit parameter, stop bit parameter and check bit parameter;

[0032] It is understandable that the execution subject of the present application can be a host expansion device based on RS485 bus, or a terminal or a server, which is not limited here. The present application embodiment is described by taking the server as the execution subject as an example.

[0033] Specifically, the UART port of the single-chip microcomputer is connected to the relevant pins of the RS485 transceiver to realize the sending, receiving and direction control of data. The TX pin of the UART port of the single-chip microcomputer is connected to the DI pin of the RS485 transceiver to form a data sending channel, and the RX pin of the UART port is connected to the RO pin of the RS485 transceiver to form a data receiving channel. In order to realize the data transmission direction control of the RS485 bus, a GPIO control pin of the single-chip microcomputer is connected to the DE and RE pins of the RS485 transceiver, and the sending and receiving directions of the data are controlled by the logic high and low levels. After the hardware connection is completed, the communication parameters are configured to form an independent RS485 host interface group. The baud rate parameters of the sending channel are set and configured in the range of 1200bps to 115200bps. By selecting an appropriate baud rate value to meet the communication rate requirements of the specific application scenario, this step is implemented by the UART baud rate register of the single-chip microcomputer. The data bit parameters of the receiving channel are configured and set to a fixed 8 bits. This configuration is completed through the UART configuration register of the single-chip microcomputer, which is used to define the effective bit length of each frame of data to ensure that the data format between the host and the slave is consistent. The stop bit parameters of the receiving channel are set. The stop bit is configured to 1 or 2 bits according to the actual communication requirements. The setting of this parameter is also implemented through the UART configuration register of the single-chip microcomputer to define the end mark length of each frame of data and provide synchronization support for the receiving device. At the same time, select an appropriate check mode for the receiving channel to improve the reliability of data communication. In scenarios where there are no special check requirements, the check mode is set to no check mode; in scenarios where communication error detection requirements are high, odd check or even check mode is selected. The specific configuration of the check mode is completed through the check bit register of the single-chip microcomputer UART module, the purpose of which is to perform check calculations on the received data, thereby providing error detection capabilities during the communication process. Write the baud rate configuration data, data bit configuration data, stop bit configuration data, and check bit configuration data into the non-volatile memory of the single-chip microcomputer to ensure the persistence and reusability of the parameters. By writing the above configuration parameters into the non-volatile memory of the microcontroller, such as EEPROM or Flash memory, these configurations are directly loaded when the system is powered on and initialized, avoiding the problem of reconfiguration every time it is started, thereby significantly improving the startup efficiency and stability of the system. The writing process calls the memory write interface of the microcontroller, stores the configuration data in the specified storage unit through a specific command sequence, and performs data verification after the writing is completed to ensure that the stored data is consistent with the original configuration. Through the above steps, an independently configured RS485 host interface group is obtained.

[0034] Step 200, construct a 5-level data stack structure for the RS485 host interface group, each level of data stack includes a data frame buffer, a data frame length counter and a data frame status register, and obtains a host data frame management unit;

[0035] Specifically, the data communication format of the RS485 host interface group is configured, and the communication format of the data frame is standardized by defining the start bit, data bit, check bit and stop bit of the data frame. In this process, various parameters are standardized according to actual application requirements, for example, a fixed start bit length, 8 data bits, 1 or 2 stop bits and no check, odd check or even check are selected to ensure that the transmitted data frame can be correctly parsed between the host and the slave. The RAM space of the single-chip microcomputer is allocated for storage. By rationally planning the memory resources of the single-chip microcomputer, a fixed size storage space of 256 bytes is allocated for each data stack to build a data frame storage area. The purpose of allocation is to provide sufficient and independent storage resources for each level of data stack, avoid resource competition between different data frames, and ensure the stability and efficiency of memory utilization. The data frame storage area is partitioned into 5 levels, and 5 independent data frame buffer areas are constructed according to the first-in-first-out principle to form a cache structure with clear hierarchy and orderly operation. At the same time, in order to facilitate efficient management of the 5-level data buffer area, a read-write pointer is set for it. By setting the read pointer to indicate the data read position and the write pointer to indicate the data write position, the data in the buffer can be accurately located and operated. The pointer mechanism ensures that the access of the data frame in the stack follows the strict first-in-first-out rule to avoid data confusion and conflict problems. The length of the data frame pointed to by the data access pointer is counted to record the actual number of bytes of each data frame. By introducing the data frame length counter, the value of the counter directly reflects the size of the data frame. The data frame corresponding to the data frame length counter is marked with a status. A status register is configured for each data frame. The content of the register includes information such as whether the data frame has been received, whether it has been processed, and whether it needs to be forwarded, so as to achieve comprehensive monitoring of the data frame life cycle. In order to improve the robustness of the 5-level data buffer, an overflow protection mechanism is designed for it. By setting the overflow protection value and underflow protection value of the buffer, system abnormalities caused by too much or too little data can be effectively prevented. For example, when the data in the buffer exceeds its allocated storage range, the overflow protection mechanism will trigger a corresponding alarm or discard the excess data; when the data in the buffer is too little, the underflow protection mechanism will alleviate the problem by suspending the current task or requesting more data. The overflow protection mechanism significantly enhances the stability and fault tolerance of the buffer area. The overflow protection mechanism is integrated into the 5-level data buffer area and combined with the data frame length counter and data frame status register to form a host data frame management unit with complete functions and reasonable structure.

[0036] Step 300, the host data frame management unit performs host interaction task processing, obtains the host data frame by monitoring the receiving flag of the RS485 bus host interface, and stores the host data frame in the corresponding data frame buffer area;

[0037] It should be noted that the data receiving flag of the RS485 bus host interface is monitored in real time through the external interrupt or polling mechanism of the single-chip microcomputer or controller. By detecting the receiving flag bit, it is determined whether the host has new data arriving, thereby determining the host communication status. In this process, the data integrity detection is performed in combination with the start flag bit and the end flag bit of the data reception to ensure that the received data frame is complete. If the received flag bit does not indicate that the data frame is complete, the incomplete data is discarded and the new data frame continues to arrive. Through this mechanism, invalid data generated due to interference or errors is effectively filtered out. After successfully receiving the complete data frame, the host received data is checked. Based on the check bit parameters in the communication protocol, the correctness of the data frame is determined by calculating the check code of the received data frame and comparing it with the check code attached during the transmission process. According to the preset check rules, such as odd check or even check, the corresponding check code is generated and then compared with the check field in the received data frame. If the check passes, the data frame is marked as valid data; if the check fails, the data frame needs to be marked as invalid, and it is decided whether to record the error log or trigger the error handling process according to the application scenario. For data frames marked as valid, they are stored in the 5-level data buffer of the host data frame management unit. A buffer storage location is allocated for valid data frames by allocating a storage location pointer. The storage location pointer points to a specific location in the 5-level data buffer, ensuring that each data frame can find a unique storage area in the buffer. When allocating storage locations, the buffer is managed according to the first-in-first-out principle, so that the earliest frame is processed first to avoid data accumulation or delay. The valid data frame is written to the buffer pointed to by the storage location pointer, and the write pointer position is updated at the same time to prepare for the storage of the next frame of data. While the data frame is stored, the data frames in the buffer are counted to record the total number of data frames currently stored and the length of each data frame. The data frame counting is achieved by adding a counter, which increases as each frame of data is written, and the length of a single frame is recorded for subsequent analysis and processing. The data from the counter provides the system with real-time feedback on the communication volume, which helps to evaluate the usage of the bus and the system load status. These statistical data are combined with the specific data frames stored in the buffer and encapsulated according to the preset data structure to generate a complete host data frame. The encapsulated host data frame contains the content, length, count and related tag information of the data frame, forming a standardized structure. The encapsulated host data frame is stored in the corresponding data frame buffer.

[0038] Step 400, performing scheduling task processing on the host data frame in the host data frame management unit, sending the data frame to be sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, and obtaining a data forwarding result;

[0039] Specifically, the data frame buffer in the host data frame management unit is periodically scanned to check the data storage status of different levels in the buffer. By scanning the status register of each level of the buffer, the mark of the status register can indicate whether there is an unprocessed data frame, the priority of the data frame, and whether the data frame has been assigned as a sending task. By scanning, the storage status of the current buffer is obtained, thereby generating a cache scanning result. Based on the cache scanning result, the data frames in the cache are prioritized. The sorting is based on the mark information in the data frame status register, including the urgency of the task, the order of receiving the data frame, and whether there is a retransmission requirement. Through these mark information, an orderly data processing queue is constructed, in which the data frames with high priority will be sent first. The data frames in the data processing queue are verified for validity. By checking the integrity and verification status of the data frame again, invalid data frames caused by interference or other reasons are filtered out. The integrity check is based on the head and tail identifiers of the data frame, and the verification status is determined by recalculating the check code of the data frame and comparing it with the original check code. The verified data frame is marked as a data frame to be sent. The slave bus status is detected for the data frame to be sent to determine whether the RS485 slave bus is in an idle state. The bus status detection depends on the bus control signal or the status register of the transceiver. If the bus is busy, the system will temporarily suspend the sending task and wait for the next detection. When the bus status mark shows idle, the system immediately starts the sending operation and sends the data frame to be sent to the target slave through the RS485 slave interface. During the data transmission process, a data transmission record is generated at the same time, including information such as the transmission time, the target address, and the data frame content. After the data frame is successfully sent, the response data frame of the slave is monitored in real time. This operation captures the response by monitoring the data returned by the slave, and saves the captured response data frame as the slave response data. The slave response data contains the confirmation information, error information or other application layer feedback of the target slave. After receiving the slave response data, the system performs address resolution on it and determines its corresponding target host according to the address information carried in the data frame. The extraction of the target address information depends on the resolution of the response data frame format, including the source address, target address and other identification fields, so as to ensure the accuracy of the forwarding path. Based on the target address information, the slave response data is forwarded to the data frame buffer of the corresponding host. After the forwarding operation is completed, the result of the entire process is encapsulated as a data forwarding result, and the detailed information of each step in the communication is recorded.

[0040] Step 500: Perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain a task scheduling sequence;

[0041] Specifically, each data frame in the data forwarding result is analyzed, and the amount of communication resources occupied by the data frame is determined by calculating the transmission time of the data frame. According to the length of the data frame and the communication rate of the RS485 bus, the transmission period of a single frame of data is obtained. The calculation formula of the transmission period is that the transmission time is equal to the length of the data frame multiplied by the transmission time per bit, where the transmission time per bit is determined by the reciprocal of the bus baud rate. The data transmission period is divided into time slices according to the number of hosts, and a fixed time period is allocated to each host interaction task to form a time slice allocation table. The core principle of time slice allocation is to ensure that the communication task of the host is completed within the specified time, while trying to avoid overlapping or wasting time slices. In order to achieve this goal, the transmission period is subdivided into multiple small time slices, and allocated to different tasks according to the importance of the host task and the amount of resources required, so that each task has a clear execution window. Priority is set for the tasks in the time slice allocation table to optimize the execution order of the tasks. The basis for priority setting is mainly the urgency of data transmission and the importance of the task. For example, tasks with high real-time requirements will be given higher priority, while ordinary tasks will be delayed. By comprehensively evaluating the urgency of the task, a task priority table is generated and input into the scheduling control unit. In the scheduling control unit, the execution time of tasks is allocated in order of priority to generate an orderly task execution sequence. A timeout threshold is set for the task execution sequence to ensure that the execution time of the task does not exceed the expected range. The timeout threshold is set based on the data transmission cycle and the importance of the task, including setting a maximum execution time for each task. Through this step, the overall timing disorder caused by the long execution time of a task is effectively avoided. The application of task timeout parameters runs through the task execution process. The system will record the start time and end time of each task in real time and save this information as a task execution record, including the actual running time of the task, the execution result, and whether a timeout occurs. The task execution record is analyzed in time to calculate the deviation between the actual execution time and the preset time. Through statistical analysis of the deviation data, the timing adjustment value is obtained. The timing adjustment value reflects the potential problems in the task scheduling process, such as insufficient time slice allocation, unreasonable priority setting, or too long execution time of some tasks. Based on the timing adjustment value, the task scheduling is dynamically optimized, the time slice allocation table and task priority setting are updated, and the optimized task scheduling sequence is generated.

[0042] Step 600: Input the task scheduling sequence into the human-computer interaction task module for status monitoring, record the number of online hosts, data stack usage rate, and data transmission success rate, and obtain the system operation status record.

[0043] Specifically, by detecting the host communication status in the task scheduling sequence, the response of each host is counted to obtain the host online record. According to the time slice and data interaction task assigned to each host in the task scheduling sequence, whether the host responds as expected is monitored in real time. For the host that does not return a response within the set time slice, it is recorded as a response timeout state, and whether the host is offline is further determined according to the number of response timeouts or the duration. Through this step, dynamic statistical data on the number of online hosts is obtained, and the online status of the hosts in the current system is intuitively reflected. The capacity of the 5-level data buffer area in the host data frame management unit is counted. The stack usage rate is generated by calculating the proportion of the used space of each level of buffer area to the total space. The calculation of the stack usage rate is based on the real-time status of the buffer area, and the writing and reading of the data frame is continuously monitored, and the statistical results are updated according to the current occupancy of the buffer area. Through real-time monitoring, the usage status of each level of buffer area is dynamically reflected, and the problem of insufficient resources or space waste is identified. All statistical results are summarized into a storage status report. At the same time, in order to comprehensively evaluate the communication quality of the system, the success rate of the data forwarding result is counted. The data transmission success rate is obtained by calculating the ratio of the number of successfully transmitted data frames to the total number of transmitted data frames. The transmission success rate reflects the reliability and stability of the RS485 bus in the current communication environment. For the statistical results of the transmission success rate, it is compared with the preset threshold. When the transmission success rate is lower than the threshold, an alarm message is automatically generated to indicate the existence of communication anomalies or performance bottlenecks. At the same time, the communication quality report records the success rate, failure reasons and fault location information of each task. The number of online hosts, storage status reports and communication quality reports are integrated to form system operation status data and generate status monitoring records. Based on the status monitoring records, operation status reports are generated regularly to record various key indicator parameters of system operation. The operation status report includes basic indicators such as the number of online hosts, data stack usage rate and data transmission success rate, and provides trend analysis and prediction functions in combination with the historical operation data of the system. For example, by comparing historical data, the report indicates whether the stack usage rate is at risk of overload, whether the transmission success rate has a continuous downward trend, or whether the host online status is affected by the external environment.

[0044] In the embodiment of the present application, a single RS485 bus network is implemented to support the function of multi-host access, which significantly improves the scalability and flexibility of the system, so that multiple host devices can monitor and control slave devices at the same time. Through the design of the 5-level data stack structure, an independent data cache space is provided for each host interface, which effectively avoids data congestion and loss problems and improves the reliability of data interaction. A task scheduling mechanism based on time slices is adopted to reasonably allocate the communication resources of the host to ensure the real-time and fairness of multi-host data interaction. A complete data verification and protection mechanism is designed, including functions such as data frame integrity detection, checksum comparison and overflow protection, which significantly improves the accuracy and reliability of data transmission. A flexible parameter configuration function is implemented to support independent configuration of the communication parameters of each RS485 interface to meet the communication needs of different application scenarios. A comprehensive status monitoring function is provided to monitor the system operation status in real time, including indicators such as the host online status, data stack usage and transmission success rate, which is convenient for system maintenance and fault diagnosis.

[0045] In a specific embodiment, the process of executing step 100 may specifically include the following steps:

[0046] Connect the UART port of the microcontroller, connect the TX pin to the DI terminal of the RS485 transceiver to obtain the transmission channel, and connect the UART port of the microcontroller, connect the RX pin to the RO terminal of the RS485 transceiver to obtain the receiving channel;

[0047] Connect the control port of the microcontroller, connect the control pin to the DE and RE terminals of the RS485 transceiver to obtain the direction control channel;

[0048] Set the baud rate parameter of the sending channel within the range of 1200bps to 115200bps to obtain the baud rate configuration data;

[0049] The data bit parameter of the receiving channel is set to a fixed 8 bits to obtain the data bit configuration data;

[0050] Set the stop bit parameter of the receiving channel to 1 or 2 bits to obtain the stop bit configuration data;

[0051] The check mode of the receiving channel is set to one of no check, odd check or even check, and the check bit configuration data is obtained;

[0052] The baud rate configuration data, the data bit configuration data, the stop bit configuration data and the check bit configuration data are written into the non-volatile memory of the single chip computer to obtain an independently configured RS485 host interface group.

[0053] Specifically, the transmit pin (usually the TX pin) in the UART port of the microcontroller is connected to the data input pin (DI end) of the RS485 transceiver to ensure that the digital signal transmitted by the microcontroller through the TX pin can correctly enter the RS485 transceiver for it to be sent to the RS485 bus. At the same time, the receive pin (usually the RX pin) in the UART port of the microcontroller is connected to the data output pin (RO end) of the RS485 transceiver, so that the data received from the RS485 bus is transmitted to the RX pin of the microcontroller through the RS485 transceiver. In order to achieve dynamic control of the communication direction, the direction control pin of the RS485 transceiver is connected. A control port pin of the microcontroller is simultaneously connected to the drive enable pin (DE end) and the receive enable pin (RE end) of the RS485 transceiver. The RS485 transceiver switches the transmit and receive modes by controlling the high and low level states of the DE and RE pins. When the DE pin is high and the RE pin is low, the RS485 transceiver is in the transmit mode; when the DE pin is low and the RE pin is high, the transceiver is in the receive mode. By configuring the logic state of the microcontroller control port pin, the function of the direction control channel is dynamically realized. After completing the hardware connection, configure the communication parameters of the microcontroller's UART port to ensure the correctness of the communication. Configure the baud rate, which defines the number of bits transmitted per second. The formula is:

[0054] in, Indicates the baud rate, which defines the transmission rate of communication; Indicates the clock frequency of the microcontroller, which is the basic clock for the operation of the UART module; Indicates the value of the baud rate register, which is an important parameter for controlling the baud rate. The value of , so that the baud rate meets the communication requirements. Configure the data bit parameters. The data bit is the number of valid bits contained in each data frame, usually 8 bits. This parameter is set through the UART control register to ensure that the format of the data frames sent and received is consistent to avoid communication failure. Set the stop bit, which is used to mark the end of each frame of data. The stop bit length is 1 bit or 2 bits. The longer the length, the stronger the anti-interference ability of the communication, but the transmission efficiency will be reduced accordingly. The configuration of the stop bit is completed through the UART control register. In order to ensure the reliability of communication, set the check mode. The check mode is no check, odd check or even check. The purpose of the check is to detect errors during the communication process. For example, for odd check, the setting of the check bit needs to ensure that the total number of "1"s of all data bits in the data frame is an odd number. The logical representation of the check is: ;

[0055] in, Indicates the value of the check bit, which is 0 or 1; Indicates the first data bits, the value is 0 or 1; Indicates the total number of data bits in the data frame; mod represents the modulo operation, which is used to calculate parity. After completing all the above configurations, write the parameters such as baud rate, data bit, stop bit and check mode into the non-volatile memory of the microcontroller (such as EEPROM or Flash). Non-volatile memory is a storage medium that can save data after power failure, which is used to ensure the persistence of communication parameters. The writing process includes specifying the storage address, loading the parameter data and performing the write operation. Finally, an independently configured RS485 host interface group is obtained.

[0056] In a specific embodiment, the process of executing step 200 may specifically include the following steps:

[0057] The data communication format of the RS485 host interface group is configured, and the start bit, data bit, check bit and stop bit of the data frame are divided to obtain the data frame format standard;

[0058] Allocate storage to the MCU RAM space, allocate a fixed-size storage space of 256 bytes to each data stack, and obtain a data frame storage area;

[0059] The data frame storage area is partitioned into five levels, and five independent data frame buffer areas are constructed according to the first-in-first-out principle to obtain a five-level data buffer area, and a read-write pointer is set for the five-level data buffer area. The read pointer indicates the data read position, and the write pointer indicates the data write position to obtain a data access pointer;

[0060] Count the length of the data frame pointed to by the data access pointer, record the actual number of bytes of each data frame, obtain the data frame length counter, and mark the status of the data frame corresponding to the data frame length counter, mark the processing status of the data frame, and obtain the data frame status register;

[0061] Overflow protection is set for the 5-level data buffer area, and the overflow protection value and underflow protection value of the buffer area are set to obtain the overflow protection mechanism;

[0062] The overflow protection mechanism is applied to the 5-level data buffer, and the data frame buffer, the data frame length counter and the data frame status register are integrated to obtain a host data frame management unit.

[0063] Specifically, the data communication format of the RS485 host interface group is configured. By configuring the start bit, data bit, check bit and stop bit of the data frame, the basic format of the data frame is defined to ensure the consistency and reliability of data exchange between the host and the slave. The start bit is used to mark the beginning of the data frame. It is a low-level signal, and its length is expressed as a bit time, that is:

[0064] in, Indicates the time length of the start position; Indicates the baud rate. The data bit is the core part of each frame of data and defines the effective information for transmission. The data bit length is set to 8 bits, each bit represents binary "0" or "1". The data bit is guided by the start bit, and the receiving device can parse it synchronously. After receiving the complete 8-bit data, the check bit verifies the integrity of the data frame through the parity check algorithm. The calculation formula of the check bit is:

[0065] in, Indicates the value of the check bit, which is 0 or 1; Indicates The value of the data bit; Indicates the total number of data bits; mod indicates the modulo operation, which is used to determine parity. The stop bit marks the end of the data frame, and its length is usually 1 or 2 bits. The time length is:

[0066] in, Indicates the length of the stop bit time; Indicates the number of stop bits (1 or 2). After the data frame format standard is defined, the RAM space of the microcontroller is allocated for storage to provide support for data frame management. According to the requirements, a fixed size of storage space is allocated to each data stack, such as 256 bytes, to form a unified data frame storage area. Assume that the total system RAM size is , the number of storage stacks that can be allocated is , then the space size of each stack Satisfaction relationship:

[0067] This storage allocation ensures memory isolation between different tasks to avoid conflicts. After the storage area is divided, it is divided into 5 levels of data cache. Each cache manages a set of data frames independently and operates according to the first-in-first-out principle. In order to implement the first-in-first-out mechanism, read and write pointers are set for each cache to indicate the read and write positions of the data respectively. Assume that the total size of the cache is , the current write pointer position is , the read pointer position is , the conditions for writing data are: ;

[0068] The conditions for reading data are: ;

[0069] Through this circular buffering method, the data flow in the buffer area is effectively managed. In order to record the specific information of each data frame, the length of the frame pointed to by the data access pointer is counted and the status is marked. The length counter of the data frame is used to record the number of bytes of the data frame. Assuming that the current frame contains bytes, the counter value is:

[0070] ;

[0071] in, Indicates the length of the data frame; The number of valid bytes in the data frame. At the same time, the status register will mark the processing status of the data frame, including whether it has been received, whether it has passed the verification, whether it is waiting to be sent, etc. These marks serve as the basis for subsequent task scheduling. In order to enhance the robustness of the buffer area, an overflow protection mechanism is set for it. When the amount of data in the buffer area exceeds the upper limit of the capacity, the system will trigger the overflow protection value ;When the buffer is empty, the underflow protection value is triggered The conditions for overflow protection and underflow protection are: ;

[0072] in, Indicates the current cache usage space; and The overflow protection mechanism is applied to all 5-level data buffers, and the data frame buffer, length counter and status register are integrated to form a complete host data frame management unit.

[0073] In a specific embodiment, the process of executing step 300 may specifically include the following steps:

[0074] Monitor the data receiving flag of the RS485 bus host interface, determine the receiving status of the host data, obtain the host communication status, and perform data integrity detection on the host communication status, confirm the reception of the complete data frame through the receiving flag bit, and obtain the host receiving data;

[0075] The host receives the data and verifies it, generates a check code according to the check bit parameter and compares it with the received check code to obtain the data verification result, and then screens the data verification result, marks the data that passes the verification as a valid data frame, and obtains a valid data mark;

[0076] Allocate a cache area for the data frame corresponding to the valid data mark, determine the storage location in the 5-level data cache area, obtain a storage location pointer, and write the data frame pointed to by the storage location pointer into the corresponding data frame cache area, complete data storage according to the first-in-first-out principle, and obtain a cached data frame;

[0077] Count the cached data frames, record the total number of data frames and the length of a single frame, obtain data frame statistics, combine the data frame statistics with the cached data frames and encapsulate them, generate host data frames according to a preset data structure, and store the host data frames in the corresponding data frame cache area.

[0078] Specifically, the data receiving flag of the RS485 host interface is monitored in real time through hardware interrupt or software polling mechanism. When the data sent by the host reaches the receiving device, the receiving flag of the UART module will be set, indicating that there is a new data frame waiting to be processed. The logical state of the receiving flag is described by the following formula:

[0079] ;

[0080] in, Indicates the status of the receiving flag, 1 means data has arrived, 0 means no data; this flag is automatically set by the hardware to trigger data reading. When receiving a data frame, the system reads the received data frame and performs integrity check on it. Data integrity check is determined by checking the existence of the frame header and frame tail flags. If the received frame header and frame tail flags match, the data frame is considered complete. For example, if the frame header flag is and the frame end mark is , the integrity condition is expressed as:

[0081] Integrity test ;

[0082] The data frame that passes the integrity check is marked as the host received data. The host received data is checked. The check code is generated according to the check bit parameter in the communication protocol and compared with the received check code carried in the data frame. The check code is generated using the parity check method, and its formula is:

[0083] in, Indicates the generated checksum; Indicates the first data bits, the value is 0 or 1; Indicates the total number of data bits; mod is the modulus operation, which is used to determine the parity of the check bit. The checksum in the received data frame If they are equal, the verification passes; otherwise, the verification fails. The data frame that passes the verification is marked as a valid data frame. For a valid data frame, it is stored in the 5-level data buffer. The storage location of the data frame is determined by allocating a storage location pointer. Assume that the capacity of each level of buffer is , the write pointer position of the current buffer is , then the storage location pointer update formula is:

[0084] ;

[0085] in, Indicates the position of the write pointer; the mod operation is used to cyclically update the write pointer to ensure that it is always within the cache range. Data frames are stored according to the first-in-first-out principle. After the storage operation is completed, the read and write pointers are updated to maintain dynamic management of the cache. After the data storage is completed, the cached data frames are counted to record the total number of data frames and the length of a single frame. The counter formula for the total number of data frames is: ;

[0086] in, Indicates the total number of data frames stored in the buffer. The length of a single frame is calculated based on the number of bytes in the data frame. Assuming the length of the data frame is , then its calculation is: ;

[0087] in, is the number of bytes in the current data frame. After completing the counting and length recording, the data frame statistics are combined and encapsulated with the cached data frame, and the host data frame is generated according to the preset data structure, including the frame header, data bit, check bit, frame tail and length information. The encapsulated data frame is stored in the corresponding data frame buffer area for subsequent task scheduling and data forwarding.

[0088] In a specific embodiment, the process of executing step 400 may specifically include the following steps:

[0089] Scan the data frame buffer area in the host data frame management unit, check the data storage status of the buffer areas at all levels, obtain the buffer scanning result, and prioritize the data frames in the buffer scanning result, determine the processing order according to the mark of the data frame status register, and obtain the data processing queue;

[0090] Verify the validity of the data frames in the data processing queue, confirm the integrity and verification status of the data frames, obtain the data frames to be sent, and perform slave bus status detection on the data frames to be sent to determine whether the RS485 slave bus is in an idle state and obtain a bus status mark;

[0091] Send data frames based on bus status tags, send data frames to the target slave through the RS485 slave interface, obtain data sending records, perform response monitoring on the data sending records, receive response data frames returned by the slave, and obtain slave response data;

[0092] Perform address resolution on the slave response data, determine the target host according to the address information in the data frame, and obtain the target address information;

[0093] The slave response data is forwarded to the data frame buffer of the corresponding host based on the target address information, the data forwarding is completed, and the data forwarding result is obtained.

[0094] Specifically, the data frame buffer in the host data frame management unit is scanned, and the data frame information stored in the current system is obtained by traversing the storage status of each level of the buffer, and its processing priority is determined in combination with the data frame attributes marked by the status register. The data frame status register contains a marking field, such as "to be sent", "processing" or "completed", which provides a basis for data frame sorting. The scanning operation traverses each buffer in a loop, and the scanning process of the current cache is described by the following formula:

[0095] in, Indicates cache scan results; Indicates the total number of cache areas; For the The data frame counter in each buffer indicates the number of frames stored; For the The priority weight of each cache area is used to distinguish the importance of different buffer levels; is a function that generates a sorting score for a buffer based on a counter and a priority weight. By calculating the scan results of all buffers, the current data frame status is classified and processed, and a data processing queue is generated according to the priority. After the data processing queue is generated, each data frame in the queue is validated to ensure that its integrity and check status meet the requirements. The integrity of the data frame is determined by the frame header and frame tail markers, and the check status is achieved by recalculating the check code and comparing it with the check field carried in the data frame. Assume that a data frame contains Data bits, checksum The calculation formula is:

[0096] in For the data bits, the value is 0 or 1; mod means modular operation, which is used to calculate the parity of the check bit. If the calculated check code is the same as the check code carried in the data frame If the data frame is consistent, the check is passed and the data frame is marked as a frame to be sent. The slave bus status is detected for the data frame to be sent to determine whether the RS485 slave bus is in an idle state. The slave bus status is indicated by the status register of the hardware interface. Assume that the bus idle state is marked as , which is defined as follows: ;

[0097] when When the system is idle, the system allows the data frame to be sent; otherwise, the system will wait for the bus to be released. After the bus is idle, the data frame is sent to the target slave through the RS485 slave interface, and a data sending record is generated. The sending record contains information such as the sending time, target address, and data length, which is used to track the communication process. After the data is sent, the response data returned by the slave is monitored and received. The response data is received by monitoring the frame header mark returned by the slave, and the complete response data frame is parsed according to the protocol. Assume that the length of the response data is , then its receiving time is expressed as:

[0098] in, Indicates the receiving time; Indicates the total length of the response data frame; is the baud rate. After successfully receiving the slave response data, perform address resolution on it. Address resolution is to determine the target host of the response data based on the target address field carried in the response data frame. Assume that the target address field is , whose value is passed through the data frame parsing function Get: ;

[0099] in, Indicates the complete content of the response data frame; is a parsing function used to extract the target address. After parsing the target address, the response data frame is forwarded to the data frame buffer of the corresponding host, and the data is stored according to the first-in-first-out principle. The integrity and order of the forwarding operation are maintained by the read and write pointers of the target host buffer. The write pointer update formula is: ;

[0100] in, The write pointer position of the target host buffer area; Indicates the total capacity of the buffer. After the data forwarding process is completed, a complete data forwarding result is generated, including the forwarding success status, the target host address and the data frame content, providing a record for the subsequent communication process.

[0101] Before performing task scheduling timing processing based on the data forwarding result, it also includes: extracting timing features from historical data frame transmission records, calculating feature parameters such as data frame length distribution, transmission delay mean, packet loss rate fluctuation, etc. based on a sliding time window, establishing a feature vector matrix, and performing data standardization processing on the feature vector matrix to obtain a data transmission feature vector; inputting the data transmission feature vector into a sparse Bayesian learning model, using a variational inference method to establish a priori probability distribution, optimizing the model parameters by maximizing the marginal likelihood function, setting an L1 regularization constraint to control the model complexity, and obtaining an initial prediction model; performing parameter decomposition on the initial prediction model, constructing a unitary matrix transformation using the Schmidt orthogonalization method, projecting the prediction parameters into an orthogonal subspace, dividing the prediction task according to the principle of computational complexity balance, obtaining N independent estimators, and allocating corresponding feature subsets and computing resources to each estimator to obtain an estimator group; constructing a message passing network based on the estimator group, designing a message update rule based on an expectation propagation algorithm, transmitting probability distribution information between estimators through an iterative calculation process, realizing collaborative optimization of parameters, and setting a convergence condition to control the number of iterations, and obtaining to the optimized estimator group; the output results of the optimized estimator group are weighted and fused according to the preset weights, and the prediction bias of a single estimator is eliminated by an integrated learning strategy, and a comprehensive evaluation index system is constructed, including the transmission delay prediction value, the packet loss rate prediction value and the bandwidth utilization prediction value, to obtain the performance evaluation result; a multi-level dynamic threshold mechanism is established for the performance evaluation result, and the alarm threshold and tolerance range of each indicator are dynamically adjusted by a fuzzy control algorithm according to real-time status parameters such as system load rate and network congestion, to obtain the performance monitoring threshold; a real-time evaluation module is constructed based on the performance monitoring threshold, and a sliding window method is used to continuously monitor the change trend of the performance indicator. When a performance degradation trend is detected or the indicator is lower than the threshold, a hierarchical optimization strategy is started, and an optimization instruction including an optimization level and a trigger time is generated to obtain an optimization trigger signal; the optimization trigger signal is correlated with the current transmission status data, and a decision tree algorithm is used to select the optimal scheduling plan from the preset optimization strategy library, and the adjustment step of the optimization parameter is determined according to the degree of performance degradation, and a scheduling optimization instruction including a time slice reallocation plan, a priority adjustment plan and a cache area configuration plan is generated to obtain the scheduling optimization parameter.

[0102] In a specific embodiment, the process of executing step 500 may specifically include the following steps:

[0103] The transmission time of the data frame in the data forwarding result is calculated, and the data transmission period is obtained according to the data frame length and the RS485 communication rate. The data transmission period is divided into time slices according to the number of hosts, and a fixed time period is allocated to each host interaction task to obtain a time slice allocation table;

[0104] Prioritize the tasks in the time slice allocation table, set the processing order according to the urgency of data transmission, obtain the task priority table, and input the task priority table into the scheduling control unit, allocate the execution time according to the priority order, and obtain the task execution sequence;

[0105] Set a timeout threshold for the task execution sequence, set the maximum execution time according to the data transmission cycle, obtain the task timeout parameter, and apply the task timeout parameter to the task execution process, record the start time and end time of the task, and obtain the task execution record;

[0106] Perform time analysis on the task execution records, calculate the deviation between the actual execution time and the preset time, obtain the timing adjustment value, and optimize the task scheduling based on the timing adjustment value, update the time slice allocation and priority setting, and obtain the task scheduling sequence.

[0107] Specifically, the transmission time of the data frame in the data forwarding result is calculated. The transmission time of the data frame Depends on the length of the data frame and RS485 communication rate , and its calculation formula is:

[0108] in, Indicates the transmission time of the data frame; Indicates the length of the data frame; Indicates the communication rate of RS485; the total number of bits in the data frame is determined by the byte length Multiply by 8 bits per byte. After calculating the transmission time of each frame of data, divide these time periods into the number of hosts. Time slices are divided to ensure that each host interaction task is assigned to a fixed time period. Assume that the total available time is the cumulative sum of all data frame transmission times, then the average time slice of each host is It is expressed as:

[0109] in, It is the sum of all data frame transmission cycles in the system; is the number of hosts participating in task scheduling; It is the basic time slice allocated to each host task. Based on the result of time slice division, the task is prioritized to determine the execution order of the tasks. The priority is set according to the urgency of data transmission, which is determined by a comprehensive evaluation of the importance and timeliness of the task. Assume that the urgency of each task is expressed by Indicates that the higher the value, the higher the task priority. The order of the task queue is expressed as: ;

[0110] in, Indicates The priority weight of each task; Sort is a function that sorts tasks from high to low priority; the priority sorting result determines the execution order of tasks within the time slice. After the priority queue is input into the scheduling control unit, the execution time of tasks is allocated in turn according to the priority to generate a task execution sequence. Each task in the task execution sequence needs to set a timeout threshold To prevent a task from exceeding the expected time and affecting the overall scheduling of the system. The setting of the timeout threshold is related to the data transmission cycle, and its formula is: ;

[0111] in, is the maximum execution time of the task; is the timeout factor used to adjust the tolerance range (for example, 1.1 means 10% extra time is allowed). The actual execution process of the task needs to record its start time and end time , the record can be represented as:

[0112] Task execution time ;

[0113] This record provides data support for subsequent time analysis. After the task is completed, the task execution record is analyzed to calculate the deviation between the actual execution time and the preset time. The calculation formula is: ;

[0114] in, is the actual execution time of the task; is the scheduled execution time of the task. Based on the deviation value , optimize the task scheduling. For example, when the actual execution time of some tasks obviously exceeds expectations, readjust the time slice allocation, allocate more time slices to the tasks that take longer, and reduce the time slices of other tasks. This optimization is completed by updating the time slice allocation table and priority setting to generate a new task scheduling sequence.

[0115] In a specific embodiment, the process of executing step 600 may specifically include the following steps:

[0116] Detect the host communication status in the task scheduling sequence, count the host response status, obtain the host online record, and analyze the host online record. Determine the online status by judging the host response timeout and obtain the number of online hosts.

[0117] Perform capacity statistics on the 5-level data buffer area in the host data frame management unit, calculate the ratio of used space to total space, obtain the stack utilization rate, and record and analyze the stack utilization rate, update the usage of data buffer areas at all levels in real time, and obtain a storage status report;

[0118] The success rate of data forwarding results is counted, the ratio of the number of successfully transmitted data frames to the total number of transmissions is calculated, the transmission success rate is obtained, and the transmission success rate is judged by a threshold. When it is lower than the preset threshold, an alarm message is generated to obtain a communication quality report;

[0119] Integrate the number of online hosts, storage status reports and communication quality reports to form system operation status data and obtain status monitoring records;

[0120] Generate an operation status report based on the status monitoring record, record various indicator parameters of system operation, and obtain the system operation status record.

[0121] Specifically, the host communication status in the task scheduling sequence is detected to count the host response. The host online status is recorded by monitoring whether a valid response data frame is received in the communication window of each host task. Assume that the host response time is , the communication timeout threshold is , the host's response status Defined as: ;

[0122] in, Indicates the online status of the host, 1 means online, 0 means offline; is the actual time the host responds; is the maximum response time allowed by the system. , get the number of online hosts :

[0123] in, is the total number of hosts; For the The online status of each host. The capacity of the 5-level data buffer in the host data frame management unit is counted to calculate the ratio of the used space to the total space and obtain the stack usage rate. Assume that the total capacity of each level of buffer is , the used space is , stack usage It is expressed as:

[0124] in, Indicates the total space of the cache; Indicates the currently used space; For stack utilization. Real-time updates The value of is used to generate storage status reports for data caches at all levels, including current usage, remaining space, and possible overflow risks. After completing cache statistics, the success rate of data forwarding results is counted to evaluate the reliability and efficiency of communication. Data transmission success rate Defined as the number of successfully transmitted data frames The total number of transmitted data frames Ratio of:

[0125] in, Indicates the number of successfully transmitted data frames; Indicates the total number of data frames attempted to be transmitted; is the data transmission success rate, in percentage. To ensure the communication quality, With preset threshold For comparison. When a communication quality alarm message is generated, it indicates the existence of link anomalies or equipment failures. After integrating the number of online hosts, cache status reports, and communication quality reports, an operation status data set is generated, namely, the status monitoring record. This record contains indicators such as host online status, cache usage, and data transmission success rate. Based on the status monitoring record, an operation status report is generated, which records the statistical data, trend analysis, and abnormal alarms of various key indicators.

[0126] The host expansion method based on RS485 bus in the embodiment of the present application is described above. The host expansion device 10 based on RS485 bus in the embodiment of the present application is described below. Figure 2 In the embodiment of the present application, an embodiment of the host expansion device 10 based on the RS485 bus includes:

[0127] The parameter configuration module 11 is used for configuring the parameters of the RS485 bus host interface to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter;

[0128] A construction module 12 is used to construct a 5-level data stack structure for the RS485 host interface group, each level of the data stack includes a data frame buffer, a data frame length counter and a data frame status register, and obtain a host data frame management unit;

[0129] The interactive task processing module 13 is used to perform host interactive task processing on the host data frame management unit, obtain the host data frame by monitoring the receiving flag of the RS485 bus host interface, and store the host data frame in the corresponding data frame buffer area;

[0130] The scheduling task processing module 14 is used to perform scheduling task processing on the host data frame in the host data frame management unit, and send the data frame to be sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, so as to obtain a data forwarding result;

[0131] The scheduling timing processing module 15 is used to perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain the task scheduling sequence;

[0132] The status monitoring module 16 is used to input the task scheduling sequence into the human-computer interaction task module for status monitoring, record the number of online hosts, data stack usage rate, data transmission success rate, and obtain system operation status records.

[0133] Through the cooperation of the above components, the function of supporting multiple host access in a single RS485 bus network is realized, which significantly improves the scalability and flexibility of the system, and enables multiple host devices to monitor and control slave devices at the same time. Through the design of the 5-level data stack structure, an independent data cache space is provided for each host interface, which effectively avoids data congestion and loss problems and improves the reliability of data interaction. The task scheduling mechanism based on time slices is adopted to reasonably allocate the communication resources of the host to ensure the real-time and fairness of multi-host data interaction. A complete data verification and protection mechanism is designed, including functions such as data frame integrity detection, checksum comparison and overflow protection, which significantly improves the accuracy and reliability of data transmission. A flexible parameter configuration function is realized, which supports independent configuration of the communication parameters of each RS485 interface to meet the communication requirements of different application scenarios. A comprehensive status monitoring function is provided to monitor the system operation status in real time, including indicators such as the host online status, data stack usage and transmission success rate, which is convenient for system maintenance and fault diagnosis.

[0134] See also Figure 3 , Figure 3 This is a schematic block diagram of the structure of an electronic device 300 provided in an embodiment of the present application. The electronic device 300 includes a processor 301 and a memory 302. The processor 301 and the memory 302 are connected via a device bus 303, wherein the memory 302 may include a non-volatile storage medium and an internal memory.

[0135] The non-volatile storage medium can store a computer program. The computer program includes program instructions, and when the program instructions are executed by the processor 301, the processor 301 can execute any of the above host expansion methods based on the RS485 bus.

[0136] The processor 301 is used to provide computing and control capabilities to support the operation of the entire electronic device 300 .

[0137] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor 301, the processor 301 can execute any of the above host expansion methods based on the RS485 bus.

[0138] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a partial structure related to the present application scheme, and does not constitute a limitation on the electronic device 300 involved in the present application scheme. The specific electronic device 300 may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0139] It should be understood that the processor 301 may be a central processing unit (CPU), and the processor 301 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0140] It should be noted that those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the electronic device 300 described above can refer to the corresponding process of the aforementioned host expansion method based on RS485 bus, which will not be repeated here.

[0141] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by one or more processors, the one or more processors implement the host expansion method based on the RS485 bus as provided in the embodiment of the present application.

[0142] The computer-readable storage medium may be an internal storage unit of the electronic device 300 in the aforementioned embodiment, such as a hard disk or memory of the electronic device 300. The computer-readable storage medium may also be an external storage device of the electronic device 300, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped with the electronic device 300.

[0143] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0144] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable an electronic device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.

[0145] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A host expansion method based on RS485 bus, characterized in that, The method comprises: The RS485 bus host interface is parameterized to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter; The RS485 host interface group is constructed into a 5-level data stack structure, wherein each level of data stack comprises a data frame buffer, a data frame length counter and a data frame status register, and a host data frame management unit is obtained; The host data frame management unit performs host interaction task processing, obtains the host data frame by monitoring the receiving flag of the RS485 bus host interface, and stores the host data frame in the corresponding data frame buffer area; The host data frame in the host data frame management unit is subjected to scheduling task processing, and the data frame to be sent is sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, so as to obtain a data forwarding result; Perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain a task scheduling sequence; The task scheduling sequence is input into the human-computer interaction task module for status monitoring, and the number of online hosts, data stack usage rate, and data transmission success rate are recorded to obtain a system operation status record.

2. The host expansion method based on RS485 bus according to claim 1, characterized in that, The RS485 bus host interface is parameterized to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter, including: Connect the UART port of the single-chip microcomputer, connect the TX pin to the DI terminal of the RS485 transceiver to obtain a transmission channel, and connect the UART port of the single-chip microcomputer, connect the RX pin to the RO terminal of the RS485 transceiver to obtain a receiving channel; Connect the control port of the single chip microcomputer, connect the control pin to the DE terminal and RE terminal of the RS485 transceiver, and obtain a direction control channel; The baud rate parameter of the transmission channel is set within the range of 1200 bps to 115200 bps to obtain baud rate configuration data; The data bit parameter of the receiving channel is set to a fixed 8 bits to obtain data bit configuration data; Setting the stop bit parameter of the receiving channel to 1 bit or 2 bits to obtain stop bit configuration data; Setting the check mode of the receiving channel to one of no check, odd check or even check to obtain check bit configuration data; The baud rate configuration data, the data bit configuration data, the stop bit configuration data and the check bit configuration data are written into the non-volatile memory of the single-chip computer to obtain an independently configured RS485 host interface group.

3. The host expansion method based on RS485 bus according to claim 1, characterized in that, The RS485 host interface group is constructed into a 5-level data stack structure, each level of the data stack includes a data frame buffer, a data frame length counter and a data frame status register, and a host data frame management unit is obtained, including: The data communication format of the RS485 host interface group is configured, and the start bit, data bit, check bit and stop bit of the data frame are divided to obtain the data frame format standard; Allocate storage to the MCU RAM space, allocate a fixed-size storage space of 256 bytes to each data stack, and obtain a data frame storage area; The data frame storage area is partitioned into five levels, and five independent data frame buffer areas are constructed according to the first-in-first-out principle to obtain a five-level data buffer area, and a read-write pointer is set for the five-level data buffer area, and a data access pointer is obtained by indicating a data read position through a read pointer and indicating a data write position through a write pointer; Counting the length of the data frame pointed to by the data access pointer, recording the actual number of bytes of each data frame, obtaining a data frame length counter, and marking the status of the data frame corresponding to the data frame length counter, marking the processing status of the data frame, and obtaining a data frame status register; Perform overflow protection setting on the 5-level data buffer area, set the overflow protection value and underflow protection value of the buffer area, and obtain an overflow protection mechanism; The overflow protection mechanism is applied to the 5-level data buffer area, and a data frame buffer area, a data frame length counter and a data frame status register are integrated to obtain a host data frame management unit.

4. The host expansion method based on RS485 bus according to claim 1, characterized in that, The host data frame management unit performs host interaction task processing, obtains the host data frame by monitoring the receiving flag of the RS485 bus host interface, and stores the host data frame in the corresponding data frame buffer area, including: The data receiving flag of the RS485 bus host interface is monitored to determine the receiving state of the host data, obtain the host communication state, and perform data integrity detection on the host communication state, confirm the reception of the complete data frame through the receiving flag bit, and obtain the host receiving data; Verify the data received by the host, generate a check code according to the check bit parameter and compare it with the received check code to obtain a data verification result, and screen the data verification result, mark the data that passes the verification as a valid data frame, and obtain a valid data mark; Allocate a cache area for the data frame corresponding to the valid data mark, determine the storage position in the 5-level data cache area, obtain a storage position pointer, and write the data frame pointed to by the storage position pointer into the corresponding data frame cache area, complete data storage according to the first-in-first-out principle, and obtain a cached data frame; The cached data frames are counted, the total number of data frames and the length of a single frame are recorded, a data frame statistic is obtained, the data frame statistic is combined and encapsulated with the cached data frame, a host data frame is generated according to a preset data structure, and the host data frame is stored in a corresponding data frame cache area.

5. The host expansion method based on RS485 bus according to claim 1, characterized in that, The scheduling task processing is performed on the host data frame in the host data frame management unit, and the data frame to be sent is sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, to obtain the data forwarding result, including: Scanning the data frame buffer area in the host data frame management unit, checking the data storage status of the buffer areas at all levels, obtaining a buffer scanning result, and prioritizing the data frames in the buffer scanning result, determining the processing order according to the mark of the data frame status register, and obtaining a data processing queue; The data frames in the data processing queue are verified for validity, the integrity and verification status of the data frames are confirmed, the data frames to be sent are obtained, and the slave bus state detection is performed on the data frames to be sent, and it is determined whether the RS485 slave bus is in an idle state, and a bus state mark is obtained; Sending a data frame based on the bus status mark, sending the data frame to the target slave through the RS485 slave interface, obtaining a data sending record, performing response monitoring on the data sending record, receiving a response data frame returned by the slave, and obtaining slave response data; Performing address resolution on the slave response data, determining the target host according to the address information in the data frame, and obtaining the target address information; The slave response data is forwarded to the data frame buffer area of ​​the corresponding host based on the target address information, the data forwarding is completed, and a data forwarding result is obtained.

6. The host expansion method based on RS485 bus according to claim 1, characterized in that, The task scheduling timing processing is performed based on the data forwarding result, a fixed time slice is allocated to each host interaction task, the data transmission time and task priority are set, and the task scheduling sequence is obtained, including: Calculate the transmission time of the data frame in the data forwarding result, obtain the data transmission period according to the data frame length and the RS485 communication rate, divide the data transmission period into time slices according to the number of hosts, allocate a fixed time period to each host interaction task, and obtain a time slice allocation table; Prioritize the tasks in the time slice allocation table, set the processing order according to the urgency of data transmission, obtain a task priority table, input the task priority table into the scheduling control unit, allocate execution time according to the priority order, and obtain a task execution sequence; Setting a timeout threshold for the task execution sequence, setting a maximum execution time according to the data transmission cycle, obtaining a task timeout parameter, and applying the task timeout parameter to the task execution process, recording the start time and end time of the task, and obtaining a task execution record; Perform time analysis on the task execution record, calculate the deviation between the actual execution time and the preset time, obtain the timing adjustment value, and optimize the task scheduling based on the timing adjustment value, update the time slice allocation and priority setting, and obtain the task scheduling sequence.

7. The host expansion method based on RS485 bus according to claim 1, characterized in that, The task scheduling sequence is input into the human-computer interaction task module for status monitoring, recording the number of online hosts, data stack usage rate, and data transmission success rate, and obtaining a system operation status record, including: Detecting the host communication status in the task scheduling sequence, counting the host response status, obtaining the host online record, and analyzing the host online record, determining the online status by judging the host response timeout, and obtaining the number of online hosts; Perform capacity statistics on the 5-level data buffer area in the host data frame management unit, calculate the ratio of used space to total space, obtain the stack utilization rate, record and analyze the stack utilization rate, update the usage of data buffer areas at all levels in real time, and obtain a storage status report; The success rate of the data forwarding result is counted, the ratio of the number of successfully transmitted data frames to the total number of transmissions is calculated to obtain the transmission success rate, and the transmission success rate is subjected to a threshold judgment. When it is lower than a preset threshold, an alarm message is generated to obtain a communication quality report; Integrate the number of online hosts, the storage status report and the communication quality report to form system operation status data and obtain a status monitoring record; Based on the status monitoring record, an operation status report is generated to record various index parameters of the system operation to obtain a system operation status record.

8. A host expansion device based on RS485 bus, characterized in that: Used to execute the host expansion method based on RS485 bus as described in any one of claims 1 to 7, the host expansion device based on RS485 bus comprises: The parameter configuration module is used for performing parameter configuration on the RS485 bus host interface to obtain an independently configured RS485 host interface group, wherein the RS485 host interface group includes a baud rate parameter, a data bit parameter, a stop bit parameter and a check bit parameter; A construction module is used to construct a 5-level data stack structure for the RS485 host interface group, each level of the data stack includes a data frame buffer, a data frame length counter and a data frame status register, and obtain a host data frame management unit; An interactive task processing module is used to perform host interactive task processing on the host data frame management unit, obtain host data frames by monitoring the receiving flag of the RS485 bus host interface, and store the host data frames in the corresponding data frame buffer area; The scheduling task processing module is used to perform scheduling task processing on the host data frame in the host data frame management unit, and send the data frame to be sent to the target slave through the RS485 slave interface when the RS485 slave bus is idle, so as to obtain a data forwarding result; A scheduling timing processing module, used to perform task scheduling timing processing based on the data forwarding result, allocate a fixed time slice to each host interaction task, set the data transmission time and task priority, and obtain a task scheduling sequence; The status monitoring module is used to input the task scheduling sequence into the human-computer interaction task module for status monitoring, record the number of online hosts, data stack usage rate, data transmission success rate, and obtain system operation status records.

9. An electronic device, characterized in that: The electronic device comprises: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instructions in the memory so that the electronic device executes the host expansion method based on RS485 bus as described in any one of claims 1-7.

10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, a host expansion method based on the RS485 bus as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Shared bus polling method and device based on collaborative multi-task scheduling mechanism

    CN106569897A

  • Modbus RTU bus controller and control method

    CN109951366A

  • Data communication method, device and equipment and computer readable storage medium

    CN112491675A

  • Master-slave station communication method and system

    CN113938350A

  • Information communication method and device, computer equipment and storage medium

    CN115982072A

Cited By

  • Hardware acceleration equipment management system and method applied to network security product

    CN120909969A

  • Special equipment display screen data interaction method with CAN communication

    CN121657958A

  • A data interaction method for display screen of special equipment with CAN communication

    CN121657958B