Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How do I use Visual Basic and DDE to get data out of an Allen Bradley PLC?

DDE and PLCs

How do I use Visual Basic and DDE to get data out of an Allen Bradley PLC?

by  chakorules  Posted    (Edited  )
You'll need to make sure you have RS Linx running and a DDE topic created. In our example code below, our DDE topic is called "DDE".

Open a new project in Visual Basic.

Use this sample code provided to try some COLD DDE linking to a text box control in Visual Basic.

<<<<<<<<<<<<BEGIN 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
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search