This function is used to send raw M-Bus frames.
To send raw wired M-Bus frames to a slave that can not use the normal primary address, mbusSelectSecondary can be used to select the address to make it available as primary address 253.
When sending wireless M-Bus frames, the frame data must start with the Control field followed by the CI field and the rest of the data, skipping large parts of the header.
To change the address used when sending wireless M-Bus frames, use mbusSetSenderAddress.
Input:
handle : SYSHANDLE
A handle to the connection
frame : PTR
The frame to send
size : INT
The size of the frame in bytes.
Returns: INT
1
|
- Success
|
0
|
- Not supported
|
-1
|
- Invalid handle
|
-9
|
- Communication error
|
-13
|
- Invalid frame.
|
Declaration:
FUNCTION mbusSend : INT;
VAR_INPUT
handle : SYSHANDLE;
frame : PTR;
size : INT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
mb : SYSHANDLE;
END_VAR;
FUNCTION ParseString:INT;
VAR_INPUT
str : STRING;
dst : PTR;
END_VAR;
VAR
i : INT;
pos : INT;
arr : ARRAY[0..300] OF SINT;
END_VAR;
i:=1;
pos := 0;
WHILE i < strLen(str := str) DO
IF strMid(str := str, start := i, length := 1) <> " " THEN
arr[pos]:=hexToSint(hex:=strMid(str:=str, start:=i, length:=2));
i := i + 2;
pos := pos + 1;
ELSE
i := i + 1;
END_IF;
END_WHILE;
memcpy(dst:=dst, src:=ADDR(arr), len:=pos);
ParseString:=pos;
END_FUNCTION;
FUNCTION SendN23;
VAR
rc : INT;
len : INT;
tx_frame : ARRAY [1..300] OF USINT;
END_VAR;
len := ParseString(dst := ADDR(tx_frame), str:=
"44"+
"8c2075"+
"900f002c25b30a000021924d4f2fb66e01"+
"7a7500200710"+
" 9058475f4bc91df878b80a1b0f98b629 "+
"024aac727942bfc549233c0140829b93"
);
rc := mbusSetSenderAddress(handle:=mb, sec_addr:="1234567893153303");
DebugFmt(message:="mbusSetSenderAddress(): \1", v1:=rc);
rc := mbusSend(handle:=mb, frame := ADDR(tx_frame), size := len);
DebugFmt(message:="mbusSend(): \1", v1:=rc);
END_FUNCTION;
PROGRAM sender;
VAR
rc : INT;
END_VAR;
rc := mbusOpen(type:=2, handle:=mb);
DebugFmt(message:="mbusOpen(): \1", v1:=rc);
BEGIN
SendN23();
Sleep(delay:=10000);
END;
END_PROGRAM;
|