【问题标题】:32Feet.Net connecting to Bluetooth speakers32Feet.Net 连接蓝牙音箱
【发布时间】:2014-05-15 23:16:45
【问题描述】:

所以我正在尝试从脚本连接蓝牙扬声器。我正在使用 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 的新手,所以我对此不太了解,我尝试在线跟踪代码以了解我所在的位置。

【问题讨论】:

    标签: c# bluetooth 32feet


    【解决方案1】:

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

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

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

    然后

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

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

    【讨论】:

    • BluetoothDeviceInfo.SetServiceState(BluetoothService.Handsfree, true);所以我在调用 find(devInfo) 之后就在我的项目中添加了这行代码。但是由于没有对象,这条线不会编译。我错过了什么吗?
    • 好的,所以现在当我运行我的脚本时,它会提示用户点击屏幕上的徽章(我使用的是 windows 8.1)有没有办法绕过这个并在没有点击的情况下直接连接?
    • 为了帮助其他人,是 SetServiceStart 和 BluetoothWin32Authentication 完成这项工作,还是需要其他魔法?塔
    • 所以我没有使用SetServiceStart,只是BluetoothWin32Authentication。我点击了你也评论过的这个链接,它帮助我了解了我在哪里犯了错误。 stackoverflow.com/questions/6998072/…
    猜你喜欢
    • 1970-01-01
    • 2019-01-31
    • 2011-08-23
    • 2018-03-20
    • 2014-10-12
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多