Calculating outflow from the inflo
//A function to read a tag in the payload
const get = (tag) => {
if(!isNaN(tag)) {
return tag;
}
const value = msg.payload[tag];
const infoValue = value === undefined ? 'undefined' : value;
undefinedCount += value === undefined;
flatInfoMsg.payload[tag] = infoValue;
infoMsg.payload.getValues[tag] = infoValue;
usedValues[tag] = infoValue;
return value;
};
// Function to set a tag in the payload
const set = (tag, value) => {
msg.payload[tag] = value;
calcs[tag] = value;
const infoValue = value === undefined ? 'undefined' : value;
flatInfoMsg.payload[tag] = infoValue;
infoMsg.payload.setValues[tag] = infoValue;
infoMsg.payload.both[tag] = {result: infoValue, usedValues: usedValues};
usedValues = {};
};
const va = {
lag_group:{
lev_m3: "level_tag", //m3
outflow : "inflow_tag", // in m3/h
},}
// computing outflow from inflow
let prevqty_lag_group = context.get("prevqty_lag_group") || 0;
context.set("prevqty_lag_group", (msg.payload["qty_lag_group"]));
// flow OUT = prev_qty - qty + INflow
set("outqty_lag_group", prevqty_lag_group - msg.payload["qty_lag_group"] + (get(va.lag_group.flow)/60 * dt));
_str1 : qty in the tank
_str1,-1 : previous value of the qty in the tank
_str2 : inflow (qty/min)
double flow=Str.ToDouble(_dojavascript.get("_str1",-1))-Str.ToDouble(_str1)+Str.ToDouble(_str2);
if (flow>0)
return flow;
else
return "0";
// ================================
// New MX Common function
// ================================
/**
* Description : Calculating outflow from the inflow
*
* _str1 : qty in the tank
* _str2 : inflow (qty/min)
*/
return MxFlow_out_from_in(_dojavascript, _str1, _str2);
Was this article helpful?