If you want to read or set a parameter that does not have a custom getter or setter within an XBee device class, you can do so. All the XBee device classes include two methods to get and set any AT parameter.

Get a parameter

You can read the value of any parameter of an XBee device using the GetParameter(string) method. Use this method to get the value of a parameter that does not have its own getter method within the XBee device object.

Method Description

GetParameter(string)

Gets the value of the given parameter from the XBee device. Argument must be a string with the name of the parameter. Returned value is a byte array containing the parameter value.

The GetParameter(string) method may fail for the following reasons:

  • The parameter argument is null, throwing an ArgumentNullException.

  • The length of the parameter argument is different than 2, throwing an ArgumentException.

  • The device is not connected, throwing an InterfaceNotOpenException.

  • There is a timeout reading the parameter, throwing a TimeoutException.

  • Other errors are caught as XBeeException.

Get a parameter from the XBee device
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");

// Connect the device
myXBeeBLEDevice.Connect();

// Get the value of the Sleep Time (SP) parameter.
byte[] sleepTime = myXBeeBLEDevice.GetParameter("SP");

Set a parameter

To set a parameter that does not have its own setter method, you can use the SetParameter(string, byte[]) method provided by all the XBee device classes.

Method Description

SetParameter(string, byte[])

Sets the given parameter with the provided value in the XBee device. Arguments must be a string with the name of the parameter to set and a byte array with the new value of the parameter.

The SetParameter(string, byte[]) method may fail for the following reasons:

  • The parameter or parameter value arguments are null, throwing an ArgumentNullException.

  • The length of the parameter argument is different than 2, throwing an ArgumentException.

  • The device is not connected, throwing an InterfaceNotOpenException.

  • There is a timeout setting the parameter, throwing a TimeoutException.

  • Other errors are caught as XBeeException.

Set a parameter in the XBee device
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");

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

// Configure the Node ID using the SetParameter method.
byte[] sleepTime = myXBeeBLEDevice.SetParameter("NI", Encoding.ASCII.GetBytes("YODA"));