在C#.NET框架中获取蓝牙设备的列表 [英] Getting a list of bluetooth devices in a C# .NET framework

查看:606
本文介绍了在C#.NET框架中获取蓝牙设备的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个简单的C#.NET Framework控制台应用程序.

在其中,我试图获取当前已连接到计算机的配对的蓝牙设备的列表.但是,我不知道如何从代码中访问任何蓝牙服务.

我环顾了互联网,我所能找到的就是在通用Windows项目(UWP)中实现此目的的一种方法,在这里我可以简单地使用using Windows.Devices.Bluetooth命名空间,其中包含我需要的所有内容,但是在.NET中. NET Framework控制台应用程序,此名称空间不可用.

我不需要任何高级方法来使用蓝牙,我只需要列出当前已连接并已配对的蓝牙设备即可.

解决方案

尝试使用以下代码:

            BluetoothClient client = new BluetoothClient();
            List<string> items = new List<string>();
            BluetoothDeviceInfo[] devices = client.DiscoverDevicesInRange();
            foreach (BluetoothDeviceInfo d in devices)
            {
                items.Add(d.DeviceName);
            }

通过Package Manager控制台安装 32feet.NET ,您将获得BluetoothClient的引用.

PM> Install-Package 32feet.NET -Version 3.5.0

安装后,您将在参考中获得 InTheHand.Net.Personal dll. 然后在代码中使用InTheHand.Net.Sockets; 添加名称空间

现在您将可以访问 BluetoothClient

希望这会有所帮助!

I have created a simple C# .NET framework console application.

In it, I am trying to get a list of paired bluetooth devices currently connected to the computer. However, I cannot figure out, how to access any bluetooth services from within the code.

I looked around the internet, and all I could find was a way to do this in an universal windows project (UWP), where I can simply use the using Windows.Devices.Bluetooth namespace which contains everything I would need, however in the .NET framework console application, this namespace is not available.

I don't need any advanced way to work with the bluetooth, all I need is a list of currently connected and paired bluetooth devices.

解决方案

Try using below code :

            BluetoothClient client = new BluetoothClient();
            List<string> items = new List<string>();
            BluetoothDeviceInfo[] devices = client.DiscoverDevicesInRange();
            foreach (BluetoothDeviceInfo d in devices)
            {
                items.Add(d.DeviceName);
            }

You will get the reference of BluetoothClient by installing 32feet.NET through Package Manager Console.

PM> Install-Package 32feet.NET -Version 3.5.0

After Installation you will get InTheHand.Net.Personal dll in the References and then add the namespace using InTheHand.Net.Sockets; in your code

Now you will be able to access BluetoothClient

Hope this helps!!

这篇关于在C#.NET框架中获取蓝牙设备的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆