【正文】
OPC接口技術 談英姿 東南大學自控系工業(yè)自動化教研室 內容提要 ? 概述 ? OPC基本原理 ? OPC DA 接口標準 ? OPC AE 接口標準 ? OPC HDA 接口標準 ? OPC XML接口標準 OPC基本原理 ? 通用 OPC結構及組成 ? 對象及接口概述 ? 必需的接口定義 ? 可選的接口定義 ? 服務器地址空間及配置 ? 時間同步與順序發(fā)送機制 ? EnumOPC對象屬性條目 通用 OPC結構及組成 ? OPC數(shù)據(jù)訪問規(guī)范 ? OPC報警和事件規(guī)范 ? OPC數(shù)據(jù)交換規(guī)范 ? OPC歷史數(shù)據(jù)訪問規(guī)范 ? OPC批處理規(guī)范 ? OPC安全性規(guī)范 ? OPC XML規(guī)范 對象及接口概述 ? OPC對象 OPC對象有三個: 服務器 (OPC Server)、 組(OPC Group)和 項 (OPC Item) ? OPC接口 服務器 ? OPC Server即 OPC啟動服務器,通過它獲得其他對象和服務的起始類,并用于返回 OPC Group類對象。 OPC Server級別有多種屬性,其中包含一個 OPC服務器對象的狀態(tài)和版本等信息。這種級別中的對象由客戶應用創(chuàng)建。 IOPCServer接口包含管理 OPC Group級別中的對象的方法。如將組加入服務器或從服務器中刪除組的方法( AddGroup, RemoveGroup)。IOPCBrowseServerAddressSpace接口包含查找服務器地址空間的方法。 IOPCCommon接口方法用于通知服務器語言的設置和客戶機的名稱。 標準 OPC服務器對象 必需的接口定義 ? OPC服務器必需的接口有 Iunknown IOPCServer IOPCCommer IConnectionPointContainer 組 (OPC Group) ? OPC Group存儲由若干 OPC Item組成的 Group信息,并用于返回 OPC Item類對象。 OPC Group級別管理被稱為OPC Item的各個過程變量。IOPCItemMgt接口提供將項加入組或從組中刪除項的方法(“ AddItem”,“ RemoveItem”)。IOPCGroupStateMgt接口的方法用于處理組專用的參數(shù)或復制組。 標準 OPC組對象 項 (OPC Item) ? OPC Item存儲具體 Item 的定義、數(shù)據(jù)值、狀態(tài)值等信息。 OPC Item級別的一個對象代表與一個過程變量的連接。該對象的唯一接口是 OPCItemDisp。關于 OPC Item的信息可以在屬性表中找到,例如數(shù)值(“ Value”)屬性或存取路徑(“ AccessPath”)屬性。 OPC項對象 I O P C I t e m D is pIUnknownO P C I t e m對象OPC 的過程數(shù)據(jù)構造 ? OPC項代表了與服務器中的數(shù)據(jù)的連接??蛻舫绦驅?OPC項的操作都是通過包容此項的 OPC組來進行的,而不是直接把OPC項作為一個對象來操作。每個 OPC項都有值 (Value)。品質 (Quality)和時間戳 (Time Stamp)三個屬性。 EnumOPC對象屬性條目 IUnknownEnumOPCItemAttributes對象IEnumOPCItemAttributesOPC客戶與 OPC服務器 自定義接口OPC服務器O P C 接口物理接口SCADA 系統(tǒng)硬件設備物理接口 硬件設備C + + 客戶應用自動化接口V B 客戶應用自定義接口與自動化接口 OPC Automation wrapper Automation client (Visual Basic, Excel,…) custom interface server Custom client (C++,….) custom interface server 自定義接口與自動化接口 ? 自定義接口效率高,通過該接口,客戶能夠發(fā)揮 OPC服務器的最佳性能,采用 C++ 語言的客戶一般采用定制接口方案; ? 自動化接口使解釋性語言和宏語言訪問OPC服務器成為可能,采用 VB等 語言的客戶一般采用自動化接口 OPC DA 接口標準 ? 數(shù)據(jù)訪問方式 ? DA功能實現(xiàn)過程 ? DA的對象與接口 數(shù)據(jù)訪問方式 ? 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功能實現(xiàn)過程 1. OPC DA客戶連接到 DA服務器,建立OPC Group和 OPC Item; 2. 通過 Group 和 Item進行數(shù)據(jù)訪問; 3. 處理完畢,關閉連接。 OPC DA對象的層次模型 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