Issue with PLC Tag Count Logic – Unexpected Raw Value in Hourly/Daily Counts

Hello,
Currently, I have a setup where I am reading some tag information from the PLC, such as scanner statistics. For each tag, I have a Value Changed script where I count the change in tag value, as shown in the image below:

The HourlyCount is reset every 30 minutes, and the DailyCount is reset every day at 12:00 AM. I use a gateway script to reset these values. Additionally, based on the PLC's local time, the tag values themselves are sometimes reset to 0.

The issue I'm facing is that occasionally, the HourlyCount and DailyCount are taking the raw value of the PLC tag(where Hourly Count is 12345678) instead of calculating the increment between the previous and current values. Normally, the count should increment by 1, as the PLC tag value typically increases by 1.

Is there anything wrong with this logic?

How many tags have this same or similar script?

This is the UDT and is used in many places

You have 4 blocking calls in a value change script. Value change scripts should execute in single digit ms. On top of that, value change scripts execute in limited thread pool of 3 for all change events across the gateway.

It wouldn’t surprise me if you’re running into the queue limit.

This script should probably be a gateway tag change event, that is generic enough to handle any UDT with the proper structure.

At a minimum you should combine the reads and writes into single calls.

1 Like

This might not be the answer you're looking for, but stuff like this should really be done in the PLC. Way simpler to keep the logic in the PLC with a totalizer

1 Like