Script about calculate the cumulative downtime

Tag History is not a good solution for this because you want values at 08:00 and 20:00 and the historian doesn't interpolate well.

The best solution is to record the timestamp, runStatus and count (and the product code, the machine ID and anything else that may prove useful in future) in a separate data table. I recommend using a non-resetting counter so that you can very easily calculate the production between any two dates.

  • You can trigger a record using Gateway Event Scripts, Tag Change event.
  • You can also schedule records using the Gateway Event Scripts, Scheduled. Use this to ensure a count value at 08:00 and 20:00. (In one of my applications I record on the hour and every 15 minutes. This ensures that I have counts for all sorts of weird production schedules - subject to 15 minute start time.)

For calculated uptime / downtime you need to run a query for the machine and time period of interest and then loop through the results to calculate the total uptime / downtime.

This data structure also makes it very easy to produce Time Series charts showing the production count through the shift. Downtime will appear as flat-lines on the chart.