连接蓝牙设备/如何设置rfcommfunction

我正在尝试连接到BlueTooth设备

我已配对它,当我搜索它时,我发现它:

private async void Grid_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { ListBox1.Items.Clear(); var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); var device = devices.FirstOrDefault(c => c.Name.Contains("BMMTCA32")); foreach (var element in device.Properties) { var strMessage = element.Key + (element.Value == null ? "" : " = " + element.Value.ToString()); ListBox1.Items.Add(strMessage); } } 

这是我的ListBox中的输出:

 System.ItemNameDisplay = BMMTCA32-01 System.Devices.DeviceInstanceId = BTHENUM\{00001101-0000-1000-8000-00805f9b34fb}_LOCALMFG&0048\8&f358302&0&0012F31DECF3_C00000000 System.Devices.Icon = C:\Windows\System32\DDORes.dll,-2001 {51236583-0C4A-4FE8-B81F-166AEC13F510} 123 = C:\Windows\SYSTEM32\DDORes.dll,-3001 System.Devices.InterfaceEnabled = True System.Devices.IsDefault = False System.Devices.PhysicalDeviceLocation 

但我的问题是如何连接到它?

当我尝试使用Googeling时,我会得到答案,例如你设置了rfcommfunction吗? 有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/windows/apps/dn263090.aspx 。

但是当我看到那个页面时,我迷失了,因为我没有在清单文件中写什么。

简而言之:我如何连接到设备?

PS:这是一个Windows Tablet程序。

所以你想知道你必须在清单文件中写什么,以及如何连接?

清单文件:

       
  • 您可以将ID保留为"any"
  • 函数类型可以是"name:serialPort"或示例中指定的serviceId。

连接:

 StreamSocket _socket; RfcommDeviceService service = await RfcommDeviceService.FromIdAsync(device.id); await _socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName); 

应该可以做到这一点。