Repository navigation
Bool Array Datatype
BOOLARRAY is a fixed-size array of boolean values. Unlike scalar types, it operates on the entire array by default and exposes a rich set of list-style helper methods for common bit-manipulation patterns.
from ethernetip_emulator.server.device import actions
# Tag definition
("O_Steps", actions.type.BOOLARRAY([False, False, False, False]))Returns the full array (or a sub-range) as a list[bool].
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Tag name. |
key |
slice | None |
full array | Sub-range to read. |
actions.boolarray.get_val("O_Steps") # → [False, False, True, False]
actions.boolarray.get_val("O_Steps", slice(1, 3)) # → [False, True]Writes a list of booleans to the array, or to a sub-range if key is provided.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Tag name. |
value |
list[bool] |
— | Values to write. |
key |
slice | None |
full array | Sub-range to write. |
actions.boolarray.set_val("O_Steps", [True, False, True, False])
actions.boolarray.set_val("O_Steps", [True], slice(2, 3)) # write only index 2Reads a single element by zero-based index. Returns None if the tag does not exist.
actions.boolarray.get_bit("O_Steps", 0) # → FalseWrites a single element by zero-based index.
actions.boolarray.set_bit("O_Steps", 0, True)Flips a single element and returns the new value. Returns None if the tag does not exist.
actions.boolarray.toggle_bit("O_Steps", 2) # → True (was False)Returns the total number of elements in the array, or None if the tag does not exist.
actions.boolarray.size("O_Steps") # → 4Returns the number of True elements.
actions.boolarray.count("O_Steps") # → 2Returns the number of False elements.
actions.boolarray.count_clear("O_Steps") # → 2Returns True if at least one element is True.
actions.boolarray.has_any("O_Steps") # → TrueReturns True if every element is True.
actions.boolarray.is_full("O_Steps") # → FalseReturns True if every element is False.
actions.boolarray.is_empty("O_Steps") # → FalseBOOLARRAY treats False as an empty slot and True as an occupied slot. The list operations below use this convention to implement queue- and stack-like behaviour on a fixed-size PLC array.
Writes value into the first False slot (scanning left to right). Returns True on success, False if no empty slot is available.
# [False, False, False, False]
actions.boolarray.append("O_Steps", True) # → True
# [True, False, False, False]Writes value into the last False slot (scanning right to left). Returns True on success, False if no empty slot is available.
# [True, False, False, False]
actions.boolarray.prepend("O_Steps", True) # → True
# [True, False, False, True]Removes (sets to False) the last True element and returns its value. Returns None if the array is empty.
# [True, False, False, True]
actions.boolarray.pop("O_Steps") # → 1 (True)
# [True, False, False, False]Inserts value at index, shifting all subsequent elements one position to the right. The last element is discarded if the array is full. Returns False if there is no room (last element is True), True on success.
# [True, False, False, False]
actions.boolarray.insert("O_Steps", 1, True)
# [True, True, False, False]Removes the element at index, shifting subsequent elements one position to the left. The last element is set to False. Returns the removed value, or None if the element at index was already False.
# [True, True, False, False]
actions.boolarray.remove("O_Steps", 0) # → 1
# [True, False, False, False]Sets all elements (or a sub-range) to False.
actions.boolarray.clear("O_Steps")
# [False, False, False, False]Flips every element in the array (or a sub-range).
# [True, False, True, False]
actions.boolarray.invert("O_Steps")
# [False, True, False, True]on_change for BOOLARRAY works the same as other datatypes, but defaults to the full array slice when no key is provided — unlike scalar types which default to slice(0, 1).
# Fires when any element in the full array is written
@actions.boolarray.on_change("O_Steps")
def any_step_changed(attr, key, value):
print(f"Steps updated: {actions.boolarray.get_val('O_Steps')}")
# Fires only when index 0 is written
@actions.boolarray.on_change("O_Steps", key=slice(0, 1))
def step_0_changed(attr, key, value):
print(f"Step 0 is now {value[0]}")See Working with Actions for full documentation on key and defer.
| Method | Description |
|---|---|
get_val(name, key?) |
Read the full array or a sub-range as list[bool]
|
set_val(name, value, key?) |
Write a list of booleans to the array or a sub-range |
get_bit(name, index) |
Read a single element by index |
set_bit(name, index, value) |
Write a single element by index |
toggle_bit(name, index) |
Flip a single element; returns the new value |
size(name) |
Return the total number of elements |
count(name, key?) |
Count True elements |
count_clear(name, key?) |
Count False elements |
has_any(name, key?) |
True if any element is True
|
is_full(name, key?) |
True if all elements are True
|
is_empty(name, key?) |
True if all elements are False
|
append(name, value, key?) |
Write into the first False slot |
prepend(name, value, key?) |
Write into the last False slot |
pop(name, key?) |
Clear and return the last True element |
insert(name, index, value, key?) |
Insert at index, shifting right |
remove(name, index, key?) |
Remove at index, shifting left |
clear(name, key?) |
Set all elements to False
|
invert(name, key?) |
Flip all elements |
on_change(name, callback?, key?, defer?) |
Register a change listener |