Before communicating with the Digi device via Bluetooth Low Energy, you must establish the connection. Use the Connect() method of the Digi device object to do so.

The Connect() method triggers an authentication process with the physical Digi device and uses the Bluetooth password to unlock the communication. This process is executed in the background by the Digi IoT Library for .NET MAUI. Once authentication is complete and the device is connected, you can interact with it using the APIs provided by the library.

If the device is not connected, any task executed by the device object involving communication with the physical object returns an InterfaceNotOpenException runtime exception, terminating the execution of your application. Similarly, if you try to connect with a device that is already connected, you receive an InterfaceAlreadyOpenException runtime exception and your application exit.

Open the device connection

// Instantiate a Digi device object.
DigiBLEDevice myDigiBLEDevice = new DigiBLEDevice("00:00:00:00:00:00", "password");

// Connect the device.
myDigiBLEDevice.Connect();

The Connect() method may fail for the following reasons:

  • There is an error during the Bluetooth authentication process, returning a BluetoothAuthenticationException.

  • The device is already connected, returning an InterfaceAlreadyOpenException.

All other possible errors return a DigiIoTException.

In the case of XBee devices, the Connect() action performs other operations in addition to connecting the device. It also reads the device identification information and determines the operating mode and protocol of the XBee device.