impulse-counter
Description
The impulse-counter block works as a simple integer counter controlled by impulses and by commands sent from the command block. It stores the current value defined by the start_value parameter or restored after a project restart, and then increments it, decrements it, or sets it directly based on input signals.
The block operates only within the configured range from value_from to value_to. Changes performed by the up and down commands from the command block or by a rising edge are limited to this range, so the counter never goes below the configured minimum or above the configured maximum.
The block has one input and three outputs. It does not require the use of inputs labeled using the tag block.
Configuration parameters
| Parameter name | Value |
|---|---|
start_value |
Required parameter that defines the initial counter value. It must be an integer within the range from value_from to value_to. The set command from the command block always restores exactly this value. |
value_from |
Required parameter that defines the minimum allowed counter value. |
value_to |
Required parameter that defines the maximum allowed counter value. It must be greater than value_from. |
movement |
Required parameter that defines the step used by the up and down commands from the command block and by the false -> true rising edge. The value must be a positive integer greater than zero. |
persistent_state |
Optional boolean parameter with the value true or false. When it is set to true, after restart the block attempts to restore the last persisted counter value. The value is not persisted immediately, but about 10 minutes after the last change. If a restart or power loss happens earlier, an older value may be restored. When it is set to false or the parameter is omitted, counting starts again from start_value after restart. |
Input handling
The block requires at least one input connection. If its input is not connected to anything during initialization, the block switches to the Input disconnected. error state.
The following control methods are supported:
- The
setcommand from thecommandblock sets the current value tostart_value. - The
resetcommand from thecommandblock sets the current value to the minimum, that isvalue_from. - The
upcommand from thecommandblock increases the current value bymovement. - The
downcommand from thecommandblock decreases the current value bymovement. - The
false -> truerising edge works the same way as theupcommand from thecommandblock. - A numeric input value from the
value_from ... value_torange sets the counter directly to that value.
Detailed operating rules:
- for the
upcommand from thecommandblock and for the rising edge, the result is limited tovalue_to - for the
downcommand from thecommandblock, the result is limited tovalue_from - if a number outside the allowed range appears at the input, that message is ignored
- logical values other than the
false -> trueedge are ignored - date and time values are ignored
- text is accepted only if it can be parsed as an integer
- values of type
double, temperature, and percent are converted to an integer by truncating the fractional part when used for direct setting
The block does not require the use of inputs labeled using the tag block.
Block outputs
| Output number and name | Output description |
|---|---|
| 1. Current value. | Returns the current counter value as an integer. |
| 2. Minimum reached. | Returns true when the counter is at the minimum value value_from. In all other cases it returns false. |
| 3. Maximum reached. | Returns true when the counter is at the maximum value value_to. In all other cases it returns false. |
Block status description
The description visible below the block shows the current counter value as text.
Examples:
012-5
Errors visible to the user
The block can display the following error messages:
| Error code | Error description |
|---|---|
Invalid start_value. |
The start_value parameter was not provided, is not an integer, or is outside the range from value_from to value_to. |
Invalid value_from. |
The value_from parameter was not provided or is not a valid integer. |
Invalid value_to. |
The value_to parameter was not provided or is not a valid integer. |
Invalid from/to range. |
The range is invalid because value_from is greater than or equal to value_to. |
Invalid movement. |
The movement parameter was not provided, is not a valid integer, or has a value less than or equal to zero. |
Input disconnected. |
No other block has been connected to the block input. |
Examples
- If
start_value = 10,value_from = 0,value_to = 100, andmovement = 5, then thesetcommand sent from thecommandblock will set the counter to10. - For the same configuration, the
resetcommand sent from thecommandblock will set the counter to0. - If the current value is
10, then theupcommand sent from thecommandblock or afalse -> trueedge will change it to15. - If the current value is
98andmovement = 5, then theupcommand sent from thecommandblock will set the counter to100, not to103. - If the current value is
3andmovement = 10, then thedowncommand sent from thecommandblock will set the counter to0, not to-7. - If the value
42is provided at the input, the counter will be set to42as long as it is within the configured range. - If the value
150is provided at the input while the range is0 ... 100, that message will be ignored. - If the value
18.9is provided at the input, the counter will be set to18.