Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLC Interfacing using Visual Basic and RSLinx 4

Status
Not open for further replies.

garyjh

Computer
Sep 26, 2002
5
0
0
US
Hello Guys

I am new to PLCs so please bare with me on this.

I am working on (or at least trying to) an application that uses a PLC. I will be communicating to this PLC via the ethernet and RSLinx.

I am assuming that RSLinx will be setup with the address or IP address of the PLC, is this correct?

Inside of RSLinx will be a data table that I can query somehow from within Visual Basic to get the status of some event or possible start an event by setting a bit or byte
am I on the right track so far?

How would I go about addressing the PLC and the data tables?
Does any one out there have an example of how I might do this?

Thank You

Gary

 
Replies continue below

Recommended for you

Hello;
It is a little more complicated than that. First you must have either the OEM or the professional version of RSlinx. You then configure the "Ethernet devices" driver with the IP address of your PLC.
Then you can access the data either via DDE or a method called OPC. In your case you must access the data via DDE using the VBA native DDE functions. I do not know what the exact syntax is, and will be quite complicated.
 
You must have RSlinx Prof V2.3 or greater, once you set up rslink to read the ethernet gateway or direct to the PLC The DDE stuf is easy. Just assign an topic to your target PLC in RSLinks OPC/DDE setup.
Now to access data in let's say excell it is simple:
DDE(application, topic, item)
=DDE(rslinx, PLC1, "N7:1"

Now in VB and VBA not so quick I hope you are familiar with these because you will need to do things like open a channel to rslinx before DDE reads and DDE pokes.

I found if you are going this method make sure the data you need is lined up tight. I have some bad examples of this stuff if ya need.
 
If you want to try DDE to Excel you can download my example here:


Called:
Allen Bradley SLC500 DDE Link to Excel Logger 1.4

You'll need atleast RS Linx Single Node, configure a DDE topic in RS Linx. Then you can use Excel to get either Hot Links or Cold Links from the PLC. If you need to get alot of information, you might want to check into OPC. RS Linx Single Node is an OPC server and you can get information out of the PLC using OPC if you prefer.

Or if you want to see a VB 6.0 version of DDE. I'll let you have what I got, but I don't have the MS Access database write function working yet.

Chris Elston
Automation & Controls Engineer
Download Sample PLC Ladder Logic Code
at MrPLC.com
 
Oh yeah..

Here is a short sample code:

Warning...The above reference:

DDE(application, topic, item)
=DDE(rslinx, PLC1, "N7:1"

Will only work in Excel or you have to enable Excel reference in your library to use that call in VB 6.0. The native VB calls for DDE are below.

Please also look at this post here:

I asked alot of questions and most of the leg work I am telling you know, I just found out myself.

<<<<<<<<<<<START SAMPLE CODE>>>>>>>>>>>>>>
Public Const DDETOPIC As String = &quot;DDE&quot;

Sub DDEreadStation1()
On Error GoTo MessageRSLinxDead:

'make sure the DDE Channel is Closed before we define a Topic channel
txtStat1Force.LinkMode = 0
txtStat1Status.LinkMode = 0

'set the Application and Topic of the Control Property
'DDETOPIC is a Public Constant in MainSubs Module
'I might use a configuration file later and let the user set this
txtStat1Force.LinkTopic = &quot;RSLinx|&quot; & DDETOPIC
txtStat1Status.LinkTopic = &quot;RSLinx|&quot; & DDETOPIC

'set the Address of the PLC we want to read
txtStat1Force.LinkItem = &quot;N7:1&quot;
txtStat1Status.LinkItem = &quot;B3:1/1&quot;

'set the DDE mode to COLD Link, we will request the data manually
txtStat1Force.LinkMode = 2
txtStat1Status.LinkMode = 2

'tell VB to get the data from the PLC NOW!
txtStat1Force.LinkRequest
txtStat1Status.LinkRequest
txtStat1TimeStamp.Text = Now()

GoTo SkipMessage

MessageRSLinxDead:
MsgBox (&quot;RSLINX is not running. Can not continue!&quot;)
SkipMessage:

End Sub Chris Elston
Automation & Controls Engineer
Download Sample PLC Ladder Logic Code
at MrPLC.com
 
Thanks everyone for your replies

I have another question

Has anyone out there ever used a DLL from rockwell software called rsiopcauto.dll?

This DLL allows me to communicate using OPC to RSLinx single node version.

I was given some sample VB code by rockwell software that showed how it was possible to communicate to a PLC using OPC and RSLinx.

The code that I was given all resided within a VB form and it seamed to work just fine.

I then put this code into a class and found that when I tried to communicate to the PLC it did not seam to communicate very well by that I mean whenever I would try to read from a same memory location the value would vary from time to time eventhough it never changed on the PLC itself.

I was kinda thinking that maybe I should have left the code in the form and used that instead of putting it into a class module?

Can somebody out there please help me with this?

Thank You

Gary






 
Hi Gary

I have a lot of experience programming in Visual Basic with the RSLinx OPC Automation interface and would be happy to help you out if I can. Its really easy once you get your head round the basics.

I programmed all of my OPC communications code in Class modules and it functions just fine so you didn't make any mistakes there.

I'm guessing that you need to work out what type of OPC group connection you need. OPC can support three general types of data read; Sync, Async and Subscribed. I would need to understand a little bit more about what you are trying to do and then I could give you some examplecode.

I also have a compiled HTML help file which gives details about the properties, methods and events of the RSLinx OPC interface. I'm not sure how to upload it here 'cos I'm new so I can send it by email if you like.

Keith
 
Hi Gary
i am new to PLCs. i have a project to control view the status of the rslogix5000 and display status in visual basic. Actually the vb is controlling the downloading of program in rslogix. So vb monitors the status in rslogix. i am actually extracting the status by identifying the colour for run,prog mode from the rslogix. But i feel it is not so stable. my customer keeps complaning about it. i want to improve on this project. Is there any way i can get the status of rslogix by querying or reading any registers from vb. i need to find out Battery at fault,run mode, rem run, programmode, nocontroller,io not reponding etc i mean all the status.in any of the fault conditions i have to display error or may be stop downloading
it would be very helpfull if you could help me
thanks
roopa
 
The function I think you require is the @MODE function. This is available directly from the RSLinx application and does not require the use of RSLogix 5000

Try this:
In RSLinx, create an DDE/OPC topic pointing to your processor. For this example call it ModeTest
Now open Excel and insert the following string in one of the cells;
=RSLINX|ModeTest!'@Mode,L1,C1'

This will return a string stating the mode of the processor (Remote Program / Run etc.)

I've used these functions a lot in the past but only by using DDE in VB, not OPC. This is easily achieved. Create a new VB project. Create a Textbox. Set the LinkTopic property to RSLinx|ModeTest (where ModeTest is the name of your topic). Set the LinkItem to @Mode. Set the LinkMode to Automatic. The textbox should now show the mode.

I will look into whether this works also in OPC and contribute later.

There are also a lot of other @ functions available although all do not work on all controller platforms. You can find out more by looking at the online help.
 
FAO - KiethMcr

I am going to try and pull out the rung comments from an slc5/03 so that by documenting the plc code ie
Step 1 Advance CAn Clamps
Step 2 Wait Operator Accept
Step 3 Can Table Forward

we would have a system specification updated when we save the plc code and comments

and would like to use RSLinx OPC Automation Interface in order to pull the data from the plc to MS Word

Have you any ideas

I would be interested in you sending me your OPC sample programs to peter.j.orford@bnfl.com

Regards
Pedro
 
KeithMcr
you told me i can use @Mode function to access the status of the plc.is there any other function for all the io,battery,whether rslogix is downloading to processor,and at some contidition like if the processor is switched to remrun mode i must stop donwloading etc. if there is where can i get the list of functions.
Actually i am not able to test whether it will work here as i do not have the setup and rslinx with me. So i must be quite sure it works when i go down to customers place(oversea's).if you can help me how and where can i find the documentation for all this it will be very helpfull.

thanks
roopa
 
I have the following versions of software

RSLogix Professional V5.20.00
RSLogix Gateway V2.40.01 (Build 16)

I have connected channel 0 of an SLC 5/03 through RSLinx and all works fine


I have created a form in VBA through RSLogix 500 and created some command buttons and text boxes onto it


I want to be able to click a command button on the VBA form and set an bit in the the SLC 5/03

I want to be able to read an integer register from the plc N7:00 and display it in a text box

Can the above be achieved using RSLogix 500 and RSLinx


Regards
Peter Orford
Control Engineering Group
WestingHouse
 
(1) Pedro / Peter.
The RSLinx OPC Automation Interface CANNOT be used to upload or download either PLC Code or Documentation. RSLinx OPC can only allow upload/download/subscription to data-table points and arrays. The only way I know to access the type of information you are talking about is by using the RSLogix Automation Interface. This effectively allows you to control the RSLogix application 'remotely'. I could imagine a scenario where you use this interface to upload the program and then either convert the program to a text format or export the comments. You could then parse the text document to find the data you need. Alternatively, it may be possible to upload the program and then navigate the COM object model of the automation interface to find the data you need. Both are possible ways to achieve what you wish however they are relatively complex. Either way, RSLinx OPC Automation will not help you here.

(2) Roopa
I found the following information in the current RSLinx release notes reagrding the @ functions

&quot;RSLinx can obtain general processor information or trigger events using DDE/OPC predefined items.The following predefined items can be used with all PLC types:

@Mode returns the current mode of the processor as a string (Run, Program, Remote Run, or Remote Program).
@ProcessorName returns the name of the program running in the processor.
@Revision returns the firmware version of the processor as a string.
@PLCType returns the processor type as a string.
@Status returns the current status of the processor as a string (Ok or Faulted).
@StatusNumber returns the current status of the processor as a number.
@SwitchTopic is used to switch between alias topics in OPC clients.

The following predefined items are used with Logix5000 family processors:
@FreeMem returns total unused memory (I/O + data table + general).
@FreeMemDT returns unused data table memory (not applicable to 1756-L1).
@FreeMemGM returns unused general memory (applicable to 1756-L55M16 only).
@FreeMemIO returns unused I/O memory.
@TotalMem returns total available memory (I/O + data table + general).
@TotalMemDT returns total available data table memory (not applicable to 1756-L1).
@TotalMemGM returns total available general memory (applicable to 1756-L55M16 only).
@TotalMemIO returns total available I/O memory.
@CLTagUpdateAddressSpace forces RSLinx to update its' Logix5000 tag database.
@RedundancyMode monitors the processor state in a ControlLogix redundant system.
@IsPresent allows you to check if your ControlLogix processor is available prior to performing reads or writes. The time out value is consistent with the communications timeout value in the configured PLC-5 topic.&quot;

More help should be available on each of these points either via the RSLinx help files or via online RSI resources:
(3) Peter / Pedro (?)
I will email you a sample VB6 application in the next few minutes as I don't know how to upload here.

Keith
 
Might I suggest using an activex control from Consolitech Corporation. I have a lot of experience using this software and it works really well. I was able to send data from A SLC 500 PLC to Excel incuding time and date stamping of data. I was also able to send data to Word and perform comparisons of data entered by user to that of data in an Access data base. There is no need for RS linx when using this software. This software allows you to map to every register within the SLC 500, including the s registers which provide status information about the CPU such as faults etc. plcsavvy
 
Status
Not open for further replies.
Back
Top