A little Help with Pylogix

btjiii

Member
Join Date
Aug 2014
Location
Los Angeles County
Posts
18
I am trying to use pylogix to write to a string array ID_Data_Table_Name. In the array there are 200 possible entries. For example:ID_Data_Table_Name[0] (value) 'John Doe'
ID_Data_Table_Name[1](value) 'Jane Doe' , etc until there is an empty one.

I am trying to make a user interface to type in the name and have it fill the string value(in the next available).

Thanks.

BTW pylogix is an awesome program.

ID_Name.JPG
 
Something like this should get you started. It should function but could be better:

Code:
from pylogix import PLC

def write_new_name(new_name):
    """
    Reads the string array, writes the name provided
    to the next empty location
    """
    success = False
    with PLC() as comm:
        comm.IPAddress = '192.168.1.9'
        names = comm.Read('ID_Data_Table_Name[0]', 200)

        for i, name in enumerate(names.Value):
            if name == '':
                tag = 'ID_Data_Table_Name[{}]'.format(i)
                comm.Write(tag, new_name)
                success = True
                break

    if not success:
        print('Array is full?')

write_new_name('zaphod beeblebrox')
 
Code:
### Initialize index into ID_Data_Table_Name

index=0


### Loop over increasing indices as long as the string at each index is not ''

while indices<200 and com.Read('ID_Data_Table_Name[{0}]'.format(index)).Value:
  index += 1


if i<200:
  com.Write('ID_Data_Table_Name[{0}]'.format(index), new_string)
OR perhaps



Code:
for index in range(200):
  tag_name = 'ID_Data_Table_Name[{0}]'.format(index)
  if not com.Read(tag_name).Value:
    com.Write(tag_name, new_string)
    break
I forget if break with work in a [for member in list] construct.


OR


Code:
for index in range(200):
  tag_name = 'ID_Data_Table_Name[{0}]'.format(index)
  if com.Read(tag_name).Value: continue
  com.Write(tag_name, new_string)
  break
OR even


Code:
def write_new_name(new_name, com):
  for index in range(200):
    tag_name ='ID_Data_Table_name[{0}]'.format(index)
    if com.Read(tag_name).Value: continue
    com.Write(tag)name,new_name)
    return index
So it returns the index written on success, and None when it runs out of indices.


For extra credit:

  • Write as a class
  • Exception handling
 
Last edited:
Excellent. Just curious, what GUI framework are you using?
I want to use HTML. I’m using this to control access to different levels on an HMI. I want give others the ability to add users without accessing studio 5000.

So right now I have it where user input adds name, RFID card number, and level.

Do you have suggestions?
 
If you want to use a web framework, check out django. If you just want an application that runs on a desktop/laptop, TKinter, WXPython or Qt.

TKinter is kind of the defacto python GUI framework. It's simple, lightweight but lacking and kind of ugly. It's good for getting things done quickly though.

WXPython has a lot more features and is a good balance between simple and featureful.

Qt is cross platform, is more difficult to use and install, but is super powerful

Being that you are new to python, I'd start with Tkinter. There are lots of resources out there for all of them.
 
django should do the job, also flask. Even Jupyter, but Jupyter is a bit close to the iron and overkill for what it sounds like what you are doing, so I suspect you want one of the others. Of course, then you're a web server admin 'n'all that entails. If this a single specialized app that you want people to connect to e.g. via their smartphones, there are also simpler approaches that simply add a bit of code to your python script, that don't require a full web server.



What is the nature of the app, where people can add their name and RFID? Is this on an intranet, so security (authentication and authorization) is implicit by the fact that they can get to your host?
 
If you want to use a web framework, check out django. If you just want an application that runs on a desktop/laptop, TKinter, WXPython or Qt.

TKinter is kind of the defacto python GUI framework. It's simple, lightweight but lacking and kind of ugly. It's good for getting things done quickly though.

WXPython has a lot more features and is a good balance between simple and featureful.

Qt is cross platform, is more difficult to use and install, but is super powerful

Being that you are new to python, I'd start with Tkinter. There are lots of resources out there for all of them.

I will check out Tkinter.
Thanks
 
django should do the job, also flask. Even Jupyter, but Jupyter is a bit close to the iron and overkill for what it sounds like what you are doing, so I suspect you want one of the others. Of course, then you're a web server admin 'n'all that entails. If this a single specialized app that you want people to connect to e.g. via their smartphones, there are also simpler approaches that simply add a bit of code to your python script, that don't require a full web server.



What is the nature of the app, where people can add their name and RFID? Is this on an intranet, so security (authentication and authorization) is implicit by the fact that they can get to your host?

Yes it's on an Intranet.The production operators for our oven have their own login so we can tell who was logged in when certain things happen and others can't perform certain functions. Their Supervisors can't add new people to the system (so far). I'll also check out Django and Flask.

Thanks again for the help.
 
Nice work dmroeder. I didn't know pylogix existed. I will tell the guys at work.


I have written a python program used to calculate hydraulic cylinder bore, rod diameter, HPU and accumulator size. I used Tkinter because I wanted something light weight. I am generating plot files using matplotlib too and then reading and writing .json files.


Tkinter isn't as nice as QT if you want a sophisticated looking interface because it doesn't have a designer like QT does that allows one to drag objects onto a form or canvas. However, if you just want to display parameters then Tkinter is relatively easy but everything gets to be more complicated as the projects get bigger. Tkinter has some weirdness to it for instance I often get an entry routine called twice for hitting the return key once.
 
Nice work dmroeder. I didn't know pylogix existed. I will tell the guys at work.


I have written a python program used to calculate hydraulic cylinder bore, rod diameter, HPU and accumulator size. I used Tkinter because I wanted something light weight. I am generating plot files using matplotlib too and then reading and writing .json files.


Tkinter isn't as nice as QT if you want a sophisticated looking interface because it doesn't have a designer like QT does that allows one to drag objects onto a form or canvas. However, if you just want to display parameters then Tkinter is relatively easy but everything gets to be more complicated as the projects get bigger. Tkinter has some weirdness to it for instance I often get an entry routine called twice for hitting the return key once.

Thanks Peter! I'm with you on the differnet GUI's, if you want to bang out something simple, Tkinter gets the job done. If you need something more powerful, Qt is the way to go.
 

Similar Topics

Hey guys, I have a client that has a v-notch chlorinator that doesn't run off a 4-20mA loop, it instead has two discrete inputs that drive the...
Replies
6
Views
1,857
Hey all. I need some guidance here. This is something I came across today when a Ref guy noticed that the HMI isn't displaying the correct time...
Replies
2
Views
1,447
i am a beginner plc programmer and have some confusion, a little help would be appreciated . why do we use a normally close contact when we are...
Replies
11
Views
2,935
Hello everyone! So, for my job I need to use the web server of a S7-1200 for setting some variables. Thing is, since I'm not the only one using it...
Replies
1
Views
1,362
Hi all, looking for some assistance in how to write a small prog using CCW. I have a signal which pulses approximately every 1.5s for about 0.2s...
Replies
7
Views
1,596
Back
Top Bottom