16,721
社区成员




'===============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