A bus communication method and system
By using RS232 daisy chain and RS485 bus to separately manage communication and data transmission in industrial automation systems, automatic allocation of logical addresses and status monitoring are achieved, solving the real-time and efficiency problems in bus communication, and supporting topology self-healing and fault isolation during hot-plugging.
Patent Information
- Application Number
- CN202611201840.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-10
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, the bus communication method in industrial automation distributed input/output systems suffers from problems such as reduced real-time communication due to the shared medium for heartbeat monitoring and data transmission, increased workload due to manual configuration of logical address dependencies, high probability of address conflicts, and data collisions and arbitration failures when multiple slave stations share the bus.
The RS232 daisy chain and RS485 bus are used to manage communication and data transmission separately. The logical address is automatically allocated and the status is monitored through enumeration frames and health polling frames. The aggregated data frame broadcast and logical address sequential time-division response are used to eliminate bus collisions and improve transmission efficiency.
It achieves physical and logical isolation between management communication and data transmission, improves the real-time performance and utilization efficiency of bus communication, solves the problems of automated address configuration and low communication efficiency, and supports topology self-healing and fault isolation during hot-plugging.
Smart Images

Figure CN123115028A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial automation control and fieldbus communication technology, and in particular to a bus communication method and system for distributed input / output systems, which can also be referred to as a fieldbus system (FBUS) in practical engineering applications. Background Technology
[0002] In industrial automation distributed input / output (I / O) systems, the master node and multiple remote slave modules typically communicate via a fieldbus. In existing solutions, device identification, heartbeat detection, and input / output data reading / writing usually share the same physical bus medium.
[0003] This bus communication method has the following drawbacks: First, management communication frames such as heartbeat monitoring share the same channel as data communication frames. The transmission of management communication frames occupies the data transmission window, and large-scale data read / write operations can easily cause heartbeat response delays, resulting in reduced real-time communication and false heartbeat timeouts. Second, the logical address allocation of slave modules often relies on hardware DIP switches, increasing the workload of manual configuration and the probability of address conflicts. Third, the traditional master-slave polling mechanism requires each slave module to initiate an independent request and response, resulting in multiple frame header overheads and inter-frame idle intervals, leading to low utilization of the bus's effective data load. Fourth, when multiple slaves share the bus, without orderly time-division control, data collisions and bus arbitration failures can easily occur on the shared transmission medium.
[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] In view of this, the present invention provides a bus communication method and system, aiming to solve the problems of timing interference, manual configuration of logical addresses, and low data interaction efficiency caused by the shared medium for bus communication management and data transmission in the prior art. By deploying RS232 daisy chain and RS485 bus, the RS232 daisy chain is used to transmit enumeration frames and health polling frames to complete the automatic allocation of logical addresses and status monitoring. The RS485 bus broadcasts aggregated data frames containing read and write instructions of multiple slave modules and time-division response according to logical address order, thereby realizing physical and logical isolation between device management and data communication, completing automatic address allocation without DIP switches, and improving bus transmission efficiency and real-time performance.
[0006] This invention provides a bus communication method, including: The master node constructs an enumeration frame containing a device count field and sends it to the RS232 daisy chain. Each slave module reads the device count field in sequence to determine its own logical address, increments the device count field and appends its own device type information before forwarding it. The end slave module sends the processed enumeration frame back to the master node. The master node sends health polling frames to the RS232 daisy chain at a preset period. Each slave module receives the health polling frame, rewrites the corresponding running status field, and forwards it. The master node parses the returned health polling frame to determine the online status of each slave module. The master control node merges the read and write commands of each slave module that is online and in normal condition to generate an aggregated data frame, and broadcasts it on the RS485 bus; Each slave module receives the aggregated data frame and performs input / output channel read / write operations. Each slave module controls the enable pin of its own RS485 transceiver to switch to transmit mode in sequence according to the determined logical address order, and uses the RS485 bus in a time-division multiplexing manner to send response data.
[0007] In some optional embodiments, when the end slave module sends back the enumeration frame, the end slave module transmits the enumeration frame up to the master node station by station along the reverse transmission path of the RS232 daisy chain.
[0008] In some optional embodiments, after the master node receives the enumeration frame, it parses the device type information in the enumeration frame, creates a node structure for each slave module in physical memory and constructs a doubly linked list, and allocates a contiguous storage index range for each slave module in the global data array.
[0009] In some optional embodiments, when sending enumeration frames, the master node manages the process through a state machine: when in the initial state, the first frame is sent and the process transitions to the waiting-for-response state; if no valid return frame is received within the preset retransmission interval, the waiting-for-response state is maintained and the enumeration frame is retransmitted; if a valid return frame is received, the process transitions to the completion state.
[0010] In some optional embodiments, determining the online status of each slave module includes: The master node maintains a first timeout counter for each slave module; If a health polling frame for rewriting the status of a slave module is not received within the preset waiting time, the first timeout counter corresponding to the slave module will be incremented by one. When the value of the first timeout counter continuously reaches the preset first threshold, the master node marks the slave module as having a communication failure state and removes the slave module from the list of generating aggregated data frames.
[0011] In some optional embodiments, information entries containing heartbeat request flags and data placeholders are reserved for each slave module in the health polling frame; when each slave module matches its own information entry and the status is heartbeat request flag, it rewrites the heartbeat request flag to the actual operating status value and writes the collected temperature data or the number of relay actions into the data placeholders.
[0012] In some optional embodiments, after a slave module marked as having a communication failure state resumes communication, when the master node receives the rewritten health polling frame from the slave module again on the RS232 daisy chain, it will clear the first timeout counter of the slave module and migrate the slave module back to the normal state to resume generating the corresponding aggregated data frame.
[0013] In some optional embodiments, when generating an aggregated data frame, the master node traverses each slave module in a normal state, writes write instructions and output data for output slave modules, writes read instructions and data placeholder space for input slave modules, and concatenates the read and write instructions of each slave module into a composite frame containing the total length of sub-messages and the slave number count.
[0014] In some optional embodiments, when each slave module occupies the RS485 bus to send response data, the master node maintains a second timeout counter on the RS485 bus for each slave module; when the number of times a slave module fails to send response data on the RS485 bus reaches a preset second threshold, the master node marks the slave module as having a communication failure state.
[0015] In some optional embodiments, before each slave module occupies the RS485 bus to send response data, each slave module detects the level status on the RS485 bus to determine whether the bus is idle; when the bus is idle and the transmission timing corresponding to its own logical address is reached, the slave module controls the enable pin of its own RS485 transceiver to switch to high-level transmission mode, and after the transmission is completed, the enable pin is switched back to low-level reception mode.
[0016] In some optional embodiments, when each slave module controls the enable pin, a state machine maintains the bus idle state, the occupied transmit state, and the waiting-to-release state; when a bus level change is detected or a transmit completion event is triggered, the state machine is driven to transition between the idle state, the occupied transmit state, and the waiting-to-release state.
[0017] In some optional embodiments, when the master node receives data frames from an RS232 daisy chain or an RS485 bus, the serial port direct memory access controller is configured to loop mode, the received serial port data is continuously written into a circular buffer in physical memory, and the data frames are parsed from the circular buffer through a timer interrupt service routine.
[0018] In some optional embodiments, a global fault convergence register in bitmap format is maintained in the physical memory of the master node, where each binary bit in the bitmap corresponds to the logical address of a slave module; when any slave module is in an abnormal state, the master node sets the corresponding binary bit; when all slave modules are in a normal state, the global fault convergence register is cleared.
[0019] In some optional embodiments, when accessing data from a slave module, the data is read and written by locating the corresponding storage index range in the global data array based on the logical address of the target slave module through the global read / write interface, thereby shielding the physical connection order of the slave modules on the RS232 daisy chain.
[0020] In some optional embodiments, when monitoring bus communication quality, the master node accumulates the number of successful transmissions, the expected number of replies, and the actual number of replies in physical memory in real time, calculates the bus packet loss rate based on the expected number of replies and the actual number of replies, and writes the calculated packet loss rate into the system status register.
[0021] In some optional embodiments, a unified frame format is used when transmitting data frames on RS232 daisy chain and RS485 bus. The unified frame format includes a frame initiator identifier field, a function code field, a sub-message length field, a device count field, a variable-length sub-message content field, and a frame tail check field that covers the frame initiator identifier to the end of the sub-message.
[0022] This invention provides a bus communication system, comprising: The device enumeration module is configured such that the master control node constructs an enumeration frame containing a device count field and sends it to the RS232 daisy chain. Each slave module reads the device count field in sequence to determine its own logical address, increments the device count field and appends its own device type information before forwarding it. The end slave module sends the processed enumeration frame back to the master control node. The health polling module is configured so that the master node sends health polling frames to the RS232 daisy chain at a preset period. Each slave module receives the health polling frame, rewrites the corresponding running status field, and forwards it. The master node parses the returned health polling frame to determine the online status of each slave module. The data aggregation module is configured so that the master node merges the read and write commands of each slave module with a normal online status to generate an aggregated data frame, and broadcasts it on the RS485 bus; The response interaction module is configured so that each slave module receives aggregated data frames and performs input / output channel read / write operations. Each slave module controls the enable pin of its own RS485 transceiver to switch to transmit mode in sequence according to the determined logical address order, and uses the RS485 bus in a time-division multiplexing manner to send response data.
[0023] In some optional embodiments, a fault determination module is also included, configured to have the master node maintain a first timeout counter for each slave module; when a health polling frame for rewriting the status of a slave module is not received within a preset waiting time, the first timeout counter corresponding to the slave module is incremented by one; when the value of the first timeout counter continuously reaches a preset first threshold, the master node marks the slave module as a communication fault state and removes the slave module from the list of generating aggregated data frames.
[0024] In some optional embodiments, a bus arbitration module is also included, configured to detect the level status on the RS485 bus to determine whether the bus is idle before each slave module occupies the RS485 bus to send response data; when the bus is idle and the transmission timing corresponding to its own logical address is reached, the enable pin of its own RS485 transceiver is controlled to switch to high-level transmission mode, and after the transmission is completed, the enable pin is switched back to low-level reception mode.
[0025] In some optional embodiments, a status aggregation module is also included, configured to maintain a global fault aggregation register in a bitmap format in the physical memory of the master node, wherein each binary bit in the bitmap corresponds to the logical address of a slave module; when any slave module is in an abnormal state, the master node sets the corresponding binary bit; when all slave modules are in a normal state, the global fault aggregation register is cleared.
[0026] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention.
[0027] The bus communication method and system of the present invention have the following beneficial effects: By setting up independent RS232 daisy chains and RS485 buses, management communication and data transmission are decoupled at the physical layer, avoiding heartbeat polling from occupying the data communication window; automatic allocation of device logical addresses without DIP switches is achieved through daisy chains; and collision conflicts on the shared data bus are eliminated by adopting aggregated data frame broadcasting and time-division enabling control based on logical addresses, reducing frame header overhead and inter-frame idle time, and improving the real-time performance and utilization efficiency of bus communication. Attached Figure Description
[0028] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.
[0029] Figure 1 This is a flowchart of a bus communication method according to an embodiment of the present invention; Figure 2This is a schematic diagram of a dual-bus system architecture according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the device identification daisy chain being added station by station according to an embodiment of the present invention; Figure 4 This is a master state machine transition diagram of a three-stage protocol according to an embodiment of the present invention; Figure 5 This is a schematic diagram of the health polling daisy chain station-by-station backfilling according to an embodiment of the present invention; Figure 6 This is a schematic diagram of the structure of a bus communication system according to an embodiment of the present invention. Detailed Implementation
[0030] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the invention will be more comprehensive and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0031] Furthermore, the accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0032] The flowchart shown in the attached diagram is merely an illustrative example and does not necessarily include all steps. For example, some steps may be broken down, while others may be combined or partially combined. Therefore, the actual execution order may change depending on the specific circumstances.
[0033] In distributed multi-node communication, channel separation and decoupling refers to independently dividing the management state maintenance path and the high-throughput data interaction path in the physical medium and transmission time domain, eliminating channel contention, latency jitter, and communication window encroachment caused by heartbeat control frames and data payload frames on the same physical medium. Step-by-step serial topology progression utilizes the forward and reverse transmission characteristics of point-to-point physical connections between nodes, transmitting data hop-by-hop along the topology path and accumulating information to achieve adaptive resolution and logical order determination of node physical topology relationships in a configuration without physical switches. Data aggregation and time-division arbitration integrate multi-node read / write instructions into a single broadcast payload to eliminate redundant frame headers and inter-frame idle overhead, and combines this with time-domain phase partitioning control based on node logical order to drive medium transmit / receive enable, achieving conflict-free response on a half-duplex shared medium. The application of these mechanisms establishes a parallel dual-channel control system where management control and data transmission are independent. On the one hand, it eliminates the encroachment of management frames on the data bus time window to reduce communication latency; on the other hand, it ensures shared bus utilization efficiency and communication timing accuracy through deterministic time-domain allocation.
[0034] like Figure 1 and Figure 2 As shown, this invention provides a bus communication method applied to a dual-bus communication system consisting of a master node (master station) and multiple slave modules (slave station 1, slave station 2...slave station N). The system deploys two independent serial buses at the physical layer: The first group is an RS232 daisy-chain management bus using the RS232 level standard, specifically used for transmitting device enumeration frames and health polling frames. The master node is equipped with a first serial port, and each slave module is equipped with a first serial port facing upstream and a second serial port facing downstream. In the forward transmission path, the transmitter (TX) of the master node's first serial port is connected to the receiver (RX) of slave 1's first serial port; the transmitter (TX) of slave 1's second serial port is connected to the receiver (RX) of slave 2's first serial port, and so on, forming a point-to-point topology. Utilizing the full-duplex nature of RS232, the daisy chain also includes a reverse transmission path, where the last slave N sends data to the receiver (RX) of the previous slave via the transmitter (TX) (or reverse transmitter) of its second serial port, relaying it upstream station by station to the receiver (RX) of the master node's first serial port.
[0035] The second group is an RS485 shared data bus using the RS485 differential level standard. The master node and each slave module are equipped with RS485 transceivers. The differential pins A and B of all RS485 transceivers are connected in parallel to the same pair of A / B differential signal lines, which are specifically used to transmit aggregated data frames.
[0036] The bus communication method in this embodiment includes the following collaborative steps: In step S100, the master node constructs an enumeration frame containing a device count field and sends the enumeration frame to the RS232 daisy-chain management bus. Each slave module sequentially reads the device count field through the input serial port to determine its own logical address, then increments and updates the device count field, appends its own device type information to the frame, and forwards it to the next node through the output serial port. After completing the processing of the enumeration frame, the end slave module at the end of the link sends the processed enumeration frame back to the master node.
[0037] In some other alternative implementations, the physical level interface of the daisy-chain management bus can be replaced with a TTL serial level interface or an RS422 full-duplex interface, in addition to the RS232 standard.
[0038] In step S200, the master node sends health polling frames to the RS232 daisy-chain management bus at preset time intervals. After receiving the health polling frame, each slave module identifies the entries related to itself in the frame, rewrites and fills the corresponding running status fields, and then forwards the modified health polling frame downstream of the link. After receiving the health polling frame returned by the link, the master node determines the current online status of each slave module by parsing the data of each running status field in the frame.
[0039] In some other alternative implementations, the preset time interval can be adjusted within a range of 100 milliseconds to 5000 milliseconds, depending on the system's real-time response requirements.
[0040] In step S300, the master node traverses each slave module that is online and in normal condition, splices and merges its corresponding read instructions, write instructions or control parameters into a single aggregated data frame, and then broadcasts the aggregated data frame through the shared RS485 data bus.
[0041] In some other alternative implementations, the sub-instruction sequence contained within the aggregated data frame can be arranged in ascending order of the slave module's logical address, or it can be sorted and combined according to the data transmission priority.
[0042] In step S400, each slave module receives the aggregated data frame via the RS485 data bus and performs corresponding input / output channel read / write operations according to the instructions within the frame. Before preparing to send response data, each slave module, based on the timing window determined by the logical address in step S100, sequentially controls the enable pin of its own physical interface's RS485 transceiver to switch to the transmit enable state, and time-divisionally occupies the RS485 data bus to send back the corresponding response data segment. After the response data segment is sent, the enable pin is switched back to the receive enable state.
[0043] In some other alternative implementations, the enable pin can be controlled by a dedicated hardware timer of the microcontroller, or by sending a completion interrupt via the serial port in conjunction with a general-purpose GPIO pin to switch the level state.
[0044] In the above communication process, steps S100 and S200 establish a DIP-free address allocation and independent health monitoring mechanism through a point-to-point serial daisy-chain management bus, while steps S300 and S400 complete centralized data reading and writing and time-division response through a multi-point shared RS485 data bus. These two physically separate buses work in concert: the daisy-chain management bus handles dynamic link topology discovery and heartbeat diagnosis, preventing management messages from occupying the communication bandwidth of the shared data bus; the RS485 data bus uses the logical address determined by the daisy-chain management bus to achieve collision-free time-division transmission, while the master node dynamically constructs aggregated data frames based on the online status determined by the daisy-chain management bus, skipping offline or faulty modules and avoiding invalid occupation of the data bus time window. Through physical topology separation and control logic coordination, the technical problems of mutual encroachment between management communication and data communication timing, false alarms of hot-plug faults, and decreased bus utilization efficiency as the number of devices increases are solved.
[0045] Compared with existing technologies, this embodiment divides the physical interface into an independently operating daisy-chain management bus and a shared data bus, eliminating the crowding of high-frequency data interaction transmission windows by management heartbeat messages and ensuring the real-time read and write performance of input / output channels. Combined with time-division enabling control based on logical addresses and data aggregation broadcasting, it eliminates bus conflicts and duplicate frame header overhead during multi-node concurrent communication, improving the data transmission utilization efficiency of the shared medium. By utilizing dynamic logical address allocation and real-time online status monitoring, it achieves topology self-healing and fault isolation during the hot-plugging process of slave modules, eliminating the binding restrictions of physical connection order on upper-layer application software logic.
[0046] In one specific implementation, when the end-slave module sends back an enumeration frame, it transmits the enumeration frame upstream along the reverse transmission path of the RS232 daisy chain to the master node. The end-slave module determines that it is at the end of the daisy chain physical topology by detecting that its downstream-facing second serial port has no physical signal response within a preset timeout period.
[0047] Specifically, after updating the device count field within the enumeration frame and appending its own device type information, the end-slave module redirects the enumeration frame from the forward data receive buffer to the reverse data send buffer. The daisy-chain management bus has a full-duplex physical transmission channel, including a forward transmission path from the master node to each slave module, and a reverse transmission path from the end-slave module back to the master node. The end-slave module sends the enumeration frame in the reverse data send buffer to the second serial port of the previous-level slave module via the second serial port.
[0048] Each intermediate slave module is internally configured with a reverse data forwarding channel. When the second serial port of an intermediate slave module receives a reverse enumeration frame from downstream, the microprocessor triggers the serial port direct memory access (DMA) controller to directly transfer the received data packet to the transmit buffer of the first serial port and send it to the next higher-level slave module. This process is passed up the reverse transmission path station by station until the enumeration frame is transmitted to the receive serial port of the master node, completing the closed-loop return of topology information.
[0049] In some other alternative implementations, the intermediate slave module can also pass the reverse enumeration frame up station by station through a hardware switching circuit to physically connect the reverse receive pin of the second serial port with the reverse transmit pin of the first serial port; or, a serial port receive interrupt service routine can be used inside the microprocessor to realize the software bridge forwarding of data packets from the downstream serial port to the upstream serial port through a double buffer queue structure.
[0050] like Figure 3 As shown, during the automatic device enumeration process in step S100, the master node constructs an enumeration frame containing a frame initiator identifier, a function code, a device count field, and a frame tail checksum. In the enumeration frame sent by the master node, the initial device count field is set to 0.
[0051] The enumeration frame is sent by the transmitter (TX) of the first serial port of the master node and transmitted along the forward transmission path of the RS232 daisy-chain management bus: After receiving the enumeration frame from the receiver RX of the first serial port facing upstream from station 1, its microprocessor reads the device count field in the frame (currently 0), adds 1 to the value (i.e., 0+1=1) to determine its logical address in the system as 1; then, station 1 updates the device count field in the frame to 1, appends the device type code (e.g., the code representing the digital input DI module) stored in itself to the frame, recalculates the checksum (e.g., CRC16) covering the entire frame, and forwards it to the next node, station 2, by the transmitter TX of the second serial port facing downstream; After receiving an enumeration frame with a device count field of 1 on the first serial port facing upstream from station 2, the receiver RX reads the count and determines its own logical address as 2 (i.e., 1+1=2). Then, it increments the device count field to 2 and appends its own device type code (e.g., the code representing the digital output DO module) to the frame. After recalculating the checksum, the sender TX of the second serial port continues to forward it to the next slave module, and so on.
[0052] When the enumeration frame is forward-transmitted to the end slave module (slave N), the end slave module determines that it is at the end of the daisy-chain physical topology by detecting that its downstream-facing second serial port has no physical signal response within a preset timeout period. After updating the device count field (incrementing to N) and appending its own device type code, the end slave module redirects the enumeration frame from the forward data receive buffer to the reverse data send buffer.
[0053] The end-slave module utilizes the reverse transmission path in the full-duplex physical channel of the RS232 daisy chain management bus to send the processed enumeration frame to the receiving end RX of the next-level slave module through its downstream-facing second serial port transmitter TX (or reverse transmitter). The frame is then transmitted upwards station by station along the reverse transmission path by the reverse DMA forwarding channel configured within each intermediate slave module, and finally transmitted back to the receiving end RX of the first serial port of the master control node, thus completing the closed-loop acquisition of logical address allocation and device type topology information of the entire network of slave modules.
[0054] The above scheme utilizes the bidirectional full-duplex physical characteristics of daisy chains to achieve loopback transmission of topology discovery data without the need for additional physical wiring resources. This avoids channel contention and collisions between forward management control and reverse data backhaul, and improves the transmission determinism and reliability of the automatic bus topology enumeration process.
[0055] In one specific implementation, after the master node receives the enumeration frame, it parses the device type information in the enumeration frame, creates a node structure for each slave module in physical memory and constructs a doubly linked list, and allocates a contiguous storage index range for each slave module in the global data array. Upon receiving the enumeration frame transmitted back along the RS232 daisy chain, the master node extracts and parses the device type information and the total number of devices arranged in logical address order within the enumeration frame.
[0056] First, the master node dynamically allocates the corresponding number of device node structure spaces in physical memory based on the total number of devices resolved. Each device node structure contains a logical address field, a device type field, an online status field, a first timeout counter field, a second timeout counter field, a global index offset field, a health status data field, and pointers to the predecessor and successor nodes, respectively. The master node constructs a doubly linked list for dynamically maintaining information about each slave module by sequentially concatenating the pointers of the device node structures.
[0057] Specifically, the master node allocates a contiguous global data array in physical memory and, based on the channel data byte length corresponding to the parsed device type information, calculates the starting offset and data occupancy length of each slave module in the global data array. The master node then fills the calculated starting offset into the global index offset field of the corresponding device node structure, thereby allocating a contiguous and independent storage index range for each slave module in the global data array.
[0058] In some other alternative implementations, the device nodes can be organized using pointer arrays or static linked lists instead of doubly linked lists to manage slave module nodes under different memory allocation mechanisms. In other alternative implementations, the storage index range of the global data array can be divided into equal portions of fixed byte length, reserving storage space uniformly according to the maximum channel data requirements.
[0059] Compared with the prior art, this embodiment establishes a memory abstraction structure containing doubly linked lists and continuous index ranges for each slave module in the physical memory of the master node, thereby realizing the mapping between physical topology information and storage space and providing structured memory support for the dynamic management of slave modules and efficient data access.
[0060] In one specific implementation, such as Figure 4 As shown, the master control node integrates a three-stage protocol master state machine, configuring state machine variables and corresponding hardware timers in physical memory to achieve closed-loop control of the entire system lifecycle. The master state machine mainly includes the device identification state IDENTIFY, the normal operation state RUNNING, and the communication failure state COMM_FAULT.
[0061] After the system powers on or resets, the main state machine first enters the IDENTIFY state. In the IDENTIFY state, the main state machine further performs progressive control through sub-states: The master node initializes the master state machine, bringing it into the initial state INIT (marked as state 0 in the diagram). While in the initial state INIT, the master node constructs an enumeration frame containing an initial device count field (value 0) and sends it to the RS232 daisy-chain management bus. Simultaneously, it starts a hardware timer with a preset retransmission interval of 500 milliseconds, driving the master state machine to transition from the initial state INIT to the waiting-for-response state WAIT_RESP (marked as state 1 in the diagram). In the WAIT_RESP state, if the hardware timer times out and no return frame is received or the received data verification fails, a timeout retransmission event is triggered. The master node remains in the WAIT_RESP state and retransmits the enumeration frame. If the master node receives a valid return frame that has passed verification within the preset retransmission interval, it triggers an enumeration success event, driving the master state machine to transition from the waiting response state WAIT_RESP to the enumeration completion state DONE (marked as state 2 in the figure).
[0062] After the master node parses the device information and establishes a global mapping in the DONE state (enumeration complete state), it drives the master state machine to transition from the IDENTIFY state to the RUNNING state (normal operation state). In the RUNNING state, periodic health polling on the RS232 daisy chain and token aggregation data interaction on the RS485 bus run in parallel. When a slave module accumulates a preset threshold number of consecutive timeouts (e.g., the first timeout counter or the second timeout counter reaches 3), the fault isolation condition is triggered. The master state machine drives the slave module's state to transition from the normal operation state RUNNING to the communication fault state COMM_FAULT and removes it from the data broadcast list. When a slave module in the communication failure state COMM_FAULT responds to the health poll again and successfully rewrites the running status field, a state self-healing event is triggered. The master state machine then drives the slave module to transition from the communication failure state COMM_FAULT back to the normal running state RUNNING, resuming its data interaction.
[0063] Specifically, while waiting for a response, the master node continuously listens to the receiver buffer via direct access to the serial port memory. If the hardware timer reaches the preset retransmission interval and the master node does not receive the return frame, or the received return frame fails the cyclic redundancy check, the master node remains in the waiting response state, resets and starts the hardware timer, and sends the enumeration frame to the RS232 daisy chain management bus again. If the master control node receives a return frame within the preset retransmission interval, and the return frame is determined to be a valid data frame through cyclic redundancy check, the master control node immediately stops the hardware timer, drives the state machine to transition from the waiting response state to the completed state, and triggers the master control node to parse the device type information accumulated in the return frame.
[0064] In some other alternative implementations, the preset retransmission interval of the state machine can be dynamically adjusted using an incremental backoff algorithm, or the state transition control of the state machine can be replaced by periodic polling by a software timer task in the real-time operating system, instead of being triggered by a hardware timer interrupt.
[0065] Through the above scheme, this embodiment can achieve robust control of the automatic device enumeration process without DIP switches by cooperating with the state machine and the retransmission timer, effectively blocking the loss of enumeration frames caused by occasional interference or lack of readiness of communication cables, and ensuring reliable convergence of the system during the topology initialization phase.
[0066] In one specific implementation, based on the above embodiments, the master node allocates and maintains a first timeout counter in physical memory for each slave module.
[0067] Specifically, when the master node sends a health polling frame to the RS232 daisy chain, it initiates reception monitoring with a preset waiting time. If no health polling frame rewriting the running status of a slave module is received within the preset waiting time, the master node increments the value of the first timeout counter corresponding to that slave module in its physical memory. Then, the master node compares the current value of the first timeout counter with a preset first threshold. When the value of the first timeout counter continuously increases and reaches the preset first threshold, the master node modifies the running status identifier corresponding to that slave module in its physical memory, marks the slave module as having a communication failure state, and removes the logical address of that slave module from the online slave list for generating aggregated data frames, so that subsequent constructed aggregated data frames no longer contain read / write instructions for that slave module.
[0068] In some other alternative implementations, the accumulation and status determination of the first timeout counter can also be periodically triggered by an independent timer interrupt service routine inside the master control node, and the specific value of the preset first threshold can be dynamically configured to any integer between 2 and 5 according to the intensity of electromagnetic interference on site.
[0069] Through the above scheme, this embodiment can replace the single timeout judgment with a continuous timeout accumulation judgment mechanism, effectively filtering out occasional electromagnetic interference and instantaneous communication jitter in the industrial field, preventing the normally operating slave module from being mistakenly switched to an offline fault state, and greatly reducing the false alarm rate of communication faults in the system.
[0070] In one specific implementation, such as Figure 5 As shown, in the health status polling phase of step S200, the master node constructs a health polling frame containing information entries for each known logical address slave module. The master node initializes the heartbeat request flag in each information entry to a preset request code value of 0x00, fills the subsequent data placeholder space with a default zero value, and then sends it from the transmitter TX of the first serial port to the forward transmission path of the RS232 daisy-chain management bus.
[0071] Health polling frames are transmitted along the forward transmission path: When the receiver RX1 of the first serial port facing upstream of station 1 receives the frame, the microprocessor matches the information entry belonging to its own logical address 1; when it recognizes that the current heartbeat request flag is 0x00, station 1 rewrites the heartbeat request flag to the status code 0x01 representing normal operation, and formats and writes the onboard temperature sensor data obtained by internal sampling and the cumulative number of relay contact actions recorded in the non-volatile memory into the corresponding placeholder space. After recalculating the check code, it is sent to the next node station 2 by the transmitter TX2 of the second serial port facing downstream. After receiving the rewritten health polling frame from the receiver RX1 of the first serial port of station 2, it matches the entry of its own logical address 2, and similarly rewrites the heartbeat request flag from 0x00 to 0x01. It also writes the internally collected temperature data and the cumulative number of relay contact actions into the placeholder space, and after re-verification, it forwards it downstream from the transmitter TX2 of its second serial port. Subsequently, each slave module sequentially performs the same heartbeat flag rewriting (from 0x00 to 0x01) and health data entry actions.
[0072] After the end slave module (slave N) finishes processing, it redirects the rewritten complete health polling frame to the reverse transmission path. The end slave module sends the frame to the receiver RX2 of the previous slave module through its second serial port transmitter TX2 (or reverse transmitter), and it is then passed up the transmission station by station by station through the reverse DMA channel of each intermediate slave module (between the second serial port receiver RX2 and the first serial port transmitter TX1), and finally back to the receiver RX of the first serial port of the master node.
[0073] The master node receives and parses the returned health polling frames: The master node retrieves the status value of each information entry. If the center jump request flag of an information entry of a slave module is still 0x00 (i.e., it has not been rewritten to 0x01), it is determined that the slave module has not made a polling response this time. The master node increments the first timeout counter corresponding to the slave module in physical memory. When the first timeout counter continuously increases to the preset first threshold (e.g., 3 times), the master node sets the slave module to a communication failure state and removes it from the broadcast list of the aggregated data frame.
[0074] In some other alternative implementations, the heartbeat request flag and the actual operating status value can also be in the form of multi-bit binary encoding to transmit status codes containing specific fault types such as over-temperature warnings and power supply abnormalities; the data types filled in the data occupancy space are not limited to temperature data or the number of relay actions, but can also be expanded to fill in health parameters such as operating voltage, load current, communication error statistics or module cumulative running time, depending on the specific type of the slave module.
[0075] Through the above scheme, this embodiment can simultaneously confirm the online status of each slave module and collect internal health indicator data within a single health polling cycle, thereby improving the data richness and transmission efficiency of health monitoring without increasing the number of management communication frames.
[0076] In one specific implementation, when a slave module marked as having a communication failure status restores its physical hardware connection or eliminates electromagnetic interference, the slave module reconnects to the RS232 daisy chain.
[0077] First, the master node sends periodic health polling frames to the RS232 daisy chain via its first serial port. The slave modules in recovery mode receive these health polling frames via their first serial ports and match them with the information entries corresponding to their logical addresses using their internal microprocessors. When the current state of the information entry is a heartbeat request flag, the slave module rewrites the heartbeat request flag from its initial value to a state value representing normal operation. Simultaneously, it writes its internally collected temperature data and action count into the corresponding placeholder space and forwards it downstream via its second serial port until the last slave module sends the rewritten health polling frame back to the master node along the reverse transmission path.
[0078] Specifically, after receiving the returned health polling frame and completing frame verification, the master node parses the information entries of each slave module. When the master node identifies that a slave module marked as having a communication failure has successfully rewritten its running status field, the master node accesses the device node structure corresponding to that slave module in physical memory and directly clears the value of its first timeout counter to zero.
[0079] Then, the master node modifies the online status field of the slave module from a status code indicating a communication failure to a status code indicating a normal online status.
[0080] Next, during the subsequent generation of aggregated data frames, the master node identifies that the slave module has returned to normal online status when traversing the device node linked list. It then repackages the slave module's read / write instructions and data placeholders into the aggregated data frame and broadcasts it to the slave module via the RS485 bus, thus resuming data interaction and response arbitration with the slave module.
[0081] In some other alternative implementations, after the master node detects that a slave module in a communication failure state has rewritten the health polling frame, it can start a recovery confirmation counter in physical memory. The master node does not immediately clear the first timeout counter. Instead, it only clears the first timeout counter and performs the online state transition operation when it has received a preset number of successfully rewritten health polling frames, such as two or three times, and the recovery confirmation counter reaches the set value. This is to avoid frequent state switching jitter in slave modules under critically unstable link conditions.
[0082] Through the above solution, this embodiment can achieve automatic identification, self-healing of status and data interaction and re-acceptance of slave modules after communication recovery after fault isolation, without stopping bus operation or manually intervening to modify the master control configuration, thus improving the system's continuous operation capability during module hot-swapping and recovery from occasional interference.
[0083] In one specific implementation, the process by which the master node generates the aggregated data frame includes: First, the master node traverses the doubly linked list of device nodes maintained in physical memory to select each slave module whose online status flag is normal online.
[0084] Specifically, the master node sequentially reads the device type field of each slave module. When the current slave module is determined to be an output type slave module, such as a digital output (DO) module, a relay control module, or an analog output (AO) module, the master node extracts the channel output data to be sent according to the corresponding storage index range in the global data array, and generates a write instruction sub-message containing a write instruction opcode and the channel output data. When the current slave module is determined to be an input type slave module, such as a digital input (DI) module, an analog input (AI) module, or a temperature sensor acquisition module, the master node generates a read instruction sub-message containing a read instruction opcode and a data placeholder space filled with a specific value, according to the expected channel input data length of the module.
[0085] Then, the master node concatenates the generated write instruction sub-messages and read instruction sub-messages in memory in ascending order of the logical addresses of each slave module, and adds frame header information to the front of the sub-message sequence. The frame header information contains the total length of the sub-messages calculated by accumulating all sub-messages, as well as the count of the number of slaves participating in this data interaction, thereby constructing a composite aggregated data frame.
[0086] In some other alternative implementations, the order in which sub-messages are spliced within the composite frame can also be arranged according to the type of data channel or sorted according to the priority of data updates; the data space in the read instruction sub-message can also be filled with all zero bytes, all one bytes, or a specific check sequence.
[0087] The above scheme integrates the control commands and data requests of multiple normally online slave modules into a single composite data frame for unified broadcasting, eliminating the frame overhead and transmission interval caused by addressing each slave module separately and sending frames independently, thereby improving the load utilization of bus transmission and the efficiency of high-frequency data interaction.
[0088] In one specific implementation, the master node establishes a second fault tracing mechanism independent of the daisy-chain management bus at the communication layer of the shared data bus. Specifically, the master node allocates and maintains a separate second timeout counter for each slave module in the device node list in physical memory. After broadcasting an aggregated data frame to each slave module in a normal online state via the shared data bus, the master node initiates a response reception waiting timing window for each addressed slave module. First, if the master node fails to receive a valid response data segment from the slave module at the specified logical address on the shared data bus within the preset timing window, the master node increments the count value of the second timeout counter corresponding to that slave module by one; if the master node successfully receives a valid response data segment from the slave module within the preset timing window, the second timeout counter corresponding to that slave module is cleared to zero. Then, after each update of the second timeout counter, the master node compares its count value with the preset second timeout threshold. When the value of the second timeout counter of a slave module increases continuously and reaches the preset second timeout threshold, the master node modifies the online status field of the slave module to a communication failure status through a status change instruction in physical memory, and removes the logical address identifier of the slave module from the list of nodes to be sent in the subsequent generation of aggregated data frames.
[0089] In some other alternative implementations, the value of the preset second timeout threshold can be dynamically configured according to the communication baud rate of the shared data bus and the real-time number of slave modules, for example, it can be set to any integer between 2 and 5 times; or, the accumulation and reset mode of the second timeout counter can be replaced by an error rate statistics mode based on a fixed time sliding window, when the proportion of the number of times the slave module does not respond on the shared data bus within the set time sliding window reaches a preset proportion, the communication failure status is triggered.
[0090] Compared with the prior art, this embodiment establishes an independent second timeout counter mechanism on the shared data bus, which can accurately distinguish between occasional interference and continuous physical faults in the data transmission link. This prevents the slave module from being erroneously disconnected due to a single data collision or occasional noise. At the same time, it ensures that the slave module can be quickly identified and isolated when a continuous data bus communication failure occurs, avoiding the faulty node from continuously blocking the time-sharing occupancy window of the shared data bus, thereby improving the real-time transmission efficiency and communication robustness of the shared data bus.
[0091] In one specific implementation, each slave module performs bus status detection and hardware enable pin level switching control before occupying the shared data bus to send response data.
[0092] Specifically, the microprocessor of each slave module detects the differential voltage level on the shared data bus via its input pins. When the voltage on the differential bus remains within a predetermined no-data-transmission range for a duration that reaches a preset time window, the bus is determined to be idle. When the bus is determined to be idle and the system time reaches the transmission time window corresponding to the slave module's own logical address, the microprocessor drives the general-purpose input / output pin connected to the RS485 transceiver enable pin to a high level, switching the RS485 transceiver to a high-level enabled transmission mode. Then, the microprocessor sends response data to the shared data bus via a serial port peripheral. After the data transmission is complete, the microprocessor pulls the general-purpose input / output pin low, driving the RS485 transceiver enable pin back to a low-level enabled receive mode, thus releasing the shared data bus occupancy.
[0093] In some other alternative implementations, the level state detection of the shared data bus can be achieved by capturing the bus idle time period through the timer inside the microprocessor, or by detecting the edge changes of the bus differential signal through hardware logic gate circuits; the level switching of the enable pin can also be automatically controlled by the transceiver hardware circuit according to the data stream of the transmitted serial port.
[0094] Compared with the prior art, this embodiment improves the transmission success rate and communication stability of the shared data bus by implementing bus level idle detection and time-sharing control based on logical addresses before each slave module sends response data, and by accurately switching the high and low levels of the hardware enable pin mode.
[0095] In one specific implementation, the microprocessor inside the slave module controls the switching of the transceiver enable pin through a three-state control state machine. This state machine includes a bus idle state, a transmit-occupying state, and a wait-to-release state.
[0096] Specifically, in the bus idle state, the microprocessor controls the general-purpose input / output pins to output a low level, keeping the transceiver in receive mode while continuously monitoring the level status on the communication bus. When the bus is detected to be idle and the timing matches the logical address transmission sequence of the slave module, a bus idle detection event is triggered, driving the state machine to transition from the bus idle state to the occupied transmit state. In the occupied transmit state, the microprocessor drives the general-purpose input / output pins to switch to a high level, switching the transceiver to transmit mode, and pushes the response data segment to be transmitted into the transmit buffer through the serial direct memory access controller to begin data transmission.
[0097] Then, when the serial port hardware completes transmission and triggers a transmission completion interrupt event, the driver state machine transitions from the transmission-occupied state to the waiting-to-release state. In the waiting-to-release state, the microprocessor controls the general-purpose input / output pins to return to a low level and starts an internal hardware timer for a 50-microsecond delay to ensure that the stop bit at the end of the data frame is completely sent to the bus and to eliminate interference levels at the end of the medium. When the hardware timer reaches its preset duration and triggers an overflow event, the driver state machine transitions from the waiting-to-release state back to the bus idle state, completing one bus occupation and release cycle.
[0098] In some other alternative implementations, the state transition conditions of the state machine also include a bus level collision event. When in the occupied transmit state, if the level signal read back by the microprocessor through the serial port receiver is inconsistent with the output level signal of the transmitter, a bus collision event is triggered, driving the state machine to directly transition from the occupied transmit state to the waiting-to-release state, pulling the enable pin low to turn off the transmit mode.
[0099] Through the above scheme, this embodiment constructs a three-state control state machine including idle, occupied transmission, and waiting to be released, which finely controls the switching timing of the enable pin throughout the data interaction process, eliminates the risk of frame tail data truncation caused by the early shutdown of the enable pin, and bus contention caused by the delayed shutdown of the enable pin, thereby improving the communication reliability of time-division arbitration response on the shared medium.
[0100] In one specific implementation, the process of the master node receiving data frames from an RS232 daisy chain or an RS485 bus is specifically implemented as follows: The microprocessor of the master node configures the receive channel of the Direct Memory Access Controller associated with its universal asynchronous transceiver to circular mode. A contiguous physical memory space is allocated as a circular buffer, and the starting physical address and buffer length of this circular buffer are configured in the peripheral data destination address register and transfer count register of the Direct Memory Access Controller.
[0101] When a data frame is input on the RS232 daisy chain or RS485 bus, the Direct Memory Access Controller automatically writes bytes from the serial port receive buffer continuously into a circular buffer in physical memory. When the write pointer reaches the boundary of the circular buffer, it automatically resets to zero and starts writing again from the starting physical address, forming a continuous data write loop.
[0102] The master node configures periodic timer interrupt service routines by initializing hardware timers. Each time a timer interrupt service routine is triggered, it reads the write pointer position updated in real-time by the current direct memory access controller and calculates the difference between this position and the read pointer position maintained in physical memory. When the write pointer and read pointer are not equal, the timer interrupt service routine continuously extracts the byte stream from the read pointer position, identifies the frame start identifier, and verifies the frame length. After successful verification, it extracts the complete data frame and submits it to the data parsing module, while simultaneously updating the read pointer position to the end of the successfully parsed data.
[0103] In some other alternative implementations, the non-blocking reception mechanism for serial port data can also be configured to be based on the serial bus idle interrupt combined with the direct memory access dual buffer alternating switching mode, or the periodically triggered timer interrupt can be replaced with a hardware interrupt response mechanism based on the direct memory access half-transmission completion and transmission completion events, so as to realize the continuous reception and parsing of bus data frames.
[0104] Compared with existing technologies, this embodiment achieves zero-copy hardware-level takeover and non-blocking asynchronous parsing of the bus data stream by configuring the direct memory access controller in a circular mode and cooperating with the physical memory ring buffer and timer interrupt parsing. This eliminates the system throughput bottleneck and frame loss risk caused by frequent interruptions of the microprocessor by single-byte receive interrupts under high-frequency communication, and ensures the stability and continuity of bus data frame reception.
[0105] In one specific implementation, based on the above embodiments, a global fault convergence register in bitmap format is set up and maintained in the physical memory of the master node.
[0106] First, the master node allocates a contiguous storage space in physical memory as a global fault convergence register. Each binary bit in the global fault convergence register establishes a one-to-one mapping with a slave module whose logical address has been allocated within the system. Specifically, let the logical address of the slave module be... The slave module is mapped to the first fault convergence register in the global fault register. bits, of which It is an integer greater than or equal to 1 and less than or equal to the total number of online slave stations.
[0107] Specifically, when the master node determines that any slave module is in a communication failure or abnormal state, the master node sets the binary bit corresponding to the logical address of that slave module using a bitmask operation. For example, when the slave module with logical address 3 is in an abnormal state, the master node sets the second binary bit of the global fault convergence register to logical 1. Then, when all slave modules in the system have recovered and are in a normal state, the master node performs a clear operation on the global fault convergence register, updating the integer value to zero.
[0108] In some other alternative implementations, the global fault convergence register can be expanded to a single-byte integer variable, a double-word integer variable, or a bit array consisting of multiple bytes, depending on the total number of slave modules in the system. In addition, the status representation logic can also be configured in reverse, that is, a low-level logic 0 represents an abnormal state and a high-level logic 1 represents a normal state.
[0109] Compared with existing technologies, this embodiment uses a bitmap format to centrally map the operating status of each slave module, which can achieve fast query and aggregation of the global fault status of the system with extremely low memory overhead. This avoids the computational overhead of traversing the node linked list one by one to query the status, and improves the real-time performance of system status monitoring.
[0110] In one specific implementation, the master node provides a global read / write interface to achieve decoupled access to slave module data.
[0111] Specifically, when application layer software needs to access data from the target slave module, it calls a unified global read / write interface and inputs the logical address of the target slave module. After obtaining the input logical address, the global read / write interface searches the doubly linked list of device nodes maintained in physical memory, compares the logical address field in the node structure, and matches the corresponding device node structure. Upon successful matching, the global read / write interface reads the global index offset field in the device node structure and, combined with the channel byte length of the target slave module, accurately locates the starting and ending memory address range of the target slave module in the global data array.
[0112] Then, if a read operation is performed, the global read / write interface directly extracts the data from the memory address range corresponding to the global data array and returns it to the application layer software; if a write operation is performed, the global read / write interface writes the control data passed in by the application layer software into the memory address range corresponding to the global data array, which is then read when generating data frames later.
[0113] In some other alternative implementations, the specific implementation of locating the storage index range can also be to establish a direct index mapping array or hash table in physical memory with logical addresses as keys and physical memory offset addresses as values, and obtain the global index offset by replacing linked list retrieval with direct addressing.
[0114] Compared with existing technologies, this embodiment establishes a mapping mechanism between global read / write interfaces and logical addresses, directly locating data operations to the physical memory range of the global data array. This completely cuts off the dependence of data access on the physical topology order of the underlying daisy chain at the software abstraction layer, achieving decoupling between the upper-layer application logic and the physical connection order of the hardware, which facilitates the plugging and unplugging of slave modules and dynamic adjustment of the topology.
[0115] In one specific implementation, the master node establishes and maintains a communication quality monitoring data structure in physical memory to perform real-time statistics and calculations on the communication quality of the shared data bus.
[0116] Specifically, the master node allocates a contiguous counter variable storage area in physical memory to accumulate the number of successful transmissions, the expected number of responses, and the actual number of responses in real time. Within each statistical time window, when the master node broadcasts an aggregated data frame to the shared data bus, it reads the number of slave modules in normal online status contained in the aggregated data frame and adds this number to the expected response count accumulation variable. When the master node receives a valid response data segment from a slave module within a preset response reception window, it increments both the actual response count accumulation variable and the successful transmission count accumulation variable. When the number of aggregated data frames transmitted reaches a preset statistical frame number (e.g., 100 frames), the master node reads the accumulated expected and actual response counts within the current statistical time window and calculates the packet loss rate of the shared data bus within the current statistical time window using the following formula: In the formula, Represents packet loss rate. This represents the expected number of replies. This represents the actual number of responses. After the calculation is complete, the master node writes the calculated packet loss rate value into the system status register mapped in physical memory, and resets the variables for the expected number of responses, the actual number of responses, and the number of successful transmissions to zero, in order to start the calculation of the next round of statistical time window.
[0117] In some other alternative implementations, the packet loss rate can also be calculated based on a sliding window mechanism. That is, the master node establishes a circular queue in physical memory to save the response status of each slave module within a preset number of historical times, and dynamically updates and calculates the packet loss rate after each data interaction. The packet loss rate data written to the system status register can also be configured as a triggered interrupt output, which sends a warning to the host computer when the packet loss rate exceeds a preset threshold.
[0118] Through the above scheme, this embodiment can realize real-time continuous monitoring of the communication quality of the shared data bus. By accumulating data in physical memory and calculating dynamic packet loss rate, it provides the system with a quantitative basis for evaluating communication degradation, which helps to identify the impact of electromagnetic interference in the industrial field on physical layer transmission in a timely manner and ensures the reliability of bus operation and maintenance.
[0119] In one specific implementation, a unified frame format definition is used for data transmission on both the daisy-chain management bus and the shared data bus. Specifically, this unified frame format is constructed sequentially in the byte sequence of physical memory: First, there is a 1-byte frame initiator identifier field, used to distinguish the sending body of the data frame, where frames initiated by the master node are set to a fixed first characteristic value, and frames replied by slave modules are set to a fixed second characteristic value; followed by a 1-byte function code field, used to characterize the service type to which the data frame belongs, including device enumeration type, health polling type, and data interaction type; then, there is a 2-byte sub-message length field, used to indicate the total number of bytes in the subsequent variable-length sub-message content field; next, there is a 1-byte device count field, used to record the number of devices participating in communication or enumeration; then, there is a variable-length sub-message content field, used to carry specific control commands, channel status, or sampling data; finally, there is a 2-byte frame tail check field placed at the end of the frame, where the checksum covers all data bytes from the frame initiator identifier field to the end of the variable-length sub-message content field.
[0120] During the data frame transmission process, the master node or slave module first fills the frame initiator identifier, function code, sub-message length, device count, and sub-message content into the transmission buffer in sequence. Then, it calls the cyclic redundancy check algorithm to perform check calculations on the data in the transmission buffer from the first byte to the end of the sub-message content, generating a 2-byte check value and appending it to the frame tail. Next, it drives the corresponding serial port peripheral to send the complete data frame in the buffer to the daisy-chain management bus or shared data bus. During the packet reception process, the receiving end parses the received data bytes in sequence. First, it confirms the data frame type by matching the frame initiator identifier and function code. Then, it reads the sub-message length field to extract the complete data frame. Finally, it performs a check comparison on the received data frame. After the check passes, it parses the sub-message content.
[0121] In some other alternative implementations, the check algorithm for the frame tail check field can be replaced with an XOR check or an accumulator check; the byte length of the sub-message length field can also be set to 1 byte or 4 bytes according to the single frame payload requirements.
[0122] Compared with the prior art, this embodiment simplifies the parsing logic of the communication protocol stack between the master node and each slave module by adopting a unified frame structure format on the daisy-chain management bus and the shared data bus, and reduces the physical memory occupation of the program code; the frame tail verification mechanism covering the entire frame body ensures the integrity of dual-bus data transmission and improves the reliability of data verification during heterogeneous bus transmission.
[0123] like Figure 6As shown, the present invention also provides a bus communication system, which can also be called a fieldbus system (FBUS) in practical engineering applications, including: a device enumeration module M100, a health polling module M200, a data aggregation module M300, and a response interaction module M400.
[0124] In one embodiment, the device enumeration module M100 is configured in the master node and each slave module. The master node constructs an enumeration frame containing a device count field with an initial value set to zero, and pushes it to the RS232 daisy-chain management bus via the first serial port transmitter. Each slave module is equipped with a first serial port facing the physical upstream and a second serial port facing the physical downstream, and receives the enumeration frame sequentially. The microprocessor of the slave module reads the device count field value in the enumeration frame, determines the value as its logical address in the system, then increments the device count field value by one, appends its own device type code to the enumeration frame, regenerates the checksum, and forwards it to the next slave module via the second serial port. After completing the above processing, the end slave module located at the end of the link writes the enumeration frame into the reverse transmission path and transmits it back along the RS232 daisy chain to the receiving end of the master node. The master node receives and parses the enumeration frame to obtain the total number of online slave modules and device type topology information in the system. In some other alternative implementations, the RS232 daisy chain can be replaced with other point-to-point full-duplex serial communication physical links.
[0125] In one embodiment, the health polling module M200 is configured in the master node and each slave module. The master node sends health polling frames to the RS232 daisy chain at preset time intervals. Each health polling frame contains a status mapping area corresponding to each known logical address. Upon receiving the health polling frame, each slave module addresses to the status mapping area corresponding to its own logical address, rewrites the running status identifier therein to the current actual running status value, and forwards the updated health polling frame to downstream nodes via a second serial port. Finally, the last slave module transmits the updated frame back to the master node along the reverse transmission path. The master node parses the status identifiers of each slave module in the returned health polling frame to determine the current online communication status of each slave module. In some other optional embodiments, the periodic health polling frames can be replaced by out-of-band event-triggered heartbeat detection frames.
[0126] In one embodiment, the data aggregation module M300 is configured in the master node. Based on the online communication status determined by the health polling module M200, the master node iterates through and filters out all slave modules that are in a normal online state. The master node extracts read / write control commands for each slave module in a normal online state, concatenates and packages multiple read / write control commands to construct an aggregated data frame containing the total length of sub-messages and a count of the number of normally online slave modules, and broadcasts it via the RS485 bus. In other optional embodiments, the data broadcast medium can also adopt other shared bus structures that support multiple nodes in parallel.
[0127] In one embodiment, the response interaction module M400 is configured in each slave module and the master node. Each slave module receives aggregated data frames through its transceiver connected to the RS485 bus, parses the read / write instructions for itself, and performs read / write operations on the input / output channels. Each slave module determines its own time slot window for sending response data based on the logical address determined by the device enumeration module M100. When the corresponding time slot window arrives, the slave module controls the transceiver's enable pin to switch to a high-level transmit mode and sends the response data segment to the RS485 bus. After the response data segment is sent, the slave module controls the enable pin to pull low to restore the low-level receive mode, realizing time-division multiplexing and collision-free transmission of multiple slave modules on the shared RS485 bus. In some other optional embodiments, the switching control of transmit / receive enable can be implemented through automatic data flow control logic in the hardware circuit.
[0128] In the above system architecture, the device enumeration module M100, health polling module M200, data aggregation module M300, and response interaction module M400 work together collaboratively. During the topology initialization phase, the device enumeration module M100 converts the physical connection sequence of slave modules into logical addresses, providing an address mapping reference for subsequent modules. The health polling module M200 operates independently on the RS232 daisy chain, periodically updating the online status of slave modules, avoiding the occupation of data bus bandwidth by health status detection. The data aggregation module M300 dynamically generates composite data frames based on the online status provided by the health polling module M200, avoiding invalid data polling of faulty or offline slaves. The response interaction module M400 uses the logical addresses determined by the device enumeration module M100 to sequentially and time-divisionally switch the enable state on the RS485 bus, ensuring conflict-free return transmission of response data on the shared medium. Through the collaborative operation of these modules, complete decoupling of management communication and data communication is achieved, resolving the technical problems of mutual interference between bus management and data transmission, as well as communication conflicts on the shared bus.
[0129] Compared with existing technologies, this system achieves physical separation of management and data paths by deploying topology enumeration and health monitoring on an RS232 daisy chain and data interaction on an RS485 shared bus. This eliminates the encroachment of management messages on the data transmission time window and ensures the real-time performance of high-frequency data acquisition. At the same time, by using aggregated data broadcasting and time-division control based on logical addresses, it eliminates multiple frame header overheads and bus contention conflicts, thereby improving the utilization rate of the shared bus.
[0130] In one specific implementation, based on the above embodiments, the system further includes a fault determination module. This fault determination module is configured in the microprocessor of the master node, and establishes and maintains a first timeout counter variable for each registered slave module in the physical memory of the master node. After the master node sends a health polling frame containing a heartbeat request flag via an RS232 daisy chain, it starts a response wait timer with a preset duration of 200 milliseconds. When the response wait timer expires and no health polling frame is received from the slave module at the corresponding logical address after rewriting its status and sending back, the fault determination module drives the first timeout counter value of the corresponding slave module in the physical memory to increment by 1. The fault determination module compares the current value of the first timeout counter with a preset first threshold (e.g., set to a value of 3). When the value of the first timeout counter continuously increases to reach the first threshold, the fault determination module updates the online status field of the slave module from normal online status to communication fault status, and drives the data aggregation module M300 to update the list of nodes to be processed for generating aggregated data frames. The slave module with the communication fault status is removed from the aggregated data frame packet queue, and generation and sending of read / write instruction sub-messages are stopped. In some other optional implementations, the preset first threshold can be dynamically adjusted according to the bus communication baud rate and the real-time electromagnetic ambient noise intensity, such as being set to an adjustable value between 2 and 5; or, the first timeout counter can be uniformly accessed and managed using a centralized hardware timer register array.
[0131] Through the above scheme, this embodiment can filter out occasional electromagnetic interference in industrial sites by using a continuous multi-round timeout accumulation mechanism, avoiding misjudging temporary communication disturbances as physical node offline; at the same time, after confirming the failure of the slave module, it is promptly removed from the data broadcast list, eliminating the unnecessary overhead for the faulty node, and improving the system's communication anti-interference capability and bus bandwidth utilization.
[0132] In one specific implementation, based on the above embodiments, the system further includes a bus arbitration module. This bus arbitration module is deployed in the microprocessor of each slave module and is electrically connected in hardware to the enable pin and serial port receive pin of the RS485 transceiver.
[0133] Before the slave module sends a response data segment to the RS485 bus, the bus arbitration module acquires the voltage level on the RS485 bus in real time through the microprocessor's input pins. The microprocessor determines the bus occupancy status by detecting changes in the differential signal line voltage level or the idle interrupt flag of the serial port receiver. When the bus voltage level remains at a logic high level (no data transmission) for a duration that reaches a preset idle detection threshold, the RS485 bus is determined to be in an idle state.
[0134] The bus arbitration module internally includes a timing calculation unit associated with a logical address. After determining the bus is idle, this timing calculation unit calculates the corresponding transmission timing delay based on the logical address obtained by the slave module during the automatic device enumeration phase. When the time reaches the slave module's dedicated transmission timing window, the microprocessor controls a general-purpose input / output pin to output a high-level signal to the RS485 transceiver's enable pin, driving the RS485 transceiver's transmit driver to turn on and the receive driver to turn off, completing the hardware switch from low-level receive mode to high-level transmit mode. After completing the mode switch, the microprocessor transmits the response data to the RS485 bus via the serial port.
[0135] After the response data transmission is completed and the serial port transmission completion interrupt event is triggered, the bus arbitration module controls the general-purpose input / output pins to output a low-level signal, pulls the enable pin low, makes the RS485 transceiver's transmit driver high-impedance and the receive driver turn on, thereby switching back to the low-level receive mode and releasing the RS485 bus.
[0136] In some other alternative implementations, the bus arbitration module can detect the bus level status through an external hardware differential voltage comparator, which converts the bus level into a logic signal and inputs it to the external interrupt pin of the microprocessor. The control of the enable pin can also be achieved by independently connecting the transmit enable terminal and the receive enable terminal to different pins of the microprocessor for independent control, or by using an RS485 transceiver chip with integrated hardware automatic flow control function to switch between transmit and receive modes.
[0137] Compared with existing technologies, this embodiment achieves conflict-free response of multiple slave modules on the same shared RS485 bus by combining physical layer level detection and time-division control mechanism based on logical address through bus arbitration module, eliminating data collisions caused by concurrent transmission of multiple nodes; at the same time, by accurately switching the level of enable pin, it ensures timely release of bus occupancy state and instant recovery of reception state.
[0138] In one specific implementation, based on the above embodiments, the bus communication system further includes a status aggregation module.
[0139] This status aggregation module is configured in the master node and is used to allocate and maintain a global fault aggregation register in bitmap format in the master node's physical memory. In the bitmap, each binary bit establishes a one-to-one mapping relationship with a slave module assigned a unique logical address. For example, the logical address is... The slave module corresponds to the first in the global fault convergence register. bits, of which It is an integer greater than or equal to 1. The master node monitors the communication and operating status of each slave module in real time. When the logical address is When the slave module is in an abnormal state such as communication timeout, hardware failure, or data verification anomaly, the status aggregation module drives the master node to update the global fault aggregation register. Each binary bit is set to the value 1. When all slave modules in the system have recovered and maintained a normal online state, the status aggregation module drives the master node to clear all binary bits of the global fault aggregation register, resetting the overall value of the register to 0. The master node completes the global status judgment by reading the integer value of the global fault aggregation register: when the register value is greater than 0, the binary bits set to 1 and their corresponding faulty slave logical addresses are retrieved by bitmask verification; when the register value is equal to 0, it is determined that all slave modules in the bus system are in normal operating state.
[0140] In some alternative implementations, the global fault convergence register can be configured as a single-byte structure, a 32-bit unsigned integer variable, or a 64-bit unsigned integer variable; for systems with a large number of nodes, it can be composed of multiple integer variables with consecutive memory addresses concatenated to form a continuous bitmap mapping area. Furthermore, the binary bit logic control can also be configured as reverse logic, i.e., using a value of 0 to represent an abnormal state and a value of 1 to represent a normal state.
[0141] Through the above scheme, this embodiment can establish a highly condensed state mapping structure in physical memory. The host computer or application program can grasp the working status of the global nodes through a single memory read and bit operation without traversing the device linked list one by one. This reduces the processor's computing power occupation for state query and improves the system's fault diagnosis response speed.
[0142] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. A bus communication method, characterized in that, include: The master control node constructs an enumeration frame containing a device count field and sends it to the RS232 daisy chain. Each slave module reads the device count field in sequence to determine its own logical address, increments the device count field and appends its own device type information before forwarding it. The end slave module sends the processed enumeration frame back to the master control node. The master control node sends health polling frames to the RS232 daisy chain at a preset period. Each slave module receives the health polling frame, rewrites the corresponding running status field, and forwards it. The master control node parses the returned health polling frame to determine the online status of each slave module. The master control node merges the read and write commands of each slave module whose online status is normal to generate an aggregated data frame, and broadcasts it on the RS485 bus; Each of the slave modules receives the aggregated data frame and performs input / output channel read / write operations. Each of the slave modules controls the enable pin of its own RS485 transceiver to switch to transmit mode in sequence according to the determined logical address order, and uses the RS485 bus in a time-division multiplexing manner to send response data.
2. The bus communication method according to claim 1, characterized in that, When the end slave module sends back the enumeration frame, the end slave module transmits the enumeration frame upwards along the reverse transmission path of the RS232 daisy chain to the master node station by station.
3. The bus communication method according to claim 1, characterized in that, After the master node receives the enumeration frame, it parses the device type information in the enumeration frame, creates a node structure for each slave module in physical memory and constructs a doubly linked list, and allocates a contiguous storage index range for each slave module in the global data array.
4. The bus communication method according to claim 1, characterized in that, When sending the enumeration frame, the master control node manages it through a state machine: when in the initial state, the first frame is sent and the system enters the waiting response state; if no valid return frame is received within the preset retransmission interval, the system remains in the waiting response state and the enumeration frame is retransmitted; if a valid return frame is received, the system enters the completion state.
5. The bus communication method according to claim 1, characterized in that, Determining the online status of each of the slave modules includes: The master control node maintains a first timeout counter for each of the slave modules; If a health polling frame indicating a rewritten status of a slave module is not received within a preset waiting time, the first timeout counter corresponding to the slave module is incremented by one. When the value of the first timeout counter continuously reaches the preset first threshold, the master control node marks the slave module as having a communication failure state and removes the slave module from the list that generates the aggregated data frame.
6. The bus communication method according to claim 5, characterized in that, After the slave module, which was marked as being in a communication failure state, resumes communication, when the master node receives the health polling frame rewritten by the slave module on the RS232 daisy chain again, it clears the first timeout counter of the slave module and migrates the slave module back to the normal state to resume generating the corresponding aggregated data frame.
7. The bus communication method according to claim 1, characterized in that, Before each slave module occupies the RS485 bus to send response data, each slave module detects the level status on the RS485 bus to determine whether the bus is idle. When the bus is idle and the transmission timing corresponding to its own logical address is reached, the slave module controls the enable pin of its own RS485 transceiver to switch to high-level transmission mode. After the transmission is completed, the enable pin is switched back to low-level reception mode.
8. The bus communication method according to claim 7, characterized in that, When each of the slave modules controls the enable pin, a state machine maintains the bus idle state, the occupied transmit state, and the waiting-to-release state; when a bus level change is detected or a transmit completion event is triggered, the state machine is driven to transition between the idle state, the occupied transmit state, and the waiting-to-release state.
9. The bus communication method according to claim 1, characterized in that, When transmitting data frames on the RS232 daisy chain and the RS485 bus, a unified frame format is used. The unified frame format includes a frame initiator identifier field, a function code field, a sub-message length field, a device count field, a variable-length sub-message content field, and a frame tail check field that covers the frame initiator identifier to the end of the sub-message.
10. A bus communication system, characterized in that, include: The device enumeration module is configured such that the master control node constructs an enumeration frame containing a device count field and sends it to the RS232 daisy chain. Each slave module reads the device count field in sequence to determine its own logical address, increments the device count field and appends its own device type information before forwarding it. The end slave module sends the processed enumeration frame back to the master control node. The health polling module is configured such that the master control node sends health polling frames to the RS232 daisy chain at a preset period, each slave module receives the health polling frame, rewrites the corresponding running status field and forwards it, and the master control node parses the returned health polling frame to determine the online status of each slave module. The data aggregation module is configured to have the master control node merge the read and write instructions of each of the slave modules whose online status is normal to generate an aggregated data frame, and broadcast it on the RS485 bus; The response interaction module is configured to receive the aggregated data frame and perform input / output channel read / write operations by each of the slave modules, and each of the slave modules controls the enable pin of its own RS485 transceiver to switch to transmit mode in sequence according to the determined logical address order, and uses the RS485 bus in a time-division multiplexing manner to send response data.
