You are not registered yet. Please click here to register!

plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!

Go Back - Interactive Q & A > - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old March 11th, 2019, 07:41 AM   #1

turbohamad is offline
Join Date: Jun 2009
Location: Multan
Posts: 49
Read The Tags Value through RSLINK by VBA code in Excel

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.
  Reply With Quote
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Accessing Global Object Parameter Values in VBA Code dl5051 LIVE PLC Questions And Answers 0 September 21st, 2015 11:31 AM
RSview SE and Visual Basic SCAN.PLC LIVE PLC Questions And Answers 9 May 29th, 2015 02:20 PM
FTViewSE Read Parameter tags in VBA IanRobo75 LIVE PLC Questions And Answers 3 December 4th, 2014 10:11 AM
Looping VBA code in Excel pagewe LIVE PLC Questions And Answers 8 February 10th, 2003 10:19 AM
Auto generate code in Excel? PhilRey LIVE PLC Questions And Answers 9 January 17th, 2003 06:32 AM

All times are GMT -5. The time now is 06:17 AM.