我试图让我的Windows平板电脑应用程序通过蓝牙与其他设备进行通信。列出并连接到蓝牙设备
首先我想扫描设备,然后我想连接到选择的设备。
我做了一个简单的测试应用程序:空白的首页,并添加一个按钮和一个listboxto它。然后我尝试了下面的代码女巫我别的forund那里这里SO:
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);
}
但是,这并没有给出任何平均值列表。
我有一种感觉,我做错了。请让我回到正轨。