Record and Reset the tag values every hour via transaction group

Hi team,

I need to record a list of tags every hour at times like 1:30, 2:30, 3:30, etc. During a shift, there will be 8 records.

For example:

  • Tag: ProductionStartDateTime - 30-05-2024 11:30 (expression tag)
  • ProductionEndDateTime - current time

I want to record the tag values via a transaction group and then reset the tag. The trigger for this transaction is a boolean tag, which will be enabled when the time crosses every hour, e.g., 30-05-2024 12:30.

Initially, I set the expression tag as follows

if ({[~]Global Tags/Current Minute} = 30 && {[~]Global Tags/Current Second} = 0, 1, 0)

However, some recorded tag values were null because they were reset after the hour. I then modified the expression to:

if ({[~]Global Tags/Current Minute} = 29 && {[~]Global Tags/Current Second} > 50, 1, 0)

But the same issue occurred. Finally, I changed it to:

if ({[~]Global Tags/Current Minute} = 29 && {[~]Global Tags/Current Second} > 45, 1, 0)

This worked fine, but the recorded times are not exactly one hour apart. For example:

  • ProductionStartDateTime - 30-05-2024 11:30:00
  • ProductionEndDateTime - 30-05-2024 12:29:47

The runtime is not exactly one hour, and when I check the total runtime for the shift, it is 478 minutes instead of 480 minutes because of this issue.

Any ideas on how to overcome this?

This sounds like a job for a Gateway Event Script.
Set it up for (30 * * * *) to have a script run at half-past the hour.

The real problem is that you have created a race condition. If you are recording process or machine counters then I would recommend never resetting them and recording ever-increasing numbers. It makes it very easy to calculate the difference in value between any two timestamps and also gives you some protection against loss of data if a value is missed for some reason (Ignition offline, network error, etc.).

If you must reset the values then do it in the same script that reads the tags and use system.tag.readBlocking to ensure that you've captured the values before writing the reset value out.

1 Like

Thanks for the suggestion, but how to configure to get exactly at 1:30:00
i tried but got the data at 1:29:57. i think there's no way tp configure custom second in scheduled event

Edited:

I got the root cause of this issue,

My recorded time is exactly 1:30:00
but my ProductionEndTime: 1:29:57
its an expression tag

dateFormat({[~]Global Tags/Current Time}, "yyyy-MM-dd HH:mm:ss")

note: /Current Time is changing every second but ProductionEndTime executes every 8 second even if i put it as fixed rate

The gateway event will trigger at xx:30:00.

Yes, your system is fragile and will break from time to time. You need to run things in sequence - not on time values. I suggest a redesign.

I wouldn't reset the value (except, perhaps at the start of shift). Keep it as an odometer-style value and log the difference from the previous hour.

Better yet, just log the odometer value and use the database to calculate the values.

1 Like