Disabling Gateway Timer Scripts via Script Method

Hello Everyone,

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.

Does anyone have any thoughts?

Have the script check a connection status value prior to running the script.

2 Likes

Thanks for the input.
I will give this a try and see how it works out!

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.

Thanks for the help.
I came up with the following. Not really sure if I need the try/except…

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')

try:
	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)
except:
	print 'PLC_100_1_1 or PLC_100_RL02_MF is Offline'

So the try/except will only catch a python or java error.

Use an else on the first if statemen rather than the except.

If you edit your post and slap that code in the </> formatting block I can show you what I mean.

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

OK… this is what I mean with no try/except

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.