Skip to content

d-latch

Description

The d-latch block works as a bistable switch controlled by input events. Each regular input event that matches the condition defined by the input_edge parameter toggles the output state between true and false.

The block has one input and one output. It does not require the use of inputs labeled with the tag block.

In addition to regular toggling, the block also supports commands sent from the command block:

  • set: sets the output state to true
  • reset: sets the output state to false

Configuration parameters

Parameter name Value
Trigger edge (input_edge) Required parameter that defines which input event should toggle the block state. Supported values are: rising, falling, both, true, false, null, none.
Restore state after power loss (persistent_state) Optional boolean parameter with the value true or false. When set to true, after restart the block tries to restore the last persisted output state. The persistent save does not happen immediately, but about 10 minutes after the last change. If a restart or power loss happens earlier, an older state may be restored. When set to false, the state is not restored after restart.

Meaning of the input_edge parameter:

  • rising: toggle after a change interpreted as false -> true
  • falling: toggle after a change interpreted as true -> false
  • both: toggle on every logical state change
  • true: toggle after every input event whose new value can be interpreted as logical true
  • false: toggle after every input event whose new value can be interpreted as logical false
  • null: toggle only after receiving the null value
  • none: disable the reaction to regular input events

Input handling

The block requires at least one input connection. If there is no connection, it enters the disconnected state and does not react to events.

Detailed operating rules:

  • the set command from the command block sets the output state to true
  • the reset command from the command block sets the output state to false
  • a regular input event that matches the input_edge condition toggles the block state to the opposite of the current one
  • for the values rising, falling, both, true, and false, the input must be interpretable as a logical value; other values are ignored
  • for the null value, the block reacts only when the new input value is null
  • for the none value, all regular input events are ignored, but the set and reset commands still work

Examples of values that can be interpreted logically include boolean values and the numbers 0 and non-zero.

Block outputs

The block has one output.

The current remembered block state appears on the output as a logical value:

  • true after being set with the set command
  • false after being set with the reset command
  • the opposite of the previous value after each valid toggling event

If persistent_state is enabled and the block state was previously persisted successfully, then after project startup the block restores that state and sends it again to the output.

Block status description

The description visible below the block shows its current state or a problem:

  • true when the current block state is on
  • false when the current block state is off
  • Input disconnected. when the block has no input connection
  • Invalid input_edge configuration. when the input_edge parameter is invalid or missing

Errors visible to the user

The block can display the following error messages:

Error code Error description
Invalid input_edge configuration. The input_edge parameter is invalid or missing.
Input disconnected. No other block is connected to the block input.

Examples

  • If input_edge = rising, then the first input change from false to true will toggle the output to true, and the next rising edge will toggle it back to false.
  • If input_edge = true, then every new input value interpreted as true will toggle the block state, even if the previous value was also interpreted as true.
  • If the command block sends the set command, the output will be set to true regardless of the input_edge parameter.
  • If input_edge = none, regular input events will not change the block state, but the reset command will still set the output to false.