canLoggerRead2 (Functionblock)

Top  Previous  Next

Architecture:

NX32 / NX32L

Device support:

MX2 turbo/encore/warp, NX-200, NX-400, LX2, LX5

Firmware version:

4.69 / 1.11.00


This function will read the oldest record stored in the logger when operating in mode 2 (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.

 

 

Input:

port : SINT (1/2) (default 1)

The port of the logger.

 

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.

 

time : INT

The time-stamp. (Look here for information).

 

ready : BOOL

True if a message has been received.

 

 

Declaration:

FUNCTION_BLOCK canLoggerRead2;
VAR_INPUT
  port     : SINT := 1;
  data     : PTR;
END_VAR;
VAR_OUTPUT
  xtd     : BOOL;
  ID       : DINT;
  time     : INT;

  datasize : SINT;

  ready   : BOOL;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  LogBuf : ARRAY [1..1300] OF SINT;
  buf   : ARRAY [1..8] OF SINT;
  reader : canLoggerRead2;
END_VAR;
 
PROGRAM Example;
VAR
  FilterID : SINT;
END_VAR;
 
// Initialize CAN
canOpen(baud := 250);
FilterID := canFilterCreate(xtd := TRUE, startID := 16#0EFDD600, length := 6);
canLoggerSetup(mode:=2,buffer := ADDR(LogBuf), size := SIZEOF(LogBuf));
reader(data := ADDR(buf));
...
 
BEGIN
  ...
  reader();
  IF reader.ready THEN
    DebugMsg(message:="Message received!");
    DebugFmt(message:="-reader.time= \1", v1 := reader.time);
    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;