mbusScan (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX4

Firmware version:

1.94.00


This function is used to scan for slaves on wired M-Bus.

The search for primary addresses is done by checking every address. Depending on the baud rate, this can take a few minutes.

 

The search for secondary addresses is done using a mask, where only the address space containing devices will be scanned. Depending on the baudrate and the devices on the bus, the scan can take many minutes.

 

 

Input:

handle : SYSHANDLE

A handle to the connection

 

smode : SINT default 1

The scan mode determining the address type to scan for:

1

- Primary address (0-250)

2

- Secondary (16 character id)

 

mask : STRING default "FFFFFFFFFFFFFFFF"

String containing the mask to use for filtering the addresses in scan mode 2.

The mask must be 16 characters long and must use 'F' as placeholder for unknown values.

The mask contains:

4 bytes with the device ID, encoded as BCD.

2 bytes for the manufacturer ID as binary.

1 byte for the device version as binary.

1 byte for the device media as binary.

 

For a device with device ID 12345678, manufacturer ID 0x1C36, version 123 and medium 7, the secondary address would be "12345678361C7B07".

To search for a device ID 12345678, use mask "12345678FFFFFFFF".

To search for devices starting with "123", use mask "123FFFFFFFFFFFFF".

For the device ID, each nibble can be replaced with 'F', the rest of the fields can only use wildcards for the entire field, i.e. 'FF' for version or medium, 'FFFF' for manufacturer ID.

 

cb_found : CALLBACK

The callback function to call for every found slave. (See the mbusScanFoundCallback callback declaration below)

 

cb_progress : CALLBACK

Callback function to call before every search to indicate the progress. (See the mbusScanProgressCallback callback declaration below)

 

 

 

Returns: INT

1

- Success

0

- Not supported

-1

- Invalid handle

-5

- Invalid interface type

-7

- Invalid mask.

-9

- Communication error

 

Declaration:

FUNCTION mbusScan : INT;
VAR_INPUT
  handle     : SYSHANDLE;
  cb_found   : CALLBACK;
  cb_progress : CALLBACK;
  mask       : STRING := "FFFFFFFFFFFFFFFF";
  smode       : SINT := 1;
END_VAR;

 

FUNCTION CALLBACK mbusScanFoundCallback;
VAR_INPUT
  handle      : SYSHANDLE; // Handle to the connection.
  secondary   : STRING; // The secondary address of the slave. Only available for smode 2.
  primary     : INT; // The primary address of the slave.
END_VAR;
END_FUNCTION;

 

FUNCTION CALLBACK mbusScanProgressCallback;
VAR_INPUT
  handle      : SYSHANDLE; // Handle to the connection.
  secondary   : STRING; // The mask of the secondary address currently being scanned.
  primary     : INT; // The primary address currently being scanned. -1 for secondary scan.
END_VAR;
END_FUNCTION;

 

 

Example:

INCLUDE rtcu.inc
 
FUNCTION CALLBACK OnScan;
VAR_INPUT
  handle      : SYSHANDLE;
  secondary   : STRING;
  primary     : INT;
END_VAR;
  DebugFmt(message:="device found: \1: "+secondary, v1:=primary);
END_FUNCTION;
 
FUNCTION CALLBACK OnProgress;
VAR_INPUT
  handle      : SYSHANDLE;
  secondary   : STRING;
  primary     : INT;
END_VAR;
  DebugFmt(message:="scanning: \1: "+secondary, v1:=primary);
END_FUNCTION;
 
PROGRAM test;
VAR
  mb : SYSHANDLE;
  rc : INT;
END_VAR;
 
  ...
  // Open wired M-Bus interface
  rc := mbusOpen(handle := mb);
  ...
  // Start scan for any secondary address
  rc := mbusScan(handle:=mb, cb_found:=@OnScan, cb_progress:=@OnProgress, smode:=2, mask:="FFFFFFFFFFFFFFFF");
  DebugFmt(message:="mbusScan(): \1", v1:=rc);
BEGIN
 
  ...
END;
END_PROGRAM;