Compactlogix Write Data to a File

jthornton

Member
Join Date
Jul 2002
Location
Poplar Bluff, MO
Posts
295
Is it possible to write data from a CompactLogix PLC over the LAN to a server in comma delimited or some other format? Ideally the data is appended to a file and a new file started each day.


The controller is a 1769-L24ER-QB1B and has an Ethernet switch for valves and such.



The data is date, time, cycle time etc. The data is stored now in a user defined data type using wall_clock, string, and real data types. It stores 100 cycles pushing out the old when a new is inserted.



If it's possible some key search words would be nice.


Thanks
JT
 
If you have a Panelview on the system, it can write to a csv to a networked drive much easier than a CPX can.
 
Thanks so much for that bit of info, and yes there is a Panelview 600 Plus IIRC on the machines. I just found this page on using the Panelview to log data.


I've also just found the pylogix Python library that can read the tags in the PLC which might be an easy way to just put a Raspberry Pi in the cabinet and have it read the data and if needed they can get it with a thumb drive.


Thanks
JT
 
Last edited:
Thanks so much for that bit of info, and yes there is a Panelview 600 Plus IIRC on the machines. I just found this page on using the Panelview to log data.


I've also just found the pylogix Python library that can read the tags in the PLC which might be an easy way to just put a Raspberry Pi in the cabinet and have it read the data and if needed they can get it with a thumb drive.


Thanks
JT

If you want to give pylogix a try and need any help, hit me up.
 
dmroeder I got to work with pylogix and the CompacLogix today and if you happen by I have a question about it.


Following your example code I did the following:
with PLC() as comm:
comm.IPAddress = '192.168.117.130'
ret = comm.Read('Machine_Cycle_Counter')
print(ret.TagName, ret.Value, ret.Status)


Do you need to open a new comm each time you read the tag?


What I need to do is to gather some data when the Machine_Cycle_Counter increments.


Thanks
JT
 
No, you don't need to instantiate PLC() each time you read, you wouldn't want to do this because you'd be opening a connection each time. If you just call another Read(), the connection will be open and another request will be sent to the PLC.

It's important to understand how with statements behave in python. There are some magic methods that are called when a with statement ends (the indent returns to the same "level" as the with statement), .Close() will be called automatically and close the connection. You could still use comm.Read(), but it would open a new connection, which would be inefficient. Consider:

Code:
from pylogix import PLC

with PLC('192.168.1.10') as comm:
    # first read, new connection is opened
    ret = comm.Read('BaseDINT')
    print(ret)

    # second read, same connection is used
    ret = comm.Read('BaseDINT')
    print(ret)

# with ended, so the next read will open a new connection
ret = comm.Read('BaseDINT')
print(ret)

So it sounds like you want to continuously monitor Machine_Cycle_Counter tag, when the value changes, you want to read some other tags? Sound about right?
 
Try something like this:

Code:
import time
from pylogix import PLC


monitor_tag = 'Machine_Cycle_Counter'

def pull_data(c):
    """
    Pull some data from the PLC.  Add more reads/writes as
    necessary.
    """
    stuff = c.Read('BaseSTRING')
    t = c.GetPLCTime()
    
with PLC('192.168.1.10') as comm:

    run = False
    # read our value at start
    init = comm.Read(monitor_tag)
    
    # if the read was successful, save the value and
    # allow us to monitor the tag
    if init.Status == 'Success':
        # make last value = to current value so we don't pull
        # our data the first time we run
        last_value = init.Value
        run = True

    # run a loop to monitor our tag
    while run:
        try:
            value = comm.Read(monitor_tag).Value

            # if the value changed, gather our data
            if value != last_value:
                # our tag changed, call pull_cata
                pull_data(comm)
                last_value = value
            else:
                # take a 0.5 second nap if the value didn't change
                time.sleep(0.5)
        except KeyboardInterrupt:
            run = False
        except:
            run = False
 

Similar Topics

I'm having trouble writing data from a CompactLogix PLC to a ControlLogix PLC. My CompactLogix (IP 192.1.5.70) configuration : Mu...
Replies
7
Views
3,035
I'm using a 1769-L16ER-BB1B. I'm storing recipe data in an array of user-defined data types. For disaster recovery purposes, I need to make sure...
Replies
12
Views
8,810
Dear Experts, Can you help me, I am using compactlogix cpu with ILX34-MBS485 card as Rs485 master in serial modbus network to make communication...
Replies
5
Views
2,813
Does anyone know of a method to write a value to a plc tag from a pc that has no RSLinx or Logix5000 software installed? I can connect through...
Replies
4
Views
2,522
Hello, we want to write a program in C/C++ to communicate with AB CompactLogix PLC. It will be run in Linux. The basic task of this program is to...
Replies
4
Views
4,159
Back
Top Bottom