Run Always expression processing sequence

Transaction group - Run-Always Expressions, sequence of processing

I am trying to use the order of the processing of Items in the Run_Always Expressions, but the it does not appear that the items are processing in order as listed. Basically trying to create logic to initiate the trigger using the values from the last timer run to read data from Basic OPC/Group Item. From manuals, understand that Run-Always Expression Items will run every minute without trigger.

The application is to record how much material pumped into tank by using the tank level with 1 minute execution scheduling. Flow sensors not giving accurate readings, and have 14 tanks to implement this logic.

Logic is:
Basic OPC/Group Items
HCLLEVEL (Float) WWTP/EQ/Tanks/1/LevelGal

Run-Always Expressing Items (Ignore Trigger)
SLev (Float) if({[~]Status}=0,{[~]WWTP/EQ/Tanks/1/LevelGal},{[~]Slev2}+0)
SLev2 (Float) {[~]Slev}
EndFill (Boolean) if(({[~]WWTP/EQ/Tanks/1/LevelGal} - {[~]LastLevel}<10) && {[~]Status}=1,1,0)
Status (Boolean) if(({[~]WWTP/EQ/Tanks/1/LevelGal} - {[~]LastLevel})>10.00,1,0)
LastLevel (Float) {[~]WWTP/EQ/Tanks/1/LevelGal}

Triggered Expression Items (Trigger is EndFill)
Slev3 (Float) {[~]Slev}
Elev (Float) {[~]WWTP/EQ/Tanks/1/LevelGal}
TotalGal (Float) {[~]WWTP/EQ/Tanks/1/LevelGal}-{[~]Slev3}

Any help or recommendations/suggestions would be very much appreciated.

While I like transaction groups, they don’t lend themselves well to the kind of process where you need a previous value. Consider using a gateway timer script instead, and save values of interest from the previous run to tags.

EDIT: Almost forgot. Welcome!.

Jordon:
Thank you for the reply. I viewed the gateway timer script training. Trying to figure out the best way to implement this. Do you have an example of something similar, or where you script to write to tags? Would you use the script to put data into database, or set tags and use transaction group to look at tag value being set to update the database? Can you point me in direction on training or manual to help reduce my learning curve on this?
Still doing a lot of learning and any help would be appreciated.

Writing to tags:
https://docs.inductiveautomation.com/display/DOC79/system.tag.write

System.db for running queries and doing other db tasks:
https://docs.inductiveautomation.com/display/DOC79/system.db

edit: sorry forgot this was 7.9

It’s difficult for me to follow what your process is supposed to be. Maybe if you could state that, we might be able to come up with a better example.

1 Like

Jordon:

At the plant where I work, we have a lot of chemicals. Unfortunately, many of the chemicals are not flow meter friendly, or tank level sensor friendly (adhesives, HCL, Caustic, methanol). What I am trying to do is determine for each tank, how much material is pumped into the tank, and how much material is pumped out of the tanks. My experience has shown from reviewing data for reports, that the tank levels can vary as much as 100 gallons over a course of hours without filling/draining the tanks due to atmospheric conditions.

What I am trying to do is monitor the tank level every minute. I have shown that if the tank level changes more than 10 gallons a minute, it is because someone if filling/pumping from the tank. For filling the tank, if I look at the tank level every minute, compare the last value read 1 minute prior, if the value is greater than 10 gallons, I can be sure the operator is filling the tank. This is the start level. This could continue from 1 minute (transferring from tank to tank) to several hours (supply tanker). When the difference between the current read and the previous read is less than 10, then conclude the filling operation is complete. Take the difference from the current level – start level will give me the amount of material that has been added to that tank. I want to write into data base a line that has start time, end time, gallons in, or reverse logic, gallons out. Then I can confidently generate usage for each tank.

Thanks for taking time to review.

Charlie

Also note, that I have 15 tanks of various materials that I want to apply this logic.

One way to do this is to enable tag history on these tags (you would need to disable partitioning though) and set it to log parodically with an interval of 1 minute.

Then you can use a query to calculate the difference between consecutive readings.

select intvalue, intvalue - coalesce(lag(intvalue) over (order by t_stamp), 0) as diff
FROM [test].[dbo].[sqlth_1_data]
where tagid = 1

Thank you for the information, I will do some more investigating and trying this tactic. Appreciate the help, have a good week end.

No prob! You can do the exact same thing with a gateway timer script, you just need to create your own table(s) and write insert or update queries, that’s actually the way i would do it.