switch
Description
The switch block controls forwarding of changes received on the input labeled as tag1. When the control input tag2 has the value true, the block forwards changes from tag1. When tag2 has the value false, the block stops forwarding those changes.
The block has two inputs labeled using the tag block and one output. It supports all logic value types on the tag1 input. The tag2 input is used only to control the switch state and accepts only boolean values true or false.
Configuration parameters
| Parameter name | Value |
|---|---|
Set output to NULL when inactive (nullIfInactive) |
Required boolean value true or false. When set to true, switching the block to the inactive state with tag2 = false causes the block to emit the null value at the output. When set to false, disabling the block changes only the block state without emitting any additional value. |
Remember last value (rememberLastValue) |
Required boolean value true or false. When set to true, the last value received on tag1 while the block is inactive is remembered and will be emitted after the block is enabled again with tag2 = true. When set to false, values received after project stabilization while the block is inactive are ignored. |
Input handling
The block requires exactly one tag1 connection and exactly one tag2 connection.
| Input number and name | Description |
|---|---|
tag1: Data input |
Any logic value type may be sent to this input. If the block is active, the received change is forwarded to the output. If the block is inactive, the change may be remembered or ignored, depending on the rememberLastValue parameter. |
tag2: Switch control |
This input accepts only boolean values. Sending true enables forwarding of changes from tag1. Sending false disables forwarding of changes from tag1. Values of other types are ignored. Sending the same boolean value again does not change the block state. |
Detailed operating rules:
- if
tag1delivers a change while the block is active, the change is forwarded to the output immediately - if
tag1delivers a change while the block is inactive andrememberLastValue = true, the block remembers only the last such change - if
tag1delivers a change while the block is inactive andrememberLastValue = false, the change is ignored after project stabilization - during project startup, the last change from
tag1may be remembered for later emission even whenrememberLastValue = false - if, after a value has been remembered, the
tag2input switches the block to the active state, the remembered change is emitted at the output - if
nullIfInactive = true, switching to the inactive state additionally emits thenullvalue
Ignored cases:
- values from the
tag2input that are not boolean values - subsequent values from
tag2that do not change the current active or inactive state of the block - values from
tag1received while the block is inactive if they are not subject to remembering
Block outputs
The block has one output.
The same change that previously arrived at tag1 appears at the output if the block was active at the time of reception or if the change had been remembered earlier and the block was then enabled.
If nullIfInactive = true, the block emits the null value at the output when switching to the inactive state.
The description visible below the block reflects the current state, for example:
idleafter the block has been created, before the first significant activity appearsactivewhen the block is enabled but there is no textual representation of the last emitted valueinactivewhen the block is disabled and thenullIfInactiveparameter does not emitnullactive: trueoractive: 23when the last emitted value can be represented as textinactive: nullwhen the block was disabled withnullIfInactiveenabled
Errors visible to the user
The block can display the following error messages:
| Error code | Error description |
|---|---|
Invalid null_if_inactive configuration. |
The nullIfInactive parameter has an invalid value and cannot be read as true or false. |
Invalid remember_last_value configuration. |
The rememberLastValue parameter has an invalid value and cannot be read as true or false. |
Too many tag1 connections. |
More than one tag block has been connected to the tag1 input. |
Missing tag1 block connection. |
No tag block has been connected to the tag1 input. |
Too many tag2 connections. |
More than one tag block has been connected to the tag2 input. |
Missing tag2 block connection. |
No tag block has been connected to the tag2 input. |
Examples
- If
tag2receives true, and then thefalse -> truechange appears ontag1, the same change will be forwarded to the output. - If
tag2has the value false,rememberLastValue = true, and the values10,20,30appear ontag1one after another, then after the block is enabled again only the last remembered change, that is the one related to the value30, will be emitted at the output. - If
tag2has the value false andnullIfInactive = true, then at the moment of disabling the block it will emit thenullvalue at the output. - If
tag2receives text or a number instead of a boolean value, such a message will be ignored and the block state will not change.