PLC Interfacing using Visual Basic and RSLinx
PLC Interfacing using Visual Basic and RSLinx
(OP)
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
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





RE: PLC Interfacing using Visual Basic and RSLinx
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.
RE: PLC Interfacing using Visual Basic and RSLinx
Gary
RE: PLC Interfacing using Visual Basic and RSLinx
http://www.ktech-usa.com
RE: PLC Interfacing using Visual Basic and RSLinx
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.
RE: PLC Interfacing using Visual Basic and RSLinx
http://www.mrplc.com/cgi-bin/code/filedisplay.cgi?category=excel
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
http://www.mrplc.com
Download Sample PLC Ladder Logic Code
at MrPLC.com
RE: PLC Interfacing using Visual Basic and RSLinx
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:
http://www.plctalk.net/qanda/showthread.php?s=&threadid=1093&highlight=dde
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 = "DDE"
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 = "RSLinx|" & DDETOPIC
txtStat1Status.LinkTopic = "RSLinx|" & DDETOPIC
'set the Address of the PLC we want to read
txtStat1Force.LinkItem = "N7:1"
txtStat1Status.LinkItem = "B3:1/1"
'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 ("RSLINX is not running. Can not continue!")
SkipMessage:
End Sub
Chris Elston
Automation & Controls Engineer
http://www.mrplc.com
Download Sample PLC Ladder Logic Code
at MrPLC.com
RE: PLC Interfacing using Visual Basic and RSLinx
http://www.software.rockwell.com/download/comms/rslinx/rslinx%20product%20guide.htm
Happy hunting...
RE: PLC Interfacing using Visual Basic and RSLinx
Another option for low cost ActiveX DLLs to communicate with your PLC is http://www.vhmiautomation.com
The ActiveX DLLs can be used in VB, VBA, C++, Delphi, etc...
Regards,
Phil Covington
RE: PLC Interfacing using Visual Basic and RSLinx
Though it's not finished, you can still get the feel of VB and DDE if you wish:
http://www.mrplc.com/cgi-bin/code/filedisplay.cgi?category=machvb
Chris Elston
Automation & Controls Engineer
http://www.mrplc.com
Download Sample PLC Ladder Logic Code
at MrPLC.com
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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.
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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
RE: PLC Interfacing using Visual Basic and RSLinx
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
"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."
More help should be available on each of these points either via the RSLinx help files or via online RSI resources: http://www.software.rockwell.com
(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
RE: PLC Interfacing using Visual Basic and RSLinx
RE: PLC Interfacing using Visual Basic and RSLinx
roopa
RE: PLC Interfacing using Visual Basic and RSLinx
WOULD YOU HELP[ ME TO SOLVE THIS PROBLEM. lAST TIME I USING hizac PLC FROM hitachi. But i want to print out the ladder from cpu, with RS 232. Maybe somebody tell me how to connect from cpu to printer (dot matrix).
thanx.
Hasan.
RE: PLC Interfacing using Visual Basic and RSLinx
Im new to this forum so bare with me. I have been reading all the info ye have supplied in relation to VB accessing PLC data through RS Linx(OPC)/gateway setup. Im in the process of trying to set this up on a test system, with little VB experiance im finding it difficult to start off on the right foot!
Keith, you have presented what i think is the answer to my problem, could i see a sample of what you have spoken about, im sure it will help me a lot as I am new to the VB field but have extensive PLC experiance.
Thanx in advance
RE: PLC Interfacing using Visual Basic and RSLinx
I'd also like a peek at your VB code.
As others are, I'm looking at building an application to monitor a couple of tags and record them to MS Access or a flat file. A second application will read a user selectable span of data, display it, and optionally export it.
Thanks in advance.
RE: PLC Interfacing using Visual Basic and RSLinx
RE: PLC Interfacing using Visual Basic and RSLinx
I have successfully created an HMI using VB6. This can be done by downloading after market drivers. Refer to a previous thread from this forum. http://www.eng-tips.com/viewthread.cfm?qid=89373