# Programmatically enable/disable device connection

**URL:** <https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031>\
**Category:** Ignition\
**Created:** [September 12, 2023, 5:14pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031 "2023-09-12T17:14:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dick.willis](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@dick.willis](https://forum.inductiveautomation.com/u/dick.willis)\
**Post date:** [September 12, 2023, 5:14pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/1 "2023-09-12T17:14:56Z")

</div>

I have a similar need (not the same root cause, though). We have OMRON sensors that communicate with Ignition over TCP. Every few days, "something" glitches and they stop sending. The workaround is to Disable/Save and then Enable/Save those connections.

We have added a tag to detect the glitch (there is a timestamp embedded in the data packet from the sensor, so when that timestamp is stale, it means the device has stopped sending). When that tag reaches 2 minutes, we'll send out an alarm to an Ignition Admin.

But ... what we'd rather do is have that event trigger a script that would programmatically disable and enable the Device Connection.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 12, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/2 "2023-09-12T17:26:07Z")

</div>

Try this: [system.device.setDeviceEnabled - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.device.setDeviceEnabled)

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [September 12, 2023, 5:33pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/3 "2023-09-12T17:33:05Z")

</div>

I think we use [system.device.restart - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.device.restart) for a similar purpose.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 12, 2023, 5:39pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/4 "2023-09-12T17:39:26Z")

</div>

🤯

I must have been on vacation or something when that got added.

---

<div class="post-metadata">

**Author:** ![dick.willis](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@dick.willis](https://forum.inductiveautomation.com/u/dick.willis)\
**Post date:** [September 12, 2023, 5:41pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/5 "2023-09-12T17:41:47Z")

</div>

I'll try it

---

<div class="post-metadata">

**Author:** ![dick.willis](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@dick.willis](https://forum.inductiveautomation.com/u/dick.willis)\
**Post date:** [September 12, 2023, 6:29pm UTC](https://forum.inductiveautomation.com/t/programmatically-enable-disable-device-connection/79031/6 "2023-09-12T18:29:31Z")

</div>

Anybody got a good approach for parsing out a DeviceName from a tag's OPCItemPath? Looks like it is delimited with square-brackets ... I'll try something based on that definition.

nm: [Split Regex expression to get tag OPCItemPath 'Device' name - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/split-regex-expression-to-get-tag-opcitempath-device-name/16425)
