Dual-protocol real-time communication method and apparatus, computer equipment, storage medium

By dividing the execution domain on a single microcontroller and adopting snapshot buffers and critical section protection mechanisms, real-time bridging of communication between EtherCAT and industrial controllers is achieved, solving the real-time and reliability issues between EtherCAT and PLC, reducing cost and complexity, and making it suitable for HIFU equipment.

CN123123068APending Publication Date: 2026-11-17CHONGQING HAIFU (HIFU) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611486143.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-22
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In existing technologies, data interaction between EtherCAT and industrial PLCs suffers from real-time and reliability issues, especially in HIFU devices. Existing solutions are costly, complex, and unsuitable for cost-sensitive and space-constrained applications.

Method used

On a single microcontroller, the system software is divided into a first execution domain and a second execution domain. The first execution domain is driven by interrupts to complete the EtherCAT protocol stack processing, while the second execution domain is driven by timer interrupts to drive the industrial controller protocol stack. Data exchange is carried out through a shared PDO memory area, and a snapshot buffer and critical section protection mechanism are used to avoid data contention, thereby realizing real-time communication of dual protocols.

Benefits of technology

While ensuring the real-time performance of EtherCAT communication, it reduces hardware costs and system complexity, and achieves the integrity and reliability of industrial controller communication, making it suitable for cost-sensitive and size-constrained application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123068A_ABST
    Figure CN123123068A_ABST
Patent Text Reader

Abstract

This disclosure provides a dual-protocol real-time communication method and apparatus, computer equipment, and storage medium, belonging to the field of focused ultrasound therapy equipment control technology. The dual-protocol real-time communication method of this disclosure includes: dividing the system software into a first execution domain and a second execution domain on a single microcontroller; in the second execution domain, decomposing the industrial controller communication protocol into a finite state machine containing data exchange paths and disconnection / reconnection paths, serving as the industrial controller communication protocol state machine; setting a snapshot buffer between the industrial controller communication protocol state machine and the process data object memory area, and employing a critical section protection mechanism to implement atomic protection for data copying between the process data object memory area and the snapshot buffer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure belongs to the field of focused ultrasound therapy equipment control technology, specifically relating to a dual-protocol real-time communication method and apparatus, computer equipment, and storage medium. Background Technology

[0002] In the overall control system of focused ultrasound therapy equipment, the real-time industrial Ethernet fieldbus (Ethernet for Control Automation Technology, EtherCAT), as a high-performance real-time Ethernet fieldbus, can meet the requirements of high-intensity focused ultrasound (HIFU) therapy equipment for multi-axis motion control, real-time data acquisition, and high-speed response. EtherCAT slave devices typically need to complete the transmission and reception of process data (PDO) within a strict communication cycle of 1ms or even shorter, which places extremely high demands on the system's real-time performance.

[0003] However, some auxiliary control functions of HIFU equipment, such as water treatment system control, still rely on industrial programmable logic controllers (PLCs). Industrial PLCs play a crucial role in automation control, and many existing systems use vendor-specific Ethernet communication protocols to exchange data with field devices via Transmission Control Protocol / Internet Protocol (TCP / IP). To achieve data interaction between the EtherCAT master station and the industrial PLC, a bidirectional bridge of the EtherCAT and industrial controller communication protocols is needed. This means forwarding control data from the EtherCAT master station to the industrial PLC and simultaneously transmitting feedback data from the industrial PLC back to the EtherCAT network. Summary of the Invention

[0004] This disclosure aims to at least solve one of the technical problems existing in the prior art, and provides a dual-protocol real-time communication method and apparatus, computer equipment, and storage medium.

[0005] In a first aspect, embodiments of this disclosure provide a dual-protocol real-time communication method, including:

[0006] On a single microcontroller, the system software is divided into a first execution domain and a second execution domain. The first execution domain is interrupt-driven and completes the full processing of the real-time industrial Ethernet fieldbus slave protocol stack within a preset first communication cycle. The second execution domain runs the industrial controller communication protocol stack, sets the execution request flag bit by a timer interrupt, and drives the industrial controller communication protocol state machine to advance step by step after polling the execution request flag bit in the main loop. The first execution domain and the second execution domain exchange data through a shared process data object memory area.

[0007] In the second execution domain, the industrial controller communication protocol is decomposed into a finite state machine containing data exchange paths and disconnection reconnection paths, which serves as the state machine of the industrial controller communication protocol. Each time the processing function of the industrial controller communication protocol state machine is called, only one operation step corresponding to the current state is executed and then the process returns, so that the worst-case execution time of a single execution does not exceed the first communication cycle.

[0008] A snapshot buffer is set between the industrial controller communication protocol state machine and the process data object memory area, and a critical section protection mechanism is used to implement atomic protection for data copying between the process data object memory area and the snapshot buffer.

[0009] In some embodiments, the single microcontroller employs a main loop polling architecture and does not deploy a real-time operating system.

[0010] In some embodiments, the snapshot buffer includes a send snapshot buffer and a receive snapshot buffer;

[0011] When sending data to the industrial controller, global interrupts are disabled, the data of the real-time industrial Ethernet fieldbus output process data object is copied to the sending snapshot buffer, global interrupts are enabled after the copy is completed, and a write request message is constructed based on the sending snapshot buffer in the subsequent write request state.

[0012] When receiving data from the industrial controller, the received industrial controller data is stored in the receiving snapshot buffer, the global interrupt is disabled, the data in the receiving snapshot buffer is copied to the memory of the real-time industrial Ethernet fieldbus input process data object, and the global interrupt is enabled after the copy is completed.

[0013] In some embodiments, the critical section protection mechanism includes:

[0014] After saving the current interrupt mask register state, disable global interrupts;

[0015] With global interrupts disabled, perform a data copy between the process data object memory region and the snapshot buffer;

[0016] After the data copy is completed, the saved interrupt mask register status is written back.

[0017] In some embodiments, in the second execution domain, register access to the Ethernet controller employs a non-blocking access method; the non-blocking access method includes:

[0018] When sending data, the data is written into the transmit buffer of the Ethernet controller and a transmit command is issued, and then the process returns immediately.

[0019] When receiving data, the data in the receive buffer is read by directly manipulating the receive buffer pointer register of the Ethernet controller;

[0020] When querying the status, the status register is polled via a single serial peripheral interface transaction.

[0021] In some embodiments, the industrial controller communication protocol state machine accumulates received data across multiple state machine clock cycles when receiving messages;

[0022] When the accumulated received data reaches the length of the transmission encapsulation header, the length field in the transmission encapsulation header is parsed to obtain the total message length;

[0023] When the accumulated received data reaches the total length of the message, the received messages are parsed.

[0024] In some embodiments, the dual-protocol real-time communication method further includes:

[0025] In each data exchange cycle, a specified byte in the sent data is set to the bitwise inverse of the corresponding byte in the received data to detect whether the communication link is alive.

[0026] After each data exchange is completed, the session watchdog timer is reset in the processing function of the industrial controller communication protocol state machine.

[0027] When the session watchdog timer reaches the preset duration and there is no successful data exchange, or when multiple consecutive data exchanges fail, the industrial controller communication protocol state machine switches from the data exchange path to the disconnection and reconnection path.

[0028] In some embodiments, the serial peripheral interface communication of the external temperature sensor adopts the direct memory access transmission mode, and multiple registers are continuously read in burst read mode within a single chip select cycle.

[0029] During the direct memory access transfer, real-time industrial Ethernet fieldbus protocol stack processing is performed by the central processing unit.

[0030] In some embodiments, the dual-protocol real-time communication method further includes the following security protection steps:

[0031] Monitor the real-time status of the industrial Ethernet fieldbus application layer. When it is detected that the application has exited the running state, immediately force all digital outputs to shut down and record the status code.

[0032] Set up an independent hardware watchdog timer and refresh the independent hardware watchdog timer periodically in the main loop;

[0033] Set a timeout counter for all serial peripheral interface transmission operations;

[0034] Set a timeout for direct memory access transfers and abort the transfer after the timeout.

[0035] Secondly, embodiments of this disclosure provide a dual-protocol real-time communication device, comprising:

[0036] The execution domain module is used to divide the system software into a first execution domain and a second execution domain. The first execution domain is interrupt-driven and completes the full processing of the real-time industrial Ethernet fieldbus slave protocol stack within a preset first communication cycle. The second execution domain runs the industrial controller communication protocol stack, sets the execution request flag bit by a timer interrupt, and drives the industrial controller communication protocol state machine to advance step by step after polling the execution request flag bit in the main loop. The first execution domain and the second execution domain exchange data through a shared process data object memory area.

[0037] The state machine module is used to decompose the industrial controller communication protocol into a finite state machine containing data exchange paths and disconnection reconnection paths in the second execution domain, which serves as the state machine of the industrial controller communication protocol. Each time the processing function of the industrial controller communication protocol state machine is called, only one operation step corresponding to the current state is executed and then the process returns, so that the worst case execution time of a single execution does not exceed the first communication cycle.

[0038] The data protection module is used to set up a snapshot buffer between the industrial controller communication protocol state machine and the process data object memory area, and to implement atomic protection for data copying between the process data object memory area and the snapshot buffer using a critical section protection mechanism.

[0039] Thirdly, embodiments of this disclosure provide a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the dual-protocol real-time communication method provided in the first aspect.

[0040] Fourthly, embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the dual-protocol real-time communication method provided in the first aspect. Attached Figure Description

[0041] Figure 1 This is a flowchart illustrating a dual-protocol real-time communication method provided in an embodiment of this disclosure.

[0042] Figure 2 This is a schematic diagram of the structure of a dual-protocol real-time communication device provided in an embodiment of this disclosure.

[0043] Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0045] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “including,” “comprising,” or “containing,” and similar terms mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. The terms “connected,” “linked,” or similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. The terms “upper,” “lower,” “left,” and “right,” etc., are used only to indicate relative positional relationships, and these relative positional relationships may change accordingly when the absolute position of the described objects changes.

[0046] In this disclosure, "multiple or several" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0047] Currently, implementing dual-protocol bridging typically employs a dual-processor solution, a multi-tasking solution based on a Real-Time Operating System (RTOS), or a Linux / embedded processor-based solution. The dual-processor solution uses two independent processors: one running the EtherCAT slave protocol stack, and the other running the industrial controller communication protocol. Data exchange occurs between the two via inter-chip communication (such as Universal Asynchronous Receiver / Transmitter (UART) or Serial Peripheral Interface (SPI)). However, this approach is costly, requires a large printed circuit board (PCB) area, and has high system complexity. The RTOS-based multi-tasking solution runs the RTOS on a single processor, handling EtherCAT and industrial controller communication protocols separately through task scheduling. However, the introduction of the RTOS increases system overhead, task switching latency can affect EtherCAT's real-time performance, and the RTOS itself requires additional flash memory and random access memory (RAM) resources. The Linux / embedded processor-based solution uses a high-performance application processor to run a Linux system and implements two protocols through a software protocol stack. However, it has high cost and power consumption and is not suitable for cost-sensitive and size-constrained application scenarios in HIFU devices.

[0048] Therefore, how to enable the EtherCAT slave protocol stack and the industrial controller Ethernet communication protocol stack to share the central processing unit (CPU) resources without interfering with each other on a low-cost microcontroller without an RTOS, ensuring that the hard real-time performance of EtherCAT is not compromised, and at the same time ensuring the integrity and reliability of industrial controller communication, has become a technical problem that urgently needs to be solved in this field.

[0049] To at least solve one of the aforementioned technical problems, this disclosure provides a dual-protocol real-time communication method and apparatus, computer equipment, and storage medium. The dual-protocol real-time communication method and apparatus, computer equipment, and storage medium provided in this disclosure will be described in further detail below with reference to the accompanying drawings and specific embodiments.

[0050] In a first aspect, embodiments of this disclosure provide a dual-protocol real-time communication method. Figure 1 This is a flowchart illustrating a dual-protocol real-time communication method provided in an embodiment of this disclosure, as shown below. Figure 1 As shown, the dual-protocol real-time communication method provided in this embodiment includes the following steps S101 to S103.

[0051] S101 divides the system software into a first execution domain and a second execution domain on a single microcontroller.

[0052] In step S101 above, the first execution domain is interrupt-driven, meaning its processing is triggered by an interrupt event, without relying on the main loop polling. When an interrupt event occurs corresponding to the first execution domain, the microcontroller pauses the currently executing program and executes the corresponding interrupt service routine (ISR). After processing, it returns to the original program to continue execution. Thus, the first execution domain can obtain a definite response opportunity and complete the full processing of the EtherCAT slave protocol stack within a preset first communication cycle. In other words, within one first communication cycle, the first execution domain can complete the protocol processing, state progression, and PDO update operations required by the slave protocol stack, thereby ensuring the real-time and deterministic nature of EtherCAT communication. Because the first execution domain is interrupt-driven, its execution is not affected by whether the second execution domain is currently running. Therefore, even if the second execution domain is processing the industrial controller communication protocol stack, the first execution domain can still obtain an execution opportunity in a timely manner.

[0053] In one embodiment, the first communication period can be one millisecond. For example, the period of the first timer interrupt can be set to one millisecond, and the first execution domain completes the full processing of the EtherCAT slave protocol stack within each one-millisecond period, including mailbox processing, state machine advancement, and PDO updates. In another embodiment, the first communication period can also be set to other preset period values ​​according to the communication requirements of the real-time industrial Ethernet fieldbus, such as 500 microseconds or 2 milliseconds, as long as the first execution domain can complete the full processing of the EtherCAT slave protocol stack within the first communication period. Preferably, the first communication period is one millisecond. When the first communication period is one millisecond, the worst-case execution time of a single execution of the industrial controller communication protocol state machine in the second execution domain does not exceed one millisecond, thereby ensuring that the processing of the second execution domain does not crowd out the real-time processing window of the first execution domain, and the EtherCAT slave protocol stack can operate stably.

[0054] The second execution domain runs the industrial controller communication protocol stack. An execution request flag is set by a timer interrupt. The main loop polls this flag and then drives the industrial controller communication protocol state machine to advance one step at a time. Specifically, when a timer interrupt arrives, only one execution request flag is set, indicating that the second execution domain needs to advance once. In each iteration of the main loop, the execution request flag is checked. When it is detected that the flag is set, the processing function of the industrial controller communication protocol state machine is called, causing the state machine to execute one operation step corresponding to the current state, and then it returns immediately. This cooperative execution method avoids complex protocol processing during timer interrupts and prevents prolonged lingering on a single operation in the main loop. Therefore, the second execution domain does not occupy the microcontroller's processing resources for extended periods, nor does it preempt the execution of the first execution domain. Even if the second execution domain is running, an interrupt corresponding to the first execution domain can still interrupt the second execution domain, ensuring that the first execution domain receives priority processing.

[0055] The first and second execution domains exchange data through a shared PDO memory area. The PDO memory area can be used to cache bidirectional data between EtherCAT communication and industrial controller communication. The first execution domain can write data sent from the EtherCAT master to the PDO memory area, and the second execution domain reads this data from the PDO memory area and sends it to the industrial controller via the industrial controller communication protocol stack. Conversely, the second execution domain can also write data received from the industrial controller to the PDO memory area, and the first execution domain reads this data from the PDO memory area and uploads it to the EtherCAT master via the EtherCAT slave protocol stack. Thus, the first and second execution domains can exchange data without inter-chip communication or additional hardware bridging, achieving bidirectional data bridging between the EtherCAT slave protocol stack and the industrial controller communication protocol stack.

[0056] S102, in the second execution domain, the industrial controller communication protocol is decomposed into a finite state machine containing data exchange paths and disconnection reconnection paths, which serves as the industrial controller communication protocol state machine.

[0057] In step S102 above, the data exchange path is used to complete normal data read and write operations, and the disconnection reconnection path is used to restore the connection in case of communication failure. Industrial controller communication protocols may originally include multiple stages such as connection establishment, connection negotiation, parameter negotiation, data read and write, and exception handling. If a traditional blocking implementation is used, a single call may wait for the connection to complete, for a response to arrive, or for data to be received, thus occupying the central processing unit (CPU) for a long time. This embodiment of the disclosure decomposes the industrial controller communication protocol into a finite state machine (FSM), dividing the protocol processing into multiple states, each state corresponding to an independently executable operation step.

[0058] Each time the state machine's processing function is called, it executes only one operation step corresponding to the current state and then returns. In other words, the state machine processing function does not wait for network events during the current call, nor does it loop and poll until a certain event occurs. For example, in the phase where data needs to be sent, the state machine processing function can simply complete the message construction and sending operations and then return immediately; in the phase where data needs to be received, the state machine processing function can simply check if data has arrived, receive it if so, and return directly if no data is received, waiting for the next call; in the phase where a connection needs to be established, the state machine processing function can simply issue a connection request or query the connection status without waiting for the connection to complete during the current call. In this way, the execution time of the industrial controller communication protocol state machine is limited to a small range.

[0059] Since each call executes only one operation step before returning, the worst-case execution time for a single execution does not exceed the first communication cycle. Thus, the processing of the second execution domain will not encroach on the processing time of the first execution domain within a first communication cycle. Even if the industrial controller communication protocol itself contains waiting stages, such as waiting for connection establishment, waiting for a response, or waiting for data reception, these will not occupy the CPU for extended periods within the real-time processing window of the first execution domain. Therefore, the first execution domain can complete the processing of the EtherCAT slave protocol stack in a timely manner within each first communication cycle, and the second execution domain can gradually advance the industrial controller communication protocol state machine under the polling drive of the main loop, achieving coexistence of the two protocol stacks on a single microcontroller.

[0060] S103, a snapshot buffer is set between the state machine of the industrial controller communication protocol and the memory area of ​​the process data object, and a critical section protection mechanism is used to implement atomic protection for the data copy between the memory area of ​​the process data object and the snapshot buffer.

[0061] In step S103 above, since the first execution domain is driven by an interrupt and the second execution domain is driven by the main loop polling, the two execution domains may asynchronously access the same PDO memory area. If the industrial controller communication protocol state machine directly reads and writes the PDO memory area, and the first execution domain also updates the PDO memory area while processing an interrupt, data contention may occur. For example, while the industrial controller communication protocol state machine is reading the PDO memory area, an interrupt from the first execution domain arrives and modifies the memory area, causing the industrial controller communication protocol state machine to read some old data and some new data, resulting in data tearing. To avoid the above problems, this embodiment of the disclosure sets up a snapshot buffer between the industrial controller communication protocol state machine and the PDO memory area.

[0062] When the industrial controller communication protocol (ICP) state machine needs to interact with the PDO memory area, it can temporarily store data copies through a snapshot buffer. This allows the ICP state machine to perform subsequent processing based on the data in the snapshot buffer without directly accessing the PDO memory area. Similarly, when the first execution domain updates the PDO memory area, it does not directly affect the snapshot data currently being used by the ICP state machine. The snapshot buffer decouples data access between the first and second execution domains, reducing the risk of data contention.

[0063] Meanwhile, the data copying between the PDO memory region and the snapshot buffer employs a critical section protection mechanism for atomicity protection. That is, during the copying of data from the PDO memory region to the snapshot buffer, or vice versa, the critical section protection mechanism prevents interruptions from affecting the copying process. Therefore, the data copy can be completed as a whole, without being interrupted by interruptions in the first execution domain, thus avoiding the situation where only a portion of the data is copied. Through the snapshot buffer and critical section protection mechanism, the consistency and reliability of data exchange between the first and second execution domains are guaranteed.

[0064] In the dual-protocol real-time communication method provided in this embodiment, the EtherCAT slave protocol stack and the industrial controller communication protocol stack coexist. The first execution domain is interrupt-driven and completes the full processing of the EtherCAT slave protocol stack within a preset first communication cycle, ensuring the real-time performance and determinism of EtherCAT communication. The second execution domain sets the execution request flag bit by timer interrupt. After the main loop polls, it drives the industrial controller communication protocol state machine to advance step by step. The worst-case execution time of a single execution does not exceed the first communication cycle. Therefore, the second execution domain will not occupy the real-time processing window of the first execution domain, and the EtherCAT slave protocol stack can operate stably.

[0065] The two execution domains exchange data bidirectionally through a shared PDO memory area, eliminating the need for inter-chip communication or additional hardware bridging, a dual-processor solution, or separate hardware channels for the two protocols. This reduces hardware costs, PCB area, and system complexity. By decomposing the industrial controller communication protocol into an FSM that includes data exchange and reconnection paths, and performing only one operation step per call before returning, the problem of long CPU usage during connection, transmission, and reception operations in traditional blocking protocol stacks is avoided. This allows the industrial controller communication protocol to progress gradually in a cooperative architecture driven by a main loop polling mechanism, without blocking the real-time processing of the first execution domain, while still enabling normal data exchange and reconnection after anomalies.

[0066] By setting a snapshot buffer between the industrial controller communication protocol state machine and the PDO memory area, and employing a critical section protection mechanism to implement atomic protection for data copying between the PDO memory area and the snapshot buffer, data races and data tearing problems caused by asynchronous access to shared data by the first and second execution domains are avoided, ensuring the consistency and reliability of data exchange between the two execution domains. Therefore, this embodiment of the present disclosure simultaneously guarantees the hard real-time performance of EtherCAT communication and the integrity and reliability of industrial controller communication on a single microcontroller, offering advantages such as low cost, small size, good real-time performance, and high reliability.

[0067] In some embodiments, the single microcontroller employs a main loop polling architecture and does not deploy a real-time operating system.

[0068] After power-on initialization, this single microcontroller enters an infinite main loop. Within this loop, it sequentially polls and executes various tasks or checks execution request flags. For urgent events with high real-time requirements, interrupt service routines handle the process, returning to the main loop after interrupt handling. Since no real-time operating system is deployed, there is no task scheduler on this single microcontroller, and no need to allocate additional stack space and task control blocks for task switching. This saves the flash memory and random access memory resources occupied by the real-time operating system itself, and also avoids the latency and uncertainty caused by task switching. In this main loop polling architecture, the first execution domain is still interrupt-driven to complete the full processing of the EtherCAT slave protocol stack within a preset first communication cycle. The second execution domain uses timer interrupts to set execution request flags. The main loop polls these flags in each iteration, and when a flag is set, it drives the industrial controller communication protocol state machine to advance one step, executing one operation step and then immediately returning. Therefore, a single microcontroller can achieve dual-protocol real-time communication without relying on a real-time operating system. This ensures the hard real-time performance of EtherCAT communication while reducing system resource overhead and implementation complexity, making it particularly suitable for cost-sensitive and size-constrained applications in focused ultrasound therapy equipment.

[0069] In some embodiments, the snapshot buffer includes a send snapshot buffer and a receive snapshot buffer. When sending data to the industrial controller, global interrupts are disabled, data of the real-time industrial Ethernet fieldbus output process data object is copied to the send snapshot buffer, global interrupts are enabled after the copy is completed, and a write request message is constructed based on the send snapshot buffer in the subsequent send write request state. When receiving data from the industrial controller, the received industrial controller data is stored in the receive snapshot buffer, global interrupts are disabled, data in the receive snapshot buffer is copied to the memory of the real-time industrial Ethernet fieldbus input process data object, and global interrupts are enabled after the copy is completed.

[0070] The snapshot buffer includes a send snapshot buffer and a receive snapshot buffer. The send snapshot buffer is used for temporary storage of data in the sending direction, where the sending direction refers to the direction in which the industrial controller communication protocol state machine sends data to the industrial controller; the receive snapshot buffer is used for temporary storage of data in the receiving direction, where the receiving direction refers to the direction in which the industrial controller communication protocol state machine receives data from the industrial controller.

[0071] For the transmission direction, when the industrial controller communication protocol state machine needs to send data to the industrial controller, it disables global interrupts, copies the data in the EtherCAT output process data object to the transmission snapshot buffer, and then enables global interrupts after the copy is complete. The transmission snapshot buffer stores a copy of the output process data object at the moment of copying. Subsequently, in the write request state, the industrial controller communication protocol state machine constructs a write request message based on the data in the transmission snapshot buffer, instead of directly accessing the EtherCAT output process data object. Therefore, even if the first execution domain updates the output process data object in a subsequent interrupt, it will not affect the data already copied to the transmission snapshot buffer, thus ensuring that the data sent to the industrial controller is consistent data at the same time.

[0072] For the receiving direction, when the industrial controller communication protocol state machine receives data from the industrial controller, it first stores the received industrial controller data in the receive snapshot buffer. Then, it disables global interrupts and copies the data in the receive snapshot buffer to the EtherCAT input process data object memory. After the copy is complete, it enables global interrupts. The receive snapshot buffer temporarily stores a copy of the data received from the industrial controller. After being copied to the input process data object memory, the first execution domain can read the data from the input process data object memory. Therefore, when the first execution domain reads the input process data object in a subsequent interrupt, it reads the completely copied data, not the data being modified, thus avoiding data tearing.

[0073] By setting the above-mentioned send snapshot buffer and receive snapshot buffer, a data copy can be established between the industrial controller communication protocol state machine and the EtherCAT process data object memory. This avoids data contention when the first execution domain and the second execution domain asynchronously access the same memory area, ensuring data consistency and reliability in real-time communication between the two protocols.

[0074] In some embodiments, the critical section protection mechanism includes: saving the current interrupt mask register state and then disabling global interrupts; performing a data copy between the process data object memory region and the snapshot buffer while the global interrupts are disabled; and writing back the saved interrupt mask register state after the data copy is completed.

[0075] Before entering the critical section, the current interrupt mask register state is saved. This interrupt mask register state records whether the global interrupt is enabled or disabled before entering the critical section, so that the interrupt mask state can be restored to the state before entering the critical section when exiting the critical section, instead of unconditionally enabling the global interrupt. By saving this state, a basis can be provided for subsequent interrupt recovery, especially in nested interrupt environments, to avoid destroying the mask state of the upper-level interrupt due to mistakenly re-enabling interrupts.

[0076] Secondly, after saving the current interrupt mask register state, global interrupts are disabled. Disabling global interrupts prevents subsequent data copying from being interrupted. Since the data copy between the process data object memory area and the snapshot buffer needs to be completed as a whole, interruption during the copying process could lead to data being modified halfway through the copy, resulting in data tearing and incomplete or inconsistent data in the snapshot buffer or process data object memory area. Therefore, performing the copy with global interrupts disabled ensures the atomicity of the copy operation.

[0077] Then, with global interrupts disabled, a data copy is performed between the process data object's memory area and the snapshot buffer. This copy can be either copying data from the process data object's memory area to the snapshot buffer, or copying data from the snapshot buffer to the process data object's memory area, depending on whether the current direction is sending or receiving. Regardless of the direction, the copy process is completed with global interrupts disabled, thus avoiding interruption by interrupt handling in the first execution domain.

[0078] Finally, after the data copy is complete, the saved interrupt mask register state is written back. By writing back the previously saved interrupt mask register state, the interrupt mask state before entering the critical section can be restored. For example, if the global interrupt was enabled before entering the critical section, it will be enabled again after writing back; if the global interrupt was disabled before entering the critical section, for example, if it is currently in a higher-priority interrupt service routine, it will remain disabled after writing back and will not be erroneously re-enabled. This ensures both the atomicity of the data copy and interrupt safety in nested interrupt environments.

[0079] In some embodiments, in the second execution domain, the register access of the Ethernet controller adopts a non-blocking access mode; the non-blocking access mode includes: when sending data, writing data into the transmit buffer of the Ethernet controller and returning immediately after issuing a transmit command; when receiving data, reading the receive buffer data by directly operating the receive buffer pointer register of the Ethernet controller; when querying the status, polling the status register through a single serial peripheral interface transaction.

[0080] In the second execution domain, register access to the Ethernet controller employs a non-blocking access method. This non-blocking access method means that when the second execution domain accesses the Ethernet controller, it does not wait for network events to occur, nor does it block for extended periods during the access operation. Instead, it returns immediately after completing the current register read / write operation, thus ensuring that the single execution time of the second execution domain does not exceed the first communication cycle. Specifically, this non-blocking access method can include three scenarios: sending data, receiving data, and querying status.

[0081] When sending data, the second execution domain writes the data to be sent into the Ethernet controller's transmit buffer, issues a send command to the Ethernet controller, and then returns immediately. At this time, the Ethernet controller hardware completes the data transmission asynchronously; the second execution domain does not need to wait for the transmission to complete or for a response from the other party. In this way, the transmission operation does not block the second execution domain, nor does it consume the real-time processing time of the first execution domain.

[0082] When receiving data, the second execution domain reads the data from the receive buffer by directly manipulating the receive buffer pointer register of the Ethernet controller, without calling potentially blocking receive functions in the official library. For example, the current data position can be determined by reading the receive buffer read pointer register, and then data can be read from the receive buffer. After reading, the second execution domain can return immediately without waiting for subsequent data to arrive. By directly manipulating the pointer register, the overhead of library function calls is reduced, and the receive operation remains non-blocking. Only when the receive command is issued may there be a very brief wait for internal state updates of the Ethernet controller; this wait time is much shorter than the first communication cycle.

[0083] When querying the status, the second execution domain polls the status register through a single serial peripheral interface transaction to determine events such as whether a connection has been established and whether data has arrived. Each query requires only one serial peripheral interface transaction, reads one status register, and then returns immediately. In this way, status queries do not occupy the serial peripheral interface bus for a long time, nor do they block the second execution domain.

[0084] With the above-mentioned non-blocking access method, the worst-case execution time of a single operation when the second execution domain accesses the Ethernet controller is short, which can meet the requirement of not exceeding the first communication cycle, so as not to occupy the real-time processing window of the first execution domain and ensure the real-time performance and reliability of dual-protocol real-time communication.

[0085] In some embodiments, when the industrial controller communication protocol state machine receives a message, it accumulates the received data across multiple state machine clock cycles; when the accumulated received data reaches the length of the transmission encapsulation header, it parses the length field in the transmission encapsulation header to obtain the total message length; when the accumulated received data reaches the total message length, it parses the received messages.

[0086] When receiving messages, the state machine of the industrial controller communication protocol does not receive the complete message at once, but rather accumulates the received data gradually over multiple state machine clock cycles. Because the second execution domain uses a single-step finite state machine and non-blocking access, each call to the state machine processing function executes only one operation step before returning. Therefore, for a single receive operation, only a portion of the data may be read from the Ethernet controller. When the message returned by the industrial controller is long, or when transport layer fragmentation occurs, the complete message will arrive intermittently across multiple receive operations. Therefore, the industrial controller communication protocol state machine appends the received data that can be read at each state machine clock cycle to the receive accumulation buffer, instead of requiring the complete message to be read at once.

[0087] During the data accumulation process, the industrial controller communication protocol state machine first determines whether the accumulated received data has reached the length of the transmission encapsulation header. The transmission encapsulation header is located at the beginning of the message and contains a length field indicating the complete message length. When the accumulated received data has not yet reached the transmission encapsulation header length, it means that even the message header has not been completely received. In this case, the state machine does not parse the length field but returns directly, waiting for the next state machine clock cycle to continue accumulating received data. When the accumulated received data reaches the transmission encapsulation header length, the state machine parses the length field in the transmission encapsulation header to obtain the total length of the complete message. This total length represents the number of complete bytes from the beginning of the transmission encapsulation header to the end of the message.

[0088] After obtaining the total message length, the industrial controller communication protocol state machine continues to accumulate received data in subsequent state machine clock cycles and determines whether the accumulated received data has reached the total message length. If the total message length has not been reached, it means that the complete message has not yet been received, and the state machine returns directly, waiting for the next state machine clock cycle to continue receiving. When the accumulated received data reaches the total message length, it means that the complete message has been received, and the state machine parses and processes the received message, such as extracting data items from write responses and read responses, or performing connection management protocol negotiation confirmation, etc. Therefore, even under the constraints of non-blocking access and single-step state machines, the industrial controller communication protocol state machine can correctly receive and reassemble complete messages arriving across multiple state machine clock cycles, ensuring the integrity and reliability of the industrial controller communication protocol processing.

[0089] In some embodiments, the dual-protocol real-time communication method further includes: in each data exchange cycle, setting a specified byte in the transmitted data to the bitwise inverse of the corresponding byte in the received data to detect whether the communication link is alive; resetting the session watchdog timer after each data exchange is completed in the processing function of the industrial controller communication protocol state machine; and when the session watchdog timer reaches a preset duration and there is no successful data exchange, or multiple consecutive data exchange failures occur, causing the industrial controller communication protocol state machine to switch from the data exchange path to the disconnection and reconnection path.

[0090] Specifically, in each data exchange cycle, the industrial controller's communication protocol state machine can set a specified byte in the transmitted data to the bitwise inverse of the corresponding byte in the received data, serving as an XOR heartbeat byte. That is, if a specified byte in the data received from the industrial controller is 'A', then the corresponding byte in the data sent to the industrial controller is set to the bitwise inverse of 'A'. After receiving this data, the industrial controller can verify whether this byte is the bitwise inverse of the corresponding byte from the previous frame to determine if the bidirectional communication link is functioning correctly. If the verification passes, the communication link is alive and bidirectional communication is normal; if the verification fails, the link may be malfunctioning, such as a half-open link, data corruption, or communication interruption. By setting and verifying the XOR heartbeat byte in each data exchange cycle, the liveness status of the communication link can be monitored in real time without adding extra messages.

[0091] Meanwhile, the industrial controller communication protocol state machine maintains a session watchdog timer. After each successful data exchange, the session watchdog timer is reset and restarted. In other words, as long as data exchanges continue to succeed, the session watchdog timer will not time out. When the session watchdog timer reaches its preset duration, and no successful data exchange occurs during this period, or multiple consecutive data exchanges fail, it indicates that the communication link may have been broken or there is a communication anomaly. At this point, the industrial controller communication protocol state machine transitions from the data exchange path to the disconnection and reconnection path to execute the disconnection and reconnection process. The disconnection and reconnection path may include operations such as closing the socket, opening the socket, initiating a connection, and negotiating parameters, thus enabling autonomous connection recovery after a communication anomaly. Through the cooperation of the session watchdog timer and the XOR heartbeat byte, communication anomalies can be detected and reconnection triggered in a timely manner under the constraints of a non-blocking single-step state machine, ensuring the reliability and stability of real-time communication between the two protocols.

[0092] In some embodiments, the serial peripheral interface communication of the external temperature sensor adopts the direct memory access transmission mode, and multiple registers are continuously read in burst read mode within a single chip select cycle; during the direct memory access transmission, the central processing unit executes the real-time industrial Ethernet fieldbus protocol stack processing.

[0093] In a microcontroller, the Serial Peripheral Interface (SPI) controller works in conjunction with the Direct Memory Access (DMI) controller. After the temperature sensor data reading is initiated, the DMI controller automatically handles the data transfer between the SPI peripheral and memory without requiring the CPU to participate byte-by-byte. In other words, the CPU only needs to complete the necessary register configuration and data transfer initiation operations; the subsequent data reception and storage processes are handled in the background by the DMI controller, thus freeing the CPU from the data transfer tasks of the SPI.

[0094] Simultaneously, within a single chip select cycle, multiple registers of the external temperature sensor are continuously read using a burst read method. The chip select signal remains valid throughout a single communication, with the serial peripheral interface controller continuously issuing multiple register read commands and storing the read results sequentially into memory, instead of pulling the chip select signal low and high again after each register read. This burst read method reduces the number of chip select switching operations and serial peripheral interface transaction overhead, thereby shortening bus occupancy time and improving temperature acquisition efficiency.

[0095] During direct memory access transfers, the central processing unit (CPU) does not need to wait for the serial peripheral interface data transmission to complete. Instead, it can continue executing real-time industrial Ethernet fieldbus protocol stack processing, such as mailbox processing, state machine advancement, and process data object updates. Therefore, temperature sensor data acquisition and real-time industrial Ethernet fieldbus communication can proceed in parallel. Temperature acquisition does not consume CPU processing time or encroach on the real-time processing window of the first execution domain, thus ensuring normal temperature acquisition while maintaining the real-time performance and determinism of real-time industrial Ethernet fieldbus communication.

[0096] In some embodiments, the dual-protocol real-time communication method further includes the following security protection steps: monitoring the application layer status of the real-time industrial Ethernet fieldbus, and immediately forcibly shutting down all digital outputs and recording the status code when exiting the running state is detected; setting an independent hardware watchdog timer and periodically refreshing the independent hardware watchdog timer in the main loop; setting a timeout counter for all serial peripheral interface transmission operations; setting a timeout for direct memory access transmissions and terminating the transmission after the timeout.

[0097] First, the real-time industrial Ethernet fieldbus application layer status is monitored. Specifically, during dual-protocol real-time communication, the microcontroller continuously monitors the EtherCAT application layer status to determine whether the EtherCAT slave is in operation. When an EtherCAT slave is detected to have exited the operation state, it indicates an anomaly in the real-time industrial Ethernet fieldbus communication. At this point, all digital outputs are immediately forcibly shut down to prevent continued output of control signals under abnormal communication conditions, which could lead to malfunctions of external devices. Simultaneously, the EtherCAT application layer status code is recorded for subsequent analysis of the cause of the anomaly, providing a basis for fault diagnosis and maintenance.

[0098] Secondly, an independent hardware watchdog timer is configured and periodically refreshed within the main loop. This independent hardware watchdog timer is used to reset the microcontroller in case of program crashes or main loop errors, thereby improving system security. The main loop periodically refreshes the independent hardware watchdog timer in each iteration, indicating that the main loop is still running normally. If the main loop fails to refresh the timer on time due to an error, the independent hardware watchdog timer will time out and trigger a microcontroller reset, restoring the system to normal operation and preventing prolonged program stagnation or loss of control.

[0099] Secondly, a timeout counter is set for all serial peripheral interface transmission operations. The serial peripheral interface is a crucial communication channel between the microcontroller and peripherals such as EtherCAT slave controllers, Ethernet controllers, and temperature sensors. If a serial peripheral interface transmission operation cannot complete for an extended period due to hardware malfunction, bus conflict, or peripheral unresponsiveness, it may cause program blocking. Therefore, a timeout counter is set for each serial peripheral interface transmission operation. When a transmission operation fails to complete within a preset time, it is considered a transmission timeout, and corresponding exception handling measures are taken, such as terminating the transmission, recording an error flag, or triggering a retry, thereby preventing system deadlock caused by serial peripheral interface transmission abnormalities.

[0100] Subsequently, a timeout is set for direct memory access (DMI) transfers, and the transfer is terminated after the timeout. DMI transfers are used in scenarios such as temperature sensor data acquisition. If a DMI transfer cannot be completed for an extended period due to peripheral malfunction or bus error, the DMI controller may continuously occupy the bus or be unable to proceed to the next round of data acquisition. Therefore, a timeout counter is set for DMI transfers. When a DMI transfer fails to complete within the preset time, it is determined to have timed out, and the corresponding termination operation is invoked to forcibly terminate the current DMI transfer, releasing the DMI controller and related resources. This allows the system to continue executing subsequent tasks, preventing DMI suspension from affecting the normal operation of real-time industrial Ethernet fieldbus communication and industrial controller communication.

[0101] Secondly, embodiments of this disclosure provide a dual-protocol real-time communication device. Figure 2 This is a schematic diagram of the structure of a dual-protocol real-time communication device provided in an embodiment of this disclosure, as shown below. Figure 2 As shown, the dual-protocol real-time communication device provided in this embodiment includes: an execution domain module 201, a state machine module 202, and a data protection module 203.

[0102] In the specific operation process, the execution domain module 201 can divide the system software into a first execution domain and a second execution domain. The first execution domain is interrupt-driven and completes the full processing of the EtherCAT slave protocol stack within a preset first communication cycle. The second execution domain runs the industrial controller communication protocol stack and sets the execution request flag bit by a timer interrupt. After the main loop polls this flag bit, it drives the industrial controller communication protocol state machine to advance step by step. At the same time, the first and second execution domains exchange data through the shared PDO memory area. The state machine module 202 can decompose the industrial controller communication protocol into an FSM containing data exchange paths and disconnection reconnection paths in the second execution domain, which serves as the industrial controller communication protocol state machine. Each time the processing function of the industrial controller communication protocol state machine is called, only one operation step corresponding to the current state is executed before returning, so that the worst-case execution time of a single execution does not exceed the first communication cycle. The data protection module 203 can set a snapshot buffer between the industrial controller communication protocol state machine and the PDO memory area, and use a critical section protection mechanism to implement atomic protection for data copying between the PDO memory area and the snapshot buffer. Through the cooperation of the above modules, the dual-protocol real-time communication device can achieve the coexistence of EtherCAT slave protocol stack and industrial controller communication protocol stack on a single microcontroller, ensuring both the hard real-time performance of EtherCAT communication and the integrity and reliability of industrial controller communication.

[0103] The aforementioned modules can be implemented in software, hardware, or a combination of both. For example, each module can be a computer program running in a microcontroller, a hardware circuit such as an application-specific integrated circuit (ASIC) or a field-programmable gate array (FPGA), or a combination of software and hardware. The dual-protocol real-time communication device can also include peripherals such as an EtherCAT slave controller, an Ethernet controller, and a temperature sensor to cooperate with each module in completing functions such as dual-protocol real-time communication and temperature acquisition. The dual-protocol real-time communication device can be applied in focused ultrasound therapy equipment as part of the overall control system to realize data interaction between the EtherCAT master station and the industrial controller. Since the device embodiment and the method embodiment are based on the same inventive concept, the contents, specific implementation methods, and technical effects not described in detail in the device embodiment can be found in the corresponding descriptions in the method embodiment, and will not be detailed here.

[0104] Thirdly, embodiments of this disclosure provide a computer device, Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure, such as... Figure 3 As shown, this disclosure provides a computer device including: one or more processors 301, a memory 302, and one or more I / O interfaces 303. The memory 302 stores one or more programs, which, when executed by one or more processors, enable the one or more processors to implement the dual-protocol real-time communication method as described in any of the above embodiments; the one or more I / O interfaces 303 are connected between the processors and the memory, configured to enable information interaction between the processors and the memory.

[0105] The processor 301 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); the memory 302 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), and flash memory (FLASH); the I / O interface 303 is connected between the processor 301 and the memory 302, enabling information exchange between the processor 301 and the memory 302, including but not limited to a data bus (Bus).

[0106] In some embodiments, the processor 301, memory 302, and I / O interface 303 are interconnected via a bus, and thus connected to other components of the computing device.

[0107] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the dual-protocol real-time communication method as described in any of the above embodiments.

[0108] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a machine-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), it performs the functions defined above in the system of this disclosure.

[0109] It should be noted that a computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0110] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two adjacent blocks may actually represent substantially parallel execution, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0111] It is understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of this disclosure, and this disclosure is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and substance of this disclosure, and these modifications and improvements are also considered to be within the scope of protection of this disclosure.

Claims

1. A dual-protocol real-time communication method, characterized in that, include: On a single microcontroller, the system software is divided into a first execution domain and a second execution domain. The first execution domain is interrupt-driven and completes the full processing of the real-time industrial Ethernet fieldbus slave protocol stack within a preset first communication cycle. The second execution domain runs the industrial controller communication protocol stack, sets the execution request flag bit by a timer interrupt, and drives the industrial controller communication protocol state machine to advance step by step after polling the execution request flag bit in the main loop. The first execution domain and the second execution domain exchange data through a shared process data object memory area. In the second execution domain, the industrial controller communication protocol is decomposed into a finite state machine containing data exchange paths and disconnection reconnection paths, which serves as the state machine of the industrial controller communication protocol. Each time the processing function of the industrial controller communication protocol state machine is called, only one operation step corresponding to the current state is executed and then the process returns, so that the worst-case execution time of a single execution does not exceed the first communication cycle. A snapshot buffer is set between the industrial controller communication protocol state machine and the process data object memory area, and a critical section protection mechanism is used to implement atomic protection for data copying between the process data object memory area and the snapshot buffer.

2. The dual-protocol real-time communication method according to claim 1, characterized in that, The single microcontroller adopts a main loop polling architecture and does not have a real-time operating system deployed.

3. The dual-protocol real-time communication method according to claim 1, characterized in that, The snapshot buffer includes a send snapshot buffer and a receive snapshot buffer; When sending data to the industrial controller, global interrupts are disabled, the data of the real-time industrial Ethernet fieldbus output process data object is copied to the sending snapshot buffer, global interrupts are enabled after the copy is completed, and a write request message is constructed based on the sending snapshot buffer in the subsequent write request state. When receiving data from the industrial controller, the received industrial controller data is stored in the receiving snapshot buffer, the global interrupt is disabled, the data in the receiving snapshot buffer is copied to the memory of the real-time industrial Ethernet fieldbus input process data object, and the global interrupt is enabled after the copy is completed.

4. The dual-protocol real-time communication method according to claim 1, characterized in that, The critical section protection mechanism includes: After saving the current interrupt mask register state, disable global interrupts; With global interrupts disabled, perform a data copy between the process data object memory region and the snapshot buffer; After the data copy is completed, the saved interrupt mask register status is written back.

5. The dual-protocol real-time communication method according to claim 1, characterized in that, In the second execution domain, register access to the Ethernet controller is performed using a non-blocking access method; the non-blocking access method includes: When sending data, the data is written into the transmit buffer of the Ethernet controller and a transmit command is issued, and then the process returns immediately. When receiving data, the data in the receive buffer is read by directly manipulating the receive buffer pointer register of the Ethernet controller; When querying the status, the status register is polled via a single serial peripheral interface transaction.

6. The dual-protocol real-time communication method according to claim 1, characterized in that, When receiving messages, the state machine of the industrial controller communication protocol accumulates the received data across multiple state machine clock cycles. When the accumulated received data reaches the length of the transmission encapsulation header, the length field in the transmission encapsulation header is parsed to obtain the total message length; When the accumulated received data reaches the total length of the message, the received messages are parsed.

7. The dual-protocol real-time communication method according to claim 1, characterized in that, Also includes: In each data exchange cycle, a specified byte in the sent data is set to the bitwise inverse of the corresponding byte in the received data to detect whether the communication link is alive. After each data exchange is completed, the session watchdog timer is reset in the processing function of the industrial controller communication protocol state machine. When the session watchdog timer reaches the preset duration and there is no successful data exchange, or when multiple consecutive data exchanges fail, the industrial controller communication protocol state machine switches from the data exchange path to the disconnection and reconnection path.

8. The dual-protocol real-time communication method according to claim 1, characterized in that, The serial peripheral interface communication with the external temperature sensor adopts the direct memory access transmission mode, and reads multiple registers continuously in burst read mode within a single chip select cycle. During the direct memory access transfer, real-time industrial Ethernet fieldbus protocol stack processing is performed by the central processing unit.

9. The dual-protocol real-time communication method according to claim 1, characterized in that, It also includes the following safety protection steps: Monitor the real-time status of the industrial Ethernet fieldbus application layer. When it is detected that the application has exited the running state, immediately force all digital outputs to shut down and record the status code. Set up an independent hardware watchdog timer and refresh the independent hardware watchdog timer periodically in the main loop; Set a timeout counter for all serial peripheral interface transmission operations; Set a timeout for direct memory access transfers and abort the transfer after the timeout.

10. A dual-protocol real-time communication device, characterized in that, include: The execution domain module is used to divide the system software into a first execution domain and a second execution domain. The first execution domain is interrupt-driven and completes the full processing of the real-time industrial Ethernet fieldbus slave protocol stack within a preset first communication cycle. The second execution domain runs the industrial controller communication protocol stack, sets the execution request flag bit by a timer interrupt, and drives the industrial controller communication protocol state machine to advance step by step after polling the execution request flag bit in the main loop. The first execution domain and the second execution domain exchange data through a shared process data object memory area. The state machine module is used to decompose the industrial controller communication protocol into a finite state machine containing data exchange paths and disconnection reconnection paths in the second execution domain, which serves as the state machine of the industrial controller communication protocol. Each time the processing function of the industrial controller communication protocol state machine is called, only one operation step corresponding to the current state is executed and then the process returns, so that the worst case execution time of a single execution does not exceed the first communication cycle. The data protection module is used to set up a snapshot buffer between the industrial controller communication protocol state machine and the process data object memory area, and to implement atomic protection for data copying between the process data object memory area and the snapshot buffer using a critical section protection mechanism.

11. A computer device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the dual-protocol real-time communication method according to any one of claims 1 to 9.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the dual-protocol real-time communication method as described in any one of claims 1 to 9.