Which Python Lib To Use?

kevilay

Member
Join Date
Feb 2009
Location
Ontario
Posts
174
Hey guys,

I have been plc programming for a while and recently started getting into python. I wrote some pretty cool stuff with an SQL database logging all kinds of information on a siemens PLC. I used a library called snap7.

I am going to implement the same thing onto a compact logix plc but I see there are several libraries to use. (libplctag, pycomm3, dmroeder/pylogix) There also may be some other ones I am not familiar with.

I am planning on running this on a raspberry PI so it would be best if the library was linux/arm friendly. The snap7 lib took some recompiling of binaries and some fiddling around to get it to work on the arm processor.

I am just looking for someone's experience as to which route I should go.

Thanks,
Kevin
 
My current focus is on UDT's, you won't be able to easily read an entire structure. For example, if you have a UDT that is made up of 2 DINT's:

MyUDT.Count
MyUDT.Duration

If you read MyUDT, it is going to return the raw bytes, which you would have to parse. Not ideal. You can read/write MyUDT.Count and MyUDT.Duration no problem.

I've gotten a bit of criticism for not having better UDT support, which I get. It's a lot of work though and I do it for free/fun. Better UDT support for reading entire structures by the base tag name is in the works, I just don't have a lot of free time right now. And how UDT's are packed is a hot mess.

People have utilized L5X exports of their UDT's, which they would parse in python, to generate a list of tags to read. One thing you can do with pylogix (maybe others too) is pass a list of tags to Read an it will get all the values in as few packets as possible.

https://github.com/dmroeder/pylogix/blob/master/examples/05_read_multiple_tags.py
 
That is not dmroeder in the picture.

Haha, yeah, you found that one out in real life :) It's from a movie I like. I had that same picture as my outlook avatar at work. Bumped into someone and they said, boy have you changed! It's silly of me to think that people would recognize the movie.
 
My current focus is on UDT's, you won't be able to easily read an entire structure. For example, if you have a UDT that is made up of 2 DINT's:

MyUDT.Count
MyUDT.Duration

If you read MyUDT, it is going to return the raw bytes, which you would have to parse. Not ideal. You can read/write MyUDT.Count and MyUDT.Duration no problem.

I've gotten a bit of criticism for not having better UDT support, which I get. It's a lot of work though and I do it for free/fun. Better UDT support for reading entire structures by the base tag name is in the works, I just don't have a lot of free time right now. And how UDT's are packed is a hot mess.

People have utilized L5X exports of their UDT's, which they would parse in python, to generate a list of tags to read. One thing you can do with pylogix (maybe others too) is pass a list of tags to Read an it will get all the values in as few packets as possible.

https://github.com/dmroeder/pylogix/blob/master/examples/05_read_multiple_tags.py

I can see this being a difficult process. If I can directly read the tag. In your example MyUDT.count, there shouldn't be an issue for me. To read and decode a totally flexible udt would be a process. I am pretty new with python, but quite experienced with PLCs. I may be able to assist in some development.

Btw that is a great movie ;)
 
I can see this being a difficult process. If I can directly read the tag. In your example MyUDT.count, there shouldn't be an issue for me. To read and decode a totally flexible udt would be a process. I am pretty new with python, but quite experienced with PLCs. I may be able to assist in some development.

Btw that is a great movie ;)

A lot of what it takes to handle the UDT is already there. Retrieving tag list also gets the UDT definitions. What has to happen is parsing the value and returning it to the user in a meaningful way. It gets tricky when you start nesting UDT's, defining arrays, etc.

If you use it, feel free share your experience, good or bad. And as I've mentioned, let me know if I can help.
 
I've only recently started experimenting with using Python libraries with PLC's. I used Pycomm3 to communicate with ComplactLogix PLC. Very straight forward and easy. Documentation good and thorough. I was just reading tags and writing to them, so not doing anything compelling.

One thing I did find though that was odd, possibly just inherent to that library is that when reading just one tag, it would hang for several seconds before finally reading back the tag value. My guess is that the time delay is because it's iterating through all the tags on the controller to find the tag name specified(?). I didn't dig into the underlying code to find out, but just a guess.
 
Last edited:
I've only recently started experimenting with using Python libraries with PLC's. I used Pycomm3 to communicate with ComplactLogix PLC. Very straight forward and easy. Documentation good and thorough. I was just reading tags and writing to them, so not doing anything compelling.

One thing I did find though that was odd, possibly just inherent to that library is that when reading just one tag, it would hang for several seconds before finally reading back the tag value. My guess is that the time delay is because it's iterating through all the tags on the controller to find the tag name specified(?). I didn't dig into the underlying code to find out, but just a guess.

Wow thats a crazy delay. In the siemens library I used. Snap7. It was as close to instant as I could expect. I was turning a bit on with the python program then flipping it off in the plc with a short timer and you would never even see it turn off. The whole process of reading --> writing --> reading would be <50ms
 

Similar Topics

Hello Guys, I want to establish profinet communication between siemens plc and my system using python programming. Which python lib can i use to...
Replies
12
Views
360
Hi! I'm trying to communicate with an old Kinetix 300 drive that is fully functioning. Is there any library I can use to monitor this drive with...
Replies
0
Views
426
Hi! I'm trying to communicate with an old Kinetix 300 drive that is fully functioning. Is there any library I can use to monitor this drive with...
Replies
0
Views
479
I have previously shared this elsewhere, so I apologize if you have already seen it. Here is a basic and quick introduction to Python for PLCs...
Replies
10
Views
2,245
Read and write the Tags direct using pycomm3 and LogixDriver. Just in case anybody wanted to know. Here's a sample: from pycomm3 import...
Replies
0
Views
798
Back
Top Bottom