XBee.Core 2.0.0

dotnet add package XBee.Core --version 2.0.0                
NuGet\Install-Package XBee.Core -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XBee.Core" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XBee.Core --version 2.0.0                
#r "nuget: XBee.Core, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XBee.Core as a Cake Addin
#addin nuget:?package=XBee.Core&version=2.0.0

// Install XBee.Core as a Cake Tool
#tool nuget:?package=XBee.Core&version=2.0.0                

XBee

A .NET and UWP library package for XBee wireless controllers.

  • Support for Series1, Series 2, 900HP, and Cellular
  • Simple async/await command and query model
  • .NET Rx support for async receive and sampling.

Features

  • Local and remote device discovery
  • Local and remote device configuration
  • Pin configuration
  • Pin control
  • Pin monitoring
  • Digital and analog sample monitoring via events or .NET Rx
  • Data transmit
  • Data receive via events or .NET Rx

UWP Quick Start

Here is a simple example with a coordinator and an arbitrary number of end devices that we're going to configure and monitor for sampling.

Note that for UWP apps you will need to declare a serial communications device capability in your app manifest.

  <Capabilities>
    <DeviceCapability Name="serialcommunication">
      <Device Id="any">
        <Function Type="name:serialPort" />
      </Device>
    </DeviceCapability>
  </Capabilities>

var controllers = await XBeeController.FindControllersAsync(9600);

var controller = controllers.First();

// setup a simple callback for each time we discover a node
controller.NodeDiscovered += async (sender, args) => 
{
    Console.WriteLine("Discovered {0}", args.Name);
    
	// setup some pins
    await args.Node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel2, InputOutputConfiguration.DigitalIn);
    await args.Node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel3, InputOutputConfiguration.AnalogIn);
    
	// set sample rate
    await args.Node.SetSampleRateAsync(TimeSpan.FromSeconds(5));
    
	// register callback for sample recieved from this node
	// TODO: in practice you would want to make sure you only subscribe once (or better yet use Rx)
    args.Node.SampleReceived += (node, sample) => Console.WriteLine("Sample recieved: {0}", sample);
}

// now discover the network, which will trigger the NodeDiscovered callback for each node found
await controller.DiscoverNetworkAsync();

Console.ReadKey();

// wait for the samples to flow in...

.NET Quick Start

Here is a simple example with a coordinator on COM3 and an arbitrary number of end devices that we're going to configure and monitor for sampling.

var controller = new XBeeController();

// setup a simple callback for each time we discover a node
controller.NodeDiscovered += async (sender, args) => 
{
    Console.WriteLine("Discovered {0}", args.Name);
    
	// setup some pins
    await args.Node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel2, InputOutputConfiguration.DigitalIn);
    await args.Node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel3, InputOutputConfiguration.AnalogIn);
    
	// set sample rate
    await args.Node.SetSampleRateAsync(TimeSpan.FromSeconds(5));
    
	// register callback for sample recieved from this node
	// TODO: in practice you would want to make sure you only subscribe once (or better yet use Rx)
    args.Node.SampleReceived += (node, sample) => Console.WriteLine("Sample recieved: {0}", sample);
}

// open the connection to our coordinator
await controller.OpenAsync("COM3", 9600);

// now discover the network, which will trigger the NodeDiscovered callback for each node found
await controller.DiscoverNetworkAsync();

Console.ReadKey();

controller.Dispose();

// wait for the samples to flow in...

If you don't know a priori what port the XBee will be attached to you can also scan for it:

var controller = await XBeeController.FindAndOpenAsync(SerialPort.GetPortNames(), 9600);

if(controller != null)
   // ...

Nodes

The XBeeController class represents the local serial attached XBee API. This would typically be a coordinator but could be any device to be controlled via a serial port.

While the controller represents the API, if we want to control the node itself we need to access the local node property.

var localNode = controller.Local;
// which is the same as calling await controller.GetNodeAsync(); // (address = null)

var serialNumber = await localNode.GetSerialNumberAsync();
// etc

This allows us to treat the local node and remote nodes in the same fashion.

var remoteNode = await controller.GetNodeAsync(address);
var serialNumber = await remoteNode.GetSerialNumberAsync();

The address for the remote node can be determined in a number of ways. Either connect the remote node physically and use one of the X-CTU utilities (or the above code) or use network discovery.

In some cases, you may have to cast the node to a specific device class to access functions that are not broadly supported. For example:

var remoteNode = (XBeeSeries1) await controller.GetNodeAsync(address);
var pullUpResistorConfig = await remoteNode.GetPullUpResistorConfigurationAsync();

Command and Events

XBees are based on a sort of command-event model where the coordinator is either telling the XBee to do something or the XBee is telling the coordinator that something happened.

Commands

The first type of command is what XBee calls AT commands. An example is a command that can be used to configure pins on the XBee, setting pins high or low or reserving them for input.

await node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel4, InputOutputConfiguration.DigitalHigh);

This will force pin DIO4 high. Note that which physical pin this translates to depends on the model.

Below is a table summarizing the commands supported by this library.

AT Commands
Description Query Command S1 S2 Pro900 Cellular
HV Hardware Version GetHardwareVersionAsync --
AP API Mode GetApiModeAsync SetApiModeAsync
RE Restore Defaults -- RestoreDefaultsAsync
FR Soft Reset -- ResetAsync
BD Interface Data Rate GetBaudRateAsync SetBaudRateAsync
NB Parity GetParityAsync SetParityAsync
SB Stop Bits GetStopBitsAsync SetStopBitsAsync
DB Signal Strength GetSignalStrengthAsync --
RO Packetization Timeout GetPacketizationTimeoutAsync SetPacketizationTimeoutAsync
FT Flow Control Threshold GetFlowControlThresholdAsync SetFlowControlThresholdAsync
NI Node Identifier GetNodeIdentifierAsync SetNodeIdentifierAsync
CN Exit Command Mode -- ExitCommandModeAsync
WR Write Command -- WriteChangesAsync
SH/SL Serial Number GetSerialNumberAsync --
DH/DL Destination Address GetAddressAsync SetDestinationAddressAsync
MY Source Address GetAddressAsync SetSourceAddressAsync Note 1
SC Scan Channels GetScanChannelsAsync SetScanChannelsAsync
SD Scan Duration GetScanDurationAsync SetScanDurationAsync
ND Network Discovery -- DiscoverNetworkAsync
NT Discovery Timeout GetNetworkDiscoveryTimeoutAsync SetNetworkDiscoveryTimeoutAsync
AI Association Indicator GetAssociationAsync --
A1 End Device Association GetEndDeviceAssociationOptionsAsync SetEndDeviceAssociationOptionsAsync
A2 Coordinator Association GetCoordinatorAssociationOptionsAsync SetCoordinatorAssociationOptionsAsync
DA Force Disassociation -- DisassociateAsync
D(N) DIO Configuration GetInputOutputConfigurationAsync SetInputOutputConfigurationAsync
IC Input Change GetChangeDetectionChannelsAsync SetChangeDetectionChannelsAsync
IR Sample Rate GetSampleRateAsync SetSampleRateAsync
IS Force Sample -- ForceSampleAsync
ID PAN ID / Module VID GetPanIdAsync/GetModuleVidAsync SetPanIdAsync/SetModuleVidAsync
RP RSSI PWM Timer GetRssiPwmTimeAsync SetRssiPwmTimeAsync
PR Pull-up Resistor Config GetPullUpResistorConfigurationAsync SetPullUpResistorConfigurationAsync
SM Sleep Mode GetSleepModeAsync SetSleepModeAsync
SO Sleep Mode Options GetSleepOptionsAsync SetSleepOptionsAsync
SP Sleep Period GetSleepPeriodAsync SetSleepPeriodAsync
SN Sleep Period Count GetSleepPeriodCountAsync SetSleepPeriodCountAsync
ZS Stack Profile GetStackProfileAsync SetStackProfileAsync
NJ Node Join Time GetNodeJoinTimeAsync SetNodeJoinTimeAsync
JV Channel Verification IsChannelVerificationEnabledAsync SetChannelVerificationEnabledAsync
NW Network Watchdog GetNetworkWatchdogTimeoutAsync SetNetworkWatchdogTimeoutAsync
JN Join Notification IsJoinNotificationEnabledAsync SetJoinNotificationEnabledAsync
CB Commissioning Button -- PushCommissioningButtonAsync
DD Device Type Identifier GetDeviceTypeIdentifierAsync SetDeviceTypeIdentifierAsync
%V Supply Voltage GetSupplyVoltageAsync --
EE Encryption Enable IsEncryptionEnabledAsync SetEncryptionEnabledAsync
KY Encryption Key -- SetEncryptionKeyAsync
CE Coordinator Enable IsCoordinatorAsync SetCoordinatorAsync
CH Channel GetChannelAsync SetChannelAsync
AI Association Indicator GetAssociationAsync SetAssociationAsync
NR Reset Network -- ResetNetworkAsync
PH Phone Number GetPhoneNumberAsync --
S# ICCID GetIccidAsync --
IM IMEI GetImeiAsync --
MN Network Operator GetNetworkOperatorAsync --
MV Modem Firmware Version GetModemFirmwareVersionAsync --
IP Internet Protocol GetInternetProtocolAsync SetInternetProtocolAsync
TL SSL Protocol GetSslProtocolAsync SetSslProtocolAsync
TM Client Timeout GetTcpClientConnectionTimeoutAsync SetTcpClientConnectionTimeoutAsync
DO Device Option GetDeviceOptionAsync SetDeviceOptionAsync
AN Access Point Name GetAccessPointNameAsync SetAccessPointNameAsync

All other commands are currently unsupported but feel free to file an issue if you'd like to see something that isn't here.

Note 1: Use GetIPAddressAsync.

Serial Data

The second type of command involves sending arbitrary serial data to a node. In the simplest case this can act as a transparent passthrough as most XBees will pass the serial data to their local UART. However, in the case of programmable XBees it is possible to intercept the serial data and store it, interpret it, etc.

await node.TransmitDataAsync(Encoding.UTF8.GetBytes("Hello!"));

Events

Somewhat confusingly, XBees have two different mechanisms for asychronously sending data to the coordinator. The first is sampling and the second is serial data. Samples coorespond to our pin example from above and represent the "input" part of GPIO.

As such, we can configure a pin to take and return a sample to the coordinator.

// subscribe to the node
node.SampleReceived += (o, eventArgs) => Console.WriteLine(eventArgs.DigitalSampleState);

// configure a pin for digital sampling
await node.SetInputOutputConfigurationAsync(InputOutputChannel.Channel5, InputOutputConfiguration.DigitalIn);

At this point the node is set to send samples from pin DIO5 but not necessarily to take samples. There are three ways to trigger a sample: forced, periodic, or change detect.

await node.ForceSampleAsync(); // force
await node.SetSampleRateAsync(TimeSpan.FromSeconds(5)); // periodic
await node.SetChangeDetectionChannelsAsync(DigitalSampleChannels.Input5); // change detect

The second mechanism for asynchronous remote data transmit is simply the receive side of the transparent serial channel.

node.DataReceived += (o, eventArgs) => Console.WriteLine("Received {0} bytes", eventArgs.Data.Length);

Again, this data would either be supplied by the external UART on the remote node or by the microcontroller on the remote node.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on XBee.Core:

Package Downloads
XBee

A UWP and .NET classic library for controlling XBee wireless modules.

XBee.Classic

A .NET library for controlling XBee wireless modules.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 137 9/4/2024
1.6.6 788 7/29/2020
1.6.5-alpha 421 7/13/2019
1.6.4.1 673 5/16/2019
1.6.4 562 5/15/2019
1.6.3 999 8/8/2018
1.6.2 936 4/23/2018
1.5.10 949 2/27/2018
1.5.9 959 2/18/2018
1.5.8 1,002 2/7/2018
1.5.7 1,025 1/3/2018
1.5.6 892 9/24/2017
1.5.5 898 9/23/2017
1.5.4 872 9/17/2017
1.5.3 912 9/11/2017
1.5.2 873 9/10/2017
1.5.1 863 9/10/2017
1.5.0 890 8/19/2017
1.5.0-beta 728 8/12/2017
1.4.4 927 8/5/2017
1.4.3 1,720 7/29/2017
1.4.1 1,368 7/8/2017
1.4.0 914 7/8/2017
1.3.0 1,131 7/5/2017
1.3.0-beta 883 7/4/2017
1.2.1 898 7/4/2017
1.2.0 1,023 7/4/2017
1.1.0 888 7/4/2017
1.0.0 1,417 6/15/2017
1.0.0-beta4 869 6/10/2017
1.0.0-beta3 723 6/3/2017
1.0.0-beta2 795 5/29/2017
1.0.0-beta 748 5/29/2017

Updated to .NET 8