# PLC/MES Heartbeat issue with Mitsubishi Q-Series PLCs

**URL:** <https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 8, 2024, 7:35pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379 "2024-08-08T19:35:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [August 8, 2024, 7:35pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/1 "2024-08-08T19:35:31Z")

</div>

Hello,

I'm seeing some strange behavior at the plant with our Mitsubishi Q-series PLCs. There are two heartbeat tags on the PLC - MES\_HEARTBEAT, and PLC\_HEARTBEAT.

PLC\_HEARTBEAT is a boolean that is written to (by the PLC) every second with true and false, alternating. I have a gateway tag change script configured for every PLC\_HEARTBEAT tag.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c5b9ca8e3f13ad741376c990859ee6f9691b425.png)

I write either 1 or 0 to the MES\_HEARTBEAT tag depending on its current value. The PLC monitors the amount of time between the last change in the MES\_HEARTBEAT tag, and resets the connection between itself and the Ignition gateway if 30 seconds have passed between a change in the tag value.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/d/ade7305be5109952c2ab9cd34f85bc232561e3bb.png)

My issue is that I'm seeing MES\_HEARTBEAT stay on for an abnormally long amount of time, when it should change at the same rate as the PLC\_HEARTBEAT.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e11b1cb36bffaeb30bb8e053c8a8e73b755cc677.png)

The tag group that these MES and PLC heartbeat tags belong to is set to subscribed, with a polling rate of 1000ms.

I'd appreciate any help - thanks.

---

<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:** [August 8, 2024, 7:45pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/2 "2024-08-08T19:45:39Z")

</div>

Can you change your script to use `system.opc.writeValue` instead of `system.tag.writeBlocking`?

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [August 8, 2024, 7:50pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/3 "2024-08-08T19:50:49Z")

</div>

Why not just directly write the value of the PLC Heartbeat tag to the MES\_Heartbeat tag? This way if either reads or writes gets stalled/hung the PLC should catch it. This would also simplify this significantly.

---

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [August 8, 2024, 7:59pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/4 "2024-08-08T19:59:44Z")

</div>

I've just changed my script to the following, and it's already looking better:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/929cf10c98f945bb433a6363c4741b2ed593d620.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba90a32c5b9f5459fe1d9cdabe85cff3f281759a.png)

Thanks!

Is there a rule of thumb for when to use system.opc.writeValue rather than the other write functions?

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [August 8, 2024, 8:03pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/5 "2024-08-08T20:03:38Z")

</div>

In the future, post your scripts as preformatted text as it makes it easier for us to help, but this is how I would go about it (inside your try block):

```python
tagPath = str(event.getTagPath()).replace('PLC', 'MES')
system.tag.writeAsync([tagPath], [currentValue.value])

```

If "PLC" is in your tag paths besides the heartbeat tag, use the following instead:

```python
tagPath = str(event.getTagPath()).replace('PLC_HEARTBEAT', 'MES_HEARTBEAT')
system.tag.writeAsync([tagPath], [currentValue.value])

```

---

<div class="post-metadata">

**Author:** ![Chris\_Nathan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_nathan/32/45712_2.png) [@Chris\_Nathan](https://forum.inductiveautomation.com/u/Chris_Nathan)\
**Post date:** [August 8, 2024, 8:29pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/6 "2024-08-08T20:29:55Z")

</div>

Its not clear to me why that would fix his issue. Does the write operation really take that long such that he shouldn't use .WriteBlocking? That would surprise me.

---

<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:** [August 8, 2024, 8:34pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/7 "2024-08-08T20:34:23Z")

</div>

The tag system attempts to batch writes to OPC tags together, and those batches get executed in order, one at a time. I assume he has multiple PLC and tag change scripts all trying to execute more or less at the same time, but these writes from different threads can't be batched together. So all these heartbeat writes are just waiting in line behind other writes.

I've seen this countless times. Heartbeat scripts should always bypass the tag system and use `system.opc.write*` and not `system.tag.write*`.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [August 8, 2024, 8:35pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/8 "2024-08-08T20:35:52Z")

</div>

Good to know! I'm assuming this depends a lot on how loaded the comms are, but forcing direct PLC writes would make sense. Do they essentially bypass the queue and "skip the line".

---

<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:** [August 8, 2024, 8:36pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/9 "2024-08-08T20:36:34Z")

</div>

> [@michael.flagler](#):
>
> Do they essentially bypass the queue and "skip the line".

Yes, that's exactly what's happening. There's no queue or concurrency constraints for `system.opc` calls (because there's no batching attemped). They just go directly against the OPC connection, immediately.

---

<div class="post-metadata">

**Author:** ![Chris\_Nathan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_nathan/32/45712_2.png) [@Chris\_Nathan](https://forum.inductiveautomation.com/u/Chris_Nathan)\
**Post date:** [August 8, 2024, 9:15pm UTC](https://forum.inductiveautomation.com/t/plc-mes-heartbeat-issue-with-mitsubishi-q-series-plcs/94379/10 "2024-08-08T21:15:51Z")

</div>

Awesome!! Super helpful Kevin thank you. I also missed the distinction between `system.opc.write*` and `system.tag.write*`
