Data Types Reference

Essential IEC 61131-3 data types including elementary types, generic types, and advanced constructs.

πŸš€ Enhance Your Development Experience

Get syntax highlighting, IntelliSense, and debugging support for Structured Text:

Install VS Code Extension β†’

Bit String Data Types

Bit String Data Types

VAR
    StatusByte : BYTE := 16#FF;         // 8-bit: 0 to 255
    StatusWord : WORD := 16#ABCD;       // 16-bit: 0 to 65,535  
    StatusDWord : DWORD := 16#12345678; // 32-bit: 0 to 4,294,967,295
    StatusLWord : LWORD := 16#123456789ABCDEF0; // 64-bit

    // Bit manipulation
    StatusByte.0 := TRUE;     // Set bit 0
    StatusByte.7 := FALSE;    // Clear bit 7
    Config := 16#A5;          // Hexadecimal (165 decimal)
    Mask := 2#10101010;       // Binary notation
END_VAR

Extended Integer Types

64-bit Integer Types

VAR
    // 64-bit signed integer
    PrecisionCounter : LINT := 1234567890123456789;
    
    // 64-bit unsigned integer 
    LargeFileSize : ULINT := 18446744073709551615;
    
    // High-precision calculations
    TotalProductionCount : LINT;
    MachineRunTime : ULINT;      // Microseconds since startup
END_VAR

// Usage examples
TotalProductionCount := TotalProductionCount + 1;
IF MachineRunTime > 86400000000 THEN  // 24 hours in microseconds
    DailyReset := TRUE;
END_IF;

Wide Character & Extended Time Types

Wide Character and Extended Time Types

VAR
    // Wide character (Unicode support)
    UnicodeChar : WCHAR := "A";
    MultiLanguageMessage : WSTRING := "Hello δΈ–η•Œ ΠΌΠΈΡ€";
    
    // Extended time with nanosecond precision
    PreciseDelay : LTIME := LTIME#1d2h3m4s567ms890us123ns;
    FutureDate : LDATE := LDATE#2100-12-31;
    
    // High-resolution timing
    ProcessStartTime : LTIME;
    ProcessDuration : LTIME;
END_VAR

// Unicode and timing operations
InternationalName := CONCAT_WSTR(FirstName, " ", LastName);
ProcessStartTime := GetCurrentLTime();
ProcessDuration := GetCurrentLTime() - ProcessStartTime;

Generic Data Types

Generic Data Types for Flexible Functions

// Generic function accepting any numeric type
FUNCTION ProcessAnyNumber : BOOL
VAR_INPUT
    Input : ANY_NUM;        // Accepts any numeric type
    Threshold : ANY_NUM;    // Same here
END_VAR
    ProcessAnyNumber := Input > Threshold;
END_FUNCTION

// Usage with different types
VAR
    TempValue : REAL := 25.5;
    CountValue : INT := 100;
END_VAR

Success1 := ProcessAnyNumber(TempValue, 30.0);
Success2 := ProcessAnyNumber(CountValue, 150);

Generic Type Categories

  • β€’ ANY: Any data type
  • β€’ ANY_NUM: All numeric types
  • β€’ ANY_REAL: REAL, LREAL
  • β€’ ANY_INT: All integer types
  • β€’ ANY_BIT: BOOL and bit strings
  • β€’ ANY_STRING: STRING, WSTRING
  • β€’ ANY_DATE: All date/time types

Pointer and Reference Types

Pointer and Reference Types

VAR
    // Pointer to REAL variable
    TempPointer : POINTER TO REAL;
    Temperature : REAL := 25.5;
    
    // Reference to function block
    MotorRef : REFERENCE TO MotorController;
    Motor1 : MotorController;
END_VAR

// Pointer assignment and dereferencing
TempPointer := ADR(Temperature);        // Get address
NewValue := TempPointer^;               // Dereference pointer
TempPointer^ := 30.0;                   // Assign through pointer

// Reference assignment
MotorRef REF= Motor1;                   // Create reference
MotorRef.Start := TRUE;                 // Use through reference

⚠️ Pointer Safety

  • β€’ Always check for NULL pointers before dereferencing
  • β€’ Ensure pointer targets remain valid during use
  • β€’ Use references when possible - they're safer than pointers
  • β€’ Consider memory layout in real-time systems

Β© 2025 ControlForge Systems