1 Introduction
Distributed control systems can typically be divided into four levels: field control layer, process monitoring layer, production management layer, and market operation management layer. The process monitoring layer achieves the purpose of monitoring the production process through centralized management of multiple control devices.
ForceControl PCAuto monitoring and configuration software is a software platform at the process monitoring layer. It can run on Windows 98/NT/2000/XP operating systems, communicate with common equipment from various domestic and foreign industrial control manufacturers, and combine with industrial control computers and network systems to easily and quickly construct data acquisition and monitoring systems that meet different needs.
Although ForceControl provides drivers for many commonly used devices, in practical applications, due to engineering needs and the specific characteristics of the equipment, the existing drivers provided by ForceControl cannot meet the needs of all devices. In such cases, it is necessary to develop new drivers using the interfaces provided by the ForceControl driver development kit. For ordinary users, driver development is a difficult task. However, ForceControl provides various interfaces with third-party software, such as OLE controls and internal components. This provides another solution: using development tools such as VB and VC to develop a communication program to collect data, and then using the OLE controls and other interfaces provided by ForceControl to connect the communication program with ForceControl, achieving data sharing. In this way, ForceControl can collect data from field devices without developing new drivers. The structural block diagram of this new monitoring software based on ForceControl configuration software is shown in Figure 1.
Figure 1 Software structure diagramThis paper takes a distributed control system based on RS-485 serial communication as the application background and explores the implementation of this new type of monitoring software.
2. Implementation of Serial Communication on the Host Computer
2.1 Serial Communication Interface Technology
Commonly used interfaces for serial communication include RS-232C and RS-485. Because RS-232C has a shorter communication distance, RS-485 serial communication can be used for longer distances. Conversion between RS-232C and RS-485 interfaces can be achieved using appropriate conversion modules. Most computers are equipped with communication adapters, enabling them to communicate with other computers or devices that have RS-232C interfaces. Data is transmitted in single-byte increments via a serial port, and both data and control signals move along a single wire, requiring the application of a communication protocol. Common communication protocols include: 1 start bit; 7 or 8 data bits; parity bit; 1 or 2 stop bits; and communication rate (in baud rate or bit/s).
A typical hardware configuration for a distributed control system based on RS-485 serial communication is as follows: The computer's RS-232C interface is connected to an RS-232C/RS-485 conversion module via an RS-232C serial communication cable. The conversion module is then connected to the RS-485 interfaces of each field device via an RS-485 serial communication cable. With the addition of host computer monitoring software, data from the field devices can be acquired from the computer's serial port. Serial communication can be performed in DOS or Windows environments, and communication programs can be written in assembly or high-level languages.
This article describes how to program using Windows ActiveX controls. The programming steps for writing a serial communication program using ActiveX controls are as follows:
(1) Configure the communication protocol (transmission rate, parity check, transmission bit length, stop bit);
(2) Read the line status to determine if communication is possible;
(3) Sending or receiving data;
(4) Repeat steps 2 and 3 until communication is complete.
2.2 Serial Communication Programming
Serial communication programs can be written in the Windows environment by leveraging VB's excellent interface design capabilities and powerful serial communication functions. VB 6.0 utilizes the MSComm control to send and receive data through a serial port, providing serial communication capabilities for applications.
The MSComm control is a 32-bit serial communication control for the Windows environment. Each MSComm control corresponds to one serial port. Multiple MSComm controls are used when an application requires multiple serial ports. The main properties and descriptions of the MSComm control are shown in the attached table.
Appendix: Commonly Used Properties of the MSComm Control
Before using the MSComm control, you need to add it to the toolbox: Select the "Components" item in the "Project" menu, select the "Microsoft Comm control 6.0" item in the "Controls" page, and click "OK" to complete adding the MSComm control.
MSComm provides two communication handling methods: event-driven communication and polling communication. In serial communication, an event is generated for each character received or sent. Event-driven communication uses the MSComm control's OnComm event to capture and process communication events, which include various messages related to serial communication.
The following is a program example for sending and receiving data using computer serial port 1.
Send data:
Private Sub DataSend ( )
Dim Data(5) As Byte MSComm1.Commport = 1 'Set MSComm1 to correspond to Comm1
MSComm1.Settings =”96000,N,8,1” ' 9600bit/s, no parity, 8 bits, 1 stop bit
If MSComm1.PortOpen = False, then 'Open port'
MSComm1.PortOpen = True End If Data (0) = CByte(TeAddr.Text) 'Device address
Data e(1) = &H4 'Function number reads power parameters'
Data e(2) = &H0 'Data starting address'
Data (3) = &H0 Data (4) = &H0 'Data length'
Data e(5) = &H15 MSComm1.OutBufferCount = 0 'Clear the send buffer'
MSComm1.Output = Data 'Send data'
MSComm1.PortOpen = False 'Close port'
End Sub
Received data:
Private Sub MSComm1_OnComm() Dim rec() As Byte Select Case MSComm1.CommEvent Case comEvReceive 'Serial port receive event'
rec = MSComm1.Input 'Read the input buffer'
End Select End Sub
3. ForceControl Real-Time Database and DbCom Controls
ForceControl's real-time database is an open data platform. Users can leverage the interfaces provided by the database to perform secondary development on this platform and create their own applications. The DbCom control provided by the real-time database is a convenient and efficient interface method.
DbCom is a standard OLE control that users in various common development environments (such as C++ Builder, VC++, VB, Delphi, etc.) can call to access data in a database. Through DbCom, the host computer communication program can not only read data from the ForceControl database but also configure it. During ForceControl installation, the installer automatically completes the installation and registration of DbCom. DbCom is a running OLE control; when used in an application, the database (DB) must be started simultaneously.
Below are two commonly used methods for accessing the ForceControl database using the DbCom control.
(1) Method 1: GetRealData. Used to read multiple numeric data.
Syntax: long GetRealData(long count, LPCTSTR strNames, double* data).
Parameter description: count: number of data items.
strNames: Data name string, a character variable, with data names separated by commas.
data: A double-precision floating-point pointer that returns an array of data.
Return value: Long integer.
0: Success; -1: Failure.
(2) Method 2: SetStringData. Set the database based on the data name and data value.
Syntax: long SetStringData(long nCount, VARIANT* pvTagPars, VARIANT* pvData).
Parameter description: nCount: Number of data items.
pvTagPars: A VARIANT array containing nCount data names.
pvData: A VARIANT array containing nCount data values.
Return value: 0 on success, non-zero otherwise.
The following program provides examples of two common methods for reading and writing the force control real-time database in a host computer communication program.
//Read the database
Private Sub GetParameters() 'Reads electricity and active power values
Dim count As Integer, result As Integer Dim rdata (1) As Double Dim pars As String count=2 pars=”dbkWh1.PV,dbkW1.PV” ‘Method to call DbCom
result = DbCom1.GetRealData(count, pars, rdata) 'Read data'
If result = -1 Then MsgBox("Please start the force control real-time database first!") Else kWh = rdata(0) 'Electricity value'
kW=rdata(1) 'Active power value
End If End Sub
//Set up the database
Private Sub SetParameters() 'Writes the electricity and active power values into the force control database.
Dim count As Integer, result As Integer
Dim *pTagPars(1) As VARIANT, *pVals(1)
As VARIANT count=2 pTagPars(0)=dbkWh1.PV 'Data name'
pTagPars(1) = dbkW1.PV pVals(0) = kW·h Data values
pVals(1) = kW Calling DBcom's method
result = DbCom1.SetStringData(count, pTagPars, pVals) 'Set data
End Sub
4. Conclusion
This paper proposes a novel monitoring software based on ForceControl configuration software. Utilizing the OLE control interface provided by ForceControl's real-time database, it combines the powerful functionality of ForceControl configuration software with the flexibility of VB-based self-developed programs, better meeting the needs of industrial distributed control systems. This new monitoring software has been successfully applied in practical engineering projects such as a port power distribution monitoring system.