Content

 Structured variables or types are data multiple data “chunks” grouped together into one piece of information. The 2 main reasons for structured data are

 

  1. Controllers that are limited in the amount of variables they are allowed to expose to the network.

     

  2. Network commands that require more then a simple ON|OFF or analog value.

     

The data is delimited in some way to recognize the individual parts, like a comma or carrot. This delimiter is what we will use to parse out some data, work with the individual parts, then reassemble the data and send it back to the controller.

 

 

In this example we will be working with a LonWorks UNVT made by the Distech company. The process would hold true for any structured data from any protocol once it has been imported into the Atlas database. This variable is used to modify or override the internal vars and physical input and output values in the controller. The variable has 4 parts separated by white space(aka empty char). The first is the type field, this is a string that specifies what type of var to override. Second is the index of the type field, this is a unsigned short. Third is the mode, another string specifying manual or automatic operation. The last is the value to be applied to the overriding var it is a signed long.

 

 

 

//////////////////////////////////Code//////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

_global.style.setStyle("themeColor", "haloBlue");//change the style

 

/*********************Initilize the local vars************************************/

 

con.ID = PointID;// Assign the point ID to work with

 

var output_timer:Number = setInterval(evaluateOutput, 3000);// Set timer to display updated values

var type:String = "";

var index:Number = 0;

var md:String = "";

var val:Number = 0;

var overrideVal:String = "";

var sentOverride:Boolean = false;

 

/******************Start the UI not edible until a good value comes in***********/

 

IntValType.enabled = false;

Index.enabled = false;

Mode.enabled = false;

Value.enabled = false;

Send.enabled = false;

 

 

 

 

The first bit of code just sets up the “theme” for the movie, internal variables to handle the parsed data, and disables the UI for now. By the way I am using 2 number steppers for the index and value, 2 combo-boxes for the type and mode and a button for sending the override value for my UI.

 

 

 

 

//********************* Main body functions ***************

 

function evaluateOutput(){

    if (!sentOverride){//make sure we are not sending an override or making one

        if ((String(con.output).indexOf("?") == -1) && (con.output != undefined)){//check for a good connection to the controller and a valid value

            type = String(con.output).split(" ")[0];//load the public var

            IntValType.text = type;//update the ui

            index = Number(String(con.output).split(" ")[1]);

            Index.value = index;

            md = String(con.output).split(" ")[2];

            Mode.text = md;

            val = Number(String(con.output).split(" ")[3]);

            Value.value = val;//update the ui

        }

 

        else if (String(con.output).indexOf("?") > -1){//updat ethat the controller is not communicating

            IntValType.text = "Error";

            Index.value = 0;

            Mode.text = "Error";

            Value.value = 0;

        }

 

        if (con.isNew == "1"){//if the val is new then allow the ui to work

            IntValType.enabled = true;

            Index.enabled = true;

            Mode.enabled = true;

            Value.enabled = true;

            Send.enabled = true;

        }

    }

 

    else if(con.output == overrideVal){

        sentOverride = false;

        type = String(con.output).split(" ")[0];//load the public var

        IntValType.text = type;//update the ui

        index = Number(String(con.output).split(" ")[1]);

        Index.value = index;

        md = String(con.output).split(" ")[2];

        Mode.text = md;

        val = Number(String(con.output).split(" ")[3]);

        Value.value = val;//update the ui

        IntValType.enabled = true;

    }

}

 

stop();//stops the continuation of frames

 

 

 

In my main function I first check to see if I should pause the updating of the UI because we are in the process of making or sending an override and that the connector has a value and the value is not ??? because the drive cannot connect with the controller. If that is good then we get to the meat of this lesson. Since we know the delimiter and how many parts to expect we can now parse the data and put it into our individual vars created above. First we take the output and cast it into a string type String(con.output) then split that string with our delimiter String(con.output).split(“ “). The data will now be in an array of parts and we can then choose the piece to grab and assign to the internal var type = String(con.output).split(“ “)[0]. Do this 3 more times assigning the appropriate piece to all of the internal vars and now you can adjust them , display them or do what ever you want with them as individuals.

 

 

 

 

//////////////////////////////////Code//////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

on (click){//when button is mouse clicked:

    _parent.overrideVal = _parent.type+" "+String(_parent.index)+" "+_parent.md+" "+String(_parent.val);

    _parent.con.sendOverride(_parent.PointID,_parent.overrideVal);//send and override with the current point ID and the override value

}

 

 

 

When you are done adjusting the individual vars you will need to send them back to the controller for processing. To do this you need to assemble the individuals back into the form that the controller will accept. This is done by assembling a string with the values and appropriate delimiter, and sending thru the connector. _parent.overrideVal = _parent.type+" "+String(_parent.index)+" "+_parent.md+" "+String(_parent.val); assembles the string with a “ ”(white space) between each. _parent.con.sendOverride(_parent.PointID,_parent.overrideVal); sends the override.

 

 

This could also be done without assigning the array to the individual vars and then reassembling with a for loop, but if you go that route remember that each index of the array will be a string and other type will need to be cast before then work as expected, also keep a list of what index hold what information because tempArray[7] is not as descriptive as mode, or value, or alarm.

Add Feedback