0

所以我正在尝试从脚本连接蓝牙扬声器。我正在使用 32feet.net 并且我已成功找到该设备,但是当我尝试配对并连接到它时它不起作用。

这是我用来配对设备的代码,这总是失败,不知道为什么:

 private static void connected(BluetoothDeviceInfo[] dev)
   {
      // dev[foundIndex];
       bool paired=false;

       paired = BluetoothSecurity.PairRequest(dev[foundIndex].DeviceAddress, "1166");

       if (paired)
           Console.WriteLine("Passed, Device is connected.");
       else
           Console.WriteLine("Failed....");
   }

这是连接后调用的代码以实际连接到设备:bc 是我的蓝牙客户端 var。

 bc.BeginConnect(devInfo[foundIndex].DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(Connect), devInfo[foundIndex]);

private static void Connect(IAsyncResult result)
    {
        if (result.IsCompleted)
        {
            Console.Write("Connected... ");
        }

    }

任何帮助,将不胜感激。我是 32feet.net 的新手,所以我对此不太了解,我尝试在线跟踪代码以了解我所在的位置。

4

1 回答 1

0

试试BluetoothDeviceInfo.SetServiceState。这将要求 Windows 连接到设备上的音频服务——希望这能完成这项工作。

请参阅https://32feet.codeplex.com/wikipage?title=Connecting%20to%20Bluetooth%20Services

有时我们不希望我们的应用程序自己向/从远程服务发送数据,但我们希望本地操作系统这样做。带有 HID 的键盘/鼠标/等、带有 DUN/NAP/PAN/等的网络、耳机/免提等就是这种情况。

接着

在这种情况下,简短的回答是使用BluetoothDeviceInfo.SetServiceState。该 API 等效于在蓝牙控制面板中的设备对话框的“服务”选项卡上手动选中相应的复选框。

此外,在安全简单配对的这些日子里,PairRequest只有当所有对等设备都使用旧式 PIN 码身份验证时才可以使用,否则实例化 aBluetoothWin32Authentication然后进行连接(这里间接通过SetServiceState)并在身份验证回调中处理身份验证。

于 2014-05-16T22:03:10.467 回答