Skip to content

1.1:计算平均值

场景:监测反应釜的6个温度传感器,需计算其平均温度用于控制。
运算:平均温度 = (T1 + T2 + T3 + T4 + T5 + T6) / 6
目的:获得一个更稳定、更具代表性的温度值,以替代单一传感器读数,用于PID控制或上位机显示。

javascript
const { getVariant, executeSql, exePgSqlR, exePgSqlCUD, exeSqliteSqlR, exeSqliteSqlCUD, getCurrentOrLastValue, setVariantValue, watch, watchAlarm, table, executeDataSourceSql, sendWxTextMessage, sendWxMessage, sendDingTextMessage, sendDingMessage, alarm } = require("GlobalConfig");//头文件请勿删除
const { getFormulaGroupList, getFormulaList, delFormula, getLastDownFormula, addFormula, editFormula, downloadFormula } = require("FormulaApi");//头文件请勿删除

// 需要监听的变量
const watchKeys = ["T1",  "T2",  "T3",  "T4", "T5" ,  "T6"]

/**
 * 监听变量的值变化事件
 * @param {Array} names 变量名数组
 * @param {Function} callback 回调函数
 */
watch(watchKeys, (name, value) => {
    let count = 0
    watchKeys.forEach(key => {
        count =   getVariant(key).value + count
    })
        // 设置平均温度,并且只保留整数位
        `平均温度`.value = Math.floor(count / watchKeys.length)
});

1.2:复合条件报警

场景:判断储罐进料系统是否发生故障。
运算:报警标志 = (液位 < 20%) AND (入口阀门状态 == “开”) AND (阀门开启计时 > 300秒) AND (ABS(当前液位 - 300秒前液位) < 0.5%)
目的:在液位低、阀门开启但液位不上升的异常工况下,精准触发“进料故障”报警,避免误报。

javascript
const { getVariant, executeSql, exePgSqlR, exePgSqlCUD, exeSqliteSqlR, exeSqliteSqlCUD, getCurrentOrLastValue, setVariantValue, watch, watchAlarm, table, executeDataSourceSql, sendWxTextMessage, sendWxMessage, sendDingTextMessage, sendDingMessage, alarm } = require("GlobalConfig");//头文件请勿删除
const { getFormulaGroupList, getFormulaList, delFormula, getLastDownFormula, addFormula, editFormula, downloadFormula } = require("FormulaApi");//头文件请勿删除

// 目的:在液位低、阀门开启但液位不上升的异常工况下,精准触发“进料故障”报警,避免误报。

// 需要监听的变量
const watchKeys = [ "入口阀门状态", "当前液位"]

/**
 * 监听变量的值变化事件
 * @param {Array} names 变量名数组
 * @param {Function} callback 回调函数
 */
watch(watchKeys, (name, value) => {
    if(`入口阀门状态`.value && `当前液位`.value < 0.2  ){
        // 入口阀门状态打开,并且当前液位值低于20%,开启进料故障报警检测
        startDetection()
    }  else if(`当前液位`.value >= 0.2 ){
        // 液位值大于20%,则取消报警
        `报警标志`.value = 0
    }
});


/**
 * 开启检测
 */
function startDetection(){
    // 保存旧的液位值
    const oldVal = `当前液位`.value
    // 开启一个300秒之后执行的故障报警检测
    setTimeout(()=>{
        // 设置报警标志
        `报警标志`.value =Number(`当前液位`.value < 0.2 && `入口阀门状态`.value  && (Math.abs(`当前液位`.value -  oldVal) < 0.005))
    }, 300 * 1000)
}

1.3:数据批量交换

场景:将一个主设定值(如总速度)同步到三条独立传送带的从站控制器。
运算:监测主设定值MasterSpeed,执行Speed_Line1 = MasterSpeed; Speed_Line2 = MasterSpeed; Speed_Line3 = MasterSpeed。
目的:实现“一键设定,全局同步”,提高参数设置效率与一致性。

javascript
const {getVariant,executeSql,exePgSqlR,exePgSqlCUD,exeSqliteSqlR,exeSqliteSqlCUD,getCurrentOrLastValue,setVariantValue,watch,watchAlarm,table,executeDataSourceSql,sendWxTextMessage,sendWxMessage,sendDingTextMessage,sendDingMessage,alarm } = require("GlobalConfig");//头文件请勿删除
const {getFormulaGroupList,getFormulaList,delFormula,getLastDownFormula,addFormula,editFormula,downloadFormula} = require("FormulaApi");//头文件请勿删除

// 目的:实现“一键设定,全局同步”,提高参数设置效率与一致性。

// 需要监听的变量
const watchKeys = ["MasterSpeed"]

/**
 * 监听变量的值变化事件
 * @param {Array} names 变量名数组
 * @param {Function} callback 回调函数
 */
watch(watchKeys, (name, value) => {
    // 同步到三条独立传送带的从站控制器
    `Speed_Line1`.value = `MasterSpeed`.value
        `Speed_Line2`.value = `MasterSpeed`.value
        `Speed_Line3`.value = `MasterSpeed`.value
});

1.4:多数据采集与条件赋值

场景:从一组(4个)传感器读数中,选取有效值进行计算(假设第3个传感器为有效性标志位,1有效,0无效)。
运算:监测 [V1, V2, Flag, V4]。当Flag == 1时,执行A = (V1 + V2) / 2; B = V4 * 1.1。
目的:实现条件判断下的数据筛选与并行计算,将结果分别赋予不同变量以供后续流程使用。

javascript
const { getVariant, executeSql, exePgSqlR, exePgSqlCUD, exeSqliteSqlR, exeSqliteSqlCUD, getCurrentOrLastValue, setVariantValue, watch, watchAlarm, table, executeDataSourceSql, sendWxTextMessage, sendWxMessage, sendDingTextMessage, sendDingMessage, alarm } = require("GlobalConfig");//头文件请勿删除
const { getFormulaGroupList, getFormulaList, delFormula, getLastDownFormula, addFormula, editFormula, downloadFormula } = require("FormulaApi");//头文件请勿删除

// 目的:实现条件判断下的数据筛选与并行计算,将结果分别赋予不同变量以供后续流程使用。

// 需要监听的变量
const watchKeys = ["V1", "V2", "V4"]

/**
 * 监听变量的值变化事件
 * @param {Array} names 变量名数组
 * @param {Function} callback 回调函数
 */
watch(watchKeys, (name, value) => {
    // V4状态为true时,则为有效
    if (`V4`.state === 1){
        `A`.value = (`V1`.value + `V2`.value) / 2
        `B`.value  = `V4`.value * 1.1
    }
});

SCADA帮助文档