canClose (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 closes a CAN port previously opened by canOpen. Call this function to close the CAN port when done with sending and receiving messages.

 

 

Input:

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

The port of the CAN bus.

 

 

Returns: INT

1

- Successful.

0

- The CAN bus is not open.

 

Declaration:

FUNCTION canClose : INT;

VAR_INPUT
  port : SINT := 1;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  ignition : BOOL;
END_VAR;
 
PROGRAM test;
VAR
  can_open : BOOL;
END_VAR;
 
BEGIN
  ...
  IF ignition THEN
    IF NOT can_open THEN
        IF canOpen(baud:=250) = 0 THEN
           can_open := THEN;
        ELSE
          DebugMsg(message:="CanOpen - Failed!");
        END_IF;
    END_IF;
  ELSE
    IF can_open THEN
        canClose();
        can_open := FALSE;
    END_IF;
  END_IF;
  ...
END;
END_PROGRAM;