相关疑难解决方法(0)

Windows 10上使用32feet.NET的蓝牙配对(SSP)

我刚开始一个项目,要求我将Windows 10平板电脑与另一个蓝牙设备配对.

我决定从一个简单的Windows窗体应用程序开始,熟悉这个过程.我在我的解决方案中添加了32feet.NET NuGet包,并且很快就成功搜索了设备并填充了列表框.

client = new BluetoothClient();
devices = client.DiscoverDevices();
if (devices.Length > 0)
{
    foreach (var device in devices)
    {
        lstBTDevices.Items.Add(device.DeviceName);
    }
}
else
{
    MessageBox.Show("Unable to detect any bluetooth devices");
}
Run Code Online (Sandbox Code Playgroud)

然后我添加了一个事件处理程序,以便我可以选择一个检测到的设备并尝试与它配对.

    private void LstBTDevices_SelectedIndexChanged(object sender, EventArgs e)
    {
        BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex];
        if (MessageBox.Show(String.Format("Would you like to attempt to pair with {0}?", selectedDevice.DeviceName), "Pair Device", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            if (BluetoothSecurity.PairRequest(selectedDevice.DeviceAddress, "123456"))
            {
                MessageBox.Show("We paired!");
            }
            else
            {
                MessageBox.Show("Failed to pair!");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

在我的带有廉价蓝牙2.0适配器的Windows7台式电脑上,这会导致我的手机上出现一个弹出窗口,要求我输入密码.当我输入"123456"时,配对成功.

但是,这就是问题的起点.然后我拿起我的应用程序并在我的Windows10平板电脑上运行它,现在当我选择我的手机时,它会在我的手机上显示一个弹出窗口,其中包含一个随机的6位数密码,并显示一条消息,它应该与我平板电脑屏幕上显示的内容相匹配,配对/取消按钮作为选项.按任一按钮都会导致失败. …

c# bluetooth 32feet

27
推荐指数
1
解决办法
5562
查看次数

将蓝牙设备与具有32英尺.NET蓝牙库的计算机配对

如果您想知道如何使用32feet.NET库与蓝牙设备通信,请阅读解决方案


我目前正在尝试通过蓝牙在计算机和自建的.NET Gadgeteer原型之间进行通信.

Gadgeteer原型包括主板,电源和蓝牙模块.模块处于可发现模式.

在计算机上,基于32feet .NET蓝牙的自定义蓝牙程序正在运行.程序检测范围内的所有蓝牙设备并尝试与它们配对.但是,目前还没有自动完成,我必须输入设备的配对代码.

如何在不输入配对代码的情况下配对设备?

找到设备,问题是配对部分.我做了很多实验,但没有找到解决方案......

foreach (BluetoothDeviceInfo device in this.deviceList)
{
    try
    {
        //BluetoothClient client = new BluetoothClient(this.CreateNewEndpoint(localAddress));
        //BluetoothEndPoint ep = this.CreateNewEndpoint(device.DeviceAddress);

        EventHandler<BluetoothWin32AuthenticationEventArgs> handler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(HandleRequests);
        BluetoothWin32Authentication auth = new BluetoothWin32Authentication(handler);

        BluetoothSecurity.PairRequest(device.DeviceAddress, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码块启动配对并且它可以工作,但Windows要求我输入设备的配对代码.我读到了关于BluetoothWin32Authentication以防止这种情况,但我没有把它弄好.

private void HandleRequests(object that, BluetoothWin32AuthenticationEventArgs e)
{
    e.Confirm = true;
}
Run Code Online (Sandbox Code Playgroud)

这是事件处理程序的代码(http://32feet.codeplex.com/wikipage?title=BluetoothWin32Authentication)

如果你只想让SSP设备连接时允许配对继续,那么处理回调和设置e.Confirm = True就足够了 - 但这有点不安全......


我很困惑-.-目标是应用程序和gadgeteer模块可以在没有任何用户干扰的情况下向两个方向发送数据.

没有用户交互,我无法自动配对设备吗?

是否真的如果两个设备已经配对,他们可以在没有用户交互的情况下交换数据?

c# bluetooth .net-gadgeteer 32feet

26
推荐指数
1
解决办法
6万
查看次数

标签 统计

32feet ×2

bluetooth ×2

c# ×2

.net-gadgeteer ×1