我正面临一种非常奇怪的三重头痛。我使用统一引擎和BrainLink蓝牙设备作为输入源。我通过代码自动连接到BrainLink设备,使用一个名为Neurosky.ThinkGear的库,到目前为止,这两种设备可以很好地结合在一起,但前提是设备是通过蓝牙和其他设备窗口手动配对的。
现在,我也被要求对的设备自动,这是我遇到了一个障碍。因为使用Unity,我不能使用windows运行时的东西(比如Windows.Enumeration.Devices),所以我决定为蓝牙设备使用InTheHand 32 32Feet解决方案,这似乎有点工作。如果它还没有出现在蓝牙和其他设备中,它就会出现在列表中,并且它也被列为配对设备。问题是,当通过代码而不是手动配对时,处理连接到设备的库(前面提到的Neurosky.ThinkGear)无法连接到设备。只有当设备被移除并通过蓝牙和Oher设备窗口再次配对时,它才会连接。
我目前正在测试的代码如下:
private void Start()
{
Debug.Log("Operation Start");
//btClient is a class field
btClient = new BluetoothClient();
//Search for existing paired devices that contain "brainlink" in their name
BluetoothDeviceInfo btDevice = CheckExistingPairedDevices();
if (btDevice == null)
{
Debug.Log("No paired device found, trying to discover");
//Try to discover devices in range with "brainlink" in their name
btDevice = TryDiscoverDevice();
}
if(btDevice!= null)
{
Debug.Log("Found Device " + btDevice.DeviceName+", checking for pairing");
bool paired = AttemptPair(btDevice);
Debug.Log("Pair Status: " + paired);
}
else
{
Debug.Log("Could not discover device");
}
CloseClient();
}这是处理配对的方法。目前,我从来没有传递一个值,但它在那里,以防万一,我需要支持其他设备在未来。
private bool AttemptPair(BluetoothDeviceInfo btDevice, string pin = null)
{
//Check if this device has been paired before
if (btDevice.Authenticated)
return true;
bool result = BluetoothSecurity.PairRequest(btDevice.DeviceAddress, pin);
btDevice.Refresh();
return result;
}发布于 2021-11-23 09:54:58
我对你的设备/工具一无所知,但我所知道的是,要建立蓝牙连接,我们需要首先发现设备--。
原因是这样的发现创建了一个后来用于蓝牙操作(例如配对、连接)的对象。
这个设备出现在蓝牙和其他设备中,如果它还没有出现的话,它也被列为配对设备。
我想,你说的是以前的配对设备。出现在列表中的设备可能并不意味着该设备目前已被发现。我建议在首先执行发现的地方更改代码,。
https://stackoverflow.com/questions/70077656
复制相似问题