C# 列出并连接到蓝牙设备
我正在尝试让我的Windows平板电脑应用程序通过蓝牙与其他设备通信 首先我要扫描设备,然后我要连接到choosen设备 我制作了一个简单的测试应用程序:空白的首页,并添加了一个按钮和一个列表框。然后我尝试了下面的代码,我在这里找到了其他地方,所以:C# 列出并连接到蓝牙设备,c#,.net,windows,bluetooth,windows-8.1,C#,.net,Windows,Bluetooth,Windows 8.1,我正在尝试让我的Windows平板电脑应用程序通过蓝牙与其他设备通信 首先我要扫描设备,然后我要连接到choosen设备 我制作了一个简单的测试应用程序:空白的首页,并添加了一个按钮和一个列表框。然后我尝试了下面的代码,我在这里找到了其他地方,所以: ListBox1.Items.Clear(); var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(Rf
ListBox1.Items.Clear();
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
foreach (var device in devices)
{
ListBox1.Items.Add(device);
}
但是这个列表是空的
然后我尝试只枚举设备并过滤掉不需要的设备:
var list = await DeviceInformation.FindAllAsync();
var uniqueList = new HashSet<string>();
var terminators = new List<string>() { "Audio", "Mixer", "Mic", "Realtek", "Usb", "Gmail,", "Line in", "Lyd", "Display", "surface", "@" };
foreach (var element in list)
{
var strToken = element.Name.ToUpper();
if (!uniqueList.Add(strToken))
continue;
var contains = false;
foreach (var word in terminators)
if (strToken.Contains(word.ToUpper()))
contains = true;
if (!contains)
ListBox1.Items.Add(element.Name);
}
但这并没有给出一个完整的清单
我觉得我做错了。请帮我回到正轨。我只是稍微聪明了一点,我提出了另一个问题,告诉我这是不可能的 因此,上市的解决方案是: 1配对您的设备 2.列出它们:
ListBox1.Items.Clear();
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
foreach (var device in devices)
{
ListBox1.Items.Add(device);
}
我只是稍微聪明一点,我想问另外一个问题,告诉我这是不可能的 因此,上市的解决方案是: 1配对您的设备 2.列出它们:
ListBox1.Items.Clear();
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
foreach (var device in devices)
{
ListBox1.Items.Add(device);
}
您设置了设备功能了吗?您必须自己定义Id和函数类型 有用链接:
此外,确实不能连接未配对的设备。Windows似乎不支持它。您设置了设备功能了吗?您必须自己定义Id和函数类型 有用链接: 此外,确实不能连接未配对的设备。Windows似乎不支持它