我正在尝试在 C# 应用程序中使用 32feet.NET 蓝牙库来检测附近的设备。我这个小应用程序的目的是利用人们手机的蓝牙功能让PC知道房间里有谁。
执行此类操作的最佳方法是让我想“跟踪”的设备连接一次,然后不断检查是否可以通过蓝牙检测到它们。
现在我的问题:
我知道所有这些可能都在库文档中,但对我来说真的很难阅读,而且大多数示例似乎都在 VB 中,我不知道并且很难将其转换为 C#(尤其是在涉及到AsyncCallbacks 等)。
如果有人能在正确的方向上插入我,我会非常高兴!
最佳答案
这不是答案,但我无法将这么多代码放在评论部分。更改这些代码行:
//continue listening for other broadcasting devices
listener.BeginAcceptBluetoothClient(this.BluetoothListenerAcceptClientCallback, listener);
// create a connection to the device that's just been found
BluetoothClient client = listener.EndAcceptBluetoothClient();
至
// create a connection to the device that's just been found
BluetoothClient client = listener.EndAcceptBluetoothClient();
// continue listening for other broadcasting devices
listener.BeginAcceptBluetoothClient(this.BluetoothListenerAcceptClientCallback, listener);
基本上就是改变代码的顺序.. 至于每次调用BeginXXXX方法都必须有下一个EndXXXX。和上面的所有代码,您正在尝试通过 开始 BeginAcceptBluetoothClient 已经开始 “BeginAcceptBluetoothClient”。
希望你能理解。
关于c# - 32feet.net 如何在 C# 中异步发现附近的蓝牙设备,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7773000/