turbohamad
Member
Hello friends;
I found a code for VBA use in excel to read the Tags values from RSlogix 5000 through RSlink. The code is here:
Dim OPCServer1 As OPCServer 'Create references to OPC Server
Dim WithEvents OPCGroup1 As OPCGroup 'and Group objects
Private Sub CMDDIS_Click()
On Error Resume Next
Set OPCGroup1 = Nothing 'Remove Group
OPCServer1.Disconnect 'Disconnect from server
Set OPCServer1 = Nothing
End Sub
Private Sub CMDREAD_Click()
If OPCServer1 Is Nothing Then 'When OPC server doesn't exist ...
Set OPCServer1 = New OPCServer 'Create instance of OPC Server
OPCServer1.Connect "RSLinx OPC Server" 'Connect to an OPC Server
Set OPCGroup1 = OPCServer1.OPCGroups.Add("MyOPCData")
'Create an OPC group in the OPC Server
OPCGroup1.OPCItems.AddItem"U1C1_Polled]HMI_Analog_Array[4],L113", 1
'OPCGroup1.OPCItems.AddItem "[Topic]Item", ClientHandle
OPCGroup1.IsSubscribed = True 'Receive data whenever it changes
End If
End Sub
Private Sub OPCGroup1_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
[A1] = ItemValues(1)(0)
[A2] = ItemValues(1)(1)
[A3] = ItemValues(1)(2)
[A4] = ItemValues(1)(3)
[A5] = ItemValues(1)(4)
[A6] = ItemValues(1)(5)
[A7] = ItemValues(1)(6)
[A8] = ItemValues(1)(7)
End Sub
I insert Two buttons on the sheet with caption of READ and Disconnect.
When I assign the CMDREAD() to the READ button.
I also configure the topic in the rslink with the same name as U1C1_Polled and update the topic also.
But when i try to read the tags value it is not working. I think i miss something in configuration. I am also confuse about this line
Set OPCGroup1 = OPCServer1.OPCGroups.Add("MyOPCData")
Please help me how i run this code successfully.
I found a code for VBA use in excel to read the Tags values from RSlogix 5000 through RSlink. The code is here:
Dim OPCServer1 As OPCServer 'Create references to OPC Server
Dim WithEvents OPCGroup1 As OPCGroup 'and Group objects
Private Sub CMDDIS_Click()
On Error Resume Next
Set OPCGroup1 = Nothing 'Remove Group
OPCServer1.Disconnect 'Disconnect from server
Set OPCServer1 = Nothing
End Sub
Private Sub CMDREAD_Click()
If OPCServer1 Is Nothing Then 'When OPC server doesn't exist ...
Set OPCServer1 = New OPCServer 'Create instance of OPC Server
OPCServer1.Connect "RSLinx OPC Server" 'Connect to an OPC Server
Set OPCGroup1 = OPCServer1.OPCGroups.Add("MyOPCData")
'Create an OPC group in the OPC Server
OPCGroup1.OPCItems.AddItem"U1C1_Polled]HMI_Analog_Array[4],L113", 1
'OPCGroup1.OPCItems.AddItem "[Topic]Item", ClientHandle
OPCGroup1.IsSubscribed = True 'Receive data whenever it changes
End If
End Sub
Private Sub OPCGroup1_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
[A1] = ItemValues(1)(0)
[A2] = ItemValues(1)(1)
[A3] = ItemValues(1)(2)
[A4] = ItemValues(1)(3)
[A5] = ItemValues(1)(4)
[A6] = ItemValues(1)(5)
[A7] = ItemValues(1)(6)
[A8] = ItemValues(1)(7)
End Sub
I insert Two buttons on the sheet with caption of READ and Disconnect.
When I assign the CMDREAD() to the READ button.
I also configure the topic in the rslink with the same name as U1C1_Polled and update the topic also.
But when i try to read the tags value it is not working. I think i miss something in configuration. I am also confuse about this line
Set OPCGroup1 = OPCServer1.OPCGroups.Add("MyOPCData")
Please help me how i run this code successfully.