# Check Device Connection Status Via Scripting

**URL:** <https://forum.inductiveautomation.com/t/check-device-connection-status-via-scripting/34169>\
**Category:** General Discussion\
**Created:** [April 23, 2020, 6:00pm UTC](https://forum.inductiveautomation.com/t/check-device-connection-status-via-scripting/34169 "2020-04-23T18:00:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClemsonTim80](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@ClemsonTim80](https://forum.inductiveautomation.com/u/ClemsonTim80)\
**Post date:** [April 23, 2020, 6:00pm UTC](https://forum.inductiveautomation.com/t/check-device-connection-status-via-scripting/34169/1 "2020-04-23T18:00:09Z")

</div>

Unusual application where I am retrieving all PLC values from multiple PLCs using scripting and system.opc.readValues() rather than setting up individual OPC tags due to dynamic polling rates. Is there any way to check an individual device connection Status=Connected before calling syste.opc.readValues() in order to skip devices that are subject to being powered off at any given time ? All connections are A-B devices (CompactLogix and MicroLogix) using Ignition OPC-UA Server.

Ignition 8.0.12

Thanks In Advance

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 23, 2020, 7:38pm UTC](https://forum.inductiveautomation.com/t/check-device-connection-status-via-scripting/34169/2 "2020-04-23T19:38:07Z")

</div>

One way: [system.device.listDevices()](https://docs.inductiveautomation.com/display/DOC80/system.device.listDevices)

Another path:

```auto
[System]Gateway/Devices/DeviceName/Status

```

Third way (and best, IMO): use a heartbeat.

> [@How to detect PLC failure](http://forum.inductiveautomation.com/t/how-to-detect-plc-failure/25631/7):
>
> Hi All, Thanks for the reply. I am using a bit of code in PLC to go 1,0 every sec when the PLC is healthy. . Then I am using an expression tag with the following expression - if(hasChanged({[.]PLC\_Heartbeat}),1,0) This tag is set as an alarm to flag up when the heartbeat is not healthy and I have set it to a ‘clock’ scan class. I have tested it and this seems to be working fine with following errors - Any minor/major PLC faults. PLC network/comms error. Connecti…

---

<div class="post-metadata">

**Author:** ![ClemsonTim80](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@ClemsonTim80](https://forum.inductiveautomation.com/u/ClemsonTim80)\
**Post date:** [April 23, 2020, 8:01pm UTC](https://forum.inductiveautomation.com/t/check-device-connection-status-via-scripting/34169/3 "2020-04-23T20:01:08Z")

</div>

Thanks Jordan - In my haste to try to correct the issue onsite I saw the system.device.listDevices() but incorrectly assumed that is merely provided a list of the devices and neglected to dive deeper to see that it also returns the dataset including device status.

BTW - I am using a heartbeat bit at the PLC level to not only determine that Comms are OK but also that the PLC logic is actively running - but I can’t check it until I complete the system.opc.ReadItems()

Much appreciated …
