Using OPC to realize data exchange between VC application and PLC

Using OPC to realize data exchange between VC application and PLC

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 (Micro-soft foundaTIon class). And because Microsoft's monopoly position in the operating market, the software developed with VC is stable and portable, and the software and hardware are independent [1], which can be used to develop the upper management system of the control system. RSView32 is a configuration software specially designed for industrial control. It not only contains a large number of graphic development tools and off-the-shelf graphics libraries, but also enables users to easily develop the system, as well as alarms, activity records, events, historical trends, etc. Configuration is a powerful industrial automation product [2], so it is easy to configure the underlying equipment. In the actual system development, the two tools are effectively combined by OPC technology, so that the upper VC program indirectly communicates with the lower PLC through RSView32 to obtain satisfactory results.

2 OPC Introduction

OPC (OLE for Process Control) is an open and interoperable user interface standard based on the capabilities required by Microsoft's OLE (now AcTIve), COM (Component Object Model), and DCOM (Distributed Component Object Model) technologies. It guarantees interoperability between automation/control applications and regional systems/devices. It uses OLE/COM mechanism as the application-level communication standard, adopts CLIENT/SERVER mode, and the typical OPC architecture is shown in Figure 1:


Figure 1 Typical OPC Architecture

Two sets of interface solutions are provided in the OPC specification, namely custom interfaces and automation interfaces. The custom interface is highly efficient, and the interface can achieve the best performance of the OPC server. The client adopting the C++ language generally adopts a customized interface scheme; the automation interface makes it possible for the interpreted language and the macro language to access the OPC server, and the client adopting the VB language or the like generally adopts Automation interface.

The OPC Data Access Server consists of three types of objects: Server, Group, and Item. The server object is used to indicate a specific OPC server application name and serves as a container for the group object; the group object stores Group information composed of several items and logically organizes the data items; the data item object () stores the definition and data value of the specific Item. Information such as status values, an Item represents a specific process variable. To obtain data from the OPC server, the OPC client application must specify in advance the computer name where the server application is located (the server application and the client application are not on the same PC), the OPC data access server name, and the definition of the OPC item provided by the server.

After the OPC connection is established, the client application can generally read data from the OPC server in three ways: using the synchronous interface IOPC-SyncIO, simple and effective, suitable for client programs that read only a small amount of data; using the "subscription" of the interface IOPCCallback Function OnChange, the server automatically informs the client whenever the data changes; using the asynchronous interface IOPCASyncIO2, it can directly communicate with the physical device, the speed is slow but the data accuracy is high.

3 RSView32 as an 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. It can also be used as an OPC server to connect with other third-party software supporting OPC technology. In this paper, RSView32 is used as the server, and the VC application is used as the client. The C/S mode is used to exchange data between the two.

3.1 Making RSView32 as an OPC Server [4]

Use one of the following methods to make RSView32 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 Establishing an OPC Customer Project [4]

To get data from RSView32, VC applications must use the following information:

Server: RSI.RSView32OPCTagServer;

Type: local / remote;

Server computer name or address: This can be blank if the client and server are on the same computer.

Access path: project name;

Update rate: a rate in seconds;

Entry: tagname. It can be obtained by looking at the RSView32 tag database.

4 VC application as a program implementation of OPC client

Developing a OPC client application using a custom interface in a VC environment is a key step in the implementation of the program.

4.1 Include OPC header files

To develop an OPC client application, in addition to the OPC interface, you need to include the OPC standard library files in the program. These files can be downloaded from the OPC Foundation website (website: TIon.org):

#include "opcda_i.c" OPC Data Access Interface

#include "opcda.h" OPC Data Access 2.0 header file

#include "opccomn_i.c" OPC Common Interface Definition

#include "opccomn.h" OPC Common Header

4.2 Initializing the COM Support Library

Since OPC is based on COM technology, you must first initialize the COM library with the CoIniTIalize(NULL) function before using the interface class. If successful, the function return value is equal to S_OK.

4.3 Connecting the opc server

OPC clients can connect to the OPC server and create OPC groups and OPC data items, which is the basis for OPC data access. Without this mechanism, other functions of data access are not possible [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). The implementation code is as follows:

ConnectToServer(/*in */LPOLESTR ProgID, /*in*/ BOOL IsRemote, /*out */ IUnknown **ppUnknown)

{

CLSID OPCCLSID;

HRESULT hRet=CLSIDFromProgID(ProgID,&OPCCLSID);

/ / Convert the string ProgID to a unique OPCLSID

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 Creating an OPC Group

The AddGroup() method of the IOPCServer interface creates an OPC group with the 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. code show as below:

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 Adding 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 OPCITEMDEF type structure array, which contains the detailed information of the data item. 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 a data item, initialize the ItemArray structure array 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. In the case of a small amount of data, you can use the Write() and Read() methods of the IOPCSyncIO synchronization interface to read and write data, thus implementing the OPC client (VC application) and the OPC server (RSView32). Data exchange. code show as below:

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 Interface Pointer

The Release() method must be used to delete the created OPC object and free the memory before the VC application stops running.

5 Conclusion

The OPC specification separates the hardware vendor from the application developer, which greatly improves the efficiency of both parties. Software developers can access the data in the OPC data server without knowing the essence of the hardware and the operation process. In particular, the developer develops the system in a high-level language such as C++ based on the process control system that has been configured using the configuration software for real-time monitoring. This greatly simplifies the complex process of transferring data from devices in the past. In the development of automatic batching system in an aluminum plant, the application of OPC technology conveniently realizes the data exchange between VC application and RSView32, and indirectly realizes the communication between VC application and PLC, and obtains good results.

2835 Led Strip is our main LED Strip for selling in the market now,now most of our Led Strip sell to Germany,Italy and USA,sourced by high output 2835 LED with good color conformity. 99.99% gold thread, pure copper bracket coated with silver,USA Intematix phosphor with CRI>90,SDCM≤3 each BIN,Double layer rolled copper FPC. 3M 300LSE tape attached,CE, RoHS and UL certified.

2835 Led Strip


Full CCT ranges from 2300K to 12000K

Led strip 2700K   Led strip 3000K

Led strip 4000K   Led strip 6500K


Various CRI option from 75 to 95

Led strip CRI

Application



  • City lighting, landscape lighting, commercial lighting and house contour lighting, etc.



2835 LED Strip

2835 Led Strip,Flexible Led Strip Lighting,2835 Flexible Led Strip,2835 Smd Led Strip

SHENZHEN LINGBENYANG IND. CO., LTD. ,

This entry was posted in on