【正文】
準 OPC服務(wù)器對象 必需的接口定義 ? OPC服務(wù)器必需的接口有 Iunknown IOPCServer IOPCCommer IConnectionPointContainer 組 (OPC Group) ? OPC Group存儲由若干 OPC Item組成的 Group信息,并用于返回 OPC Item類對象。 標準 OPC組對象 項 (OPC Item) ? OPC Item存儲具體 Item 的定義、數(shù)據(jù)值、狀態(tài)值等信息。 OPC項對象 I O P C I t e m D is pIUnknownO P C I t e m對象OPC 的過程數(shù)據(jù)構(gòu)造 ? OPC項代表了與服務(wù)器中的數(shù)據(jù)的連接。 EnumOPC對象屬性條目 IUnknownEnumOPCItemAttributes對象IEnumOPCItemAttributesOPC客戶與 OPC服務(wù)器 自定義接口OPC服務(wù)器O P C 接口物理接口SCADA 系統(tǒng)硬件設(shè)備物理接口 硬件設(shè)備C + + 客戶應(yīng)用自動化接口V B 客戶應(yīng)用自定義接口與自動化接口 OPC Automation wrapper Automation client (Visual Basic, Excel,…) custom interface server Custom client (C++,….) custom interface server 自定義接口與自動化接口 ? 自定義接口效率高,通過該接口,客戶能夠發(fā)揮 OPC服務(wù)器的最佳性能,采用 C++ 語言的客戶一般采用定制接口方案; ? 自動化接口使解釋性語言和宏語言訪問OPC服務(wù)器成為可能,采用 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服務(wù)器,建立OPC Group和 OPC Item; 2. 通過 Group 和 Item進行數(shù)據(jù)訪問; 3. 處理完畢,關(guān)閉連接。OPC Group Collection (Events opt.) Dim WithEvents MyGroup As OPCGroup 39。OPC Item Object Dim ItemsID(2) As String 39。s TopServer (freeware) 查找 OPC服務(wù)器 The GetOPCServers function applied to a dummy Server object allow to list the existing servers on this node or on another node (over DCOM security must be set correctly) The information about which OPC servers exist is taken from the registry, where it has been put by each server at its installation time。 returns all available servers For tServers = LBound(Servers) To UBound(Servers) 39。 connect to Matrikon server Before connecting, it is safe to check the name of the server from the server39。s tree: Dim MyServer As OPCServer Dim MyBrowser As OPCBrowser Dim vName As Variant , Orion 39。 vName 39。 display the leaves39。Tanks!Level 創(chuàng)建 OPCGroups and OPCItems Set MyGroups = 39。 fully qualified itemID ClientHandles(1) = 5 39。 adds the items tocollection nrItems, _ 39。 return parameterServerHandles ServerErrors 39。 and to generate events The role of the ServerHandles and ClientHandles will be explained later… 客戶端 的數(shù)據(jù)結(jié)構(gòu) FullyQualifiedItemID ClientHandle ServerHandle municated to server by registering group ServerError Value Quality TimeStamp 100 34543 0 OK 12: 102 22532 0 OK 12: 203 534676 0 0 OK 12: 204 787234 0 1 OK 12: 205 58432 0 0 BAD 12: returned by server when registering dynamic changes (refreshed on change) The client prepares data structures for its items and gives the server the corresponding pointers so the server can update them. Items to be written and read can be mixed in the same group. The type of the item (Boolean, Float,…) is implicit, but known at the server .. .. .. .. .. .. Dim thisGroup As OPCGroup Dim tItems As Integer Dim source As Integer Dim serverHandles(2) As Long Dim values() As Variant Dim errors() As Long serverHandles(1) = ServerHandle(11) 39。 returns be a dynamic array errors 39。 values(tItems) Next tItems () client Call Reply server Group的同步讀 single Items的異步讀 AsyncRead() AsyncReadComplete() server Dim WithEvents MyGroup ... nrItems, ServerHandles, ServerErrors, TransactionID, CancelID Call Reply client Private Sub Mygroup_AsyncReadComplete ( ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date, Errors() As Long) MsgBox (Async Read Complete) End Sub Asynchronous read separates Call and Reply. Call supplies the ServerHandles Reply returns the corresponding ClientHandles AsyncRead (source= device) AsyncReadComplete() server Call Reply client AsyncRead (source= cache) AsyncRead (source = device) Although the AsynchReadComplete carries the ClientHandle of each item, it does not tell which AsynchRead caused the AsynchReadComplete event to fire. Call and Reply are linked by the TransactionID: this ID is returned in AsynchReadComplete。 display TextTimeStamp(tItems 1).Text = DateAdd(h, 9, TimeStamps(tItems)) TextQuality(tItems 1).Text = Qualities(tItems) Next tItems End Sub This function is called each time an item in the group changes The ClientHandles (here: 5 and 6) identifies the variables, not the “fully qualified itemID” The values are displayed in the TextValue, TextTimeStamp and TextQuality fields. The refresh rate is given in the group definition. Groups Events Although transmission by gro