回复:关于WINCC和VB之间的通信问题

yanshanshanmai

  • 帖子

    200
  • 精华

    0
  • 被关注

    2

论坛等级:游士

注册时间:2007-04-07

普通 普通 如何晋级?

发布于 2009-01-14 11:48:26

0楼

Private Sub Command1_Click() '连接winccopc服务器
ItemIDs(1) = "te101" 'vb内变量组1,
ItemIDs(2) = "te102"
ItemIDs(3) = "te103"
ItemIDs(4) = "te104"
ItemIDs(5) = "te105"

ItemIDs1(1) = "te106" 'vb内变量组2
ItemIDs1(2) = "te107"
ItemIDs1(3) = "te108"
ItemIDs1(4) = "te109"
ItemIDs1(5) = "te110"

For ii = 1 To ncountx
ClientHandles(ii) = ii
ClientHandles1(ii) = ii
Next ii
GroupName = "MyGroup" '?
GroupName1 = "MyGroup1" '?
NodeName = Trim(Environ("Computername")) '取得计算机名
For tagnum = 1 To ncountx
Next tagnum
'----------- Get an instance of the OPC-Server
Set MyOPCServer = New OPCServer '分配opc
MyOPCServer.Connect ServerName, NodeName '连接到本机wincc,网络上NodeName用ip地址代替
Set MyOPCGroupColl = MyOPCServer.OPCGroups
'----------- Set the default active state for adding groups
MyOPCGroupColl.DefaultGroupIsActive = True
'----------- Add our group to the Collection
Set MyOPCGroup = MyOPCGroupColl.Add(GroupName) '取得组名
Set MyOPCGroup1 = MyOPCGroupColl.Add(GroupName1) '取得组名

Set MyOPCItemColl = MyOPCGroup.OPCItems
Set MyOPCItemColl1 = MyOPCGroup.OPCItems
MyOPCItemColl.AddItems ncountx, ItemIDs(), ClientHandles(), ServerHandles(), Errors
MyOPCItemColl.AddItems ncountx1, ItemIDs1(), ClientHandles1(), ServerHandles1(), Errors1

'----------- A group that is subscribed receives asynchronous notifications
MyOPCGroup.UpdateRate = 1000 '设置数据刷新时间
MyOPCGroup.IsActive = True '设置组为激活状态

MyOPCGroup.IsSubscribed = True
Text5.Text = "ok" '测试语句
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Des cription, vbCritical, "ERROR"

End Sub

Private Sub Command2_Click() '同步写
plaVxie(1) = Text7.Text
plaVxie(2) = Text8.Text
plaVxie(3) = Text9.Text
plaVxie(4) = Text10.Text
plaVxie(5) = Text11.Text
MyOPCGroup.SyncWrite ncountx, ServerHandles, plaVxie, pErrors ' Qualities1, TimeStamps1
End Sub

Private Sub Command3_Click() '同步读
MyOPCGroup.SyncRead OPCCache, 5, ServerHandles, plavdu, pErrors ', Qualities1, TimeStamps1
Text1.Text = plavdu(1)
Text2.Text = plavdu(2)
Text3.Text = plavdu(3)
Text4.Text = plavdu(4)
Text5.Text = plavdu(5)
End Sub

Private Sub Command4_Click() '异步写
Dim ccc As Long
plaVxie(1) = Text7.Text
plaVxie(2) = Text8.Text
plaVxie(3) = Text9.Text
plaVxie(4) = Text10.Text
plaVxie(5) = Text11.Text
MyOPCGroup.AsyncWrite 5, ServerHandles, plaVxie, pErrors, 1, ccc ', Qualities1,1' TimeStamps1
End Sub

Private Sub Command5_Click() '异步读,写入变量名要与wincc变量匹配
Dim ccc As Long
MyOPCGroup.AsyncRead 5, ServerHandles, pErrors, 2, ccc 'Qualities1, TimeStamps1
End Sub

Private Sub Command6_Click() '同步读1
MyOPCGroup.SyncRead OPCCache, 5, ServerHandles1, plavdu1, pErrors1 ', Qualities1, TimeStamps1
Text1.Text = plavdu1(1)
Text2.Text = plavdu1(2)
Text3.Text = plavdu1(3)
Text4.Text = plavdu1(4)
Text5.Text = plavdu1(5)
End Sub

Private Sub Command7_Click() '同步写1
plaVxie1(1) = Text7.Text
plaVxie1(2) = Text8.Text
plaVxie1(3) = Text9.Text
plaVxie1(4) = Text10.Text
plaVxie1(5) = Text11.Text
MyOPCGroup.SyncWrite 5, ServerHandles1, plaVxie1, pErrors1 ' Qualities1, TimeStamps1
End Sub

Private Sub Command8_Click() '读取wincc中变量名
Call FillItems
End Sub
Private Sub Command9_Click() '断开winccopc连接
MyOPCGroupColl.RemoveAll
MyOPCServer.Disconnect
Set MyOPCItemColl = Nothing
Set MyOPCGroup = Nothing
Set MyOPCGroupColl = Nothing
Set MyOPCServer = Nothing
End Sub
Private Sub Form_Load()
Call FillServers
End Sub
路漫漫,上下求索
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32563条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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