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.
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:
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:
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:
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.
Previous article:Design of electrical fire monitoring system based on CAN bus
Next article:Application of CAN bus in elevator remote monitoring system
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- ADI Live Review on April 29: Multi-parameter Optical Water Quality Analysis Platform
- 【DIY Creative LED】Main Program
- Research and Implementation of TCP/IP Protocol Stack Based on TI C6000
- How to choose TVS tube for MSP430FR2633 touch chip
- Circuit Analysis
- Tms320VC5502 and isp1581 high-speed data acquisition solution
- 2019FPGA Employment Competition and Guidance
- What kind of activities do you hope the RF/Radio Frequency section will carry out? Please leave a message in the thread.
- Oscilloscope usage tips you don't know
- Free Trial | Keysight Accelerates Signal Integrity and Power Integrity Testing