All XBee classes of the Digi IoT Library for .NET MAUI include the method ReadIOSample(), which is used to get the value of all enabled digital and analog IO channels of the XBee device.

Method Description

ReadIOSample()

Returns an IO sample from the XBee device containing the value of all enabled digital IO and analog input channels. Returned value is an IOSample object.

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

  • The device is not connected, throwing an InterfaceNotOpenException.

  • There is a timeout getting reading the sample, throwing a TimeoutException.

  • Other errors are caught as XBeeException.

You must have at least one IO line configured to read a sample.
Read an IO sample
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");

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

// Configure the DIO2_AD2 line to be ADC input.
myXBeeBLEDevice.SetIOConfiguration(IOLine.DIO2_AD2, IOMode.ADC);

// Read a sample.
IOSample sample = myXBeeBLEDevice.ReadIOSample();

// Get the DIO2_AD2 value.
int ad2Value = sample.GetAnalogValue(IOLine.DIO2_AD2);

Due to an issue in the firmware, the ReadIOSample() method will fail with a TimeoutException in XBee 3 Zigbee devices.