I am trying to write a program in C# with that connects to the Nintendo Switch JoyCon controller (which is a Bluetooth HID device) using the 32feet library. I want to bypass the buggy Bluetooth pairing system in Windows 10, so this is why I am writing my own solution. Also, I am aware that there are many drivers out there for this controller, but I haven't had much luck with any of them, and I want to try to make it myself.
Here is my code so far:
var client = new BluetoothClient();
var devices = client.DiscoverDevices().ToList();
var device = devices.FirstOrDefault(d => d.DeviceName.Contains("Joy-Con (L)"));
if (device != null)
{
Console.Out.WriteLine("Found Device!");
Console.Out.WriteLine(" Name: " + device.DeviceName);
Console.Out.WriteLine(" Address: " + device.DeviceAddress);
Console.Out.WriteLine(" Authenticated: " + device.Authenticated);
Console.Out.WriteLine(" Connected: " + device.Connected);
Console.Out.WriteLine(" HID: " + device.InstalledServices.Contains(BluetoothService.HumanInterfaceDevice));
try
{
Console.Out.WriteLine("Enabling Service...");
device.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
Console.Out.WriteLine("Connecting...");
client.Connect(device.DeviceAddress, BluetoothService.HumanInterfaceDevice); // Program.cs:line 36
Console.Out.WriteLine("Connected!");
}
catch (Exception e)
{
Console.WriteLine("Failed to connect.");
Console.Out.WriteLine(e);
}
var stream = client.GetStream();
// ...
Console.ReadLine();
}
Currently my program can discover the device, but when I try to connect, I get an exception.
Here is the output from the code above:
Found Device!
Name: Joy-Con (L)
Address: 48A5E761AB55
Authenticated: True
Connected: False
HID: True
Enabling Service...
Connecting...
Failed to connect.
System.Net.Sockets.SocketException (0x80004005): A socket operation failed because the destination host was down
at InTheHand.Net.Sockets.Win32Socket.ThrowOnSocketError(Int32 result, Boolean throwOnDisconnected)
at InTheHand.Net.Sockets.Win32Socket.Connect(EndPoint remoteEP)
at InTheHand.Net.Sockets.BluetoothClient.DoConnect(BluetoothAddress address, Guid service)
at InTheHand.Net.Sockets.BluetoothClient.Connect(BluetoothAddress address, Guid service)
at BTJoyConTest.Program.Main(String[] args) in Program.cs:line 36
As you can see, the device is paired (device.Authenticated) and it reports that it supports HID.
I've never used 32feet before, so I might be missing something from the code. Any help is appretiated.
User contributions licensed under CC BY-SA 3.0