1. 首页
  2. 编程语言
  3. VB
  4. 用VB编写OPC客户端访问WINCC

用VB编写OPC客户端访问WINCC

上传者: 2019-04-09 23:51:10上传 DOC文件 45.5KB 热度 63次
先在“引用”将近 Siemens OPC DAAutomation 2.0加入,然后开始定义全局变量。在本程序中,我使用了两个OPC组进行OPC访问,所以定义了全局变量。我们要首先定义OPC服务类型与计算机结点名。定义OPC组与OPC标签组。并定义OPC的标签数组与值数,注意,值数组一定要设为Variant。 'OPC处理:只对WINCC Const ServerName = "OPCServer.WinCC" 'OPC的类型 Const NodeName = "GUK" '结点名,即计算机名 'Dim NodeName As String Dim WithEvent s MyOPCServer As OPCServer 'OPC服务 Dim MyOPCGroupColl As OPCGroups ' Dim WithEvents MyOPCGroupOut As OPCGroup 'OPC组,本程序用两个组进行OPC连接 Dim WithEvents MyOPCGroupIn As OPCGroup Dim MyOPCItemCollIn As OPCItems 'OPC标签组 Dim MyOPCItemCollOut As OPCItems Dim ServerHandlesIn() As Long '句柄 Dim ServerHandlesOut() As Long Dim ErrorsIn() As Long '错误句柄 Dim ErrorsOut() As Long Dim WatchDataReadItem(100) As String '记录OPC的标签 Dim WatchDataReadValue(100) As Variant '存放OPC的值 Dim WatchDataWriteItem(100) As String '记录OPC的标签 Dim WatchDataWriteValue(100) As Variant '存放OPC的值 s MyOPCServer As OPCServer 'OPC服务 Dim MyOPCGroupColl As OPCGroups ' Dim WithEvents MyOPCGroupOut As OPCGroup 'OPC组,本程序用两个组进行OPC连接 Dim WithEvents MyOPCGroupIn As OPCGroup Dim MyOPCItemCollIn As OPCItems 'OPC标签组 Dim MyOPCItemCollOut As OPCItems Dim ServerHandlesIn() As Long '句柄 Dim ServerHandlesOut() As Long Dim ErrorsIn() As Long '错误句柄 Dim ErrorsOut() As Long Dim WatchDataReadItem(100) As String '记录OPC的标签 Dim WatchDataReadValue(100) As Variant '存放OPC的值 Dim WatchDataWriteItem(100) As String '记录OPC的标签 Dim WatchDataWriteValue(100) As Variant '存放OPC的值
用户评论