PDA

View Full Version : About Serial communication with CompactLogix L32E and its commands?


efel09
December 12th, 2012, 01:54 AM
Hello everyone,

I having some troubles for reading the serial of a L32E. I'm good in php programming and I'm using a serial class for opening and reading the serial port (not the first time, in the past i was able to "talk" to some mcus and other serial devices with any issue). The idea is to make a web application for "real-time" graphing for EOL F-15 40% / 60% and saving the data to MySQL db. My problem is that I'm new to PLC and I do not have any idea about the string format of the data. Header + data + End ? The people that want the program set a dummy program into de PLC with a random value. I was able to use RSLinx to copy the link of the DDE/OPC using the Ethernet Interface to Excel. The url is something like Program:MainProgram.VARIABLE_1.ACC

I tried using the hyperterminal to read the serial port and I get nothing, I read about something ASCII mode but not sure about that.

They gave to me a visualbasic program with any comment in order to figureout and the part of the program have a function ProcessChar that it may be part of the decoding function.


Private Function ProcessChar(ByVal c As Byte) As Integer
If c > 47 And c < 58 Then 'Digit
token = token & ChrW(c)
Return 1
End If
If c = 46 Then ' Dot
token = token & ChrW(c)
Return 3
End If
If c = 45 Then ' Minus
token = token & ChrW(c)
Return 4
End If
If c > 64 And c < 91 Then 'Alpha upper
currentType = TokenType.Text
token = token & ChrW(c)
Return 2
End If
If c > 96 And c < 123 Then 'Alpha lower
currentType = TokenType.Text
token = token & ChrW(c)
Return 2
End If
Return 0
End Function



In other words how do I read the variables from the serial?


Does anyone have any suggestion about how to read from the serial or any link for reference?

Thanks in advance

DamianInRochester
December 12th, 2012, 10:59 AM
I'm confused. If you have an Ethernet based CPU why are you trying to pass data using ASCII over the serial port? If this is a web application that screams "ethernet" to me.

Ken Roach
December 12th, 2012, 11:22 AM
Reading data from a CompactLogix is not as simple as parsing some ASCII strings.

There are quite a few commercial products that already do this, both as OPC servers and as standalone drivers.

AvancedHMI is a community project that includes Allen-Bradley serial drivers.

Inductive Automation Ignition is the best OPC-UA server for A-B on the market, and the OPC-UA server is free.

If you still intend to write your own driver using the serial port class, the best resources are on the RA Developer Guide website:

http://www.rockwellautomation.com/sales-partners/technology-licensing/developer-guides.page

efel09
December 12th, 2012, 12:06 PM
Thank all of you for your support.

Ken Roach, I really appreciate your suggestion, you rock!!! (my apologies if the phrase in no well used, as you can imagine I'm not an English native speaker). I will check both suggestios prior to intend to write the driver.

The problem was that I was working at the IT department and suddenly they re-assigned my duties to the Control department and they are "so busy" to assist a budy, lol. But they want the job done ASAP. I never used a PLC before, but with your suggestions I hope to solve the issue as fast and good as I can.

Finally, I'm guessing that with the use of those solutions the access to specific variables are "quite" easy, right?

Thanks again

dmroeder
December 12th, 2012, 12:45 PM
AdvancedHMI in my opinion is the way to go:

Main thread: http://www.plctalk.net/qanda/showthread.php?t=42656
SourceForge page: http://sourceforge.net/projects/advancedhmi/

efel09
December 12th, 2012, 03:03 PM
Greetings Dmroeder, thanks for the links. Actually, I agree with you about AdvancedHMI. I just downloaded from sourceforge. Since I'm running out of time, this would be the prior solution. And for the moment and because they want a web-based interface I will use VB with AdvancedHMI as interface and a socket for gathering the dato directly to php.

Thanks for your support.

ASAP I have a working solution I will be glad to share my results with the community.

efel09
December 12th, 2012, 08:55 PM
Greetings, As I mentioned before I decided to go with AdvancedHMI. I'am reading the "Quick Starting guide" but I do not know how to set the PLCaddressValue. Where do I find that?

The people of the department of Control, set a dummy program with a random value generator. I was able to copy the link to Excel and see the value. The link was generated using RSLinx

The link is like that: [NEW_TOPIC]Program:MainProgram.VARIABLE_1.ACC,L1,C1

ACC is the accumulator value, but I don't know how to format de address. I just copy the link to the PLCaddressValue field and nothing happens but an "invalid value returned! Unknown Message - 5 Cip Status 5".

Here's the picture
http://www.freeimagehosting.net/gkjrt
http://www.freeimagehosting.net/gkjrt
Any suggestion?

Thanks in advance.

dmroeder
December 12th, 2012, 09:01 PM
The PLCaddressValue is part of every AdvancedHMI object (buttons, indicators, etc). If you place an AdvancedHMI object on your AdvancedHMI form, you will find that it is one of the properties in the property panel.

I was thinking that you may not really care about using the object, but just using the driver to read values from the PLC and writing code to do something with it (put it in a text file, excel spreadsheet). You would do this by placing a driver on your form, then using "DriverName.ReadAny()" to get the value from the PLC.

dmroeder
December 12th, 2012, 09:03 PM
Do you really plan on using serial, or is Ethernet an option?

efel09
December 12th, 2012, 09:09 PM
Hello, Thanks for your suppor its really appreciated. Yes, Ethernet is an option. I will try what you suggested You would do this by placing a driver on your form, then using "DriverName.ReadAny()" to get the value from the PLC.

Thanks again

dmroeder
December 12th, 2012, 09:15 PM
Hello, Thanks for your suppor its really appreciated. Yes, Ethernet is an option. I will try what you suggested
Thanks again

Then use the EthernetIPforCLX driver.

I see you were reading arrays in your DDE example, you can do this as well. There are limits with Strings, but you can overcome this with code. I'm doing this off of memory but I think the format is "DriverName.ReadAny(TagName, NoOfElements)".

efel09
December 12th, 2012, 09:23 PM
Then use the EthernetIPforCLX driver.

I see you were reading arrays in your DDE example, you can do this as well. There are limits with Strings, but you can overcome this with code. I'm doing this off of memory but I think the format is "DriverName.ReadAny(TagName, NoOfElements).

Thanks again...

Actually the EthernetIPforCLX is the one I'm trying to use, lol. So, if my generated link from RSLinxs used in Excel is [NEW_TOPIC]Program:MainProgram.VARIABLE_1.ACC,L1,C1

In the VBStudio I picked a EthernetIPforCLX driver wich I named Driver1. The syntax would be something like "Driver1.ReadAny("VARIABLE_1", 8) if I followed the information of the this screenshot http://www.freeimagehosting.net/gkjrt

Sorry for my dumb questions, but I really trying and I'm willing to learn. At this time is a "learning in the fly", lol.

Thanks again

I will make some test hopping it works.

dmroeder
December 13th, 2012, 12:02 AM
Try this:

Dim intVariable as integer = Driver1.ReadAny(VARIABLE_1.ACC)
MessageBox.Show(intVariable)

efel09
December 13th, 2012, 12:22 AM
Greetings Dmroeder, there is no way to thank You for your help.

I have a little progress, using RSLinx "Data Monitor" I was able to found the needed tag, so I place a Digital Panel Meter (Panel1) to test the connection between the PLC and the Program. The driver was the one You suggested (EtherNET_IP).

The configuration is as followed:

EtherNET_IP.IP = 192.168.1.1
Panel1.PLCaddressValue = Program:MainProgram.VARIABLE_1.ACC 'According to RSLinx Tag

And it works just fine. Later I put a label (Label1) just for picking the data, as followed:

Label1.Text = EtherNET_IP.ReadAny(Panel1.PLCaddressValue)
And also works, my only concern for now is that I do not have a clue of how to refresh the value, it only place the instant value when the program runs for the first time and never updates again. The Digital Panel Meter (Panel1) works just fine and refresh constantly.

Using Visual Studio 2010 Express I can only get the code for the MainForm.vb and I put the Label1 code inside the "Private Sub Form_VisibleChange"


...
If components IsNot Nothing Then
For i As Integer = 0 To components.Components.Count - 1
...
End If

Label1.Text = EtherNET_IP.ReadAny(Panel1.PLCaddressValue)

End If
...


As far I get progress with this I will create a socket for sending the data to PHP and I will post any working solution

Thanks again...

efel09
December 13th, 2012, 12:50 AM
Try this:

Dim intVariable as integer = Driver1.ReadAny(VARIABLE_1.ACC)
MessageBox.Show(intVariable)

Hello again,

I just put a timer. May be that is not the best or elegant solution but at least is working, now the next step is to set the socket.

The Timer has a refresh interval of 1ms and the code is set as followed:



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Time1.Tick

Dim intVariable As Integer = EtherNET_IP.ReadAny(Panel1.PLCaddressValue)
Label1.Text = intVariable


End Sub



Regards,

dmroeder
December 13th, 2012, 11:03 AM
There is an object called BasicLabel. It has a PLC address property and it will always refresh, I'd use that instead.

Or if you wanted to use the timer and ReadAny property, I would do 2 things: Make the interval longer, like 50ms. And get rid of the variable (Label1.Text = EtherNET_IP.ReadAny(VARIABLE_1.ACC).