Sending and receiving data from the MicroPython interface of the physical XBee device means you are communicating with the MicroPython application running inside the XBee device.

Send MicroPython data

The XBee device classes of the Digi IoT Library for .NET MAUI provide the method SendMicroPythonData(byte[]) to send data to the MicroPython interface of the physical XBee device.

Method Description

SendMicroPythonData(byte[])

Sends the given data to the XBee MicroPython interface of the XBee device. Parameter must be a byte array containing the data to send.

The SendMicroPythonData(byte[]) method is asynchronous, which means your application does not block during the transmit process. The SendMicroPythonData(byte[]) method may fail for the following reasons:

  • The communication interface with the device is not open, throwing an InterfaceNotOpenException.

  • Other errors are caught as XBeeException.

Send MicroPython data
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");

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

String data = "MicroPython, are you there?";

// Send the data to the MicroPython interface.
myXBeeBLEDevice.SendMicroPythonData(Encoding.UTF8.GetBytes(data));

Receive MicroPython data

You can be notified when new data from the MicroPython interface has been received if you are subscribed to the MicroPythonDataReceived event of the XBee device classes.

Receive MicroPython data
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");

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

// Subscribe to MicroPython data received event.
EventHandler<MicroPythonDataReceivedEventArgs> handler = (sender, e) => Console.WriteLine(">> From MicroPython: " + Encoding.ASCII.GetString(e.Data));
myXBeeBLEDevice.MicroPythonDataReceived += handler;

Whenever MicroPython data is received, the handler callback is executed and provides as parameter the MicroPythonDataReceivedEventArgs object (e), which contains the received MicroPython data.