Script Calculation and writing to memory tags

Hey everyone,

Brief description of what we are trying to do:

  • On gateway timer we have our calculation script running twice a second.
  • Calculation runs and 300 tags are written using ‘system.tag.writeAll()’
  • Same values are written to a ‘.csv’ file
  • finally we perform ‘system.tag.scan()’ to force a historical scan

We export the historical data using ‘system.tag.queryTagHistory()’ and ‘system.dataset.exportExcel()’. When we exported the historical data and compare with the ‘.csv’ file we get differences. At least in out minds these two files should be the same.

I think that the tags are not being update fast enough before the historical scan occurs. But I doubt writing to 300 tags will take longer then 100ms.

some questions:

  1. Since I am writing to the memory tags via timer does the scanclass (under general properties) of tag properties matter? (how does scan evaluation work?)

  2. Is there a way to measure how long system.tag.writeAll() takes to complete all the tags?

Thanks,
Ken

system.tag.writeAll() is asynchronous and may still be doing the writes in the background when you do the system.tag.scan(). Try using system.tag.writeAllSynchronous() instead.

I will give that a go and see what results I get

Do you know of any way to measure the speed of the tag write using either of the functions?

Precision timing is best done like so:

from java.lang import System
startTS = System.nanoTime()
system.tag.writeAllSynchronous(.....)
endTS = System.nanoTime()

system.util.getLogger("someLogger").infof("writeAllSynchronous() took %dns", endTS-startTS)

You will want to collect some statistics before you make decisions based on this, as multitasking can disturb individual calls.

1 Like

Thanks,

This worked really well. Initial statistics are showing the writeAllSynchronous will not affect our timers from running too long.