Try this:
var client = new BluetoothClient();
var dlg = new SelectBluetoothDeviceDialog();
DialogResult result = dlg.ShowDialog(this);
if (result != DialogResult.OK)
{
return;
}
BluetoothDeviceInfo device = dlg.SelectedDevice;
BluetoothAddress addr = device.DeviceAddress;
Console.WriteLine(device.DeviceName);
BluetoothSecurity.PairRequest(addr, "Whatever pin");
device.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
Thread.Sleep(100); // Just in case
if (device.InstalledServices.Length == 0)
{
// I wouldn't know why it doesn't install the service
}
client.Connect(addr, BluetoothService.HumanInterfaceDevice);
I am no expert by any means, but for me:
- I need to pair the device if the device doesn't show in the Bluetooth devices. You just need to do this once with every new device you discover with the Bluetooth radio, or if you uninstall it, I do it every time anyway just in case a new device is selected.
- Start the service, once I do this the device will show that a serial port (in your case HID) is available under "Services" in the device's properties.
- Connect
In every stage something needs to happen:
- Make sure the device appears in "Bluetooth devices" in the "Control panel".
- Under the "Services" tab inside the device's "Properties" it should say "Human Interface" or something.
- That service should be ticked.
On another note, the exception that you get is really cryptic, but it just made me think if the device is not already connected to something. If you check "device.Connected" it must return false or you won't ever be able to connect.