文件名称:用VB编写OPC客户端访问WINCC
文件大小:46KB
文件格式:DOC
更新时间:2016-03-27 11:12:24
OPC VB WINCC
先在“引用”将近 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 WithEvents 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的值