如何设置RFCOMM能力

如何设置RFCOMM能力

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

问题描述

我试图连接到蓝牙设备

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

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&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

但我的问题是如何连接呢?

But my problem is how to connect to to it?

当我尝试Googeling它我得到这样的答案你设置RFCOMM能力?看到了解一些细节。

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.

推荐答案

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

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>


  • 您可以在保持标识

  • 功能类型既可以是的名称:的SerialPort或在本例中指定的服务ID

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

      应该可以做的伎俩。

      Should be able to do the trick.

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

08-20 18:40