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:
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Suction/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Suction/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Suction/Hr"],[hr])

if status == 1:
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Suction/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Suction/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Suction/Hr"],[hr])
	
if status == 2:
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Suction/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Suction/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Suction/Hr"],[hr])
	
if status == 3:
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Suction/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Suction/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Suction/Hr"],[hr])
	
if status == 4:
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Pressure/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Pressure/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Rough_Wing_Pressure/Hr"],[hr])
	
if status == 5:
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Pressure/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Pressure/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Rough_Long_Pressure/Hr"],[hr])
	
if status == 6:
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Pressure/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Pressure/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Finish_Wing_Pressure/Hr"],[hr])
	
if status == 7:
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Pressure/Sec"],[sec])
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Pressure/Min"],[min])
	system.writeBlocking(["[.]../Cut_Times/Finish_Long_Pressure/Hr"],[hr])
	
else:
	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.

Phil,

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.

3 Likes

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

1 Like