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   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old March 11th, 2019, 07:41 AM   #1
turbohamad
Member
Pakistan

turbohamad is offline
 
Join Date: Jun 2009
Location: Multan
Posts: 48
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
Old March 11th, 2019, 08:17 PM   #2
ArtWalls
Member
United States

ArtWalls is offline
 
Join Date: Apr 2016
Location: Miami, Arizona
Posts: 38
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
  Reply With Quote
Old March 12th, 2019, 01:01 AM   #3
kritesh
Member
India

kritesh is offline
 
Join Date: May 2018
Location: Noida
Posts: 6
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.
  Reply With Quote
Old March 13th, 2019, 03:42 AM   #4
turbohamad
Member
Pakistan

turbohamad is offline
 
Join Date: Jun 2009
Location: Multan
Posts: 48
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
  Reply With Quote
Old March 13th, 2019, 03:45 AM   #5
turbohamad
Member
Pakistan

turbohamad is offline
 
Join Date: Jun 2009
Location: Multan
Posts: 48
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
  Reply With Quote
Old March 13th, 2019, 05:41 AM   #6
rdrast
Lifetime Supporting Member
United States

rdrast is offline
 
rdrast's Avatar
 
Join Date: Apr 2003
Location: South Carolina Lowcountry
Posts: 5,337
#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.
__________________
------------------------------------
How to ask questions the SMART Way!

Look First, Ask Second!

  Reply With Quote
Old March 13th, 2019, 06:34 AM   #7
turbohamad
Member
Pakistan

turbohamad is offline
 
Join Date: Jun 2009
Location: Multan
Posts: 48
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
  Reply With Quote
Old March 13th, 2019, 08:18 AM   #8
turbohamad
Member
Pakistan

turbohamad is offline
 
Join Date: Jun 2009
Location: Multan
Posts: 48
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
  Reply With Quote
Old March 14th, 2019, 08:48 PM   #9
ArtWalls
Member
United States

ArtWalls is offline
 
Join Date: Apr 2016
Location: Miami, Arizona
Posts: 38
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.
  Reply With Quote
Old March 15th, 2019, 04:19 AM   #10
Ken Moore
Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: Upstate South Carolina
Posts: 2,440
Rslinx OEM works well as an OPC server, and cost a little less.
There is also a single node version that is slightly less than OEM.
__________________
"To give real service you must add something that cannot be bought or measured with money; and that is sincerity and integrity."
- Donald A. Adams

  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


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 01:32 AM.


.