Is it possible to disable/enable Gateway Scripts via scripting?
My reason for asking is that I have several Gateway Scripts running on multiple projects, and have witnessed Ignition seize up when the PLC associated with that script is down (via power loss or network loss). I haven’t been able to find the root cause of why this is happening, but I assume that because all the scripts are running on a shared thread, this may be the issue? Ultimately, I’d like to disable a script if a certain PLC is down and re-enable it once OPC reestablishes the connection.
Make sure you aren’t just using the Status tag for the device in the System tag folder… but setup some sort of a rolling number on the PLC side as then use the hasChanged expression to generate a tag that indicates that you are receiving data.
I’d also move all of your tag paths into variables instead of using duplicate magic strings everywhere. It will help to see what tags you’re writing to and change them more easily if necessary
sPLC1 = (system.tag.read('[System]Gateway/Devices/PLC_100_RL02_MF/Status').value)
sPLC2 = (system.tag.read('[System]Gateway/Devices/PLC_100_1_1/Status').value)
sOPC = 'Ignition OPC UA Server'
value = system.opc.readValue(sOPC, 'ns=1;s=[PLC_100_1_1]PLC100_To_Moving_Floor.0')
iCount = system.opc.readValue(sOPC, 'ns=1;s=[PLC_100_RL02_MF]iGTS_MF_to_PLC100')
if (sPLC1 == 'Connected') and (sPLC2 == 'Connected'):
returnQuality = system.opc.writeValue(sOPC, 'ns=1;s=[PLC_100_RL02_MF]PLC100_To_Moving_Floor.0', value.value)
if returnQuality.isGood():
iCount = int(iCount.value + 1)
system.opc.writeValue(sOPC, 'ns=1;s=[PLC_100_RL02_MF]iGTS_MF_to_PLC100', iCount)
else:
print 'PLC_100_1_1 or PLC_100_RL02_MF is Offline'
And I agree with what @nminchin said. Move your tags names to variable.
Also… if any of those PLC’s are based off ControlLogix, then the Status tag might not be accurate for connections. I’m not sure how other PLC’s work. I personally would rather see a rolling number and an expression tag that uses hasChagned to determine if the PLC is up and operating.