canLoopBackMode (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:

1.00 / 1.00.00


This activates loopback mode. This functions makes it possible to test the application configuration (send, receive, and filter) with or without a connection to a physical CAN network. The loopback mode loops all outgoing traffic back to the CAN receiver, and the transmitted message will be received if a receive filter is created with canFilterCreate, canFilterCreateOnce, or canFilterCreateX.

 

 

Input:

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

The port of the CAN bus.

 

enable : BOOL (default FALSE)

If true, loopback is enabled.

 

Note: using loopback mode requires that canOpen() has been called with the "monitor" parameter set to FALSE.

 

 

Returns: INT

1

- Successful.

0

- The CAN bus is not open.

 

Declaration:

FUNCTION canLoopBackMode : INT;
VAR_INPUT
  port   : SINT := 1;
  enable : BOOL := FALSE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  canRX : canReceiveMessage;
  buf   : ARRAY [1..8] OF SINT;
END_VAR;
 
PROGRAM CANExample;
VAR
  FilterID : SINT;
  rc       : INT;
END_VAR;
 
// Open can
canOpen(baud := 250, monitor := FALSE);
canRX(data := ADDR(buf));
 
canLoopBackMode(enable := ON);
 
// startID: Priority=3 Reserved=1 Data page=0 PGN=00FDD6
FilterID := canFilterCreate(xtd:=TRUE,startID:=16#0EFDD600,length:=6);
 
rc := canSendMessage(xtd:=TRUE,ID:=16#0EFDD600,data:=ADDR(buf),datasize:=8);
IF rc = 0 THEN
  DebugMsg(message:="CAN message sent");
ELSE
  DebugFmt(message:="CAN message failed (\1)",v1:=rc);
END_IF;
 
BEGIN
  canRX();
  ...
  IF canRX.ready THEN
    DebugMsg(message:="Message received!");
    DebugFmt(message:="canRX.xtd= \1", v1:=INT(canRX.xtd));
    DebugFmt(message:="canRX.ID= \4", v4:=canRX.ID);
    DebugFmt(message:="canRX.DataSize= \1", v1:=INT(canRX.DataSize));
  END_IF;
  ...
END;
 
END_PROGRAM;