Come from:
http://www.chint.net/bbs/dispbbs.asp?Boardid=4&ID=50915&replyID=315788&skin=1
OPC and OPC Server Design and Implementation OPC and OPC Server Design and Implementation_______opcand Design & Implementation OE OPC Server Introduction OPC (OLE for Process Control) is an industrial standard. It is established by some of the world's leading automation systems and hardware, software companies, and Microsoft to meet open and interoperability interface standards. The establishment of the OPC standard Based on Microsoft's COM technical specifications, and is managed by the OPC Foundation. OPC defines a common interface for hardware devices, software and systems of different vendors, making it possible to connect, communicate, and operate between process control and factory automation. Generally in the control system, software (such as SCADA software) containing process screens (such as SCADA software) is often used in communication with field devices: (1) use standard communication protocols, such as PROFIBUS, Modbus, Hart, CAN bus, etc., because of monitoring management Software and on-site equipment use the same communication protocol, the monitoring management software does not require drivers for field devices. (2) For devices that do not adopt standard communication protocols, monitoring management software needs to develop drivers for these devices under the equipment manufacturer. In this way, although the execution efficiency is relatively high, the compatibility is poor, the software supplier must develop drivers without an access to the device, and the equipment manufacturer must also provide the device's communication protocol. (3) Communication is performed by OPC this open protocol and process control or other system software. The advantage of this way is that the manufacturer only needs to provide a set of OPC servers regardless of whether the hardware device uses a standard communication protocol, which can support most of the monitoring and other software, nor does it require the details of your communication protocol to Software. . After the design of the OPC server, the current small DCS control system uses an OPC server, and the compatibility of the mainstream monitoring software (generally have an OPC interface), the opc client, etc. OPC client can be easily access and setup DCS. Data in. The main function of the OPC server needs to implement the configuration information of the control system, implement the OPC server object, group object, etc., and implements communication with the master of the DCS system through the OPC driver, obtains field data or set field data items, etc. . The OPC server software is mainly divided into OPC server object module, server interface module, and OPC driver module. Three modules share data through the same primary memory data area, through the synchronization of threads and mutual exclusion, can resolve sharing data Protection problem. The following is a brief introduction to the functions of each module: (1) The server interface module server interface program is mainly based on the configuration information to complete the OPC Group object and the OPC Item object, and use the tree structure to view the data item in the memory data area (Tag " ), Such as input signals of digital signal input cards, etc. (2) The OPC driver module OPC driver implements the drive section of the OPC server mainly through the TCP / IP protocol communication with multiple primary controllers (by replacing the driver, the OPC server for other products can be implemented). (3) OPC Server Object Module OPC Server Object Module is the interaction part of the OPC server program and the OPC client, mainly relying on the data access specification of the OPC Foundation.
Generally we need to achieve OPCserver, OPCGroup, EnumOPCItemAttributes and other objects, which OPCServer objects need to implement a method interface IOPCCommon, IOPCServer, IOPCItemProperties, IconnectionPointContaniner the like; OPCGroup objects need to implement IOPCSyncIO, IOPCGroupStateMgt, IOPCAsyncIO2, IOPCItemgt, IconnectionPointContainer other interface methods; EnumOPCItenAttributes need to implement IEnumOPCItemAttributes Interface Methods. The prototype of the interface method refers to the definition of opcda.idl. Using IDE in the development of the OPC server and client, Microsoft Visualc , where the OPCServer object, the definition of COM components such as OPCGroup objects, and implements Microsoft's ATL (Active Template Library Activity Touch Base "technology. The following segment code demonstrates access to the GetStarus () method of the OPC server IOPCServer interface (client can get the time, update, name and other information of the server to get the server).
OPC client: {........... Coinitialize (null); // Initialize the COM environment ...... // p c c c * psvr = null; // Defines the IOPCServer interface pointer HRESULT HR = CoCreateInstance (CLSID-OPCServer, Null, CLSCTX-ALL, IID-IOPCServer, (void **) & pSvr); // NOTE: OPCDa2.0 available OPCserver the CLSID OPCSERVERSTATUS * pServerStaus call OPCServerList by IOPCServer; // state structure defined OPCServer PSvr-> GetStaus (& pServerStaus) ; // Get the state returned by OPCServer ............ psvr-> relese (); // Release IOPCSERVER interface pointer coupInitialize (); // End COM environment} OPC server program: Class ATL-NO-VTABLE COPCSERVER: Public CComobjectrootex < CcomSingleThreadModel>, Public CComCoClass