Temperature Control Network Control System Based on RS422A Fieldbus

Publisher:csydtcLatest update time:2009-09-11 Source: 微计算机信息 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I. Overview

RS-422A bus is the "Electrical Characteristics of Balanced Voltage Digital Interface Circuits" standard published by EIA. This standard is formulated to improve the electrical characteristics of RS-232C standard and to consider compatibility with RS-232C. RS422A is a bidirectional, differential balanced drive and receiving transmission line standard interface widely used in the industry. It communicates in full-duplex mode, supports multi-point connection, and allows the creation of a network of up to 32 nodes. It has the advantages of long transmission distance (maximum transmission distance is 1200m) and fast transmission rate (100kbit/s at 1200m). Compared with other buses, such as FF, CAN, LonWorks, etc., it has the characteristics of simple structure, low cost, easy installation, and compatibility with traditional DCS. In addition, many field instruments on the market have RS422A bus interfaces, so it is easy to develop some small and medium-sized network measurement and control systems using this bus. Combined with the actual characteristics of a certain engineering project, we adopted the RS422A communication interface to realize the remote data communication system.

In this project, the system adopts a two-level master-slave bus network structure. The control of variables such as temperature is mainly realized by various intelligent instruments on the bus. The host computer modifies the given values ​​and other parameters of the intelligent instruments according to the control requirements, as well as the monitoring and display of some digital quantities. The intelligent instruments selected for this project are produced by Shanghai Dahua-Qianye Instrument Co., Ltd., with quite complex parameters and strong control and communication functions. At the same time, taking advantage of the rich hardware and software resources of the host computer and using Windows as the operating platform, the developed application software has powerful management functions and a very friendly human-computer interface. The application software of this system is developed using Microsoft Visual C++6.0, making full use of the flexibility and speed of VC++, and the convenient interface for window programming and multi-task programming. The developed software has complete data acquisition, setting, alarm, real-time monitoring and other functions. The application results show that the system effectively realizes the monitoring of the temperature control system with good results.

2. System Structure

The intelligent instrument has relatively complete functions and high control accuracy. It comes with an RS422A communication card, with more than 100 communication commands, and a large amount of data uploaded and received, mainly including the temperature setting value of each step, PID parameter value, alarm parameter value, sensor correction value, fuzzy control parameter value, etc. The field bus adopts the RS422A bus because the RS422A bus has the advantages of simple structure, low cost and easy installation. The intelligent instrument is hung on the RS422A bus and connected to the PC serial port through the RS422A/232C converter. For this purpose, there are more than a dozen (expandable) intelligent instruments, an RS422A/232C converter, and each instrument is set with a unique address. The temperature control is completed by the lower computer (intelligent instrument). The functions completed by the main control computer are 1) actively reading the relevant data of the lower computer 2) changing the set value of the temperature control and other parameters, but not directly completing the temperature control. 3) Displaying the temperature control curve screen, the temperature controller centralized display screen and the dynamic display of alarm data. 4) Data storage, statistics, reports, etc. The hardware structure diagram of the system is shown in Figure 1.

System hardware structure diagram

Figure 1 System hardware structure diagram

3. Communication Protocol

1) The physical layer uses a balanced standard RS422 interface to improve the reliability of data transmission. In the balanced standard RS422A,

Both the transmitter and the receiver work in a differential mode. Each signal is transmitted using two wires, and 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 agrees that the baud rate is 9600bps, even parity, 1 start bit, 7 data bits, 1 stop bit, and ASCII code is used as the transmission code. The transmission frames on the bus are divided into command frames and data frames. The command frames are further divided into address command frames containing address information for establishing a connection and control command frames that require uploading or downloading data for an established connection. The text format of the latter and the data frame is as follows:

The latter and the text format of the data frame

3) The network layer implements the functions of the protocol of this layer by the PC. In the transmission frame on the bus, the address command frame is sent by the control PC in the form of broadcast, which is used to wake up a certain instrument on the bus, and handshake to request to establish a communication relationship with it. Then the corresponding instrument returns the local address to the control PC, and the handshake is successful; otherwise, the instrument returns a negative response to the PC. When the PC wants to communicate with other instruments other than the current communicating instrument, it must first abandon the current communication relationship and send a communication abandonment command frame. Then re-establish the connection in the above manner. The format of establishing a connection, abandoning the connection, and the response of the temperature controller are as follows:

Abandon the connection and the temperature controller's response format

ENQ, EOT, and ACK are control codes and end codes, indicating the end of a frame.

4) Application layer The application layer of the RS422A bus network system of industrial intelligent instruments is to frame the information transmitted between the control PC and the intelligent instrument, that is, the data format is defined according to a certain format and meaning.

4. System software design

The system management software adopts object-oriented technology, based on Windows2000 platform, and developed with VC++6.0. The system application software consists of two major parts: real-time dynamic process and historical record browsing. The real-time dynamic process includes three modules: data acquisition and setting, operation control, and data management. The data acquisition and setting module regularly collects and sets real-time data from the lower computer, i.e., the intelligent instrument. The control module mainly controls the operation or stop of the instrument and the operation segment selection. The data management module includes data communication, data display, alarm, printing, storage and other functions.

According to the characteristics of real-time systems, multiple tasks in the monitoring software run simultaneously. In order to prevent one task from blocking other tasks when it is executed, we fully utilize the characteristics of Windows system that allows multi-process and multi-threaded programming, and divide the system into several modules. First, the historical record browsing and real-time dynamic process are divided into two processes, because the two processes are very different. The data in the historical record browsing is static, there is no requirement for real-time performance, and it can be run during or after the production process. When developing this part of the program, you don’t need to consider the time issue. The real-time dynamic process is a task with high real-time requirements. In this process, the main tasks are to complete communication, display, control, printing, etc., and data dumping must also be completed.

(1) Dynamic process design

The term thread refers to the sequential execution of program instructions, with each program executing a series of instructions in the program code independently. From the user or application programming perspective, the threads in a program run simultaneously. The operating system usually achieves this sense of simultaneity by quickly switching control between threads and threads (but if the computer has multiple processors, the system can directly execute threads simultaneously). When a program needs to complete multiple tasks at a time (as many reference programs do), putting each task in a different thread not only makes the program more efficient, but also simplifies development work.

When designing a real-time dynamic process, we divide it into two threads: the main thread and the communication thread. The main thread starts the communication thread regularly, and the communication thread automatically suspends after completing a communication task. Under normal circumstances, the time between the main thread resuming the communication thread twice is enough to ensure the complete execution of a communication thread.

In terms of data storage, in order to improve the dynamic performance of the system and require fast access to the data storage area, we store the data in two places. The process data of the ongoing production process is first stored in the data buffer opened in the memory, so that the main thread can access it quickly. In addition, the data of several communications is regularly stored on the hard disk, which can prevent data loss caused by accidents such as power outages.

When designing the program, we adopted the idea of ​​object-oriented design. For example, we regarded the temperature controller as an object, and the relevant data structure and its operations were completely encapsulated in a class. In this way, the data structure separation of the program can also be achieved, which will greatly facilitate software expansion, software development and debugging.

The main implementation methods of the software are as follows:

In the overloaded void CRS422AnetView::OnDraw(CDC*pDC) function, the custom function StartOfSystem(pDC) is called, which opens and configures the serial port, starts the communication thread, 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, the timing interval is 5 seconds

CwinThread*m_pThreadd=AfxBeginThread(CommProc,this->GetDocument(), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL); // Create and suspend thread

if (m_pThreadd == NULL)

{

CloseHandle(m_hCom);

return FALSE;

}

else

{

m_bConnected=TRUE;

m_pThreadd->ResumeThread(); // Resume thread running

}

}

UINT CommProc (LPVOID pParam) is an auxiliary communication thread, which completes the setting value and the reading of dynamic data. Its program flow chart is as follows:

Program flow chart

void CRS422AnetView::OnTimer(UINT nIDEvent)is a function that responds to the timer message. The timing is triggered. In this program, the timing interval is 5 seconds. In this function, the auxiliary communication thread is restored, the data display program is called, and the data is refreshed regularly.

(2) Design of historical record browsing process

The purpose of browsing historical records is to review the past production process. It can combine the product quality with the process settings for analysis, and 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 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 on site for a long time. The system runs stably and reliably, giving full play to the convenience of network management and improving production efficiency. Obviously, for some medium and small-scale measurement and control systems, RS422A is a good choice.

Reference address:Temperature Control Network Control System Based on RS422A Fieldbus

Previous article:Design of electrical fire monitoring system based on CAN bus
Next article:Application of CAN bus in elevator remote monitoring system

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号