Store Integer Values from one OPC tag to an Array tag

I have an OPC tag that updates with new Integer values. I need to take the previous 10 values and store them into an array tag in ignition so that I can calculate the running average of the previous 10 values. The reason why I can't just use historian tags is because I need this running average to report in Ignition.

Thanks

My first suggestion:

  • Create three tags:
    • the integer array tag with length of ten.
    • an array pointer.
    • a tag to hold the average value.
  • Create a gateway onChange event script. Note that this needs to monitor something in your process that changes every time if there is a likelihood of two consecutive readings having the same value.
  • Have the even'ts script write to the array using the pointer as the array offset.
  • Add 1 to the pointer using modulo arithmatic. e.g. pointer = (pointer + 1) % 10 and write that back to the pointer tag.
  • Calculate the average and write it out to the average tag.

If you have many of these operations to do then select the tags as a group, right-click and select Create Data Type from Selected. This will create a UDT and you can use that to create multiple copies.

Sounds like the recorder() function from my free Simulation Aids module.

Thank you for the reply. This makes sense. Just one question, where can I define the initial value for "pointer"? If I define pointer = 0 in the change script, then the value with never increment as it just goes back to 0 whenever the change script is triggered.

When you create a memory tag you have the option to set the (initial) value in the tag editor or directly in the tag browser.