How to calculate cut times for different cycles using Tag Event Scripts?

Hello everyone,

I am new to Ignition/Scripting so any help extended would be greatly appreciated!

The complete cycle time on a part consists of 8 individual cuts. I am trying to calculate the cycle times for each of these 8 cuts and then historize them.
The resources I have been given are:

  1. Current_cut tag that updates for each of the 8 cuts. This tag contains the cut times in Hr:Min:Sec for each cut. The issue is that it constantly updates and does not tell you which of these 8 cuts it is on currently.
  2. Cut_status tag that ranges from 0-7. This tells me which of the 8 cuts are currently running.

I have attempted to use a tag event script to write the cut times to memory tags that I have created based on the Cut_Status. However, I have found that this only writes once, when the tag value changes even though I put a loop in there to write continuously(*code only show the if statements).

Here is the code that I wrote:

status = currentValue.value
sec = system.readBlocking([“[.]…/Springer/BUI_Cycle_Data_0_/Cut_Cycle_Time_Secs”])[0].value
min = system.readBlocking([“[.]…/Springer/BUI_Cycle_Data_0_/Cut_Cycle_Time_Mins”])[0].value
hr = system.readBlocking([“[.]…/Springer/BUI_Cycle_Data_0_/Cut_Cycle_Time_Hours”])[0].value

if status == 0:

if status == 1:
if status == 2:
if status == 3:
if status == 4:
if status == 5:
if status == 6:
if status == 7:
	print("Unable to calculate values")

My questions are:

  1. Is this the correct approach?
  2. Is there a simpler way to do this?
  3. The script only writes once - when the value changes. How can I constantly write to the tag as long as the “If condition” is true?

Thank you!

  1. No, not really. You will always be racing between the changes identifying which cut and the change for the duration. Due to the way OPC subscriptions work. You need a third tag that increments after the PLC updates the other two. This trigger tag can then have an event that uses system.opc.readValues() to obtain the two values and write them to your DB. This script can also select other memory tags to update.

  2. Perhaps. If the status changes when a particular cut starts/finishes, you could log that change with a timestamp in the DB. The deltas in the DB would be your cut times. You might need an extra status code that represents not cutting at all.

  3. Should not be necessary.


Thanks for your input!

Here are some more questions that popped up:

  1. Would I need to create this Trigger tag or would it need to come from the PLC? Since the tags coming from the PLC: “Current_cut” & “Cut_status” are updating constantly, how would the new Trigger tag help me to calculate individual cut times?
  2. I don’t have a lot of experience with databases but this could be a a chance to learn!

It would have to come from the PLC. The PLC program would have to ensure the status and duration are updated just before the end-of-cut trigger increments. The status and duration would not otherwise change.

Tag subscriptions are unordered. You cannot be sure that at the point one of those values changes that the other has the correct corresponding value. So you need to trigger off of one value, and if necessary, poll for the others.


This might be a good use case where you create a queue/FIFO in the PLC and use a transaction group.

1 Like