Read The Tags Value through RSLINK by VBA code in Excel

turbohamad

Member
Join Date
Jun 2009
Location
Multan
Posts
105
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.
 
You’ll need an open bracket in front of U1C1_Polled

Where are you getting the error? If you don’t know, open a display client with the vba window, you can step through the code by placing the cursor in the debug vba window routine you want to test and repeatedly pressing the F8 key
 
Insert VBA code to Excel Workbook
Open your workbook in Excel.
Press Alt + F11 to open Visual Basic Editor (VBE).
Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu.

Hope this will help you. If you want to enhance more knowledge and skills then you can join advance excel training course.
 
Hello Friends;
I try again and again but cannot fix it.
I think some reference of ROCKWELL AUTMATATION OPC SERVER IS MISSING in excel.

I have excel 2003 and 2007 and try to add the RSIOPC.dll file BUT ERROR MESSAGE generate not to add the define service.

I do not know why this error occur?

Please help me to read out the Tags value via OPC server of rslink.

Regards
 
Hello friends;
I also check the code by using F8 in the VBA editor of the following code

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

start from the IF OPC SERVER1 IS NOTHING after that it goes to END IF.

It means it cannot found the OPC SERVER 1

How i fix it?

Regards
 
#1: Do you have a reference defined to RSLinxOPCAuto.dll ?
#2: Try this:


Code:
Dim OPCServer1 As RSLinxOPCAutomation.opcserver
OPCServer1 = New RSLinxOPCAutomation.opcserver


OPCServer1.Connect("RSLinx OPC Server")
.
.
.


At a quick look, it looks like you aren't creating the correct Linx OPC server object.
 
Respected friends,
I can not find and add the RSLINXOPCAUTO.dll while i have rslink OEM 2.52
Version.
In excel i also can not find above file.

Regards
 
Hello friends;
When i try to add refrence risopc.dll which is in common files\rockwell in excell2003 and also try in 2007 it shows a popup can not create a new automation server or you have no privillage

How can i fix it please give me a solution?

Regards
 
I would recommend updating your RSLinx, but that won’t help. Do you have a gateway or professional activation for the software? One or the other is required to enable the OPC server functionality.
 

Similar Topics

Hi everyone. Quick questions. On UnityPro, I want to open and quickly read tags from a .STA files witouth opening the program. I have 30 plc...
Replies
2
Views
102
How to read/write tags using class3 connection with omron Nx/Nj Plc? when i am seeing wireshark packets for my existing connection its shows as...
Replies
0
Views
693
Dear Friends; I am trying to read the Tag Values in excel by using VBA. I write a code but was stuck on the following error: Dim OPC Server1 As...
Replies
21
Views
6,266
Hello, Just wondering if it is possible to make internal CitectSCADA project tags available to an OPC server. (Schneider OFS). There are...
Replies
0
Views
902
Hello Everyone, I've been trying to write a python code to read input and output tags from a PLC using CIP. I found the service...
Replies
25
Views
6,091
Back
Top Bottom