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 closepop(self): global clx global ismicro global firstrun firstrun = True if ipset: clx = PLC(ip, 2) if ismicro: App.get_running_app( ).root.ids.iplabel.text = 'Connected ' + ip + ' Micro800' else: App.get_running_app( ).root.ids.iplabel.text = 'Connected ' + ip + ' Logix' clx.Micro800 = ismicro print(ismicro) Clock.schedule_interval(update, 0.25) else: print('Nop')
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 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))
comm.IPAddress = controller_ip comm.ProcessorSlot = controller_slot if ping(controller_ip) is None: check_error_log = True print("PLC unreachable, check IP or network settings!") input("Program will exit now. Press Enter") log.write( "Error: %s PLC unreachable, check IP or network settings!\n" % (now.strftime("%c"))) log.flush() sys.exit() is_micro800 = yes_or_no("Is this a Micro8xx PLC?") comm.Micro800 = is_micro800 # discover devices devices = comm.Discover() for device in devices.Value: print(device.IPAddress) print(' Product Code: ' + device.ProductName + ' ' + str(device.ProductCode)) print(' Vendor/Device ID:' + device.Vendor + ' ' + str(device.DeviceID)) print(' Revision/Serial:' + device.Revision + ' ' + device.SerialNumber) print('') # get plc time for clx, and compact