def main(): ''' Create our window and comm driver ''' global root global comm global ProductionCount # create a comm driver comm = PLC() comm.IPAddress = ipAddress # create a tkinter window root = Tk() root.config(background='black') root.title = 'Production Count' root.geometry('800x600') # bind the "q" key to quit root.bind('q', lambda event:root.destroy()) # create a labe to display our variable ProductionCount = Label(root, text='n', fg='white', bg='black', font='Helvetica 350 bold') ProductionCount.place(anchor=CENTER, relx=0.5, rely=0.5) # call our updater and show our window root.after(1000, UpdateValue) root.mainloop() comm.Close()
def audit_rack(plc): ''' Query each slot for a module ''' with PLC() as c: c.IPAddress = plc.IPAddress f.write('%s - %s\n' % (plc.IPAddress, plc.ProductName)) for i in range(17): x = c.GetModuleProperties(i) f.write('\tSlot %d:%s rev:%s\n' % (i, x.ProductName, x.Revision)) f.write('')
''' 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)
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' A simple single write 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' comm.Write('CurrentScreen', 10)
#================================================================ # 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')
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' Write 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' comm.Write('Program:MiscHMI.TimeArray[0]', 2019)
''' the following import is only necessary because eip is not in this directory ''' import sys sys.path.append('..') ''' The simplest example of writing a tag from a PLC NOTE: You only need to call .Close() after you are done exchanging data with the PLC. If you were going to read/write in a loop or read/write more tags, you wouldn't want to call .Close() every time. ''' from eip import PLC comm = PLC() comm.IPAddress = '192.168.1.9' comm.Write('CurrentScreen', 10) comm.Close()
import cv2 from darkflow.net.build import TFNet import numpy as np import time import tensorflow as tf from eip import PLC #There is no comms error checking in this program #so if it cant find PLC it will hang up. #I am pushing data to a PLC running CLX 5000 software test = PLC() # Set the I.P to youre CLX 5000 rack test.IPAddress = "172.16.2.161" config = tf.ConfigProto(log_device_placement=True) config.gpu_options.allow_growth = True with tf.Session(config=config) as sess: options = { 'model': 'cfg/yolov2-tiny-voc.cfg', 'load': 'bin/yolov2-tiny-voc.weights', 'threshold': 0.2, 'gpu': 1.0 } tfnet = TFNet(options) colors = [tuple(255 * np.random.rand(3)) for _ in range(10)] capture = cv2.VideoCapture(0) #capture.set(cv2.CAP_PROP_FRAME_WIDTH,416) #capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 416)
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' Write to a custom size string WHen you create a custom size string, it is essentially a UDT. We cannot write to them in the same way that we can write to a standard size string. In this case, we're going to write some text to the tag String20, which is a custom string STRING20. We not only have to write the data, we have to also write the length. ''' from eip import PLC with PLC() as comm: comm = PLC() comm.IPAddress = '192.168.1.9' string_size = 20 text = 'This is some text' values = [ord(c) for c in text] + [0] * (string_size - len(text)) comm.Write('String20.LEN', len(text)) comm.Write('String20.DATA[0]', values)
end = '\n' # some tab space formatting if len(name) >= 36: tabs = '\t' if len(name) < 36 and len(name) >= 32: tabs = '\t' * 2 if len(name) < 32 and len(name) >= 28: tabs = '\t' * 3 if len(name) < 28 and len(name) >= 24: tabs = '\t' * 4 if len(name) < 24 and len(name) >= 20: tabs = '\t' * 5 if len(name) < 20 and len(name) >= 16: tabs = '\t' * 6 if len(name) < 16 and len(name) >= 12: tabs = '\t' * 7 if len(name) < 12: tabs = '\t' * 8 line = name + tabs + dtype + '\t' + offset + end text_file.write(line) # define our communication comm = PLC() comm.IPAddress = '192.168.0.167' #comm.ProcessorSlot = 2 # uncomment one of the examples. #ex_read('NewProductID') #ex_readArray('ObjectValue[0]', 10) #ex_multiRead() #ex_write('ThisTag.Thingy', '107') #ex_getPLCTime() #ex_setPLCTime() #ex_discover() #ex_getTags()
def getDevices(): ''' Get all of the devices on the network ''' with PLC() as comm: return comm.Discover()
dtype = "Type: " + str(tag.DataType) offset= "Offset: " + str(tag.Offset) end = '\n' # some tab space formatting if len(name) >= 36: tabs = '\t' if len(name) < 36 and len(name) >= 32: tabs = '\t'*2 if len(name) < 32 and len(name) >= 28: tabs = '\t'*3 if len(name) < 28 and len(name) >= 24: tabs = '\t'*4 if len(name) < 24 and len(name) >= 20: tabs = '\t'*5 if len(name) < 20 and len(name) >= 16: tabs = '\t'*6 if len(name) < 16 and len(name) >= 12: tabs = '\t'*7 if len(name) < 12: tabs = '\t'*8 line = name + tabs + dtype + '\t' + offset + end text_file.write(line) # define our communication comm = PLC() comm.IPAddress = '192.168.250.1' #comm.ProcessorSlot = 2 # uncomment one of the examples. #ex_read('NewProductID') #ex_readArray('ObjectValue[0]', 10) #ex_multiRead() #ex_write('ThisTag.Thingy', '107') #ex_getPLCTime() ex_discover() ex_getTags()
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' Write an array of values I have a tag called "LargeArray", which is DINT[10000] We can write a list of values all at once to be more efficient. You should be careful not to exceed the ~500 byte limit of the packet. You can pack quite a few values into 500 bytes. ''' from eip import PLC values = [8, 6, 7, 5, 3, 0, 9] with PLC() as comm: comm = PLC() comm.IPAddress = '192.168.1.9' comm.Write('LargeArray[10]', values)
dtype = "Type: " + str(tag.DataType) offset= "Offset: " + str(tag.Offset) end = '\n' # some tab space formatting if len(name) >= 36: tabs = '\t' if len(name) < 36 and len(name) >= 32: tabs = '\t'*2 if len(name) < 32 and len(name) >= 28: tabs = '\t'*3 if len(name) < 28 and len(name) >= 24: tabs = '\t'*4 if len(name) < 24 and len(name) >= 20: tabs = '\t'*5 if len(name) < 20 and len(name) >= 16: tabs = '\t'*6 if len(name) < 16 and len(name) >= 12: tabs = '\t'*7 if len(name) < 12: tabs = '\t'*8 line = name + tabs + dtype + '\t' + offset + end text_file.write(line) # define our communication comm = PLC() comm.IPAddress = '192.168.1.10' #comm.ProcessorSlot = 2 # uncomment one of the examples. #ex_read('NewProductID') #ex_readArray('ObjectValue[0]', 10) #ex_multiRead() #ex_write('ThisTag.Thingy', '107') #ex_getPLCTime() #ex_discover() #ex_getTags()
offset = "Offset: " + str(tag.Offset) end = '\n' # some tab space formatting if len(name) >= 36: tabs = '\t' if len(name) < 36 and len(name) >= 32: tabs = '\t' * 2 if len(name) < 32 and len(name) >= 28: tabs = '\t' * 3 if len(name) < 28 and len(name) >= 24: tabs = '\t' * 4 if len(name) < 24 and len(name) >= 20: tabs = '\t' * 5 if len(name) < 20 and len(name) >= 16: tabs = '\t' * 6 if len(name) < 16 and len(name) >= 12: tabs = '\t' * 7 if len(name) < 12: tabs = '\t' * 8 line = name + tabs + dtype + '\t' + offset + end text_file.write(line) # define our communication comm = PLC() comm.IPAddress = '192.168.1.10' #comm.ProcessorSlot = 2 # uncomment one of the examples. #ex_read('NewProductID') #ex_readArray('ObjectValue[0]', 10) #ex_multiRead() #ex_write('ThisTag.Thingy', '107') #ex_getPLCTime() #ex_discover() #ex_getTags()
''' 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)
''' 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)
''' the following import is only necessary because eip is not in this directory ''' import sys sys.path.append('..') ''' The simplest example of reading a tag from a PLC NOTE: You only need to call .Close() after you are done exchanging data with the PLC. If you were going to read in a loop or read more tags, you wouldn't want to call .Close() every time. ''' from eip import PLC comm = PLC() comm.IPAddress = '192.168.1.9' value = comm.Read('CurrentScreen') print(value) comm.Close()
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()
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' Write a little faster by providing the data type up front This only really makes sense to do if you have to write a lot of unique tags. Typically, when you write a tag, it has to fetch the data type first. This only happens the first time you read/write a uniuqe tag name. If you have, for example, 1000 tags to write and they are all unique, you would have have to fetch the data type, then write the value, which is extra 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' comm.Write('Zone1Case', 10, datatype=196)
''' the following import is only necessary because eip.py is not in this directory ''' import sys sys.path.append('..') ''' Get tag list from specific program In this case, I had a program named MiscHMI, this retrives the program scoped tags from just that program NOTE: This actually reads all of the tags from the PLC, it returns only the list of tags from the program you specified. ''' from eip import PLC with PLC() as comm: comm.IPAddress = '192.168.1.9' tags = comm.GetProgramTagList('Program:MiscHMI') for t in tags: print(t.TagName, t.DataType)
''' 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)