Partial access of ANY_BIT variables

Syntax
variable_name.size#

Meaning

partial access to →variables of one of the following ANY_BIT data types: BYTE, WORD, DWORD or LWORD

Enhancement to IEC-standard

logi.CAD 3 supports the write access to a bit, byte, word or double word of a variable, too. This write access is an enhancement to the →IEC-standard.

The following data is necessary to address a part of a variable:

  • variable_name = name of the variable

  • . = separator

  • size = prefix for the size
    Supported prefixes and their meaning:

    %X, only % or no prefix at all

    bool (single bit)

    %B

    byte (8 bits)

    %W

    word (16 bits)

    %D

    double word (32 bits)

    %L

    long word (64 bits)

  • # = corresponding bit, byte, word, double word or long word
    These specifications are integer literals (ranging from 0 for the least significant part up to the literal for the most significant part).

    Access to

    for data type

    literal

    syntax

    bit (BOOL)

    BYTE

    0 to 7

    variable_name.%X0 to variable_name.%X7

    WORD

    0 to 15

    variable_name.%X0 to variable_name.%X15

    DWORD

    0 to 31

    variable_name.%X0 to variable_name.%X31

    LWORD

    0 to 64

    variable_name.%X0 to variable_name.%X63

    byte (BYTE)

    WORD

    0 to 1

    variable_name.%B0 to variable_name.%B1

    DWORD

    0 to 3

    variable_name.%B0 to variable_name.%B3

    LWORD

    0 to 7

    variable_name.%B0 to variable_name.%B7

    word (WORD)

    DWORD

    0 to 1

    variable_name.%W0 to variable_name.%W1

    LWORD

    0 to 3

    variable_name.%W0 to variable_name.%W3

    double word (DWORD)

    LWORD

    0 to 1

    variable_name.%D0 to variable_name.%D1

    long word (LWORD)

    LWORD

    0

    variable_name.%L0

Example
VAR
VarBo : BOOL;
VarBy1, VarBy2 : BYTE;
VarLW : LWORD;
VarW : WORD;
VarDW : DWORD;
END_VAR;
 
(* reading accesses *)
VarBo := VarBy1.%X0; (* 'Bit 0' of 'VarBy1' is assigned to 'VarBo'. *)
VarBo := VarBy1.%7; (* 'Bit 7' of 'VarBy1' is assigned to 'VarBo'. *)
(* 'VarBy1.%7' is interpreted as 'VarBy1.%X7' or 'VarBy1.7'. *)
VarBo := VarLW.63; (* 'Bit 63' of 'VarLW' is assigned to 'VarBo'. *)
(* 'VarLW.63' is interpreted as 'VarLW.%X63' or 'VarLW.%63'. *)
VarBy1 := VarW.%B1; (* 'Byte 1' of 'VarW' is assigned to 'VarBy1'. *)
VarW := VarLW.%W3; (* 'Wort 3' of 'VarLW' is assigned to 'VarW'. *)
 
(* writing accesses *)
VarBy2.4 := TRUE; (* 'TRUE' is assigned to 'bit 4' of 'VarBy2'. *)
(* 'VarBy2.4' is interpreted as 'VarBy2.%X4' or 'VarBy2.%4'. *)
VarDW.%B2 := 16#F0; (* '16#F0' is assigned to 'byte 2' of 'VarDW'. *)