I. Introduction
With the development and maturation of computer technology, the application of computers is becoming increasingly widespread. In the field of automation, computers have become the preferred platform for control systems, and the application of computers for real-time and remote monitoring of production and experimentation is a major direction of modern automation development. The prerequisite for applying computers to industrial real-time control is the real-time acquisition of field data. In production and scientific experiments, many parameters often need to be measured and controlled, such as temperature, pressure, and rotational speed. The usual method is to use dedicated instruments for manual observation, recording, processing of data, and judgment, which introduces human error, and the application scope is limited by factors such as field conditions and response speed. Automatic real-time monitoring systems can effectively solve these problems. This paper uses a simple and practical real-time temperature acquisition system as an example to discuss a framework structure and implementation method for remote measurement and control using computers.
II. Hardware Components
The system architecture is shown in Figure 1, where:
The COMPUTER is a standard PC that must run the Windows 98 operating system and the VB6.0 development environment. It must have a standard RS232 or RS485 serial port and its main functions are data acquisition, processing, and system control; it serves as a human-computer interaction platform. The experiment used a PIII800 computer.
The ADAM4521 is an interface conversion module from Advantech, capable of converting RS485 or RS422 signals to RS232 signals. Since ordinary PCs only have RS232 interfaces, while typical industrial test signals conform to RS485 or RS422 standards, conversion is necessary. The Advantech ADAM4521 module features: addressable; built-in microprocessor; 115.2Kbps transmission speed; 1000VDC high-voltage isolation; RS485 surge voltage protection; input and output can be set to different baud rates; no handshake signal required.
The ADAM4013 is a thermistor input module from Advantech, capable of converting analog signals from thermistors into RS485 digital signals. The ADAM4013 module utilizes a built-in microprocessor to control an A/D converter, converting analog signals of current, voltage, or thermistor signals into digital signals. The module provides signal adjustment, A/D conversion, measurement range adjustment, and RS485 communication functions. Its excellent optical isolation effectively protects the equipment. Key features of the module include: built-in watchdog timer; 3000VDC high-voltage isolation; a sampling rate of 10 times/second; and an error of less than 0.05%. These parameters meet the requirements of most applications.
The temperature sensor is a platinum resistance thermometer (Pt100) measuring temperatures from -100℃ to +100℃. The temperature coefficient α of the ADAM4013 module is set to 0.00385. Different temperature sensors can be selected according to the required measurement range and accuracy; the corresponding parameters can be configured during software design.
The medium in the experiment was a chemical reaction between two liquids. The platinum resistance thermometer (Pt100) converted the chemical reaction temperature into an analog electrical signal, which was transmitted to the ADAM4013 module. After sampling and processing, it was converted into an RS485 digital signal. Then, after being converted by the ADAM4521 module, it became an RS232 signal that the computer could receive. After receiving the data, the computer displayed it in real time, plotted the temperature curve, and simultaneously performed background processing and storage for later use.
III. Software Implementation
The system software is mainly programmed using VB6.0 to implement communication between hardware components via RS232 serial port. The software block diagram is shown in Figure 2.
1. Introduction to the MSComm Control
In VB6.0, RS232 serial port programming is mainly achieved through the MSComm control. Below is a brief introduction to the MSComm control:
The MSComm control provides serial communication functionality for applications. The control offers two methods for handling communication: Event-driven communication is a very efficient method for handling serial port interactions. In many cases, it is necessary to be notified when an event occurs, such as when a character arrives or a change occurs on the Carrier Detect (CD) or Request To Send (RTS) line. In these cases, the MSComm control's OnComm event can be used to capture and handle these communication events. The OnComm event is generated whenever the value of the CommEvent property changes, indicating that a communication event or an error has occurred. Another method is to query events and errors by checking the value of the CommEvent property. This method may be more preferable if the application is small and self-sustaining, as it only responds to a specific event.
Each MSComm control corresponds to one serial port. If an application needs to access multiple serial ports, multiple MSComm controls must be used. Key properties of the MSComm control:
CommPort: Sets and returns the communication port number;
Settings: Sets and returns the baud rate, parity, data bits, and stop bits as a string;
PortOpen: Sets and returns the status of the communication port. It can also open and close the port.
Input: Returns and removes characters from the receive buffer;
Output: Write a string to the transfer buffer.
For more detailed information, please refer to Microsoft's online documentation MSDN.
2. Introduction to commonly used commands of the ADAM module
ADAM modules use special convention characters to implement corresponding operations, the commonly used ones being:
"%0101210600": Sets the port, 0-100 degrees, scientific units;
"#01": Read data from serial port 1;
"#02": Read data from serial port 2;
"$010": Module automatic calibration;
"$011": Offset calibration;
"$012": Read port information;
"$01M": Read the module name.
3. Main interface and some code
VB6.0 has powerful interface editing capabilities and is a fully object-oriented programming language. Human-computer interfaces implemented with it are intuitive, user-friendly, easy to operate, and easy to implement. Below is the interface created in the experiment (Figure 3):
As can be seen from the interface, the system can realize temperature acquisition settings and data display processing functions.
The key code is as follows:
Const CMDconfig = "%0101210600" 'Sets the port command characters, 0-100 degrees, scientific units
Const CMDdataIn1 = "#01" 'Read serial port 1 data command character
Const CMDdataIn2 = "#02" 'Read serial port 2 data command character
Const CMDspanCalibration = "$010" 'Calibration command character'
Const CMDoffsetCalibration = "$011" 'Offset calibration command character
Const CMDconfigStatus = "$012" 'Command character for reading port information'
Const CMDmoduleName = "$01M" 'Read module name command character
Private Sub CmdStart_OnClick() 'Start command subroutine
MSComm1.CommPort = COMnum 'Set the serial port number'
If MSComm1.PortOpen = False Then 'Open serial port'
MSComm1.PortOpen = True
End If
If COMnum = 1 Then
CMDdataIn = CMDdataIn1
Else
CMDdataIn = CMDdataIn2
End If
MSComm1.Output = CStr(CMDdataIn) & vbCr 'Issue a read command'
TimeDelay 500' Delay 500ms
Picture1.CurrentX = 0 'Draw the starting point of the curve coordinates'
Picture1.CurrentY = temperature
Timer1.Enabled = True 'Start timing'
End Sub
Private Sub MSComm1_OnComm() 'Event Response Subroutine
Select Case MSComm1.CommEvent 'Determine the MSComm1 communication event'
Case comEvReceive 'Receive event generated when Rthreshold bytes are received
MSComm1.RThreshold = 0 'Disable OnComm event reception
TimeDelay 20' delay 20ms
temperatureShow = Right(MSComm1.Input, 7) 'Read the first data byte (BCD high-order byte)
temperature = Val(temperatureShow) 'Combined numerical values, with decimal point calibration'
MSComm1.Output = CStr(CMDdataIn) & vbCr 'Send read command
MSComm1.InBufferCount = 0 'Clear the buffer'
MSComm1.RThreshold = 1 'Disable OnComm event reception
Case comEventBreak ' Received Break.'
…
Case Else
End Select
End Sub
The program typically uses the system clock for timing, which requires the system dynamic link library kernel32.dll. One point to note is that due to the limited speed of the serial port and the limited system speed, the sampling interval should generally not be less than 15 milliseconds; otherwise, delay errors will occur.
IV. Conclusion
The biggest advantage of this system is its ease of implementation. It requires no data acquisition card or hardware drivers, hardware connections are convenient, and software development is relatively easy to master. Basic VB skills and understanding of serial port control applications are sufficient, making it particularly suitable for smaller temperature measurement systems. Because the ADAM module is addressable, multiple modules can be used to measure and acquire multiple parameters. The entire system has a short development cycle, is easy to debug, and runs reliably. User interfaces can be customized as needed. The system only occupies one serial port on the PC, consuming minimal resources and having low hardware requirements. Each module can be flexibly applied in different situations.
References:
[1] Li Feng, Zeng Deliang, Serial Communication Programming Based on VB6.0, Modern Electronics Technology, 2002.10, 54-57;
[2] Zheng Chunsheng, Yu Yun, et al. Research on computer continuous real-time temperature acquisition system, Foundry Technology, 2003.024(003), 193-194;
[3] Zhou Liushun, Design of a Microcomputer Temperature Acquisition System Based on VB Programming, Chemical Engineering Design Communications, 2002.028(003), 47-48;
[4] Li Shihui, Design and implementation of computer multi-point temperature acquisition system, Computing Technology and Automation, 2001.020(001), 71-74;
[5] ADAM Acquisition Module User Manual, Advantech Inc.;
[6] Microsoft Corporation, Microsoft (China) Co., Ltd., Microsoft Visual Basic 6.0 Chinese Version Programmer's Guide, Beijing Hope Computer Company, January 1998;
[7] Fan Yizhi, Chen Liyuan, Visual Basic and RS-232 Serial Communication Control (Latest Version), China Youth Press, 2002.01.
About the author:
1. Qiao Zhihong, Master's student in Detection, Class of 2001, School of Electrical and Control Engineering, Beijing University of Technology; Research direction: Signal Processing;
2 Wu Qing, Associate Professor of Detection at the School of Electrical and Control Engineering, Beijing University of Technology, Postgraduate Supervisor, Research Interests: Signal Detection and Processing