ADVANCED: mbusSetSenderAddress (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX4,NX-400

Firmware version:

1.94.00


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
// Uncomment math.inc to add math library support.
//INCLUDE math.inc
 
//  These are the global variables of the program
VAR
  mb  : SYSHANDLE;
END_VAR;
 
// Convert hex string into SINT array
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;
 
// Send packet from OMS Annex N.2.3: gas meter with internal radio, security profile B
FUNCTION SendN23;
VAR
  rc       : INT;
  len      : INT;
  tx_frame : ARRAY [1..300] OF USINT;
END_VAR;
  // Hex string with data from example N.2.3:
  len := ParseString(dst := ADDR(tx_frame), str:=
    // C  
     "44"+
    // ELL
     "8c2075"+
    // AFL                                
     "900f002c25b30a000021924d4f2fb66e01"+
    // TPL
     "7a7500200710"+
    // Encrypted TPL/APL
     " 9058475f4bc91df878b80a1b0f98b629 "+
    // Encrypted APL
     "024aac727942bfc549233c0140829b93"
  );
 
  // Set sender address to address from DLL
  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;
// These are the local variables of the program block
VAR
  rc : INT;
END_VAR;
// The next code will only be executed once after the program starts
  rc := mbusOpen(type:=2, handle:=mb);
  DebugFmt(message:="mbusOpen(): \1", v1:=rc);
 
BEGIN
// Code from this point until END will be executed repeatedly
 
  SendN23();
 
  Sleep(delay:=10000);
 
END;
END_PROGRAM;