所以我试图从脚本连接蓝牙音箱。我正在使用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的新手所以我对此不太了解,我尝试在线跟踪代码以获得我的位置。
答案 0 :(得分:0)
试试BluetoothDeviceInfo.SetServiceState
。这将要求Windows连接到设备上的音频服务 - 希望能够完成这项工作。
请参阅https://32feet.codeplex.com/wikipage?title=Connecting%20to%20Bluetooth%20Services
有时我们不希望我们的应用程序自己向远程服务发送数据或从远程服务发送数据,但我们希望本地操作系统这样做。具有HID的键盘/鼠标/等,使用DUN / NAP / PAN /等的网络,耳机/免提等等。
然后
在这种情况下,简短的回答是使用 BluetoothDeviceInfo.SetServiceState 。这个API相当于手动检查蓝牙控制面板中“设备”对话框的“服务”选项卡上的相应复选框。
此外,在安全简单配对的这些日子里,只有当所有对等设备都使用旧式PIN码验证时才使用PairRequest
,否则请实例化BluetoothWin32Authentication
然后进行连接(此处为间接连接)通过SetServiceState
)并在身份验证回调中处理身份验证。