I have a machine that provide the data attached, the weight output is cumulative. I’m trying to calculate the weight for each hopper for each new cycle, (cycle weight=last weight - new weight)
i figured i’ll need to store an old value to execute the operation on the next cycle number, but I haven’t figured out how to do that, what would be the best way to do so in Ignition 7.7?
If you have a point that’s true at the end of each cycle, you can use that as a trigger for a Transaction Group. When triggered this would read the weight and write it to a database table. You could then read the current weight and the last weight recorded in the database to find out the accumulating weight of the hopper.
Adding to Al’s suggestion…
When you then need to query the database for completed cycles, you can use your database’s window aggregate functions to give you the deltas. For example, in Postgres, it’d look something like this:
Select t_stamp, deltaweight
Select t_stamp, weight - lead(weight) over (order by t_stamp desc) as deltaweight
Order By t_stamp Desc
Limit 2) grouptabledelta
Limit 1;Note that lead() and lag() are based on the row order involved. Since this query looks at the rows in reverse so the limit clause works right, the expressions uses lead() instead of lag(). Anyways, this approach works well for anything that records non-resetting values, including timestamps.
Oh, and you need to use a real database. MySQL can’t do this. Pretty much all the others can.
This is really useful to know Phil. We use MySQL currently but have looked briefly at Postgres and were impressed. Its command line tools look a lot less friendly but it does seem to have a lot of momentum at the moment.
Alternatively, if you only need one of the past value (that is, the last value), you could also consider to store the last value in your user-defined tags.