In the system we are finalizing install on I have a need to setup what I thought would be a simple calculation, but it is not turning out that way. I was hoping someone could give me some ideas on the best way to do this.
PI - 2012, with AF (not relevant, but maybe if someone thinks I should use AF or Event Frames to solve the problem).
PI is connected via OPC interfact to an OPC server that is reading data from a Rockwell ControlLogix PLC.
The counter that I am dealing with a simple one. It takes a photo eye and counts boxes as they pass by. The value of this counter is read by PI. So the number starts at zero (after a reset) and increments by 1 as boxes go by. The scan time is set to 10 seconds, so most of the time it goes up by 1 every scan, but sometimes it might be 2 or 3 depending on which line and how fast it is.
The operator has a reset button to reset the counter (start a new order)...actually there are two resets that are in paralell, either one does the same thing (reset the counter to zero and sets a reset bit for PI to read (holds it on for 10 seconds). One reset button is hardwired to the PLC, the other comes as an output from PI set in ProcessBook (so the operator normally presses the button on Processbook, but if PI were down we could still run just using the hard reset button).
Exception deviation is set to 1, compression deviation is set to 2. Once a line is running steady, the boxes are failry consistent so compression does a pretty good job.
Now the problem:
I need to display to the operator the number of boxes made in the last hour (or any previous hour). This would be easy if there were no resets...just take the count at the start of the hour and the count at the end and subtract them. However, since the operator can reset the thing (multiple time per hour sometimes) I can't seem to figure a good way to get this data.
For example, starting at hour 1 lets say the counter is 10, it runs up to 60 and is then reset. Runs up to 40 is reset and then continues to run and at the end of hour 1 is at 160.
The math I need is:
(60 - 10) = 50
50 + 40 + 160 = 250 counts in hour 1.
I tried setting a tag that looks at the difference between the previous value (PrevVal) and calculates difference to current value..thinking that tag would then hold a running count difference that could sum over the hour with a totalizer. However, the exception and compression plays heck with that theory as PrevVal only looks at the archive and since these lines pretty steady, it only archives numbers every several mins or so on average. I did try setting exception and compression deviation to zero...which worked fairly well, but then I got 8,640 archives a day per tag (there are currently 19 tags and it will go up as we add lines), so that seemed like hard work on the archive to store data that is easily compressable.
Any ideas on how to accomplish this? It seems such a simply thing that I must just be missing here.