Attention
IronPLC supports IEC 61131-3 Structured Text excluding I/O mapping.
Bit Access¶
Bit access selects a single bit of an integer-typed or bit-string-typed variable. The selected bit reads and writes as a BOOL.
IEC 61131-3 |
Section 2.4.1.2 (partial access) |
Support |
Supported (short form); bit form of partial-access syntax supported |
Syntax¶
IronPLC accepts two equivalent forms for bit access:
Form |
Example |
Availability |
|---|---|---|
|
|
Always supported (Edition 2 short form) |
|
|
Edition 3 partial-access syntax; see below |
Both forms denote the same bit and produce the same runtime behavior — they
differ only in surface syntax. Bit indices are zero-based, with 0 being
the least significant bit.
Bit access composes with other variable references. The bit suffix may follow any symbolic variable, including array subscripts and structure field accesses:
my_byte.3 (* simple variable *)
my_array[i].3 (* array element *)
my_record.field.3 (* structure field *)
Valid Base Types¶
Bit access is valid on any integer or bit-string type:
Type family |
Types |
Valid bit indices |
|---|---|---|
8-bit |
|
|
16-bit |
|
|
32-bit |
|
|
64-bit |
|
|
Accessing a bit outside the valid range raises P4025.
Example¶
Edition 3 Partial-Access Syntax¶
Note
This feature requires IEC 61131-3 Edition 3. Use
--dialect iec61131-3-ed3 or the rusty dialect to enable it.
See Enabling Dialects and Features for details.
IEC 61131-3:2013 adds the explicit form variable.%Xn for bit access.
Semantically it is identical to the .n short form — IronPLC lowers both
to the same representation. The Edition 3 form is gated behind
--allow-partial-access-syntax and is enabled by default under
--dialect=iec61131-3-ed3 and --dialect=rusty.
Using .%Xn without the flag raises
P4033.
PROGRAM main
VAR
my_byte_array : ARRAY[0..1] OF BYTE := [2#00000101, 2#00000000];
r : BOOL;
END_VAR
r := my_byte_array[0].%X0; (* TRUE *)
my_byte_array[0].%X1 := TRUE; (* write bit 1 *)
END_PROGRAM
The plc2plc renderer normalizes both surface forms to .n on output; the
chosen bit index is preserved.
Byte / Word / Dword / Lword Partial Access¶
IEC 61131-3:2013 also defines partial access at wider granularities:
Form |
Selects |
Status |
|---|---|---|
|
Byte |
Not yet supported |
|
Word |
Not yet supported |
|
Double word |
Not yet supported |
|
Long word |
Not yet supported |
These forms return a non-BOOL view of the underlying value and require
additional codegen work. Until they land, a source that uses them raises
P4033 when the flag is off and
P0003 (Unmatched character sequence) when the flag is on.