VB.NET编写OPC客户端,添加组报错!

dragonxue 2018-08-14 10:15:40
代码如下,运行到add group报错,但是重复运行到第3次就正常了,每次都是第三次就正常了,不知道什么原因?

'===============connect======================================
If ConnectedOPCServer Is Nothing Then
Try
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect(ServerName.Text, )

Catch ex As Exception
ConnectedOPCServer = Nothing
MessageBox.Show("OPC server connect failed with exception: " + ex.Message, "connect error", MessageBoxButtons.OK)
End Try
End If
'================add group====================================================
If Not ConnectedOPCServer Is Nothing And ConnectedGroup Is Nothing Then
Try
ConnectedOPCServer.OPCGroups.DefaultGroupIsActive = True
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add("Group1")
ConnectedGroup.UpdateRate = Val(1000)
ConnectedGroup.IsSubscribed = True

Catch ex As Exception
ConnectedGroup = Nothing
MessageBox.Show("OPC server add group failed with exception: " + ex.Message, "add group error", MessageBoxButtons.OK)
End Try
End If
'============add items==================================================
If Not ConnectedGroup Is Nothing Then
Try
Dim ItemCount As Integer = 1
Dim AddItemServerErrors As System.Array

OPCItemIDs(1) = OPCItemName(1).Text
ClientHandles(1) = 1

ConnectedGroup.OPCItems.DefaultIsActive = True
ConnectedGroup.OPCItems.AddItems(ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, AddItemServerErrors)

Catch ex As Exception
MessageBox.Show("OPC server add items failed with exception: " + ex.Message, "add items error", MessageBoxButtons.OK)
End Try
End If
...全文
562 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yishumei 2018-08-15
  • 打赏
  • 举报
回复
楼主,错误内容截个图看看

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧