# Disabling Gateway Timer Scripts via Script Method

**URL:** <https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 23, 2022, 5:10pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918 "2022-05-23T17:10:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [May 23, 2022, 5:10pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/1 "2022-05-23T17:10:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [May 23, 2022, 5:15pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/2 "2022-05-23T17:15:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [May 23, 2022, 5:38pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/4 "2022-05-23T17:38:24Z")

</div>

> [@regan.lewis](#):
>
> Thanks for the input.  
> I will give this a try and see how it works out!

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

> [@bschroeder](#):
>
> Have the script check a connection status value prior to running the script.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [May 23, 2022, 5:40pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/5 "2022-05-23T17:40:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [May 24, 2022, 6:13pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/6 "2022-05-24T18:13:07Z")

</div>

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

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [May 24, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/7 "2022-05-24T18:19:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 24, 2022, 8:00pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/8 "2022-05-24T20:00:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [May 24, 2022, 8:08pm UTC](https://forum.inductiveautomation.com/t/disabling-gateway-timer-scripts-via-script-method/59918/9 "2022-05-24T20:08:13Z")

</div>

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

```auto
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.
