Send an ISO-TP message.
The destination of the message is set in the canitpSessionCreate function, using the dst parameter.
Input:
handle : SYSHANDLE
The handle of the ISO-TP session to send the data on.
data : PTR
The buffer with the message to send.
size : INT (1..4095)
The size of the message in bytes.
Returns: INT
1
|
- Successful.
|
0
|
- Not available.
|
-1
|
- Session is not open.
|
-2
|
- Invalid parameter.
|
-3
|
- Error sending the message.
|
-11
|
- The CAN bus is not open.
|
-14
|
- Timeout sending the messge.
|
-15
|
- The CAN bus is in monitor mode.
|
-16
|
- An error is detected on the can bus.
|
Declaration:
FUNCTION canitpSessionSend : INT;
VAR_INPUT
handle : SYSHANDLE;
data : PTR;
size : INT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
buf : ARRAY [1..4096] OF SINT;
END_VAR;
FUNCTION CALLBACK canitpRecv
VAR_INPUT
handle : SYSHANDLE;
arg : DINT;
size : INT;
END_VAR;
DebugMsg(message := strFromMemory(src := PTR(arg), len := size));
END_FUNCTION;
PROGRAM example;
VAR
handle: SYSHANDLE;
rc : INT;
str : STRING;
out : ARRAY [1..4095] OF SINT;
len : INT;
END_VAR;
canOpen(baud := 250, monitor := FALSE);
rc := canitpSessionCreate(handle:=handle,
port := 1,
src := 16#12345678,
dst := 16#12345679,
cb_receive := @canitpRecv,
cb_data := ADDR(buf),
cb_arg := DINT(ADDR(buf)),
cb_size := SIZEOF(buf));
IF rc < 1 THEN
DebugFmt(message := "canitpSessionCreate=\1", v1 := rc);
RETURN;
END_IF;
str := "Hello from RTCU device";
len := strLen(str := str);
strToMemory(str := str, dst := ADDR(out), len := len);
rc := canitpSessionSend(handle:=handle, data := ADDR(out), size := len);
IF rc < 1 THEN
DebugFmt(message := "canitpSessionSend=\1", v1 := rc);
RETURN;
END_IF;
BEGIN
END;
END_PROGRAM;
|