- 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
- Navigate to where you want the program to reside, and then click New Program in the bLine menu.
- Click Edit.
- Once the form displays, select the points to use in the program.
- To trigger the program to act as a state machine, add isStateMachine marker tag to your program.
- In the Folio App, type program in the query to display all existing programs.
- 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.
- Click edit the program.
- Drag a mode block out of the block library.
- Write the mode name in the input box found on the top of the block.
- For each mode value that the current mode can take, add it on the bottom part of the block.
- In a similar way, drag finds the state block in the block library and drag it into the stage.
- Set the state name in the top input box.
- Add the state values.
Edit the mode block(s)
- Click on the pencil on top of the mode block.
- In this tab, add the logic that sets the current mode value.
- Drag the mode setter from the right side of the stage, the one that has the (mode) written next to it.
- You can select the value you set to the mode from the drop-down list.
Edit the state block(s)
- To edit a state block, click on the pencil icon.
- The tabs associated with the state values become visible.
- Click "heating = normal".
- Add the logic for what happens when the "heating" state is "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.