STRUCT_BLOCK

Top  Previous  Next

A STRUCT_BLOCK is a user-defined composite type. Struct blocks are an extremely useful facility to group variables as in this example:

 

STRUCT_BLOCK sbBufferPDU
  length : INT;
  data   : ARRAY[1..140} OF SINT;
END_STRUCT_BLOCK;

 

 

The biggest advantage of the STRUCT_BLOCK is found when writing data of different types to the serial port, PDU message, or file system.

Instead of writing the data types individually, they can be grouped in a STRUCT_BLOCK, and the device sees it as one variable.

 

STRUCT_BLOCK sbGpsData
  mode         : SINT;
  linsec       : DINT;
  latitude     : DINT;
  longitude   : DINT;
  speed       : DINT;
  course       : DINT;
  height       : INT;
  PDOP         : INT;
  HDOP         : INT;
  VDOP         : INT;
  inview       : SINT;
  used         : SINT;
END_STRUCT_BLOCK;
 
VAR
  gpsData : sbGpsData;
END_VAR;

 

To access the members of a STRUCT_BLOCK, the same syntax as used with a FUNCTION_BLOCK is used.

For example:

 

gpsData.speed := 100;

 

To send the data through a serial channel:

 

serSendData(port:=1, data:=ADDR(gpsData), size:=SIZEOF(gpsData));  

 

 

Note: Care must be taken when working with a STRING inside a STRUCT_BLOCK as the actual string is not contained in the variable (see string).