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 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 SeqResume(): comm = PLC() comm.IPAddress = '169.254.215.82' comm.Write('SEQResume', False) time.sleep(.3) comm.Write('SEQResume', True) comm.Close() return
def PauseSEQ(): comm = PLC() comm.IPAddress = '169.254.215.82' comm.Write('SEQPause', True) time.sleep(.25) comm.Write('SEQPause', False) comm.Close() return
def StartSEQ(): comm = PLC() comm.IPAddress = '169.254.215.82' comm.Write('StartSeq', True) time.sleep(.3) comm.Write('StartSeq', False) comm.Close() return
def MasterOn(): comm = PLC() comm.IPAddress = '169.254.215.82' comm.Write('MasterStart', True) time.sleep(.25) comm.Write('MasterStart', False) comm.Close() return
def Emergency(): comm = PLC() comm.IPAddress = '169.254.215.82' comm.Write('EmergencyPB', False) time.sleep(.250) comm.Write('EmergencyPB', True) comm.Close() return
def comm_check(): global comm global updateRunning global connected global connectionInProgress try: connectionInProgress = True ip = selectedIPAddress.get() port = int(selectedProcessorSlot.get()) if (not connected or comm.IPAddress != ip or comm.ProcessorSlot != port or changePLC.get() == 1): if not comm is None: comm.Close() comm = None comm = PLC() comm.IPAddress = ip if checkVarMicro800.get() == 0: comm.ProcessorSlot = port comm.Micro800 = False else: comm.Micro800 = True plcTime = comm.GetPLCTime() lbConnectionMessage.delete(0, 'end') lbErrorMessage.delete(0, 'end') if plcTime.Value is None: if btnStop['state'] == 'disabled': btnStart['state'] = 'disabled' btnStart['bg'] = 'lightgrey' lbConnectionMessage.insert(1, ' Not Connected') lbErrorMessage.insert(1, ' ' + plcTime.Status) connected = False root.after(5000, start_connection) else: lbConnectionMessage.insert(1, ' Connected') if not updateRunning: updateRunning = True connected = True connectionInProgress = False if btnStop['state'] == 'disabled': btnStart['state'] = 'normal' btnStart['bg'] = 'lightgreen' else: start_update() changePLC.set(0) except Exception as e: if app_closing: pass else: print(str(e))
def WriteSEQCount(): comm = PLC() comm.IPAddress = '169.254.215.82' seqcount = entry1.get() seqcount = int(seqcount) comm.Write('SEQCount', seqcount) time.sleep(.22) comm.Close() return
def comm_check(): global comm ip = selectedIPAddress.get() port = int(selectedProcessorSlot.get()) if (comm.IPAddress != ip or comm.ProcessorSlot != port): comm.Close() comm = None comm = PLC() comm.IPAddress = ip comm.ProcessorSlot = port
def getTags(): try: lbTags.delete(0, 'end') commGT = PLC() commGT.IPAddress = selectedIPAddress.get() if checkVarMicro800.get() == 0: commGT.ProcessorSlot = int(selectedProcessorSlot.get()) tags = commGT.GetTagList() if not tags is None: if not tags.Value is None: # save tags to a file if checkVarSaveTags.get() == 1: with open('tags_list.txt', 'w') as f: for t in tags.Value: if t.DataType == '': f.write(t.TagName + '\n') else: f.write(t.TagName + ' (DataType - ' + t.DataType + ')\n') for t in tags.Value: j = 1 if t.DataType == '': lbTags.insert(j, t.TagName) else: lbTags.insert(j, t.TagName + ' (DataType - ' + t.DataType + ')') j = j + 1 else: lbTags.insert(1, 'No Tags Retrieved') else: lbTags.insert(1, 'No Tags Retrieved') commGT.Close() commGT = None except Exception as e: if not commGT is None: commGT.Close() commGT = None if app_closing: pass else: print(str(e))
def ReadSEQCount(): comm = PLC() comm.IPAddress = '169.254.215.82' valueseqcount = comm.Read('SEQCount') lbl6 = Label(window, text="Sequence Count", bg="white", fg="Black", bd=2, relief="solid", width=15, height=2) lbl6.place(x=540, y=180) lbl7 = Label(window, text=valueseqcount, bg="Black", fg="lime", bd=3, relief="raised", width=15, height=5) lbl7.place(x=540, y=220) window.after(550, ReadSEQCount) return
def ReadOutWord(): comm = PLC() comm.IPAddress = '169.254.215.82' value = comm.Read('OutWord') lbl3 = Label(window, text="OutWord|Value", bg="white", fg="Black", bd=2, relief="solid", width=15, height=2) lbl3.place(x=410, y=20) lbl4 = Label(window, text=value, bg="Black", fg="lime", bd=3, relief="raised", width=15, height=5) lbl4.place(x=410, y=60) window.after(550, ReadOutWord) return
''' 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 pylogix import PLC with PLC() as comm: comm = PLC() comm.IPAddress = '192.168.1.9' value = comm.Read('CurrentScreen', datatype=196) print(value)
def ReadConditions(): comm = PLC() comm.IPAddress = '169.254.215.82' ECR = comm.Read('indicate.0') #!Estop Control Relay PLC MCR = comm.Read('indicate.1') #Master Control Relay PLC SCR = comm.Read('indicate.2') #!Sequence Control Relay PLC SSR = comm.Read('indicate.3') #Sequence Stop Relay PLC SPR = comm.Read('indicate.4') #Sequence Pause Relay PLC SRR = comm.Read('indicate.5') #Sequence Resume Relay PLC window.after(2000, ReadConditions) if ECR == True: lbl18 = Label(window, text="EStop On", fg="yellow", bg="red", bd=2, relief="raised", width=12, height=2) lbl18.place(x=31, y=150) elif ECR == False: lbl18 = Label(window, text="No_EStop", fg="red", bg="yellow", bd=2, relief="flat", width=12, height=2) lbl18.place(x=31, y=150) if MCR == True: lbl19 = Label(window, text="Master On", fg="White", bg="Firebrick4", bd=2, relief="raised", width=12, height=2) lbl19.place(x=161, y=150) elif MCR == False: lbl19 = Label(window, text="Master Off", fg="Firebrick4", bg="white", bd=2, relief="flat", width=12, height=2) lbl19.place(x=161, y=150) if SCR == True: lbl20 = Label(window, text="Seq On", fg="White", bg="Green", bd=2, relief="raised", width=12, height=2) lbl20.place(x=291, y=400) elif SCR == False: lbl20 = Label(window, text="Seq Off", fg="Green", bg="white", bd=2, relief="flat", width=12, height=2) lbl20.place(x=291, y=400) if SSR == True: lbl21 = Label(window, text="Seq Off", fg="White", bg="Red", bd=2, relief="raised", width=12, height=2) lbl21.place(x=291, y=440) elif SSR == False: lbl21 = Label(window, text="Seq On", fg="Red", bg="white", bd=2, relief="flat", width=12, height=2) lbl21.place(x=291, y=440) if SPR == True: lbl22 = Label(window, text="Paused", fg="White", bg="Navy", bd=2, relief="raised", width=12, height=2) lbl22.place(x=291, y=480) elif SPR == False: lbl22 = Label(window, text="Resumed", fg="Navy", bg="White", bd=2, relief="flat", width=12, height=2) lbl22.place(x=291, y=480) if SRR == True: lbl23 = Label(window, text="Resumed", fg="White", bg="Olive Drab", bd=2, relief="raised", width=12, height=2) lbl23.place(x=291, y=520) elif SRR == False: lbl23 = Label(window, text="Paused", fg="Olive Drab", bg="White", bd=2, relief="flat", width=12, height=2) lbl23.place(x=291, y=520) return
''' 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 pylogix 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 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 pylogix import PLC comm = PLC() comm.IPAddress = '192.168.111.249' comm.ProcessorSlot = 3 value = comm.Read('Dest_IP') print(value) comm.Close()
/ /_/ / ____/ /_/ / /_____/_/ \____/ """ print(ascii_art) print("Data Preserve Utility " + CODE_VERSION) print("Author: Fernando ***REMOVED***") print("Source: " + "https://github.com/TheFern2/Data_Preserve") if __name__ == '__main__': config = configparser.ConfigParser() config.read('Settings.ini') main_controller_ip = config['Settings']['PLC_IP'] comm.IPAddress = main_controller_ip comm.ProcessorSlot = int(config['Settings']['PLC_SLOT']) dp_save_remote_path = config['Settings']['Remote_Save_Path'] dp_save_local_path = config['Settings']['Local_Save_Path'] file_extension = config['Settings']['Files_Extension'] # load remote file names from ini for key in config['Remote_Files']: remote_files.append(config['Remote_Files'][key]) # load local file names from ini for key in config['Local_Files']: local_files.append(config['Local_Files'][key]) for key in config['Folder_Copy_On_Load']: paths_on_load.append(config['Folder_Copy_On_Load'][key])
def plc_init(request): client = PLC() client.Micro800 = config.get('plc', 'micro800') or False client.IPAddress = request.get('url', '') return client
from pylogix import PLC from ping3 import ping import sys import time def read_tag(tag): return comm.Read(tag) # Setup the PLC object with initial parameters comm = PLC() controller_ip = '192.168.176.1' # Change to your plc ip address controller_slot = 1 # Change to your plc slot number, Only do this if slot is not 0 comm.IPAddress = controller_ip comm.ProcessorSlot = controller_slot # ensure plc is pingable, else exit the program if ping(controller_ip) is None: print("Controller unreachable, check pc ip settings") sys.exit() # try to read a tag, else print error try: while True: value = read_tag('bool_01') time.sleep(1) # Change seconds here print(value) # Do Ctrl + C to interrupt process except NameError as e: print(e) except ValueError as e:
from pylogix import PLC from datetime import datetime import pandas as pd import time comm1 = PLC() comm1.Micro800 = True comm1.IPAddress = '192.168.0.119' comm2 = PLC() comm2.Micro800 = True comm2.IPAddress = '192.168.0.113' comm3 = PLC() comm3.Micro800 = True comm3.IPAddress = '192.168.0.116' dataframe1 = '' FirstTime = True # ========================================================== READ FROM PLC & WRITE TO DB ========================================================== loop_PLC = True fileName = 'Node06' data0 = 'Timestamp,S1, S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S21,S22,S23,S24,S25,S26,S27,S28,S29,S30,S31,S32,S33,S34,S35,S41,S42,S43,S44,S45,S46,S47,S48,S49,S50,S51,S52,S53,S54,S55\n' # open the file as write mode # data = ''.join(data2) # data = ''.join(map(str, data0))