Two timestamps for one value

I have setup a expression tag history as in picture, however, when I query the results I am getting two timestamps and two values for the same tag.

So every time there is a value change there is a higher value number first and then the "correct" number that I see in the tag browser.

Any thoughts why I see these two time stamps and one higher value? I thought I have interpolation off with the setup, but maybe I do not?

Anyone? :slight_smile: Maybe I am asking the question wrong, please let me know if any clarification is needed.

Here is another screen shot. Two values for the same timestamp.

1 Like

How is the tag's value source configured ? I mean, can you show the expression used to generate the value ?

Yes, here is the expression

Here is the tag and what I see as the float value.

the expression is

(millisBetween ({[.]Cycle Time Stop.value},{[.]Cycle Time Start.value}))/1000

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.

1 Like

On the Cycle Time Start I have this script:

if currentValue.value !=previousValue:
	value = previousValue
	system.tag.writeBlocking("[default]Line F Traub/Cycle Times/Cycle Time Stop", [value])

So it does look like it is reading the current and previous value.

Any thoughts on how to only read one value? Write the "previous cycle time" value to another memory tag?

This is always true, unless you made a typo.

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...

1 Like

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 :slight_smile:

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 :slight_smile: forgot to format ...good now

1 Like

Format the code, Jim. Format the code! </>

2 Likes

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])
2 Likes

That worked! :slight_smile:
Learned about the tagsout aspect as well. I did not know you could do that.

Thanks again!

1 Like

Not only can you do it, but you should always do it that way. It is much more performant to write all tags at once, then to write one at a time.

2 Likes

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 :slight_smile:

2 Likes