canLoggerToMemory (Function)

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 move the contents of the logger to memory.

 

In mode 1, the CAN messages will be stored in memory it the following format:

   <xtd/size><ID><data>

 

In mode 2, the CAN messages will be stored in memory it the following format:

   <xtd/size><ID><time><data>

 

Where:

xtd

4 bits

- Located in the upper nibble of the first byte; zero = standard identifier, other = extended identifier.

size

4 bits

- Located in the lower nibble of the first byte; the number of valid data bytes.

ID

4 Bytes

- The message identifier.

time

2 Bytes

- The timestamp. (Look here for information)

data

8 Bytes

- The message data.

 

 

Input:

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

The port of the logger.

 

dst : PTR;

Address of destination data area.

 

size : DINT;

The size of the memory in bytes.

 

Output:

None.

 

Returns: INT

>0

- Number of bytes written

-1

- Logger is not configured.

-2

- Illegal data found in logger.

 

Declaration:

FUNCTION canLoggerToMemory : INT;
VAR_INPUT
  port : SINT := 1;
  dst   : PTR;
  size  : DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  LogBuf : ARRAY [1..2600] OF SINT;
  read : ARRAY [1..480] OF SINT;
END_VAR;
 
PROGRAM example;
VAR
  FilterID : SINT;
  level   : INT;
  rc       : INT;
END_VAR;
 
// Initialize CAN
canOpen(baud := 250);
FilterID := canFilterCreate(xtd := TRUE, startID := 16#0EFDD600, length := 6);
canLoggerSetup(buffer := ADDR(LogBuf), size := SIZEOF(LogBuf));
canLoggerStart();
...
 
BEGIN
  ...
  canLoggerStart();
  ...
  // List the number of received CAN messages
  level := canLoggerLevel();
  IF level >= 900 THEN
    // Logger level high mark
     rc := canLoggerToMemory(dst := ADDR(read), size := SIZEOF(read));
    IF rc > 0 THEN
        ... // Handle data here
     END_IF;
  END_IF;
  ...
END;
END_PROGRAM;