Design of a Real-time Monitoring System for CNC Machine Tool Status Based on STR-6
2026-04-06 05:51:14··#1
Abstract: This paper designs the hardware structure of a real-time monitoring system for CNC machine tools based on the STR-6 wireless data transmission module. It introduces the time-division multiple access (TDMA) communication protocol used for data transmission and the methods for real-time data reception and processing. The software design of the wireless data transmission module based on multi-threading technology is also completed. Keywords: CNC machine tool; wireless communication; time-division multiple access; multi-threading In traditional CIMS (Computer Integrated Manufacturing System), the acquisition and transmission of data streams involve a large amount of cable laying, which limits the improvement of the overall control performance of the distributed industrial manufacturing system. The STR-6-based wireless transmission module can meet the requirements for stable and efficient transmission of real-time monitoring data for CNC machine tools. This paper introduces the hardware structure and software design of the wireless transmission system for CNC machine tools based on this module, and provides a detailed analysis of the communication protocol used. System Structure and Communication PrincipleCommunication Module Features The STR-6 low-power wireless transmission module developed by Shanghai Sanbo Technology Co., Ltd. provides three interface methods: standard RS-232, RS-485, and RART/TTL levels. It can be directly connected to the computer's COM1 (or COM2) and powered by the computer's USB interface. The STR-6's communication channel is half-duplex, best suited for point-to-multipoint communication. Users do not need to write additional programs; they only need to send and receive data via the interface. Other tasks, such as air-to-receive/transmit conversion and control operations, are automatically handled by the STR-6 module. System Hardware Structure The system structure diagram is shown in Figure 1. The entire system consists of several high-performance PCs: a remote monitoring terminal (master), a field monitoring center (slave), and a field monitoring unit. The field monitoring center and remote monitoring terminal are each equipped with an STR-6 module. The master and slave are connected to the STR-6 module via RS-232 serial ports, and communication occurs between two STR-6 modules (each with a 30×7×1mm antenna). Uplink commands are sent by the master to control the slave and the field monitoring unit, while downlink status data is sent to the master to transmit the current operating parameters of the CNC machine tool, such as spindle rotation and cutting force. The STR-6 module provides 0 to 7 channels. If increased system capacity is required, multiple frequency points can be set, each used by multiple CNC machine tools. This method of increasing system frequency band resources can multiply the system capacity. [align=center]Figure 1 Hardware Structure of CNC Machine Tool Status Monitoring System[/align] Time Division Multiple Access Communication Protocol This system adopts the TDMA (Time Division Multiple Access) communication protocol. The time axis is divided into time cells (EPOCH) of a certain length, each time cell is further divided into several frames, and each frame is further divided into several time slots. The repetition period of a frame is the frame period. A certain number of time slots are allocated to the master/slave in each frame for signal transmission, while the time slots where no signal is transmitted are used to receive signals transmitted by the slave/master. The master uses an accurate clock as a reference, and the slave clocks are synchronized with it to form a unified system clock. The transmission time slots of each member in the network are different from each other, and there is no mutual interference problem, but accurate time slot synchronization is necessary so that each transmission uses a unified time slot starting point as a timing reference. This system has a monitoring and control capacity of 30 data transmission machine tools. The wireless transmission rate of the data transmission module is set to 9600bps, and the basic information transmission volume of each time slot is 225 bits. Therefore, it is designed with 35ms per time slot, 3.5s per time frame, a total of 100 time slots, 35s per time element, and 10 frames. Software Implementation of the Communication ModuleOverall Program Framework As part of the real-time monitoring system, the wireless transmission module was designed as an independent module, making its application similar to the application of functions. This paper uses Visual C++ language for design. The wireless communication module program of the terminal includes a timestamp class, an encoding class, and a network communication class (or transmission class). The timestamp class mainly completes the synchronization of the entire system, and the encoding class mainly implements the RS encoding function of the data. The network communication class is mainly responsible for sending and receiving the encoded data stream. The data link terminal module mainly includes the following threads: 1. Main Thread: The main task of the main thread is to initialize the system, create and terminate child threads, and respond to menu and mouse operations. 2. The encoding/decoding thread obtains data from the host/slave, encodes it, and sends the encoded data to the transmit buffer for transmission; it also retrieves data from the receive buffer, decodes it, and obtains valid information. 3. The transmission thread is responsible for sending the data from the transmit buffer to the modem in the data transmission module; it reads the data stream from the modem and stores it in the receive buffer. Implementation of Precise Timing in Windows: TDMA networks are synchronous networks that require all users to use a unified time base and maintain a high-precision clock. As is well known, Windows is a message-based system where any event is executed by sending and receiving messages. This leads to problems, such as when the computer's CPU is occupied by a process or system resources are scarce, messages sent to the message queue are temporarily suspended and cannot be processed in real time. Therefore, it is not possible to simply trigger an event with strict timing requirements through Windows messages. Since access to the underlying computer hardware is encapsulated in Windows, achieving precise timing through direct hardware access is also difficult. Based on the millisecond-level timing requirements of this system, the QueryPerformanceFrequency() and QueryPerformanceCounter() functions are used. Before timing, the `QueryPerformanceFrequency()` function is called to obtain the clock frequency of the machine's internal timer. Then, the `QueryPerformanceCounter()` function is called before and after the event requiring strict timing. Using the difference between the two counts and the clock frequency, the precise duration of the event is calculated. The transmission thread is implemented via a serial port connection between the STR-6 and the PC. In the Microsoft Visual C++ 6.0 environment, serial communication is easily and conveniently implemented through programming ActiveX controls, saving considerable time. First, the control class `MSComm` is instantiated. Then, the serial port is initialized by calling functions of `MSComm`, setting its serial port number, baud rate, parity, data bits, stop bits, and receive trigger mode. Reading and writing to the `MSComm` class is achieved by calling the functions `GetInput()` and `SetOutput()`. The host periodically sends a network entry message, and the slave listens on the link for 35 seconds to obtain the time slot allocation and usage status of the entire network. Upon receiving the network entry message, it immediately performs a fine synchronization process, sending a synchronization request message to the host. The host, upon receiving the synchronization request message, sends a synchronization response message. After precise synchronization, the network enters a continuous operation phase, sending messages in the transmit time slot and receiving useful messages in the receive time slot. Due to clock drift, the precise synchronization process must be performed periodically. The slave user program flowchart is shown in Figure 2. The master user program flowchart is similar and will not be repeated here. [align=center] Figure 2 Slave Member Flowchart[/align] Synchronization of Encoding/Decoding Thread and Transmission Thread When the encoding/decoding thread is working, it needs to send data into the transmit buffer and read data from the buffer for decoding. The transmission thread needs to extract data from the transmit buffer and send it out, and receive data from the modem and store it in the buffer. Precise synchronization is required to ensure that there are no conflicts between them. Taking the synchronization of the encoding thread and the transmitting thread as an example, firstly, two transmit buffers E1 and E2 of the same size are defined in the transmission class, and four events are defined, corresponding to the buffer E1 empty event, the buffer E1 full event, the buffer E2 empty event, and the buffer E2 full event, respectively. In the main thread, these four events are first initialized. Since the two buffers should be empty at the beginning, the empty events of buffers E1 and E2 are signaled during initialization, while the full events of buffers E1 and E2 are non-signaled. At this time, the encoding thread and the sending thread are started. Since two sending buffers are used for operation, one must be designated as the current sending buffer and the current encoding buffer before the threads start. E1 is initialized as their initial value. When the program starts working, the empty event of the buffer is signaled, so the encoding thread performs encoding work, storing the compressed data stream into the current buffer. The sending buffer does not detect the full event of the buffer being signaled, so it waits. When the current encoding buffer becomes full, the encoding thread sets the full buffer to signaled and the empty buffer to non-signaled, and swaps the current encoding buffers. At the same time, this thread enters a waiting state. The sending thread, which is in the waiting state, hears the full event of the buffer being signaled and begins working, sending the data in the current buffer to the modem or local area network until completion. Then, the thread sets the current transmit buffer to a semaphore state when empty and a non-semaphore state when full, and swaps the current transmit buffers. This allows the encoding thread waiting for an empty buffer to occupy that buffer again, repeating this process until the encoding thread terminates. Conclusion Experiments show that the wireless data transmission module designed using the STR-6 communication module provides timely, secure, and reliable data transmission with a very low error rate. Furthermore, its small size and low power consumption allow for easy embedding into CNC machine tool monitoring systems, reducing development costs and time, and improving the flexibility of equipment applications. However, this system also has limitations. Its development is based on the Windows operating platform and lacks cross-platform compatibility. Further work is needed to expand its applications.