Attribute 'TcGenerateDeRefType'
![]() | Available from TwinCAT 3.1 Build 4026.20 |
This pragma causes user-defined data types with references and pointers as member variables to be fully resolved so that the dereferenced values can be read or written using an ADS command.
Syntax: {attribute 'TcGenerateDeRefType'}
Insertion location: Line above the declaration line of a structure
Example:
{ attribute 'TcGenerateDeRefType' }
TYPE MyStruct :
STRUCT
a: INT;
b: REFERENCE TO INT;
c: ARRAY [0..1] OF MyOtherStruct;
d: POINTER TO MyOtherStruct;
e: ARRAY [0..1] OF POINTER TO MyOtherStruct;
END_STRUCT
END_TYPE
TYPE MyOtherStruct :
STRUCT
x: ARRAY [0..2] OF INT;
y: REFERENCE TO INT;
END_STRUCT
END_TYPE
/* initialize references and pointers
to avoid ADSERR_DEVICE_INVALIDDATA error: */
stDeRef : MyStruct;
stDeRef.b REF= stDeRef.a;
stDeRef.d := ADR(stDeRef.c[0]);
stDeRef.c[0].y REF= stDeRef.a;
stDeRef.c[1].y REF= stDeRef.a;
stDeRef.e[0] := ADR(stDeRef.c[0]);
stDeRef.e[1] := ADR(stDeRef.c[1]);