• Create a new program
  • Add the mode and state blocks
  • Link the mode and state blocks
  • Edit the mode block(s)
  • Edit the state block(s)
  • Generated code
    • Setting the state values
    • Taking actions based on the state values
    • Associated string variables

Create a new program

  1. Navigate to where you want the program to reside, and then click New Program in the bLine menu.
  1. Click Edit.
  1. Once the form displays, select the points to use in the program.
  1. To trigger the program to act as a state machine, add isStateMachine marker tag to your program.
Folio App
  1. In the Folio App, type program in the query to display all existing programs.
  1. Add isStateMachine as a marker tag.

Add the mode and state blocks

  • The state machine can have one or multiple modes and one or multiple states.
  • Each mode and state has an associated string variable that represents it.
  • Each mode and state can take one of a fixed set of values.
  1. Click edit the program.
  1. Drag a mode block out of the block library.
  1. Write the mode name in the input box found on the top of the block.
  1. For each mode value that the current mode can take, add it on the bottom part of the block.
  1. In a similar way, drag finds the state block in the block library and drag it into the stage.
  1. Set the state name in the top input box.
  1. Add the state values.

Edit the mode block(s)

  1. Click on the pencil on top of the mode block.
  1. In this tab, add the logic that sets the current mode value.
  1. Drag the mode setter from the right side of the stage, the one that has the (mode) written next to it.
  1. You can select the value you set to the mode from the drop-down list.
Edit the mode block

Edit the state block(s)

  1. To edit a state block, click on the pencil icon.
Edit button
  1. The tabs associated with the state values become visible.
  1. Click "heating = normal".
  1. Add the logic for what happens when the "heating" state is "normal".
Heating = normal

Generated code

The generated code is based on the following three parts:

  • Macro setup
  • Setting the state values
  • Actions

Mode setup

The mode values are set.

After editing the mode blocks, for each mode block, a setup is generated.

macro setup

Setting the state values

The state values are set based on the linking done between the mode and state blocks.

The code is generated:

//day block

dayNumber = (dayNumber + 0.5) % 7;

if (dayNumber > 4) {

    day = "weekend";

}

else {

    day = "weekday";

}

//time block

hour = (hour + 0.5) % 24;

if (inRange(hour, 6, 18)) {

     time = "daytime";

}

else {

    time = "nightime"

}

Setting the state values

if(time = "daytime") {

    heating = "normal";

}

if(time = "nighttime") {

    eating = "economical";

}

Because the day mode is linked first in the diagram, it has greater priority. So the code is generated after the time mode code.

if (day == "weekend") {

    heating = "economical";

}

Taking actions based on the state values

The actions are done based on the current state values.

Actions

if (heating == "normal") {

    temp = 70;

}

else {

    temp = 50;

}

Associated string variables

When saving the program for each mode and state block, an associated string variable is created.