OPC接口技术的介绍.ppt
《OPC接口技术的介绍.ppt》由会员分享,可在线阅读,更多相关《OPC接口技术的介绍.ppt(103页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、OPC接口技术,谈英姿,内容提要,概述OPC基本原理OPC DA 接口标准OPC AE 接口标准OPC HDA 接口标准OPC XML接口标准,OPC基本原理,通用OPC结构及组成对象及接口概述必需的接口定义可选的接口定义服务器地址空间及配置时间同步与顺序发送机制EnumOPC对象属性条目,通用OPC结构及组成,OPC数据访问规范OPC报警和事件规范OPC数据交换规范OPC历史数据访问规范OPC批处理规范OPC安全性规范OPC XML规范,对象及接口概述,OPC对象OPC对象有三个:服务器(OPC Server)、组(OPC Group)和项(OPC Item)OPC接口,服务器,OPC Se
2、rver即OPC启动服务器,通过它获得其他对象和服务的起始类,并用于返回OPC Group类对象。OPC Server级别有多种属性,其中包含一个OPC服务器对象的状态和版本等信息。这种级别中的对象由客户应用创建。IOPCServer接口包含管理OPC Group级别中的对象的方法。如将组加入服务器或从服务器中删除组的方法(AddGroup,RemoveGroup)。IOPCBrowseServerAddressSpace接口包含查找服务器地址空间的方法。IOPCCommon接口方法用于通知服务器语言的设置和客户机的名称。,标准OPC服务器对象,必需的接口定义,OPC服务器必需的接口有Iunk
3、nownIOPCServer IOPCCommerIConnectionPointContainer,组(OPC Group),OPC Group存储由若干OPC Item组成的Group信息,并用于返回OPC Item类对象。OPC Group级别管理被称为OPC Item的各个过程变量。IOPCItemMgt接口提供将项加入组或从组中删除项的方法(“AddItem”,“RemoveItem”)。IOPCGroupStateMgt接口的方法用于处理组专用的参数或复制组。,标准OPC组对象,项(OPC Item),OPC Item存储具体Item 的定义、数据值、状态值等信息。OPC Item
4、级别的一个对象代表与一个过程变量的连接。该对象的唯一接口是OPCItemDisp。关于OPC Item的信息可以在属性表中找到,例如数值(“Value”)属性或存取路径(“AccessPath”)属性。,OPC项对象,OPC 的过程数据构造,OPC项代表了与服务器中的数据的连接。客户程序对OPC项的操作都是通过包容此项的OPC组来进行的,而不是直接把OPC项作为一个对象来操作。每个OPC项都有值(Value)。品质(Quality)和时间戳(Time Stamp)三个属性。,EnumOPC对象属性条目,OPC客户与OPC服务器,自定义接口与自动化接口,OPC Automationwrapper
5、,Automation client(Visual Basic, Excel,),custom interface,server,Custom client(C+,.),custom interface,server,自定义接口与自动化接口,自定义接口效率高,通过该接口,客户能够发挥OPC服务器的最佳性能,采用C语言的客户一般采用定制接口方案;自动化接口使解释性语言和宏语言访问OPC服务器成为可能,采用VB等语言的客户一般采用自动化接口,OPC DA 接口标准,数据访问方式DA功能实现过程DA的对象与接口,数据访问方式,DA 的同步读取DA的异步读取DA的数据更新DA的数据订阅DA的同步写入D
6、A的异步写入,DA 的同步读取,DA的异步读取,DA的数据订阅,数据订阅传输模式,数据源: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
7、 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 3.0 allows write to cache),DA功能实现过程,OPC DA客户连接到DA服务器,建立OPC Group和OPC It
8、em;通过Group 和Item进行数据访问;处理完毕,关闭连接。,OPC DA对象的层次模型,OPCItem,OPCBrowser,OPCServer,OPCGroups (collection),OPCGroup,OPCItems (collection),OPCItem,OPCItem,OPCGroup,OPC DA 初始化连接,find out existing OPC servers,connect to that OPC server,create an OPCBrowser objectcreate an OPCGroups object,create an OPCServer
9、object,create an OPCGroup object,build array of itemschecking with the browser that these items exist in this server,add item array to the group,activate and subscribe group,nextgroup,初始化,myDummyServer.GetOPCServers,myServer.Connect,Set myBrowser = myServer.BrowserSet myGroups = myServer.Groups,mySe
10、rver = new OPCServer,Set myGroup1 = myGroups.AddSet MyItems = MyGroup1.OPCItems,FQItems11 = Device1.Temp1ClientHandle11 = 101ReDim ServerHandle1(nrItems)ReDim ServerErrors1(nrItems)ReDim Value1(nrItems),myGroup1.AddItems,myGroup1.IsActivemyGroup1.IsSubscribed,Declarations,Option Base 1 OPC arrays in
11、dices start with 1Dim WithEvents MyServer As OPCServer OPC Server Object (Events optional)Dim WithEvents MyGroups As OPCGroups OPC Group Collection (Events opt.)Dim WithEvents MyGroup As OPCGroup OPC Group Object itemsDim nrItems As IntegerDim MyItems As OPCItems OPC Item Collection ObjectDim MyItem
12、 As OPCItem OPC Item ObjectDim ItemsID(2) As String fully qualified items (see later) Dim ClientHandles(2) As Long Dim ServerHandles() As Long must be a dynamic arrayDim ServerErrors() As Long must be a dynamic array,Reference: OPC Automation 2.0 must be included into Visual Basic or C#(if missing:
13、copy opcdaauto.dll to C:WINNTSystem32opddaauto)and register it: C:regsvr32 C:WINNTSystem32opddaauto.A simple way to do it: install Software Toolboxs TopServer (freeware),查找OPC服务器,The GetOPCServers function applied to a dummy Server object allow to list the existing servers on this node or on another
14、 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。,Private Sub ShowServers(netNodeName As String) Dim dummyServer As OPCServer Dim Servers As Variant this is an ar
15、ray of strings Dim cntServers As Integer Set dummyServer = New OPCServer create a dummy server object Servers = dummyServer.GetOPCServers(netNodeName) returns all available servers For cntServers = LBound(Servers) To UBound(Servers) display the names MsgBox Servers(cntServers) Next cntServers Set Ge
16、tserver = Nothing delete this object (was created by New) Exit Sub,连接到OPC服务器,Set MyServer = New OPCServer create server objectMyServer.Connect (Matrikon.OPC.Simulation) connect to Matrikon server,Before connecting, it is safe to check the name of the server from the servers list.Also, it is preferab
17、le to include the connection in a separate routine since it can fail:,Function ServerGetCare(Name As String, ServerNode As String) As OPCServer On Error GoTo ServerGetCareErr Dim MyOPCServer As New OPCServer MyOPCServer.Connect ServerName, ServerNode connect risky Set ServerGetCare = MyOPCServer Exi
18、t FunctionServerGetCare_Err: error handler if connect fails Err.Clear MsgBox Could not connect Set MyServer = Nothing Exit Function,浏览服务器,The object OPCBrowser (of type collection) acts as a pointer to the servers tree:,Dim MyServer As OPCServerDim MyBrowser As OPCBrowserDim vName As VariantMyServer
19、.Connect Matrikon.OPC.Simulation, Orion server and node name (DCOM)Set MyBrowser = MyServer.CreateBrowser create an OPC browserMyBrowser.ShowBranches show the branchesFor Each vName In MyBrowser MsgBox Branch: & vName display the branch nameNext vNameMyBrowser.ShowLeafs explore the leavesFor Each vN
20、ame In MyBrowser MsgBox Leaf: & vName display the leavess nameNext vName,浏览,MyBrowser.MoveDown (strBranch) go down the selected branch treeMyBrowser.MoveUp go up the selected branch tree,site properties,Server root,Level,Temperature,Valve_On,Site A,Store,Machine Room,Grinder,Wash Room,Climate,server
21、,Tank,There may be leaves at every branch, since a branch may have properties,获得 ItemID,myOPCBrowser.MoveDown(TankArea)myOPCBrowser.MoveDown(Tank1)FQI = myOPCBrowser.GetItemId (Level),Of course, one can write an Item ID directly when defining a group, but it is safer to browse the server and get the
22、 FQI from there, since the delimiter depends on the server.,To get the fully qualified itemID, one positions the browser at the place where the leaf is attached to the branch and calls GetItemID,e.g. FQI could be Controller1;Tanks!Level,创建 OPCGroups and OPCItems,Set MyGroups = MyServer.OPCGroups cre
23、ate groups collectionSet MyGroup1 = MyGroups.Add(GRP1) add group, name privateSet MyItems = MyGroup1.OPCItems define the OPCItems of groupFQItemIDs(1) = Area2.Tank1.Level fully qualified itemIDClientHandles(1) = 5 arbitraryFQItemIDs(2) = Area2.Tank1.Temperature fully qualified itemIDClientHandles(2)
24、 = 6 arbitrary (but different)nrItems = 2MyItems.AddItems _ adds the items tocollection nrItems, _ input parameter FQItemIDs, _ supply fully qualified ID ClientHandles, _ supply ClientHandles ServerHandles, _ return parameterServerHandles ServerErrors return parameter ServerErrorsMyGroup1.ClientHand
25、le = 1 handle of the group (no s) !MyGroup1.IsActive = True now ready to send and receiveMyGroup1.IsSubscribed = True and to generate events,The role of the ServerHandles and ClientHandles will be explained later,客户端 的数据结构,FullyQualifiedItemID,ClientHandle,ServerHandle,Channel1.Device1.Temp1,communi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- OPC 接口 技术 介绍
限制150内