The XBee classes provide a set of methods to get and set common parameters of the physical device. Some of these parameters are saved inside the XBee object, and a cached value is returned when the parameter is requested. Other parameters are read directly from the physical XBee device when requested.
Cached parameters
There are some parameters in an XBee device that are used or requested frequently. To avoid the overhead of those parameters being read from the physical XBee device every time they are requested, they are saved inside the XBee device class as properties.
The following table lists parameters that are cached and their corresponding properties:
| Parameter | Property |
|---|---|
64-bit address |
XBee64BitAddr |
16-bit address |
XBee16BitAddr |
Node Identifier |
NodeID |
Firmware version |
FirmwareVersion |
Hardware version |
HardwareVersion |
IPv4 address (only for Cellular devices) |
IPAddress |
IMEI (only for Cellular devices) |
IMEIAddress |
XBee devices read and save previous parameters automatically when connecting them. They can be refreshed at any time using the ReadDeviceInfo() method. See Read XBee device information for more information.
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");
// Connect the device.
myXBeeBLEDevice.Connect();
// Refresh cached parameters.
myXBeeBleDevice.ReadDeviceInfo();
All cached parameters but the Node Identifier one are read-only parameters. For the Node Identifier, there is a method available in all XBee device classes that allows you to change it:
| Parameter | Method | Description |
|---|---|---|
Node Identifier |
SetNodeID(string) |
Specifies the new node identifier of the device. This method configures the physical XBee device with the provided node identifier and updates the cached property with the new value. The parameter must be a string containing the new Node ID. |
The SetNodeID(string) method may fail for the following reasons:
-
The new node identifier provided is null, throwing an ArgumentNullException.
-
The device is not connected, throwing an InterfaceNotOpenException.
-
There is a timeout setting the node identifier, throwing a TimeoutException.
-
Other errors are caught as XBeeException.
Non-cached parameters
Non-cached parameters are those arguments that are read directly from the physical XBee device every time they are requested. Due to their nature, they are not accessed through properties within the XBee device object. They way to access them (either to read or set the parameter) is through getters and setters methods.
The following table lists the non-cached parameters available in all XBee device classes with their corresponding getters and setters:
| Parameter | Method | Description |
|---|---|---|
Destination address |
SetDestinationAddress(XBee64BitAddress) |
Sets the 64-bit destination extended address of the XBee device. Parameter must be an XBee64BitAddress object with the new address. |
GetDestinationAddress() |
Returns the 64-bit destination extended address of the XBee device. Returned value is an XBee64BitAddress object with the destination address. |
|
PAN ID |
SetPANID(byte[]) |
Sets the PAN ID (Personal Area Network Identifier) of the XBee device. Parameter must be a byte array containing the new PAN ID |
GetPANID() |
Returns the operating PAN ID (Personal Area Network Identifier) of the XBee device. Returned value is a byte array containing the PAN ID. |
|
Power level |
SetPowerLevel(PowerLevel) |
Sets the output power level at which the XBee device transmits conducted power. Parameter must be an entry from the PowerLevel enumeration class. |
GetPowerLevel() |
Returns the output power level at which the XBee device transmits conducted power. Returned value is an entry from the PowerLevel enumeration class. |
All the previous getters and setters from the different parameters may fail for the following reasons:
-
The new parameter to be set is null, throwing an ArgumentNullException.
-
The device is not connected, throwing an InterfaceNotOpenException.
-
There is a timeout getting or setting the parameter, throwing a TimeoutException.
-
Other errors are caught as XBeeException.
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");
// Connect the device.
myXBeeBLEDevice.Connect();
// Set the destination address of the device.
XBee64BitAddress destinationAddress = new XBee64BitAddress("0123456789ABCDEF");
myXBeeBLEDevice.SetDestinationAddress(destinationAddress);
// Read the operating PAN ID of the device.
byte[] operatingPANID = myXBeeBLEDevice.GetPANID();
// Read the output power level.
PowerLevel powerLevel = myXBeeBLEDevice.GetPowerLevel();