Software Design of a Monitoring System Based on VB and KingSCADA
2026-04-06 03:49:07··#1
1 Introduction Currently, there are two main methods for developing monitoring system software. One is to use object-oriented visual programming languages such as VB and VC++, which include data communication, interface implementation, data processing, and database functions. The other is to use configuration software, utilizing its hardware driver functions to directly access and communicate with the hardware, while using its graphical tools to implement the monitoring interface. The former method has a heavier programming workload, especially in realistically displaying complex processes and technologies in industrial production, which requires a significant amount of time. The latter method is more dependent on hardware, and will be limited if the configuration software does not support the relevant hardware. Combining the two methods is a better choice. Utilizing the powerful data communication and processing functions provided by VB and VC++ for data acquisition, control, and processing, and using the graphical tools of configuration software for interface design, the combination of the two will make the design of monitoring system software simpler and more flexible. 2 System Overview In the design of a production monitoring system for an oilfield, the author used a combination of VB and KingSCADA to design the monitoring software for the entire system. This system has multiple measurement and control points. Some require control (e.g., pressure), which is accomplished using the PLC's analog input/output modules. Others only require measurement, such as on-site liquid level and flow rate, using instruments like fiber optic level gauges and smart flow meters. These instruments have analog and digital communication capabilities but cannot communicate directly with KingSCADA. Therefore, a communication program is written in VB to communicate with the PLC and instruments, analyze and process the data, and achieve data sharing through Dynamic Data Exchange (DDE) between VB and KingSCADA. A corresponding monitoring interface is designed in KingSCADA. The entire system adopts a multi-level distributed structure, consisting of two sub-control stations and one master control station, and is required to implement remote monitoring functionality. The system structure is shown in Figure 1. It comprises a bottom-level PLC control system, a sub-control room process monitoring system, a master control room management system, and a networked remote monitoring system. The PLC control system mainly controls the on-site equipment and includes analog input modules, analog output modules, and PID control modules. The function of the sub-control room process monitoring system is to communicate with the underlying PLCs and instruments to acquire production process data, display process flow charts, historical curves, real-time curves, alarm screens, and generate databases. [align=center] Figure 1 System Structure Diagram[/align] The main control room communicates with the sub-control room industrial control computers to acquire production process parameter reports, alarm records, and other information, providing management personnel with information to understand the overall production status and adjust production plans. The sub-control room and main control room systems are connected via Ethernet, sharing data and information. Information from the sub-control room computers is sent to the host computer via the network, where the main control room completes the data processing tasks, automatically generates various reports, and prints them out at specified times. The main control room can switch between synchronously monitoring the operation of each sub-control room system according to the operator's selection. The main control room computer also functions as a network server, transmitting these production parameters online and connecting to the local area network and the internet to achieve networked remote monitoring. Fast Ethernet is selected between the main monitoring room and the remote monitoring local area network; due to the long communication distance and the presence of interference sources between the sub-control rooms and the main control room, the RS485 serial communication standard is selected. The control room and PLC instruments use the simple and reliable RS232 serial communication standard. 3. Data Acquisition and Communication Program The data acquisition and communication program, as the interface with the instruments, PLC, and host computer monitoring software, plays a crucial role in the system software. Its functional structure is shown in Figure 2. The data acquisition and communication program on the control room monitoring computer mainly includes three parts: communication with intelligent instruments and PLCs, and communication with the main control room. All parts are written in VB, using the MSComm communication control provided by VB6.0. The MSComm control controls the serial port through timed polling, reading or sending data at regular intervals, including timed reading of data from intelligent instruments and PLCs, and timed transmission of data to the main control room computer. Writing PLC control parameters is handled using an event-driven approach. Relevant flags are set in the program; when writing is needed, the corresponding event causes the flags to change, then the corresponding processing and writing subroutines are called. Data requiring graphical display is defined as DDE variables in VB and serves as the DDE data server for the corresponding data variables in KingSCADA. The data acquisition and communication program generates an executable program that automatically runs in the background when the monitoring system software starts. The main control room computer receives data periodically transmitted from the sub-control rooms, stores it in the database, and uses it as the data source for remote monitoring page access. It also uses Flash, ASP, etc., to generate dynamic web pages and publishes them to the local area network and the internet to achieve remote monitoring. [align=center] Figure 2 Functional Structure of the Communication Program[/align] 4 Implementation of DDE in KingSCADA and VB DDE (Dynamic Data Exchange) based on the Windows message mechanism is a means for Windows applications to communicate with each other. It establishes a client/server relationship between running applications to exchange data or instructions. DDE can act as a bridge connecting the field signals of the monitoring system and the monitoring software, allowing two Windows applications to communicate by exchanging DDE messages, thereby completing data requests, responses, and transmissions. Therefore, if it is necessary to integrate monitoring data with the monitoring interface, DDE service software with general functions can be pre-written, specifying the application name (server), title name (topic), and item name (item) for the user, allowing the user to complete the configuration function of the monitoring screen according to the provided specifications. DDE provides dynamic data exchange between different programs during runtime. It's a protocol built on the Windows internal messaging system and shared global memory, used to coordinate data exchange and command calls between Windows applications. The DDE protocol uses a three-level naming convention: service, topic, and item to identify the data units transmitted by DDE. A service enables an application to exchange data with other programs; generally, a service is the application's filename. A topic is a meaningful unit of information for the server; many servers have default topics. Each dialogue between a DDE client and service program is initiated by the client, so the DDE server must be running before each client starts. DDE supports three data exchange modes: cold link (client application requests data from server); warm link (client application requests a notification from server to know when specific data items have changed); and hot link (server sends both a notification and the data itself to the user when a specific data item changes). The DDE protocol is well-encapsulated in VB and KingSCADA, making dynamic data exchange easy to implement. To establish a DDE connection, a DDE variable needs to be created in the KingSCADA data dictionary, and three identifier names need to be registered. The program name of the KingSCADA runtime system is "view", the topic is defined as "tagname", and the item is the item name defined when the DDE variable is defined. The variable name is used by KingSCADA, and the "connection object name" is used to define information about the server program. When KingSCADA, acting as a client, requests data from VB, it needs to specify the three identifier names of the server program when defining the variable. The application name is the name of the executable program in VB, the topic is the value of the linktopic property of the executable program's form in VB, and the item name is set to the name of the control in the form. In VB, DDE connections are achieved through control properties and methods. Three properties need to be set: linktopic, linkitem, and linkmode. When VB software acts as a client: the linktopic property refers to the name of the server software and the name of the file created under it; the linkitem property refers to the items specified by the linkmode property of the server software to be passed to the VB control. The `linkmode` property has three settings: "0" for none (no DDE functionality); "1" for hot (client data is updated whenever server data changes); and "2" for cold (client data is only updated when a DDE request is made). When VB acts as the server, only the `linktopic` and `linkitem` properties need to be set. The `linktopic` property refers to the form that will respond to client requests, and the controls in the form are the items requested by the client. The `linkmode` property has two options: "0" for none and "1" for server. When set to "1", the controls on the form can supply data to the client software with an established DDE pipeline; when set to "0", there is no DDE connection. A large amount of data exchange exists between the substation monitoring program and the data acquisition program, which is achieved through the DDE connection between the data acquisition program running in the background and KingSCADA. The data acquisition program acts as the DDE server, and KingSCADA acts as the client requesting data from it. The DDE connection between KingSCADA and the data acquisition program is automatically established when KingSCADA starts. 5 Conclusion The DDE connection enables information integration and sharing between the data acquisition program and the monitoring software. Using the rich graphics and configuration tools provided by KingSCADA, real-time data refresh of process flow diagrams, display of various curves and alarms can be realized. This method can give full play to the advantages of VB and KingSCADA, and make the development of monitoring system software simpler and more flexible by using VB's data communication and processing capabilities and KingSCADA's graphical tools. References [1] Lu Qiuhong, Zhang Guowei, Yan Guozheng. Application of dynamic data exchange in industrial automatic control configuration system [J]. Industrial Instrumentation and Automation Device, 2001, (6). [2] Wang Weidong, Li Chao. Realization of remote monitoring system by combining KingSCADA and PLC [J]. PLC&FA, 2002, (4). [3] KingSCADA 6.0 User Manual [Z]. Beijing Yacon Automation Software Technology Co., Ltd. About the author Li Chao (1979-) Male Teaching assistant mainly engaged in teaching and research work on computer control, fieldbus and industrial monitoring systems.