C#中的蓝牙,哪个堆栈,哪个SDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1057220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bluetooth in C#, Which stack, Which SDK?
提问by badbod99
We've got an application which needs to be able to use bluetooth for the following requirements:
我们有一个应用程序需要能够使用蓝牙来满足以下要求:
- Receive files from bluetooth devices (up to 2 devices at the same time)
- Display all bluetooth devices in range
- Send files to bluetooth devices
- Scan for bluetooth devices and transfer files at the same time
- 从蓝牙设备接收文件(最多同时接收 2 个设备)
- 显示范围内的所有蓝牙设备
- 将文件发送到蓝牙设备
- 同时扫描蓝牙设备和传输文件
We're running on Windows XP.
我们在 Windows XP 上运行。
I've done some looking around and there seems to be 3 main stacks:
我环顾四周,似乎有 3 个主要堆栈:
BlueSoleil
蓝太阳
On the BlueSoleil website, in their SDK section, it seems to mention only 1 connection is supported, which is obviously no good.
在BlueSoleil网站上,在他们的SDK部分,似乎提到只支持1个连接,这显然不好。
Windows
视窗
Only seems to support 1 bluetooth dongle, which will probably mean we can't meet all our requirements.
似乎只支持 1 个蓝牙加密狗,这可能意味着我们无法满足所有要求。
Widcomm
无线通讯
Expensive and potentially overkill? More complex API? Thoughts?
昂贵且可能矫枉过正?更复杂的API?想法?
In terms of SDK for C#, was looking at Franson Bluetools, anyone used this API?
就 C# 的 SDK 而言,正在看 Franson Bluetools,有人用过这个 API 吗?
Thanks
谢谢
采纳答案by alanjmcf
Firstly the disclaimer, I'm the maintainer of the 32feet.NET library. :-)
首先是免责声明,我是 32feet.NET 库的维护者。:-)
I've just checked, and on XP with the Microsoft stack (using one dongle) I can concurrently be receiving two OBEX PUTs and also discovering devices. That's using 32feet.NET's ObexListener class and the BluetoothClient.DiscoverDevices method. To send the OBEX PUTs one can use its ObexWebRequest class. To do multiple parallel connections with ObexListener I just had multiple threads calling its GetContext() method.
我刚刚检查过,在使用 Microsoft 堆栈(使用一个加密狗)的 XP 上,我可以同时接收两个 OBEX PUT 并发现设备。这是使用 32feet.NET 的 ObexListener 类和 BluetoothClient.DiscoverDevices 方法。要发送 OBEX PUT,可以使用其 ObexWebRequest 类。为了使用 ObexListener 进行多个并行连接,我只有多个线程调用其 GetContext() 方法。
So that's maybe simpler than we thought...
所以这可能比我们想象的更简单......
I've also tested it with Andy Hume's OBEX Server using his Brecham.Obex library and the concurrent receive works fine there too. Its available from http://32feet.net/files/folders/objectexchange/entry6511.aspx.
我还使用他的 Brecham.Obex 库在 Andy Hume 的 OBEX 服务器上对其进行了测试,并发接收在那里也能正常工作。它可以从http://32feet.net/files/folders/objectexchange/entry6511.aspx 获得。
On our Widcomm support. Hopefully it doesn't seem too "incomplete" on the client side... Inquiry (device discovery) and connections all work. The server-side still needs a little work however and there are some things the Widcomm API simply doesn't support eg. (programmatic authentication handling).
关于我们的 Widcomm 支持。希望它在客户端看起来不会太“不完整”......查询(设备发现)和连接都有效。服务器端仍然需要一些工作,但是 Widcomm API 根本不支持一些东西,例如。(程序化身份验证处理)。
What was the issue with the samples? Compile-time or run-time? On MSFT stack or Widcomm? Follow-up at http://32feet.net/forums/37.aspxif you prefer.
样品有什么问题?编译时还是运行时?在 MSFT 堆栈或 Widcomm 上?如果您愿意,请访问http://32feet.net/forums/37.aspx。
回答by arbiter
Try this: 32feet.NET. Starting from version 2.4, they support Widcomm stack in addition to Windows stack.
试试这个:32feet.NET。从 2.4 版开始,除了 Windows 堆栈之外,它们还支持 Widcomm 堆栈。
BTW: Why you need to work with two dongles at the same time? Usually single dongle can handle up to 7 devices connected simultaneously.
BTW:为什么你需要同时使用两个加密狗?通常单个加密狗可以处理多达 7 个同时连接的设备。
回答by badbod99
Time to explain exactly what we ended up doing...
是时候解释我们最终做了什么了......
2 dongles why?
2个加密狗为什么?
- If a dongle is doing a scan the transfer rate is massively slowed down
- A dongle can only support 7 concurrent transfers, if you are doing a scan, this drops to 6. If you want to send, receive and scan all at the same time, everything slows down, badly, and you are very limited in channels.
- 如果加密狗正在进行扫描,传输速率会大大降低
- 一个加密狗只能支持 7 个并发传输,如果你在做一个扫描,这个会下降到 6 个。如果你想同时发送、接收和扫描,一切都会变慢,很糟糕,而且你的通道非常有限。
So, the idea is to run one dongle continuously scanning (so devices appear as quickly as possible) and the other dongle reserved for transfers, and since it's not scanning, transfers are nice and quick.
因此,我们的想法是运行一个加密狗连续扫描(因此设备尽可能快地出现)而另一个加密狗保留用于传输,并且由于它不扫描,因此传输既好又快。
Library we used
我们使用的库
After much testing and thought, we ended up opting for WirelessCommunicationLibrary from BT framework.
经过多次测试和思考,我们最终选择了BT 框架中的 WirelessCommunicationLibrary。
It supports Widcomm, Windows, BlueSoleil and the Toshiba stack. It supports all the server side stuff we need, is a well supported commercial product, which works perfectly without error.
它支持 Widcomm、Windows、BlueSoleil 和 Toshiba 堆栈。它支持我们需要的所有服务器端的东西,是一个支持良好的商业产品,完美无误。
Which stack?
哪个栈?
Well, this is a complex one. NONE of the stacks support 2 dongles at the same time. So the only option is to run one dongle on one stack and the other dongle on another. This is where the WCL library comes in handy!
嗯,这是一个复杂的问题。没有一个堆栈同时支持 2 个加密狗。因此,唯一的选择是在一个堆栈上运行一个加密狗,而在另一个堆栈上运行另一个加密狗。这就是 WCL 库派上用场的地方!
Microsoft- If an error occurs during a scan, it's common for the whole stack to crash out. This is not ideal! You have to close and restart radio device, it takes time and is fault prone. But... the Microsoft stack does handle file transfers very nicely.
Microsoft- 如果在扫描过程中发生错误,整个堆栈崩溃是很常见的。这并不理想!您必须关闭并重新启动无线电设备,这需要时间并且容易出错。但是... Microsoft 堆栈确实可以很好地处理文件传输。
Widcomm- Widcomm stack isn't great for file transfers. There is pesky little apps which install with Widcomm which keep trying to take control from your app. You can kill the bttray.exe, which helps, but you still get some strange behaviour from the stack during transfers. I'm sure this can be resolved, but since Windows is poor for scans, makes sense to use Widcomm for scans.
Widcomm- Widcomm 堆栈不适用于文件传输。Widcomm 安装了一些讨厌的小应用程序,它们一直试图控制您的应用程序。您可以终止 bttray.exe,这会有所帮助,但在传输期间您仍然会从堆栈中获得一些奇怪的行为。我确信这可以解决,但由于 Windows 扫描性能不佳,因此使用 Widcomm 进行扫描是有意义的。
So... we've got one dongle set to Widcomm to scan over and over, and one dongle set to Microsoft set to handle only file transfers (in and out).
所以......我们有一个加密狗设置为 Widcomm 来一遍又一遍地扫描,一个加密狗设置为 Microsoft 设置为仅处理文件传输(进出)。
Getting 2 dongles to work
让 2 个加密狗工作
We went for using 2 of the same dongles, we can order them in bulk and stock them all the same reducing confusion. Each device shipped just needs 2 bluetooth dongles, simple.
我们选择使用 2 个相同的加密狗,我们可以批量订购它们并以相同的方式存放它们以减少混淆。发货的每台设备只需要 2 个蓝牙加密狗,很简单。
The only problem is, these are widcomm dongles and we need one dongle on the Windows stack. Windows doesn't recognise these as Windows dongles, so won't register them for the Windows stack. So... the is a hack you can make to the bt.inf file to make it recognise the dongle for Windows. Then you need to switch the drivers for one of the dongles to run on the Windows drivers and you're all done.
唯一的问题是,这些是 widcomm 加密狗,我们需要在 Windows 堆栈上安装一个加密狗。Windows 不会将这些识别为 Windows 加密狗,因此不会将它们注册到 Windows 堆栈。所以......这是一个你可以对 bt.inf 文件进行的黑客攻击,以使其识别 Windows 的加密狗。然后,您需要切换其中一个加密狗的驱动程序以在 Windows 驱动程序上运行,您就大功告成了。
Summary
概括
So... we've got one dongle scanning all the time, one handling transfers, each on separate stacks and it all works nicely. This is the only way I have found to get 2 dongles working smoothly on Windows. If you've got a better suggestion, please post it!
所以...我们有一个加密狗一直在扫描,一个处理传输,每个都在不同的堆栈上,一切都很好。这是我发现让 2 个加密狗在 Windows 上顺利运行的唯一方法。如果你有更好的建议,请留言!