Hello,
I have a tag with the boolean value "Running" that indicates whether the asset I am monitoring is running or not. From this tag I would like to historicize (e.g. hourly) information about how long the asset has been running.
What are the best practices for converting the binary value to time information?
The least DB storage is to simply record the value every time it changes. You can use a database's lead()
or lag()
window functions to convert these to durations, trim them to desired time periods, and handle duplicate records (such as those triggered by system restarts). This method does require a reliable connection to the PLC, and ensuring that Ignition runs any time the machine is running. (If you use Ignition's historian to capture these events, you will need to post-process queried historian data with a script to compute the durations.)
A more reliable approach is to use the PLC to maintain an odometer-style timer that rolls over predictably. Have Ignition snapshot that timer value at the top of the minute, or every five minutes, or top of the hour, whatever granularity you might want to report on. A DB's lead()
or lag()
function can be used to obtain the true deltas between logged values, taking into account the rollover. This method is best when you cannot tolerate lost aggregate information on connection losses or Ignition downtime.
The most reliable approach, with lowest DB storage, is to have the PLC capture the start/stop timestamps and load them into a FIFO. Then present the oldest unhandled FIFO record to Ignition for DB recording, and discard it after Ignition confirms that it has been recorded. Under normal conditions, Ignition will keep up, but the FIFO will hold any event timestamps while Ignition is disconnected or down. Size the FIFO for the worst-case Ignition downtime scenario.