Hello community, I need help resolving a bug in Perspective Gateway Events and Python Scripting associated with it.
I’m running on of the following:
Ignition Platform: 8.1.15
OPC-UA Module: 9.1.15
SQL Bridge Module: 10.1.15
MQTT Engine Module: 4.0.7
MQTT Transmission Module: 4.0.7
Vision Module: 11.1.15
Perspective Module: 2.1.15
Logix Driver: 5.1.15
Java Version: Azul Systems Inc. 11.0.14.1
Operating System: Linux | amd64
Work Environment: Grain Processing Facility
Objective: When an Operator is operating an wireless remote controller to control machinery that utilizes over +100 Status Inputs and “17” Command Outputs, I want to use the Perspective “Gateway Event Scripts” with the “Tag Change” handler to run a Python Script. This Python Script will evaluate over +100 Status Inputs when the “17” Command Output Tags are triggered. Inside the Script consists “Definition” functions that run sub-routines with Multi-threading and Time Libraries to merge back together in the Main Routine.
This script as said will evaluate Inputs and Outputs and when there is a Fault it the machinery/operation, it’ll notify you on the Client display an error/status message that is written to a writable Tag. So each time the operator puts in a command, it’ll run the script rather than constantly and evaluate all conditions and will display them. That is why I’m using Gateway Event Scripts and due to the Gateway Event Scripts Bug, I have my program running in the Project Library rather the Event Script.
Please note, due to a bug in the Gateway Event Scripts, “Variables defined in the outermost scope can not be seen by functions…” - (Gateway Event Scripts Bug). Therefore the Python Script is written and run inside the Project Library and that code is called inside the Gateway Event Script Tag Change Handler.
I’ve ran the code like a simulator in the “Script Console” and it runs without problem. I’ve monitored the “TagChangeScriptExecutor” in the “Log Activity” of the “Gateway Scripts” on the Gateway browser. Status of it has been Successful and run time duration is approx.: 1.214 seconds.
Samples will be provided below.
Gateway Event Scripts (Tag Change) - Tags: 1 of 17 is shown and all has been verified
[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InSelected
Gateway Event Scripts (Tag Change) - Script:
CTower_Troubleshooter2.MainProgram() //#Call Function to Run Project Library Script
Project Library Script (CTower_Troubleshooter2) - Script:
*Note: This is only samples. I know the code isn’t the most clean and effecient, I’m still a begginer who is open to new and better methods and such
#Import Libraries
import threading
import time
#Swing Input Command Tags
SwingIn = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InSelected").value
SwingOut = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutSelected").value
#Swing Input Status Tags
SwingInBoard = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InBoard").value
SwingInInt2 = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InInternal2").value
SwingInOutput = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InOutput").value
SwingInPermissive = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/InPermissive").value
SwingLowPressure = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/LowPressure").value
SwingNotInBoard = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/NotInBoard").value
SwingNotOutBoard = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/NotOutBoard").value
SwingOutBoard = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutBoard").value
SwingOutInt1 = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutInternal1").value
SwingOutInt2 = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutInternal2").value
SwingOutOutput = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutOutput").value
SwingOutPermissive = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/OutPermissive").value
SwingSlackRopeISH = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SlackRopeISH").value
SwingSlackRopeOSH = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SlackRopeOSH").value
SwingAngle = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingAngle").value
SwingBrakeReleased = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingBrakeReleased").value
SwingInBoomAngleLimit = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingInBoomAngleLimit").value
SwingInChuteAngleLimit = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingInChuteAngleLimit").value
SwingOutChuteAngleLimit = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingOutChuteAngleLimit").value
SwingPumpInAuto = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingPumpInAuto").value
SwingPumpInLocal = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingPumpInLocal").value
SwingPumpLowOil = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingPumpLowOil").value
SwingPumpRunning = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingPumpRunning").value
SwingSwash = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/SwingSwash").value
SwingZZ1P_Breaker = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ1P_Breaker").value
SwingZZ1P_Output = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ1P_Output").value
SwingZZ1Q_Breaker = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ1Q_Breaker").value
SwingZZ1Q_Output = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ1Q_Output").value
SwingZZ2_Breaker = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2_Breaker").value
SwingZZ2_Output = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2_Output").value
SwingZZ2P_Breaker = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2P_Breaker").value
SwingZZ2P_Output = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2P_Output").value
SwingZZ2Q_Breaker = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2Q_Breaker").value
SwingZZ2Q_Output = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/Swing/ZZ2Q_Output").value
#Swing In Sub-Routine
def SwingIn_Rtn(): #SWING IN COMMAND
time.sleep(0.4)
if SwingPumpRunning == True:
if (SwingPumpInAuto == True) and (SwingPumpInLocal == False): #Check that the Swing Pump is Running in Auto for Luff Operation
if (SwingIn == True) and (SwingSwash == 0): #Command to Lower is TRUE, but there is no Output to the Swash Plate of the Hydraulics
if SwingBrakeReleased == True:
if SwingInPermissive == True:
if (SwingSlackRopeISH == False) and (SwingSlackRopeOSH == False): #Check for Fault
if SwingInInt2 == True:
if (SwingInBoomAngleLimit == False) and (SwingInChuteAngleLimit == False):
if ((SwingZZ1P_Breaker == False) and (SwingZZ1P_Output == True) and (SwingOutBoard == True)) or ((SwingZZ1Q_Breaker == False) and (SwingZZ1Q_Output == True) and (SwingZZ2Q_Breaker == False) and (SwingZZ2Q_Output == True) and (SwingInBoard == True)):
print("No Faults in PLC. Check Mechincal (SwingIn_Rtn()")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "No Faults in PLC. Check Mechincal")
elif (SwingZZ1P_Breaker == True) and (SwingZZ1P_Output == True) and (SwingOutBoard == True):
print("Swing In ZZ1P Breaker is Tripped")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In ZZ1P Breaker is Tripped")
elif (SwingZZ1Q_Breaker == True) and (SwingZZ1Q_Output == True) and (SwingInBoard == True):
print("Swing In ZZ1Q Breaker is Tripped")
elif (SwingZZ2Q_Breaker == True) and (SwingZZ2Q_Output == True) and (SwingInBoard == True):
print("Swing In ZZ2Q Breaker is Tripped")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In ZZ2Q Breaker is Tripped")
elif (SwingInBoomAngleLimit == True) and (SwingInBoard == True):
print("Swing In Boom Angle is met at 14 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Boom Angle is met at 14 Degrees")
elif (SwingInChuteAngleLimit == True) and (SwingInBoard == True):
print("Swing In Chute Angle is met at 45 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Chute Angle is met at 45 Degrees")
else:
if (SwingInBoomAngleLimit == True) and (SwingInBoard == True):
print("Swing In Boom Angle is met at 14 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Boom Angle is met at 14 Degrees")
elif (SwingInChuteAngleLimit == True) and (SwingInBoard == True):
print("Swing In Chute Angle is met at 45 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Chute Angle is met at 45 Degrees")
elif (SwingSlackRopeISH == True) or (SwingSlackRopeOSH == True):
if SwingSlackRopeISH == True:
print("Swing In Slack Rope ISH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope ISH is currently Active")
elif SwingSlackRopeOSH == True:
print("Swing In Slack Rope OSH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope OSH is currently Active")
elif (SwingSlackRopeISH == True) and (SwingSlackRopeOSH == True):
print("Both Swing In Slack Rope ISH and OSH are currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Both Swing In Slack Rope ISH and OSH are currently Active")
else:
if SwingInInt2 == False:
if (SwingInBoomAngleLimit == True) and (SwingInBoard == True):
print("Swing In Boom Angle is met at 14 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Boom Angle is met at 14 Degrees")
elif (SwingInChuteAngleLimit == True) and (SwingInBoard == True):
print("Swing In Chute Angle is met at 45 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Chute Angle is met at 45 Degrees")
elif (SwingSlackRopeISH == True) or (SwingSlackRopeOSH == True):
if SwingSlackRopeISH == True:
print("Swing In Slack Rope ISH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope ISH is currently Active")
elif SwingSlackRopeOSH == True:
print("Swing In Slack Rope OSH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope OSH is currently Active")
elif (SwingSlackRopeISH == True) and (SwingSlackRopeOSH == True):
print("Both Swing In Slack Rope ISH and OSH are currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Both Swing In Slack Rope ISH and OSH are currently Active")
elif SwingBrakeReleased == False:
if SwingInPermissive == False:
if SwingInInt2 == False:
if (SwingInBoomAngleLimit == True) and (SwingInBoard == True):
print("Swing In Boom Angle is met at 14 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Boom Angle is met at 14 Degrees")
elif (SwingInChuteAngleLimit == True) and (SwingInBoard == True):
print("Swing In Chute Angle is met at 45 Degrees")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Chute Angle is met at 45 Degrees")
elif (SwingSlackRopeISH == True) or (SwingSlackRopeOSH == True):
if SwingSlackRopeISH == True:
print("Swing In Slack Rope ISH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope ISH is currently Active")
elif SwingSlackRopeOSH == True:
print("Swing In Slack Rope OSH is currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In Slack Rope OSH is currently Active")
elif (SwingSlackRopeISH == True) and (SwingSlackRopeOSH == True):
print("Both Swing In Slack Rope ISH and OSH are currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Both Swing In Slack Rope ISH and OSH are currently Active")
elif (SwingIn == True) and (SwingSwash > 0): #Command to Lower is TRUE and the Output is Active
print("Swing In has No Command Fault Present")
#system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing In has No Command Fault Present")
system.tag.writeBlocking(["[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus"], "Swing In has No Command Fault Present")
elif (SwingIn == False) and (SwingSwash == 0):
print("No Command to Swing In")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "No Command to Swing In")
elif (SwingPumpRunning == True) and (SwingPumpInAuto == False) and (SwingPumpInLocal == True):
print("Swing Pump is Running in Local")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump is Running in Local")
elif (SwingPumpRunning == False) and (SwingPumpInAuto == False) and (SwingPumpInLocal == True):
print("Swing Pump is not Running and is in Local")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump is not Running and is in Local")
elif (SwingPumpRunning == False) and (SwingPumpInAuto == False) and (SwingPumpInLocal == False):
print("Swing Pump is not Running and is in the Off Position")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump is not Running and is in the Off Position")
elif (SwingPumpRunning == False) and (SwingPumpInAuto == True) and (SwingPumpInLocal == False):
print("Swing Pump is not Running")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump is not Running")
elif SwingPumpRunning != True:
if SwingPumpLowOil == True:
print("Swing Pump has a Low Oil Fault")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump has a Low Oil Fault") #WRITE to Swing In Status
else:
print("Swing Pump is not Running")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Swing Pump is not Running") #WRITE to Swing In Status
###################### MAIN PROGRAM ##############################
def MainProgram():
###### Multi-Threading ######
if CircPumpRunning != True: #Check if the Circulating Pumps are Running
if Estop == True:
print("Estop is Currently Active")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Estop is Currently Active")
##SORRY, I CAN'T FIX THIS IN THIS POST ^^
elif HighTemp == True:
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Circulating Hydraulic Pump is High Temperature")
elif LowOil == True:
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Circulating Hydraulic Pump has Low Oil")
elif CircPumpLowOilTemp == True:
print("Circulating Hydraulic Pump has Low Oil Temperature")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Circulating Hydraulic Pump has Low Oil Temperature")
else:
print("Circulating Hydraulic Pump is not Running")
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/SwingInStatus", "Circulating Hydraulic Pump is not Running")
else:
SwingIn_Thread = threading.Thread(target = SwingIn_Rtn, args = ())
SwingIn_Thread.start()
############# Rejoining Seperate Threads to the Main Thread ############
SwingIn_Thread.join()
############### Counter to verify script is running ##############
RunScriptCounter = system.tag.read("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/RunScriptCounter").value
print("Run Script: " + str(RunScript))
RunScriptCounter += 1
system.tag.writeBlocking("[Tech Tag Provider]Shipping/Dock/TowerC/TroubleShooter/RunScriptCounter", [RunScriptCounter])
if RunScriptCounter > 50:
Sorry about some indentation in the script above, it wouldn’t let me to use tab and it got ugly.
So I’ve tested this code many times and works great, but when running it on the Client Gateway, it doesn’t update unless I press saved while the operator is putting a command in to trigger the Gateway Event Script.
Any help, would greatly be appreciated, thank you!