Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix A: Variable Type Reference

Scalar Types

TypeRust TypeSizeRangeIEC 61131-3 Equivalent
boolbool1 bytetrue / falseBOOL
u8u81 byte0 to 255USINT / BYTE
i8i81 byte-128 to 127SINT
u16u162 bytes0 to 65,535UINT / WORD
i16i162 bytes-32,768 to 32,767INT
u32u324 bytes0 to 4,294,967,295UDINT / DWORD
i32i324 bytes-2,147,483,648 to 2,147,483,647DINT
u64u648 bytes0 to 2^64 - 1ULINT / LWORD
i64i648 bytes-2^63 to 2^63 - 1LINT
f32f324 bytesIEEE 754 single precisionREAL
f64f648 bytesIEEE 754 double precisionLREAL

String Type

TypeRust TypeSizeRange
stringFixedString<N>N bytesUTF-8 text, zero-padded to capacity

Fixed-length strings are stored as zero-padded byte arrays in shared memory. The max_length field sets the capacity in bytes (default: 64, maximum: 255).

"info_test_id":      { "type": "string", "description": "Test identifier" },
"info_specimen_name": { "type": "string", "max_length": 128, "description": "Specimen name" },
"info_notes":        { "type": "string", "max_length": 255, "description": "Operator notes" }

In the control program, string variables appear as FixedString<N> fields:

// Read a string
let test_id = ctx.gm.info_test_id.as_str();
log::info!("Test: {}", test_id);

// Write a string
ctx.gm.info_test_id.set("TEST-001");

// Check if empty
if ctx.gm.info_notes.is_empty() {
    log::warn!("No notes entered");
}

Strings longer than the capacity are silently truncated at a valid UTF-8 character boundary.

Bit-Mapped Variables

Bool variables can be mapped to individual bits of an integer variable using the source and bit fields. This is useful for EtherCAT devices that pack multiple digital I/O channels into a single word.

"impact67_0_digital_inputs":  { "type": "u16", "link": "ethercat.impact67_0.digital_inputs" },
"impact67_0_digital_outputs": { "type": "u16", "link": "ethercat.impact67_0.digital_outputs" },
"ls_centering_neg": { "type": "bool", "source": "impact67_0_digital_inputs", "bit": 0 },
"ls_centering_pos": { "type": "bool", "source": "impact67_0_digital_inputs", "bit": 1 },
"ls_lift_neg":      { "type": "bool", "source": "impact67_0_digital_inputs", "bit": 2 },
"cr_lift_brake":    { "type": "bool", "source": "impact67_0_digital_outputs", "bit": 0 }

The code generator produces unpack_bits() and pack_bits() methods on GlobalMemory that are called automatically by the framework each cycle:

  1. After reading shared memory: unpack_bits() extracts each bool from its source word
  2. Your process_tick() runs — read and write the individual bools naturally
  3. Before writing shared memory: pack_bits() inserts each bool back into its source word

Unmapped bits in the source word are preserved.

Rules:

  • source must name another variable in the same project
  • source must be an integer type (u8, u16, u32, u64, i8, i16, i32, i64)
  • bit is 0-based (0 = LSB) and must be within the source type’s bit width
  • The bit-mapped variable must be type bool
  • source and bit must always be specified together

In the control program, bit-mapped variables are ordinary bools — no special access pattern:

// Read individual digital inputs
if ctx.gm.ls_centering_neg {
    log::info!("Centering negative limit reached");
}

// Set individual digital outputs
ctx.gm.cr_lift_brake = true;

Variable Configuration Fields

FieldTypeRequiredDescription
typestringyesData type (see tables above)
linkstringnoHardware FQDN link (e.g., "ethercat.el2004.output1")
descriptionstringnoHuman-readable description
initialanynoInitial value (as JSON, parsed based on type)
nonvolatileboolnoWhen true, value persists across restarts
max_lengthnumbernoString capacity in bytes (default: 64, max: 255)
sourcestringnoSource variable for bit-mapped bools
bitnumbernoBit position in source (0 = LSB)