canLoggerRead (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

MX2 pro, DX4 pro, CX1 pro-c/warp-c, MX2 turbo/encore/warp, NX-200, NX-400, LX2, LX5

Firmware version:

2.50 / 1.00.00


This function will read the oldest record stored in the logger when operating in mode 1 (see canLoggerSetup).
 

The function block must be initialized and manually updated in order to read any messages from the logger.

When a message is read from the logger, the ready flag will be set, the output variables will contain the message identifier (ID) information, and the buffer defined during initialization will contain the data.

The data is valid until the function block is updated again.

Note: this function will not affect the internal buffer.

 

The function block can only read CAN messages from the first logger.

 

 

Input:

data : PTR

Address of the buffer to receive the data in.

Note: the buffer must be 8 bytes long.

 

 

Output:

xtd : BOOL

TRUE:

Message uses the extended identifier (29 bits).

FALSE:

Message uses the standard identifier (11 bits).

 

id : DINT

The identifier of the message.

 

datasize : SINT

Number of bytes received.

 

ready : BOOL

True if a message has been received.

 

 

Declaration:

FUNCTION_BLOCK canLoggerRead;
VAR_INPUT
  data     : PTR;
END_VAR;
VAR_OUTPUT
  xtd     : BOOL;
  ID       : DINT;
  datasize : SINT;
  ready   : BOOL;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  LogBuf : ARRAY [1..1300] OF SINT;
  buf   : ARRAY [1..8] OF SINT;
  reader : canLoggerRead;
END_VAR;
 
PROGRAM Example;
VAR
  FilterID : SINT;
END_VAR;
 
// Initialize CAN
canOpen(baud := 250);
FilterID := canFilterCreate(xtd := TRUE, startID := 16#0EFDD600, length := 6);
canLoggerSetup(buffer := ADDR(LogBuf), size := SIZEOF(LogBuf));
reader(data := ADDR(buf));
...
 
BEGIN
  ...
  reader();
  IF reader.ready THEN
    DebugMsg(message:="Message received!");
    DebugFmt(message:="-reader.xtd= \1", v1 := INT(reader.xtd));
    DebugFmt(message:="-reader.ID= \4", v4 := reader.ID);
    DebugFmt(message:="-reader.DataSize= \1", v1 := INT(reader.DataSize));
  END_IF;
  ...
END;
END_PROGRAM;