连接到蓝牙设备/如何设置 rfcomm 功能 [英] Connect to Bluetooth Device / how to set the rfcomm capability

查看:34
本文介绍了连接到蓝牙设备/如何设置 rfcomm 功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到蓝牙设备

I'm trying to connect to a BlueTooth device

我已经配对了它,当我搜索它时,我找到了它:

I have paired it and when I search for it I find it :

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);
    }
}

这是我的列表框中的输出:

Here is the output in my ListBox:

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

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

But my problem is how to connect to to it?

当我尝试使用谷歌搜索时,我得到的答案是你是否设置了 rfcomm 功能?请参阅 http://msdn.microsoft.com/en-us/library/windows/apps/dn263090.aspx 了解详情.

When I try Googeling for it I get answers like Did you set the rfcomm capability? see http://msdn.microsoft.com/en-us/library/windows/apps/dn263090.aspx for some details.

但是当我查看那个页面时,我迷路了,因为我不知道在清单文件中写什么.

But when I look at that page I get lost because I don't what to write in the manifest file.

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

so in short: How do I connect to the device?

PS:这是一个Windows平板程序.

PS: It is a Windows Tablet program.

推荐答案

那么你想知道manifest文件里要写什么,以及如何连接吗?

So you want to know what you have to write in the manifest file, as well as how to connect?

清单文件:

   <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/>
      </m2:Device>
    </m2:DeviceCapability>

  • 您可以将 Id 保留为 "any".
  • 函数类型可以是 "name:serialPort" 或示例中指定的 serviceId.
    • You can keep Id at "any".
    • Function type could either be "name:serialPort" or the serviceId specified in the example.
    • 连接:

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

      应该能够做到这一点.

      这篇关于连接到蓝牙设备/如何设置 rfcomm 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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