Код: Выделить всё
try
{
BluetoothClient bluetoothClient = new BluetoothClient();
Console.WriteLine("Scanning for Bluetooth devices...");
BluetoothDeviceInfo[] devices = bluetoothClient.DiscoverDevices();
for (int i = 0; i < devices.Length; i++)
{
Console.WriteLine($"{i + 1}. {devices[i].DeviceName} ({devices[i].DeviceAddress})");
}
Console.Write("Enter the number of the device you want to connect to: ");
int deviceIndex = int.Parse(Console.ReadLine()) - 1;
if (deviceIndex < 0 || deviceIndex >= devices.Length)
{
Console.WriteLine("Invalid device number.");
return;
}
BluetoothDeviceInfo selectedDevice = devices[deviceIndex];
string deviceAddress = selectedDevice.DeviceAddress.ToString();
Console.WriteLine($"Connecting to {selectedDevice.DeviceName}...");
BluetoothEndPoint endPoint = new BluetoothEndPoint(selectedDevice.DeviceAddress, BluetoothService.SerialPort);
bluetoothClient.Connect(endPoint);
Console.WriteLine("Connected successfully!");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
Console.ReadKey();
}
Код: Выделить всё
An error occurred: The requested address is not valid in its context. 05B197028654::0000110100001000800000805f9b34fb
Подробнее здесь: https://stackoverflow.com/questions/788 ... 05b1970286