canitpOpen (Function) |
Top Previous Next |
Open an ISO-TP connection using an already opened CAN port.
A callback function is used to notify the application that a message is received. (See CALLBACK for more information)
The ISO-TP protocol uses two way communication so the CAN write capability must be enabled. If CAN write is not enabled, or monitor mode is used, then messages cannot be received or send.
canitpOpen can only be used to create a single connection, to create multiple connections, see canitpSessionCreate.
Input: port : SINT (1/2) (default 1) The port of the CAN bus to use for ISO-TP.
src : DINT The CAN ID to filter for incoming ISO-TP messages.
dst : DINT The CAN ID where ISO-TP messages are sent to.
xtd : BOOL (default TRUE) Set to FALSE to use standard identifiers (11 bits), leave at TRUE for extended identifiers (29 bits).
cb_receive : CALLBACK The callback function for received messages. (See the canitpRecv callback declaration below)
cb_data : PTR The buffer where the received message is stored.
cb_size : INT (1..4095) The size of the receive buffer. If an incoming ISO-TP message is too large for the receive buffer it will be discarded.
Returns: INT
Declaration: FUNCTION canitpOpen : BOOL;
Callback declaration: FUNCTION CALLBACK canitpRecv
Example: INCLUDE rtcu.inc
VAR buf : ARRAY [1..4096] OF SINT; END_VAR;
FUNCTION CALLBACK canitpRecv VAR_INPUT size : INT; //Size of the data received. END_VAR; DebugMsg(message := strFromMemory(src := ADDR(buf), len := size)); END_FUNCTION;
PROGRAM example; VAR rc : INT; str : STRING; out : ARRAY [1..4095] OF SINT; len : INT; END_VAR;
// Open can canOpen(baud := 250, monitor := FALSE);
// Open ISO-TP rc := canitpOpen(port := 1, src := 16#12345678, dst := 16#12345679, cb_receive := @canitpRecv, cb_data := ADDR(buf), cb_size := SIZEOF(buf)); IF rc < 1 THEN DebugFmt(message := "canitpOpen=\1", v1 := rc); RETURN; END_IF;
// Build message str := "Hello from RTCU device";
// Send message len := strLen(str := str); strToMemory(str := str, dst := ADDR(out), len := len); rc := canitpSend(data := ADDR(out), size := len); IF rc < 1 THEN DebugFmt(message := "canitpSend=\1", v1 := rc); RETURN; END_IF;
BEGIN END; END_PROGRAM; |