1 Introduction
VC (Visual C++) is a powerful Windows application visualization software development tool. VC supports object-oriented design methods and can use the powerful Microsoft Foundation Class Library MFC (Microsoft Foundation Class). And because of Microsoft's monopoly in the operating market, the software developed with VC has good stability and strong portability, and the software and hardware are independent of each other [1]. It can be used to develop the upper management system of the control system. RSView32 is a configuration software specially used for industrial control. It not only contains a large number of graphic development tools and ready-made graphic libraries, allowing users to easily develop systems, but also can configure alarms, activity records, events, historical trends, etc. It is a powerful industrial automation product [2], so it is very convenient to configure the lower-level equipment. In the actual system development, the OPC technology is used to effectively combine the two tools, so that the upper-level VC program can indirectly communicate with the lower-level PLC through RSView32 to obtain satisfactory results.
2 Introduction to OPC
OPC (OLE for Process Control) is an open and interoperable user interface standard based on the functions required by Microsoft's OLE (now Active), COM (Component Object Model) and DCOM (Distributed Component Object Model) technologies. It ensures the interoperability between automation/control applications and regional systems/equipment. It uses the OLE/COM mechanism as the application-level communication standard and adopts the CLIENT/SERVER model. The typical OPC architecture is shown in Figure 1:
Figure 1 Typical OPC architecture
The OPC specification provides two sets of interface solutions, namely, custom interface and automation interface. Custom interface is highly efficient and can bring out the best performance of OPC server. Clients using C++ language generally use custom interface solution; automation interface makes it possible for interpreted language and macro language to access OPC server. Clients using VB and other languages generally use automation interface.
OPC data access server consists of three types of objects: server, group, and item. Server object is used to indicate the name of a specific OPC server application and serves as a container for group object; group object stores group information composed of several items and logically organizes data items; data item object () stores the definition, data value, status value and other information of specific item. One item represents a specific process variable. To obtain data from OPC server, OPC client application must specify the computer name where the server application is located (the server application and client application are not on the same PC), OPC data access server name and the definition of OPC item provided by the server.
After establishing an OPC connection, client applications can generally read data from the OPC server in three ways: using the synchronous interface IOPC-SyncIO, which is simple and effective and suitable for client programs that only read a small amount of data; using the "subscribe" function OnChange of the interface IOPCCallback, the server automatically notifies the client whenever the data changes; using the asynchronous interface IOPCASyncIO2, which can communicate directly with the physical device, which is slow but has high data accuracy.
3 RSView32 as OPC Server
RSView32, one of Siemens' general-purpose configuration software for industrial control, supports OPC technology. It can be used as an OPC client to communicate with external OPC server software, or as an OPC server to connect with other third-party software that supports OPC technology. In this article, RSView32 is used as a server and the VC application is used as a client. The C/S mode is used to implement data exchange between the two.
3.1 Enable RSView32 as an OPC server [4]
Use one of the following methods to enable RSView32 as an OPC server:
(1) Select the "OPC/DDE Server" checkbox on the "Startup" page of the "Startup" editor;
(2) Issue the RTDataServerOn command (from the command line or another RSView32 component, use the RTDataServerOff command to cancel this function), which will allow other applications to read the value but not change it;
(3) Issue the RTDataWriteEnable command (from the command line or another RSView32 component, use the RTDataWriteDisable command to cancel this function), which allows writing from an external OPC application to change the RSView32 tag value.
3.2 Create an OPC client project [4]
To obtain data from RSView32, the VC application must use the following information:
Server: RSI.RSView32OPCTagServer;
Type: Local/Remote;
Server computer name or address: If the client and server are on the same computer, this can be blank.
Access path: Project name;
Update rate: A rate in seconds;
Item: Tag name. This can be obtained by viewing the RSView32 tag database.
4 VC application as OPC client program implementation
In the VC environment, use the custom interface to develop OPC client applications. The following are the key steps for program implementation.
4.1 Include OPC header files
In addition to the OPC interface, you also need to include the OPC standard library files in the program when developing OPC client applications. You can download these files from the OPC Foundation website (URL: www.opcfoundation.org):
#include "opcda_i.c" OPC data access interface
#include "opcda.h" OPC data access 2.0 header file
#include "opccomn_i.c" OPC public interface definition
#include "opccomn.h" OPC public header file
4.2 Initialize COM support library
Because OPC is based on COM technology, you must first use the CoInitialize(NULL) function to initialize the COM library before using the interface class. If successful, the function return value is equal to S_ OK.
4.3 Connecting to the OPC Server
The OPC client can connect to the OPC server and establish OPC groups and OPC data items. This is the basis of OPC data access. Without this mechanism, other functions of data access cannot be realized [4]. To connect to the OPC server, the OPC client needs to specify the computer name (if the OPC server and the OPC client are not on the same computer) and the OPC data access server name (RSI.RSView32OPCTagServer) in advance. Implementation code is as follows:
ConnectToServer(/*in */LPOLESTR ProgID,/*in*/ BOOL IsRemote,/*out */ IUnknown **ppUnknown)
{
CLSID OPCCLSID;
HRESULT hRet=CLSIDFromProgID(ProgID,&OPCCLSID);
//Convert string ProgID to unique OPCCLSID
if(IsRemote)
//opc server and opc client are not on the same computer
{
COSERVERINFO ServerInfo;
memset(&ServerInfo,0,sizeof(ServerInfo));
ServerInfo.pwszName=T2OLE("ServerComouter");
MULTI_QI qi[1];
memset(qi, 0, sizeof(qi));
qi[0].pIID=&IID_IUnknown;
HRESULT hRet=CoCreateInstanceEx(OPCCLSID,NULL,CLSCTX_REMOTE_SERVER,
&ServerInfo,1,qi);
*ppUnknown=qi[0].pItf;
}
else
//opc server and opc client are on the same computer
{
hRet=CoCreateInstance(OPCCLSID,NULL,CLSCTX_LOCAL_SERVER,IID_IUnknown,
(void **)ppUnknown);
}
}
4.4 Create OPC Group
The AddGroup() method of the IOPCServer interface can create an OPC group with a specified name and attributes. Before calling this method, you can use the Iunknown interface pointer obtained in the previous step to request the IOPCServer interface pointer through the QueryInterface() method. The code is as follows:
ppUnknown->QueryInterface(IID_IOPCServer,(void **)&pServer);
//Get the IOPCServer interface pointer
pServer->AddGroup(L"",TRUE,500,1235,&lTimeBias,&fTemp,0,&hOPCServerGroup, &dwActualRate,IID_IOPCItemMgt,& pOPCItemMgt);
4.5 Add Data Items
The AddItem() method of the IOPCItemMgt interface can add a specified number of data items with special attributes.
pOPCItemMgt->AddItems(ItemNumber,ItemArray,
(OPCITEMRESULT**)&pItemResult,(HRESULT **)&pErrors);
ItemArray is an OPCTEMDEF type structure array, which contains detailed information about the data items. The client needs to know the name of the data to be exchanged in the RSView32 tag database, the data type, and the RSView32 project name as the OPC server. Before adding data items, the ItemArray structure array must be initialized with these data item information.
4.6 Data Exchange
After successfully adding the required data items, the OPC client (VC application) and the OPC server (RSView32) can exchange data. When the amount of data is not large, the Write() and Read() methods of the IOPCSyncIO synchronization interface can be used to read and write data, thereby realizing data exchange between the OPC client (VC application) and the OPC server (RSView32). The code is as follows:
ppUnknown->QueryInterface(IID_IOPCSyncIO,(void **)&pOPCSync);
//Get the IOPCSyncIO interface pointer
pOPCSync->Read(OPC_DS_CACHE,ReadNumber,hServerRead,&pItemValue,&pErrors);
//Read ReadNumber data
pOPCSync->Write(WriteNumber,hServerWrite,WriteValue,&pErrors);
//Write WriteNumber data
4.7 Release the interface pointer
Before the VC application stops running, the Release() method must be used to delete the created OPC object and release the memory.
5 Conclusion
The OPC technical specification separates hardware suppliers and application software developers, which greatly improves the work efficiency of both parties. Software developers can access the data in the OPC data server without understanding the essence and operation process of the hardware. In particular, when developers use high-level languages such as C++ to develop systems based on process control systems that have used configuration software for real-time monitoring, the complex process of transmitting data from devices in the past has been greatly simplified. In the development of an automatic batching system in an aluminum plant, the application of OPC technology conveniently realized the data exchange between VC applications and RSView32, and indirectly realized the communication between VC applications and PLCs, achieving good results.
Previous article:Application of PLC and frequency conversion speed regulation technology in automatic complete welding center
Next article:Application of Configuration Control in Concrete Mixing Plant 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
- A pitfall of threadx queue, and also pay attention to a mistake in the tough guy tutorial
- About 48V input buck type DCDC chip
- Some characteristics of MSP430 interrupts
- Where is the SD card of sensorTile.box
- Some questions about Bluetooth Mesh
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" for free, take notes, and master the knowledge of operational amplifiers thoroughly
- About the problem of inaccurate reading of MAX6675
- Push-pull circuit
- How can a hybrid hardware engineer who doesn't know embedded programming prove that he has mastered common communication interfaces?
- Women's volleyball team wins 10th consecutive championship ahead of schedule