Have you got some code changing Cycle Time Start and Cycle Time Stop simultaneously? If so then your expression might be firing twice - once for each tag change.
currentValue.value is a true value (int,string, float, etc....) while previousValue is a QualifiedValue object, they are never equivalent.
You should also filter for initial change
It should be:
if not initialChange and currentValue.value != previousValue.value:
Not filtering for initialChange means that anytime the tag resets you will also run this tag write. So save edits to the tag, restart the gateway, etc...
Yes, thank you for catching that oversight. I did add the not initialChange, however, it still is adding the previous value to the current value.
if not initialChange and currentValue.value != previousValue.value:
value = previousValue.value
system.tag.writeBlocking("[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Stop", [value])
The 9.017 adds to the 6.013 and then I get that 15.03.
So the way I wrote the cycle time recording does not work well with storing the value for averaging
Here is how I calculate it. It works, but not for reading from the SQL DB because I read the two values.
Step 1
Cycle Time
if currentValue.value != previousValue.value:
Start = system.date.now()
system.tag.writeBlocking(["[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Start"],[Start])
Step 2
if not initialChange and currentValue.value != previousValue.value:
value = previousValue.value
system.tag.writeBlocking("[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Stop", [value])
Step 3
Previous Cycle Time
if({[.]../../What Shift Is Active.value}=1,(millisBetween ({[.]Cycle Time Stop.value},{[.]Cycle Time Start.value}))/1000,'')
@Transistor ok sorry, bad forgot to format ...good now
Make it a memory tag instead of expression tag. Use the script to write everything at once.
if not initialChange and currentValue.value != previousValue.value:
cycleTime = system.date.millisBetween(previousValue.value, currentValue.value)/1000.0
tagsOut = ["[default]Line F Traub/Cycle Times/Cycle Time Stop",
"[default]Line F Traub/Cycle Times/Previous Cycle Time"
]
system.tag.writeBlocking(tagsOut, [previousValue.value, cycleTime])
Absolutely agree and thank you!!
I am actually making edits this morning on other cycle timers based on what I have learned in this thread. Much more efficient with what I have learned in the last 24 hours