Exemple #1
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
A simple single read using a with statement.

One advantage of using a with statement is that
you don't have to call .Close() when you are done,
this is handled automatically.
'''
from eip import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('CurrentScreen')
    print(value)
Exemple #2
0
from eip import PLC

test = PLC()
test.IPAddress = "172.16.2.161"
value = test.Read("Timer.ACC")
print(value)
#Write a value: test.Write("tagname", value)
ex: test.Write("python_Real", 2.0)
test.Close()

'''
Read a list of tags at once

Reading lists and arrays is much more efficient than
reading them individually. You can create a list of tags
and pass it to .Read() to read them  all in one packet.
The values returned will be in the same order as the tags
you passed to Read()

NOTE:  Packets have a ~500 byte limit, so you have to be cautions
about not exceeding that or the read will fail.  It's a little
difficult to predict how many bytes your reads will take up becuase
the send packet will depend on the length of the tag name and the
reply will depened on the data type.  Strings are a lot longer than
DINT's for example.

I'll usually read no more than 5 strings at once, or 10 DINT's)
'''
from eip import PLC

tag_list = ['Zone1ASpeed', 'Zone1BSpeed', 'Zone2ASpeed', 'Zone2BSpeed', 'Zone3ASpeed', 'Zone3BSpeed',
            'Zone4ASpeed', 'ZOne4BSpeed', 'Zone1Case', 'Zone2Case']

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read(tag_list)
    print(value)
#================================================================
# Code for an reading an array from PLC and moving it into Excel
#================================================================

from eip import PLC
comm = PLC()
comm.IPAddress = '100.100.100.100'
' xArray is the PLC tag being read and 5 is the number of arrays to read 
array = comm.Read('xArray[0]',5)

print (array)
[1234, 2345, 3456, 4567, 5678]
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
for i, value in enumerate(array):
	ws.cell(column=1,row=i+1,value=value)

<Cell 'Sheet'.A1>
<Cell 'Sheet'.A2>
<Cell 'Sheet'.A3>
<Cell 'Sheet'.A4>
<Cell 'Sheet'.A5>
wb.save('PLC_Read.xlsx')
Exemple #5
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')


'''
Read an array of values

I have a tag called "LargeArray", which is DINT[10000]
We can read as many of them as we'd like, which makes
reading arrays the most efficient way to read data.
Read will handle multi-packet replies.

We're going to pass Read() the tag and the number
to read.
'''
from eip import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    values = comm.Read('LargeArray[0]', 500)
    print(values)
    
Exemple #6
0
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
Read a little faster by providing the data type
up front

This only really makes sense to do if you have to
read a lot of unique tags. Typically, when you read a
tag, it has to fetch the data type first.  This only
happens the first time you read a uniuqe tag name.  Once
we have read a tag, we remember the type.

If you have, for example, 1000 tags to read and they are
all unique, you would have have to fetch the data type,
then the value, which is quite a bit of overhead.

If you pass the data type up front, it will skip that
initial read...
'''
from eip import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('CurrentScreen', datatype=196)
    print(value)
'''
the following import is only necessary because eip.py is not in this directory
'''
import sys
sys.path.append('..')
'''
Read a program scoped tag

I have a program named "MiscHMI" in my main task.
In MiscHMI, the tag I'm reading will be TimeArray[0]
You have to specify that the tag will be program scoped
by appending the tag name with "Program" and the beginning,
then add the program name, finally the tag name.  So our
example will look like this:

Program:MiscHMI.TimeArray[0]
'''
from eip import PLC

with PLC() as comm:
    comm = PLC()
    comm.IPAddress = '192.168.1.9'
    value = comm.Read('Program:MiscHMI.TimeArray[0]')
    print(value)