In this article I'd like to demonstrate how to enumerate Bluetooth devices using .NETCF and the 32feet.NET library. The following code will work on both Microsoft and Widcomm Bluetooth stacks:
using System.Diagnostics;
using InTheHand.Net.Sockets;
namespace BluetoothSample
{
static class Program
{
private static void Main()
{
BluetoothDeviceInfo[] devices;
using (BluetoothClient sdp = new BluetoothClient())
devices = sdp.DiscoverDevices();
foreach (BluetoothDeviceInfo deviceInfo in devices)
{
Debug.WriteLine(string.Format("{0} ({1})",deviceInfo.DeviceName, deviceInfo.DeviceAddress));
}
}
}
}
An interesting thing I had to consider for this project was the CPU architecture or endianness of the device I'm running on and the device I'm sending data to. I needed to reverse the byte order of the numeric data I sent and received.