Sei sulla pagina 1di 10

3/19/2020 Connecting Excel to ControlLogix | PLCdev

Tools for PLC programming

Recent Posts
Home Products Tutorial Directory Glossary Recent Posts Contrib

Resources
GE Automation Connecting Excel to ControlLogix
Allen-Bradley
Siemens
PDF Electric &
Supply by John Schop
Do Supply Have you ever lost data in a CLX processor, because you downloaded new code?
Company
AX Control Unfortunately, when you donwload a program to a ControlLogix processor, you also
Distcache download the values of the tags (variables).
Networking
A solution to this problem that could be useful, is an Excel sheet that reads and writes
Hardware
values to the ControlLogix processor using the DDE/OPC capabilities of RSLinx.
PLC Programming In this article, I will show you how to create one of these sheets for your projects.
Handbooks
Allen Bradley Here's what you'll need:
Siemens
Modicon Microsoft Excel, with some basic knowledge about programming macro's in Visual
Basic
Popular Articles RSLinx (not the 'Lite' version, because that does not have DDE/OPC capabilities)
PLC Timeline A ControlLogix processor of course
Rockwell Automation's
Retroincabulator!
Let's fire up RSLogix first, and create a bunch of tags with values. In this example, I
PLC Basics
created 2 arrays, of the types DINT and REAL, each with a length of [10] tags. These
PLC Simulators
Cheap PLCs
arrays I filled with some values:

Navigation
Book reviews
Online books
Recent posts
About

RSS
Feed Me! Firefox
and Thunderbird make it
easy to keep up on the
latest articles from
PLCdev

User login
Username: *

Password: *

Log in
Create new account

www.plcdev.com/connecting_controllogix_excel 1/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev
Request new
password

I'm not going to do anything with the PLC program, I just need some data in a number of
tags.
Next, we're going to set up a DDE/OPC Topic in RSLinx. Depending on the version of
RSLinx you use, it might look slightly different, but you should be able to follw this with
the screenshots.

Assuming that you know how to setup RSLinx initally to get online with your controller,
I've skipped some steps. The setup I use looks like this in RSLinx:

As you can see, I have a 10 slot CLX rack, with a 1756-ENBT card in slot 1 (address
134.200.211.16), and two processors, one in slot 0, and one in slot 2. The one in slot 2 is
the processor we are going to use for this exercise.
Now, open up the DDE/OPC topic configuration by clicking 'DDE/OPC' and then 'Topic
Configuration' in the top menu of RSLinx.

www.plcdev.com/connecting_controllogix_excel 2/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

I'm going to create a new DDE/OPC topic called 'EXCEL_TEST', and use the Logix5550
processor in slot 2 as the data source. In order to do this, you have to click the 'New'
button, give the topic the desired name, and make sure the processor in slot 2 is selected
as the source before you click 'Done'

To test if your setup is working, at this point you can use the OPC test client provided with
RSLinx. I'm not going into detail about that, but I did make sure this worked before
continuing with the next step, creating the Excel sheet.
Let's start up good old Excel, and create a new workbook. On this workbook, place a new
command button. You can find the Command Button control in the 'Control Toolbox'
toolbar in Excel. When you have the button, right click on it and choose 'View Code'. This
will take you to the Visual Basic Editor:

www.plcdev.com/connecting_controllogix_excel 3/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

First, create a function that will open the DDE topic to Excel:

Now, if I call this function from the CommandButton1_Click event, it will open the link to
RSLinx:

The variable 'rslinx' will hold the number of the open channel. All subsequent DDE
functions use this number to specify the channel.
To save you all the steps to program the rest of the code, here is the final code to get the
array of REALs out of the controller, and put them in cells D2 – D11, and the array of
DINTs in cells E2-E11.

www.plcdev.com/connecting_controllogix_excel 4/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

Now we know how to read, it would of course be a lot of fun if we could write values as
well. I would like to be able to change the values in the cells, and then hit a 'Write Data'
button.
First, make another button on the sheet (mine looks like below now)

And then write some code for the button:

www.plcdev.com/connecting_controllogix_excel 5/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

The way this is implemented is of course very rudimentary, but once you get the concept,
the sky is the limit.
To make this easier on everybody, I've included the Excel file with the code already in it.
The only thing you have to do to make this Excel sheet work, is make sure there is an
DDE/OPC topic in your RSLinx setup called 'EXCEL_TEST', and the arrays REAL_Array and
DINT_Array in your controller (of at least length 10).

‹ User Defined Data Types (UDTs) up


and OOP

Printer-friendly version
( categories: Allen Bradley Programmable Logic Controllers )

Hard link

Submitted by Tim Young on Wed, 2009-07-01 13:51.


Thanks John for another great article.
It's worth noting that if your topic is set up then you can also make a hard reference in a
cell with the following format.
=APPLICATION|TOPIC!'TAG_NAME'
So in your example, to read the first element in the DINT_Array would be
=RSLINX|EXCEL_TEST!'DINT_Array[0]'
You'll get the number in the cell if successful otherwise it will say #REF! if there is a
problem. This is great as a quick test or if you just need a simple value.

www.plcdev.com/connecting_controllogix_excel 6/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

Communication: excel and control logix

Submitted by Anonymous (not verified) on Thu, 2010-02-04 12:11.


alright I get a number but then the actual value doesn't show in the cell... What do I
do next?
I am having problems with excel but I think I added too many topics and as u said
excel or rs linx will have trouble reading the link

Excel with Control Logix

Submitted by Anonymous (not verified) on Sun, 2009-09-06 11:21.


The downside to this method is very slow data transfer rates. I beleive most of this is due
to Excel, becuase when using Visual Basic with RSLinx Topic the transfer rates are much
faster. There are also problems related to RSLinx Topic configuration. If there are many
Topics created or some with similar names the Excel program can have troubles
connecting. I have had to delete Topics in RSLinx when this happens.

link tags

Submitted by Vu (not verified) on Wed, 2010-04-07 22:25.


Hi,I read "Connecting Excel to ControlLogix ".But I can't understand how to getdata from
rslinx when I use difference tags

Small Bug

Submitted by Ryan Quigley (not verified) on Fri, 2010-06-04 14:43.


Hello, and thanks for this tutorial! I just wanted to let you know there's a small bug in the
code. On the read error detection it should be:

If TypeName(realdata) = "Error" Then


...
If TypeName(dintdata) = "Error" Then

instead of:

If TypeName(data) = "Error" Then

Otherwise the code won't ever alert the user to an error.

Nice catch! Thanks Ryan

www.plcdev.com/connecting_controllogix_excel 7/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev
Submitted by Tim Young on Fri, 2010-06-18 21:49.
Nice catch! Thanks Ryan

Why concatenate "i"

Submitted by mike4bizz on Wed, 2012-12-05 06:38.


I am kind of confuse on why you concatenated "i" and not just use it as is. Can
you please explain why that is?
---realdata = DDERequest(rslinx, "REAL_Array[" & i & "],L1,C1")---

i is a variable determined

Submitted by Tim Young on Sun, 2012-12-09 22:30.


i is a variable determined by the for next loop. So you concatenate because
you want the message to show the actual number and not the letter i.

Data thru PLC-PanelView-PC

Submitted by Gil Flores (not verified) on Wed, 2010-06-30 14:21.


Hi, I read this grat tutorial, I am developing a project in which I must transfer 6 data from
a excel sheet, when selecting an option in the PanelView 1000+, to a Micrologix 1500. I
have seen example and already I have realised some test, but only of shipment the data
from Micrologix to excel. I'm been doing through RSLinx. Do you know how I cand send
data from excel to plc? Thanks in advance.

Below is a small macro that

Submitted by Larry (not verified) on Wed, 2010-07-07 03:02.


Below is a small macro that could be expanded for larger projects. In excel, column D
should contain the exact PLC tagname that you wish to write to, and column F should
contain the value that you wish to write into the PLC tag. Works well for me and so
simple. Oh, you also need to setup a topic called "EXCEL" in RSLINX that connects to
the PLC you wish to write to.
Sub WRITE_TO_PLC()
'open dde link: testsol=DDE Topic
RSIchan = DDEInitiate("RSLinx", "Excel")
'write data thru channel
DDEPoke RSIchan, Range("D5"), Range("F5")
DDEPoke RSIchan, Range("D6"), Range("F6")
DDEPoke RSIchan, Range("D7"), Range("F7")
'close dde channel
DDETerminate (RSIchan)
End Sub

www.plcdev.com/connecting_controllogix_excel 8/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

I have a problem with the

Submitted by Anonymous (not verified) on Tue, 2011-02-15 09:26.


I have a problem with the excel sheet. When I try to write real number like 4.5, 6.7 , 8.9
the controllogix do not receive the correct number. When I try to write real number like
4.0, 6.0, 8.0 there is no problem. Has anyone seen the same problem or found the
solution?

Probably you are using

Submitted by Anonymous (not verified) on Wed, 2011-12-14 13:45.


Probably you are using integer tags instead of real

Excel to PLC5

Submitted by Anonymous (not verified) on Tue, 2011-06-21 08:13.


Could some give procedure to write from EXCEL to PLC5
Thanks and regard,

Why not simply use the Tag

Submitted by Coowallsky (not verified) on Fri, 2011-12-16 11:38.


Why not simply use the Tag Upload/Download Utility that comes with RSLogix5000
software?

Excel Tag Read/Write

Submitted by Jay Harbath (not verified) on Thu, 2012-03-08 21:56.


The Rockwell tag utility might be too limited for someone's needs. As an example,
their PLC compare utility is pretty useless. I wrote my own that is much more user
friendly.
The software here gives you the basic tools to build whatever utility you might need.
I've used offshoots of this to read current tags, compare them to the "Gold Standard"
and flag when things have changed. The usefulness of this capability is limited by your
imagination and the read/write data rate.

2D Array

Submitted by MR Roboto (not verified) on Wed, 2012-05-23 08:27.


Thanks for the HowTo. Got it working.
What do I have to do to read out a 2Dimensional Array?
I want to read out:
www.plcdev.com/connecting_controllogix_excel 9/10
3/19/2020 Connecting Excel to ControlLogix | PLCdev

REAL-Data[0,0]
.
.
.
REAL_Data[1,3]
.
.
.etc.
Thank you

For a = 0 to 1 For i = 0 to

Submitted by Anonymous (not verified) on Tue, 2012-11-13 21:55.


For a = 0 to 1
For i = 0 to 3
Data = DDERequest(rslinx, "REAL_DATA[" & a & "," & i & "],L1,C1")
*error check
*move to cell
next i
next a
hope this helps

I also need to read a two

Submitted by R_Wispy on Tue, 2013-09-24 09:31.


I also need to read a two dimensional array, but my array is 8 x 96. Rather than
768 individual reads from the PLC using that for-next looping, is there a way to do
a single block read of all 768, or even 8 block reads of 96? I can't imagine how
slow the excel sheet would update if each array variable were a single read.

Home » Allen Bradley's PLC Programming Handbook

Terms of Use | Privacy Policy | About PLCdev | Contact Us | Write for us


Copyright © 2005-2020 plcdev.com

www.plcdev.com/connecting_controllogix_excel 10/10

Potrebbero piacerti anche