VB client 与本机WINCC服务器OPC通信问题

已锁定

zhikong

  • 帖子

    343
  • 精华

    1
  • 被关注

    31

论坛等级:奇侠

注册时间:2014-11-09

普通 普通 如何晋级?

VB client 与本机WINCC服务器OPC通信问题

1216

5

2016-01-12 12:55:59

Option Explicit
Option Base 1
Private Sub A1_Click()
Dim WithEvents MyOPCServer As OPCServer '这样声明不了,报子程序或函数属性无效不知为什么啊
'Dim MyOPCServer As OPCServer 只有这样声明才行
Dim MyOPCGroup As OPCGroup
Dim MyOPCGroups As OPCGroups
Dim MyOPCItem1s As OPCItems
Dim MyOPCItem As OPCItem

Dim itemcount As Long
Dim itemid(1) As String
Dim itemclienthandle(1) As Long
Dim itemserverhandle() As Long
Dim itemservererr1() As Long
Dim datatype As Variant
Dim path As Variant

Dim source As Integer
Dim numitem As Long
Dim serverhandles(1) As Long
Dim values() As Variant
Dim err() As Long
Dim qualitities() As Variant
Dim timestamps() As Variant


Set MyOPCServer = New OPCServer
MyOPCServer.Connect "OPCServer.WinCC", "USER-20151013JC"
  Set MyOPCGroups = MyOPCServer.OPCGroups
  MyOPCGroups.DefaultGroupUpdateRate = 1000
MyOPCGroups.DefaultGroupIsActive = True
  Set MyOPCGroup = MyOPCGroups.Add("MyGroup")
    Set MyOPCItem1s = MyOPCGroup.OPCItems
      MyOPCGroup.IsSubscribed = True
itemcount = 1
itemclienthandle(1) = 1
source = OPCCache
   itemid(1) = "aaa"  'WINCC内部变量”aaa"
MyOPCItem1s.AddItems itemcount, itemid, itemclienthandle, itemserverhandle, itemservererr1



  numitem = 1
serverhandles(1) = 1
MyOPCGroup.SyncRead source, numitem, serverhandles, values, err
Text1.Text = values(1)
MsgBox CStr(values(1)) '读出数一直为空
'MsgBox MyOPCGroups.Count
'MsgBox MyOPCServer.ServerName
'MsgBox MyOPCServer.ServerState
'MsgBox MyOPCServer.StartTime
'MsgBox MyOPCServer.LastUpdateTime
'MsgBox MyOPCServer.LocaleID '1
End Sub1

上面不知为什么用不了,withevents 语句,在WINCC1运行时,VB可以连上WINCC1,但读不出数据不知为什么,在此请在神指教
VB client 与本机WINCC服务器OPC通信问题 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32642条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。