Set to Active/Quiet State Filtered System Object by Calling Multiple Functions

var filter = new Filter();

// filter the BO

filter.objectModel = "GMS_BACNET_EO_BA_BO_1";

var binaryOutputs = searchSync(filter);

 

//Check whether or not there are BO satisfying the filter...

if (binaryOutputs == null || binaryOutputs.length == 0){

    console(" objects not found");

    terminate();

}

//... and count them

console("Binary objects count = {0}",binaryOutputs.length);

 

console("Begin alarm phase");

pointsAlarmDealarm(binaryOutputs, 1, 8);

console("Going to sleep...");

sleep(2000);

pointsAlarmDealarm(binaryOutputs, 0, 8);

console("End dealarm phase");

 

function pointsAlarmDealarm(points, value, priority){

    for (var i=0; i<points.length;i++){

        //Obtain the designation

        var point = points[i].designation; //It works also with var point = points[i];

    //Get the list of command on the Present Value, filtering by "WritePrio".

        //You can iterate with commandList.commands[i].name

        var commandList = getCommandList(point,"Present_Value",true,"WritePrio");

        var currentValue = read(point,"Present_Value");

    

    executePropertyCommand(point,"Present_Value","WritePrio",[["Value", value], ["Priority", priority]]);

        var newValue = read(point,"Present_Value");

        console("{0} on object {1} executed - Old Value: {2} - New Value: {3}",commandList.commands[0].name, i, valToString(currentValue), valToString(newValue));

    }

}

 

function valToString(val){

    //val is an objects coming from the read, thus you have to access the read value with val.value

    if (val.value==1)

        return "ACTIVE";

    return "INACTIVE";

}