This function is used to change the address used when sending Wireless M-Bus frames with mbusSend.
Input:
handle : SYSHANDLE
A handle to the connection
sec_addr : STRING
The address to use when sending.
Returns: INT
1
|
- Success
|
0
|
- Not supported
|
-1
|
- Invalid handle
|
-5
|
- Invalid interface type.
|
-6
|
- Invalid address
|
-9
|
- Communication error
|
Declaration:
FUNCTION mbusSetSenderAddress : INT;
VAR_INPUT
handle : SYSHANDLE;
sec_addr : STRING;
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;
|