Apr-30-2020, 02:32 PM
I have this code that pings a PLC to se if it is online if it is on it will start the PLC file that
corresponds to the IP, it works but when the PLC fiel ends it closes all
instead of going back to the code that validates the IP
whats wront with the code?
but i can show you the SE1_F2 (that is the one that is called if SE1_F2 is not responding)
corresponds to the IP, it works but when the PLC fiel ends it closes all
instead of going back to the code that validates the IP
whats wront with the code?
import subprocess import sys import os hostname = '172.21.12.10' response = os.system("ping " + hostname) if response == 0: print (hostname, 'PLC EN LINEA, INICIANDO REVISION') exec(open("SE1_F1.py").read()) else: print ('SE1_F1 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = ' 192.168.100.5' response = os.system("ping " + hostname) if response == 0: print ('SE1_F2 EN LINEA, INICIANDO REVISION') exec(open("SE1_F2.py").read()) else: print ('SE1_F2 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.13.10' response = os.system("ping " + hostname) if response == 0: print('SE2_R1 EN LINEA, INCIANDO REVISION') exec(open("SE2_R1.py").read()) else: print ('SE2_R1 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.13.12' response = os.system("ping " + hostname) if response == 0: print('SE2_R2 EN LINEA, INCIANDO REVISION') exec(open("SE2_R2.py").read()) else: print ('SE2_R2 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.14.10' response = os.system("ping " + hostname) if response == 0: print('SE3_M1 EN LINEA, INCIANDO REVISION') exec(open("SE3_M1.py").read()) else: print ('SE3_M1 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.14.12' response = os.system("ping " + hostname) if response == 0: print('SE3_M2 EN LINEA, INCIANDO REVISION') exec(open("SE3_M2.py").read()) else: print ('SE3_M2 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.11.10' response = os.system("ping " + hostname) if response == 0: print('SE4_S1 EN LINEA, INCIANDO REVISION') exec(open("SE4_S1.py").read()) else: print ('SE4_S1 FUERA DE LINEA, EJECUTANDO SIGUIENTE SCRIPT') hostname = '172.21.11.11' response = os.system("ping " + hostname) if response == 0: print('SE4_S2 EN LINEA, INCIANDO REVISION') exec(open("SE4_S2.py").read()) else: print("NINGUN PLC EN LINEA")the SE1_F2 is to loong to show it here
but i can show you the SE1_F2 (that is the one that is called if SE1_F2 is not responding)
from pylogix import PLC import sys sys.path.append('..') import time import pandas as pd plc_data = pd.read_excel("Actuadores.xlsx", sheet_name='Result') with PLC() as comm: comm.IPAddress = '172.21.12.12' comm.ProcessorSlot = 0 ret = comm.GetPLCTime() print( "Fecha y Hora de Registro Revision Fallas", ret.Value) time.sleep(1) Estacion = "D2M_150" Estacion2 = "D2R_155" #------------------------------------------------------------------------------------------ ESTACION D2M_150 -------------------------------------------------------------------------------# print("INICIO DE REVISION ESTACION :" , Estacion) #ACTUADOR 1 ACTUADOR = comm.Read('D2M_150.Status.Act._1.WBypassed') ret = comm.GetPLCTime() Numero_Act_EnBypass = 0 if ACTUADOR.Value == True: Sensor = "ACTUADOR 1 WORK SENSOR EN BY PASS" Numero_Act_EnBypass= (Numero_Act_EnBypass+1) temp_dict = {'PLC IP': comm.IPAddress, 'Date Time': ret.Value, 'Estacion': Estacion, 'Tag': ACTUADOR, 'Value': Sensor} plc_data = plc_data.append(temp_dict.copy(), ignore_index=True) plc_data.to_excel("Actuadores.xlsx", sheet_name='Result', index=False) print(Sensor) else: Sensor = "ACTUADOR 1 WORK OK" print(Sensor) ACTUADOR = comm.Read('D2M_150.Status.Act._1.HBypassed') ret = comm.GetPLCTime() if ACTUADOR.Value == True: Sensor = "ACTUADOR 1 HOME SENSOR EN BY PASS" Numero_Act_EnBypass= (Numero_Act_EnBypass+1) temp_dict = {'PLC IP': comm.IPAddress, 'Date Time': ret.Value, 'Estacion': Estacion, 'Tag': ACTUADOR, 'Value': Sensor} plc_data = plc_data.append(temp_dict.copy(), ignore_index=True) plc_data.to_excel("Actuadores.xlsx", sheet_name='Result', index=False) print(Sensor) else: Sensor = "ACTUADOR 1 HOME OK" print(Sensor) #ACTUADOR 2 ACTUADOR = comm.Read('D2M_150.Status.Act._2.WBypassed') ret = comm.GetPLCTime() if ACTUADOR.Value == True: Sensor = "ACTUADOR 2 WORK SENSOR EN BY PASS" Numero_Act_EnBypass= (Numero_Act_EnBypass+1) temp_dict = {'PLC IP': comm.IPAddress, 'Date Time': ret.Value, 'Estacion': Estacion, 'Tag': ACTUADOR, 'Value': Sensor} plc_data = plc_data.append(temp_dict.copy(), ignore_index=True) plc_data.to_excel("Actuadores.xlsx", sheet_name='Result', index=False) print(Sensor) else: Sensor = "ACTUADOR 2 WORK OK" print(Sensor) ACTUADOR = comm.Read('D2M_150.Status.Act._2.HBypassed') ret = comm.GetPLCTime() if ACTUADOR.Value == True: Sensor = "ACTUADOR 2 HOME SENSOR EN BY PASS" Numero_Act_EnBypass= (Numero_Act_EnBypass+1) temp_dict = {'PLC IP': comm.IPAddress, 'Date Time': ret.Value, 'Estacion': Estacion, 'Tag': ACTUADOR, 'Value': Sensor} plc_data = plc_data.append(temp_dict.copy(), ignore_index=True) plc_data.to_excel("Actuadores.xlsx", sheet_name='Result', index=False) print(Sensor) else: Sensor = "ACTUADOR 2 HOME OK" print(Sensor) print("Terminado") print("Actuadores en Bypass:", Numero_Act_EnBypass) comm._closeConnection