【正文】
OPC接口技術(shù) 談?dòng)⒆? 東南大學(xué)自控系工業(yè)自動(dòng)化教研室 內(nèi)容提要 ? 概述 ? OPC基本原理 ? OPC DA 接口標(biāo)準(zhǔn) ? OPC AE 接口標(biāo)準(zhǔn) ? OPC HDA 接口標(biāo)準(zhǔn) ? OPC XML接口標(biāo)準(zhǔn) OPC基本原理 ? 通用 OPC結(jié)構(gòu)及組成 ? 對(duì)象及接口概述 ? 必需的接口定義 ? 可選的接口定義 ? 服務(wù)器地址空間及配置 ? 時(shí)間同步與順序發(fā)送機(jī)制 ? EnumOPC對(duì)象屬性條目 通用 OPC結(jié)構(gòu)及組成 ? OPC數(shù)據(jù)訪問(wèn)規(guī)范 ? OPC報(bào)警和事件規(guī)范 ? OPC數(shù)據(jù)交換規(guī)范 ? OPC歷史數(shù)據(jù)訪問(wèn)規(guī)范 ? OPC批處理規(guī)范 ? OPC安全性規(guī)范 ? OPC XML規(guī)范 對(duì)象及接口概述 ? OPC對(duì)象 OPC對(duì)象有三個(gè): 服務(wù)器 (OPC Server)、 組(OPC Group)和 項(xiàng) (OPC Item) ? OPC接口 服務(wù)器 ? OPC Server即 OPC啟動(dòng)服務(wù)器,通過(guò)它獲得其他對(duì)象和服務(wù)的起始類,并用于返回 OPC Group類對(duì)象。 OPC Server級(jí)別有多種屬性,其中包含一個(gè) OPC服務(wù)器對(duì)象的狀態(tài)和版本等信息。這種級(jí)別中的對(duì)象由客戶應(yīng)用創(chuàng)建。 IOPCServer接口包含管理 OPC Group級(jí)別中的對(duì)象的方法。如將組加入服務(wù)器或從服務(wù)器中刪除組的方法( AddGroup, RemoveGroup)。IOPCBrowseServerAddressSpace接口包含查找服務(wù)器地址空間的方法。 IOPCCommon接口方法用于通知服務(wù)器語(yǔ)言的設(shè)置和客戶機(jī)的名稱。 標(biāo)準(zhǔn) OPC服務(wù)器對(duì)象 必需的接口定義 ? OPC服務(wù)器必需的接口有 Iunknown IOPCServer IOPCCommer IConnectionPointContainer 組 (OPC Group) ? OPC Group存儲(chǔ)由若干 OPC Item組成的 Group信息,并用于返回 OPC Item類對(duì)象。 OPC Group級(jí)別管理被稱為OPC Item的各個(gè)過(guò)程變量。IOPCItemMgt接口提供將項(xiàng)加入組或從組中刪除項(xiàng)的方法(“ AddItem”,“ RemoveItem”)。IOPCGroupStateMgt接口的方法用于處理組專用的參數(shù)或復(fù)制組。 標(biāo)準(zhǔn) OPC組對(duì)象 項(xiàng) (OPC Item) ? OPC Item存儲(chǔ)具體 Item 的定義、數(shù)據(jù)值、狀態(tài)值等信息。 OPC Item級(jí)別的一個(gè)對(duì)象代表與一個(gè)過(guò)程變量的連接。該對(duì)象的唯一接口是 OPCItemDisp。關(guān)于 OPC Item的信息可以在屬性表中找到,例如數(shù)值(“ Value”)屬性或存取路徑(“ AccessPath”)屬性。 OPC項(xiàng)對(duì)象 I O P C I t e m D is pIUnknownO P C I t e m對(duì)象OPC 的過(guò)程數(shù)據(jù)構(gòu)造 ? OPC項(xiàng)代表了與服務(wù)器中的數(shù)據(jù)的連接??蛻舫绦?qū)?OPC項(xiàng)的操作都是通過(guò)包容此項(xiàng)的 OPC組來(lái)進(jìn)行的,而不是直接把OPC項(xiàng)作為一個(gè)對(duì)象來(lái)操作。每個(gè) OPC項(xiàng)都有值 (Value)。品質(zhì) (Quality)和時(shí)間戳 (Time Stamp)三個(gè)屬性。 EnumOPC對(duì)象屬性條目 IUnknownEnumOPCItemAttributes對(duì)象IEnumOPCItemAttributesOPC客戶與 OPC服務(wù)器 自定義接口OPC服務(wù)器O P C 接口物理接口SCADA 系統(tǒng)硬件設(shè)備物理接口 硬件設(shè)備C + + 客戶應(yīng)用自動(dòng)化接口V B 客戶應(yīng)用自定義接口與自動(dòng)化接口 OPC Automation wrapper Automation client (Visual Basic, Excel,…) custom interface server Custom client (C++,….) custom interface server 自定義接口與自動(dòng)化接口 ? 自定義接口效率高,通過(guò)該接口,客戶能夠發(fā)揮 OPC服務(wù)器的最佳性能,采用 C++ 語(yǔ)言的客戶一般采用定制接口方案; ? 自動(dòng)化接口使解釋性語(yǔ)言和宏語(yǔ)言訪問(wèn)OPC服務(wù)器成為可能,采用 VB等 語(yǔ)言的客戶一般采用自動(dòng)化接口 OPC DA 接口標(biāo)準(zhǔn) ? 數(shù)據(jù)訪問(wèn)方式 ? DA功能實(shí)現(xiàn)過(guò)程 ? DA的對(duì)象與接口 數(shù)據(jù)訪問(wèn)方式 ? DA 的同步讀取 ? DA的異步讀取 ? DA的數(shù)據(jù)更新 ? DA的數(shù)據(jù)訂閱 ? DA的同步寫入 ? DA的異步寫入 DA 的同步讀取 () client Call Reply server synchronous DA的異步讀取 () myGroup_AsyncReadComplete() server Call Reply client DA的數(shù)據(jù)訂閱 server Subscribe Notify myGroup_DataChange() myGroup_DataChange() client Notify 數(shù)據(jù)訂閱傳輸模式 server Subscribe Notify myGroup_DataChange() myGroup_DataChange() client Notify () myGroup_DataChange() Notify 數(shù)據(jù)源 :cache/device client application (OPC client) fieldbus OPC server cache fieldbus device fieldbus device fieldbus connection server samples items (at the RequestedUpdateRate) and puts them into cache synchronous call over the field bus to the end device (takes a while) no need for “device access” when fieldbus operates cyclically… FB manager FB agent FB agent SynchRead reads the data either from cache (local to the PC) or reads synchronous from the device. Write is always to device (DA allows write to cache) DA功能實(shí)現(xiàn)過(guò)程 1. OPC DA客戶連接到 DA服務(wù)器,建立OPC Group和 OPC Item; 2. 通過(guò) Group 和 Item進(jìn)行數(shù)據(jù)訪問(wèn); 3. 處理完畢,關(guān)閉連接。 OPC DA對(duì)象的層次模型 OPCItem OPCBrowser OPCServer OPCGroups (collection) OPCGroup OPCItems (collection) Description An instance of an OPC Server. You must create an OPCServer object before you can get references to other objects. It contains the OPCGroups Collection and creates OPCBrowser objects. A collection containing all of the OPCGroup objects this client has created within the scope of the OPCServer that the Automation Application has connected to via () An instance of an OPCGroup object. this object maintains state information and provides the mechanism to access data for the OPCItems Collection object that the OPCGroup object references. A collection containing all of the OPCItem objects this client has created within the scope of the OPCServer, and corresponding OPCGroup object that the Automation Application has created. An automation object that maintains the item’s definition, current value, status information, last update time. Note the Custom Interface does not provide a separate Item Object. An object that browses item names in the server’s configuration. There exists only one instance of an OPCBrowser object per instance of an OPC Server object. OPCItem OPCItem OPCGroup OPC DA 初始化連接 find out existing OPC servers connect to that OPC server create an OPCBrowser object create an OPCGroups object create an OPCServer object create an OPCGroup object build array of items checking with the browser that these items exist in this server add item array to the group activate and subscribe group next group 初始化 Set myBrowser = Set myGroups = myServer = new OPCServer Set myGroup1 = Set MyItems = FQItems1[1] = ClientHandle1[1] = 101 ReDim ServerHandle1(nrItems) ReDim ServerErrors1(nrItems) ReDim Value1(nrItems) Declarations Option Base 1 39。OPC arrays indices start with 1 Dim WithEvents MyServer As OPCServer 39。OPC Server Object (Events optional) Dim WithEvents MyGroups As OPCGroups 39。OPC Group Collection (Events opt.) Dim WithEvents MyGroup As OPCGroup 39。OPC Group Object 39。 items Dim nrItems As Integer Dim MyItems As OPCItems 39。OPC Item Collection Object Dim MyItem As OPCItem 39。OPC Item Object Dim ItemsID(2) As String 39。fully qualified items (see later) Dim ClientHandles(2) As Long Dim ServerHandles() As Long 39。 must be a dynamic array Dim ServerErrors() As Long 39。 must be a dynamic array Reference: OPC Auto