Temperature control network system based on RS422A fieldbus
2026-04-06 05:58:39··#1
Abstract: This paper briefly introduces the system structure and communication protocol of a temperature control network system that uses RS422A bus to achieve remote bidirectional data communication in an engineering project. It focuses on the development of real-time monitoring and communication software using VC++ 6.0 multithreading technology. The system operates stably and reliably, fully leveraging the advantages of convenient network management and improving production efficiency. Keywords: Network control system, RS422A bus, real-time performance, multithreading . I. Overview The RS-422A bus is the EIA standard for "Electrical characteristics of balanced voltage digital interface circuits." This standard was developed to improve the electrical characteristics of the RS-232C standard while also considering compatibility with RS-232C. RS422A is a widely used bidirectional, differential balanced drive and receive transmission line standard interface in industry. It communicates in full-duplex mode, supports multi-point connections, allows the creation of networks with up to 32 nodes, and boasts advantages such as long transmission distance (maximum 1200m) and high transmission rate (100kbit/s at 1200m). Compared to other buses such as FF, CAN, and LonWorks, it features simple structure, low cost, easy installation, and compatibility with traditional DCS systems. Furthermore, many field instruments on the market have RS422A bus interfaces, making it easy to develop small to medium-sized network monitoring and control systems. Based on the specific characteristics of a particular engineering project, we adopted the RS422A communication interface to implement a remote data communication system. In this project, the system employs a two-level master-slave bus network structure. The control of variables such as temperature is mainly achieved by the various intelligent instruments on the bus. The host computer modifies the setpoints and other parameters of the intelligent instruments according to control requirements, and monitors and displays some digital quantities. The intelligent instrument selected for this project is manufactured by Shanghai Dahua-Qianye Instrument Co., Ltd. It has complex parameters and strong control and communication functions. Simultaneously, leveraging abundant host computer hardware and software resources and using Windows as the operating platform, the developed application software boasts powerful management functions and a very user-friendly human-machine interface. The system application software was developed using Microsoft Visual C++ 6.0, fully utilizing VC++'s flexibility and speed, and its convenient interface for window programming and multi-tasking programming. The developed software has comprehensive data acquisition, setting, alarm, and real-time monitoring functions. Application results show that the system effectively monitors the temperature control system with good results. II. System Structure The intelligent instrument has relatively complete functions and high control accuracy. It has a built-in RS422A communication card with over one hundred communication commands and a large amount of data uploaded and received, mainly including temperature setpoints, PID parameter values, alarm parameter values, sensor correction values, fuzzy control parameter values, etc. The fieldbus uses the RS422A bus because of its advantages such as simple structure, low cost, and easy installation. The intelligent instruments are connected to the RS422A bus and to the PC serial port via an RS422A/232C converter. A dozen (expandable) intelligent instruments and one RS422A/232C converter are configured, with each instrument assigned a unique address. Temperature control is performed by the lower-level computer (intelligent instruments). The main control computer performs the following functions: 1) Actively reads relevant data from the lower-level computer; 2) Changes the temperature control setpoint and other parameters, but does not directly control the temperature; 3) Displays the temperature control curve, the temperature controller's centralized display screen, and alarm data dynamically; 4) Data storage, statistics, and reports. The system hardware structure diagram is shown in Figure 1. [align=center] Figure 1[/align] III. Communication Protocol 1) The physical layer adopts a balanced standard RS422 interface to improve the reliability of data transmission. In the balanced standard RS422A, both the transmitter and receiver operate differentially, with each signal transmitted using two wires. The signal level is represented by the difference between the signals on the two wires. 2) Data Link Layer: This system uses asynchronous serial communication. The system specifies a baud rate of 9600bps, even parity, 1 start bit, 7 data bits, 1 stop bit, and ASCII code as the transmission code. Transmission frames on the bus are divided into command frames and data frames. Command frames are further divided into address command frames (containing address information for establishing a connection) and control command frames (requiring data upload or download for an established connection). The text format of the latter and data frames is as follows: 3) Network Layer: The PC implements the protocol functions of this layer. In the transmission frames on the bus, address command frames are broadcast by the control PC to wake up a specific instrument on the bus, initiate a handshake request to establish a communication relationship, and then the corresponding instrument sends its local address back to the control PC, indicating a successful handshake; otherwise, the instrument sends a negative response back to the PC. When the PC wants to communicate with other instruments besides the currently communicating instrument, it must first abandon the current communication relationship and send an abandon communication command frame. Then, it must re-establish the connection according to the above method. The connection establishment, connection termination, and temperature controller response formats are as follows: ENQ, EOT, and ACK are control code end codes indicating the end of a frame. 4) Application Layer: The application layer of the RS422A bus network system for industrial intelligent instruments is responsible for framing information transmitted between the control PC and the intelligent instruments; that is, the data format is defined according to certain formats and meanings. IV. System Software Design The system management software adopts object-oriented technology, is based on the Windows 2000 platform, and is developed using VC++ 6.0. The system application software consists of two main parts: real-time dynamic process and historical record browsing. The real-time dynamic process includes three major modules: data acquisition and setting, operation control, and data management. The data acquisition and setting module periodically acquires and sets real-time data from the lower-level machine, i.e., the intelligent instrument. The control module mainly controls the operation or stop of the instrument and selects the running segment. The data management module includes functions such as data communication, data display, alarm, printing, and storage. Based on the characteristics of the real-time system, multiple tasks run simultaneously in the monitoring software. To prevent one task from blocking other tasks, we fully utilize the multi-process and multi-threaded programming features of the Windows system and divide the system into several modules. First, we divide the historical record browsing and the real-time dynamic process into two processes because these two processes are very different. The data in the historical record browsing is static and has no real-time requirements. It can be run during or after the production process. When developing this part of the program, we do not need to consider the time issue. The real-time dynamic process, however, is a task with high real-time requirements. In this process, we mainly need to complete tasks such as communication, display, control, and printing, as well as data dumping. (1) Dynamic process design The term thread refers to the sequential execution of program instructions. Each program independently executes a series of instructions in the program code. From the perspective of user or application programming, the threads in the program run simultaneously. The operating system usually achieves this sense of simultaneity by quickly switching between threads and lines (but if the computer has multiple processors, the system can directly execute threads simultaneously). When a program needs to complete multiple tasks at a certain time (as many reference programs do), putting each task in a different thread not only makes the program more efficient but also simplifies the development work. In designing the real-time dynamic process, we divide it into two threads: the main thread and the communication thread. The main thread starts the communication thread at regular intervals. The communication thread is automatically suspended after completing a communication task. Under normal circumstances, the time between two resumptions of the communication thread by the main thread is sufficient to guarantee the complete execution of one communication thread. Regarding data storage, to improve the system's dynamic performance and ensure fast access to the data storage area, we store data in two locations. Process data from the ongoing production process is first stored in a data buffer allocated in memory, allowing the main thread to access it quickly. Additionally, data from several communication sessions is periodically stored on the hard drive to prevent data loss due to power outages or other unforeseen events. In program design, we adopted object-oriented design principles. For example, we treat the temperature controller as an object, and its related data structures and operations are completely encapsulated in a class. This separation of data structures in the program greatly facilitates software expansion, development, and debugging. The main implementation method of this software is as follows: The user-defined function StartOfSystem(pDC) is called within the overloaded void CRs422AnetView::OnDraw(CDC* pDC). The latter opens and configures the serial port, starts the communication thread, and sets the timer, etc. The main code is as follows: void CRs422AnetView::StartOfSystem (CDC *pDC) {... m_hCom=CreateFile (m_sPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,NULL); if(m_hCom==INVALID_HANDLE_VALUE) return FALSE; DCB dcb; if(!GetCommState(m_hCom, &dcb)) return FALSE; dcb.fBinary=TRUE; dcb.BaudRate=m_nBaud; dcb.ByteSize=m_nDataBits; dcb.fParity=TRUE; dcb.Parity=EVENPARITY; dcb.StopBits = ONESTOPBIT; return SetCommState(m_hCom, &dcb); ……//The above is the code to open and configure the serial port SetTimer(1, 5000, NULL); //Start the timer, with a timer interval of 5 seconds CwinThread *m_pThreadd = AfxBeginThread(CommProc, this->GetDocument(), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL); //Create and suspend the thread if (m_pThreadd == NULL) { CloseHandle(m_hCom); return FALSE; } else { m_bConnected = TRUE; m_pThreadd->ResumeThread(); //Resume thread execution } …… } UINT CommProc(LPVOID pParam) is the auxiliary communication thread, which completes the reading of set values and dynamic data. Its program flowchart is shown below: void CRs422AnetView::OnTimer(UINT nIDEvent) is a function that responds to timer messages. The timer is triggered, and the timer interval in this program is 5 seconds. In this function, the auxiliary communication thread is restored and the data display program is called, and the data is refreshed at regular intervals. (2) Design of the historical record browsing process The browsing of historical records is for reviewing past production processes. The quality of the product and the process settings can be combined for analysis to provide a reference for future production, so as to improve the production quality of the product. This process provides certain query functions, which can play back the historical records in the form of curves, lock important processes, and delete process records. V. Conclusion The temperature control network system based on RS422A fieldbus introduced in this article has been running in the field for a long time. The system runs stably and reliably, giving full play to the advantages of convenient network management and improving production efficiency. Obviously, for some medium and small-scale measurement and control systems, RS422A is a good choice. References: [1] David J. Kruglinski, Translated by Pan Aimin et al., Visual C++ Technical Insights (4th Edition), Tsinghua University Press, January 1999 [2] Jan Axelson, Translated by Elite Technology, Serial Port Complete, China Electric Power Press, May 2001 [3] Qinghong Computer Studio, Visual C++ Programming Techniques (Network and Database), Machinery Industry Press, January 2001 [4] KP1000 Series Digital Program Control Instrument Instruction Manual, Shanghai Dahua-Qianye Instrument Co., Ltd. [5] KP1000 Series Digital Program Control Instrument Instruction Manual, Optional Part II (Communication Interface), Shanghai Dahua-Qianye Instrument Co., Ltd.