0

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

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: It is a Windows Tablet program.

Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67

1 Answers1

1

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

Manifest file:

   <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/>
      </m2:Device>
    </m2:DeviceCapability>
  • You can keep Id at "any".
  • Function type could either be "name:serialPort" or the serviceId specified in the example.

Connecting:

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

Should be able to do the trick.

ggg
  • 961
  • 6
  • 8
  • No I get an unknown service exception. – Jens Borrisholt Nov 25 '14 at 15:20
  • NOTE device.id = \\?\BTHENUM#{00001101-0000-1000-8000-00805f9b34fb}_LOCALMFG&0048#8&f358302&0&0012F31DECF3_C00000000#{b142fc3e-fa4e-460b-8abc-072b628b3c70} – Jens Borrisholt Nov 25 '14 at 15:23
  • It it the following exception? If so you are in for some trouble, it's something quite some other devs have problems with in Windows.Bluetooth development, without a solution yet. "No such service is known. The service cannot be found in the specified namespace" – ggg Nov 25 '14 at 15:32
  • Also, some bluetooth devices just don't work well with Windows.Bluetooth.Rfcomm. (Here's a link that was very usefull for me http://blogs.windows.com/buildingapps/2014/05/07/talking-to-robots-or-other-devices-using-bluetooth-from-a-windows-runtime-app/) – ggg Nov 25 '14 at 15:37
  • "Thank you" @gl77 it is exactly that exception I get. So what is the alternative to Windows.Bluetooth.Rfcomm? – Jens Borrisholt Nov 25 '14 at 15:39
  • Exactly what is the device you're connecting to? – Matt Small Nov 25 '14 at 15:46
  • It is a devise fore mesureing Emmision gas from a car – Jens Borrisholt Nov 25 '14 at 15:46
  • The Serial Port connection and Guid should be correct seeing the DeviceInstanceId – ggg Nov 25 '14 at 15:49
  • As far as I'm aware of there aren't really reasonable alternatives, as this is supposed to be THE bluetooth library. Using a Peerfinder might work, but the MSDN also refers to Bluetooth.Rfcomm to be a better solution. http://msdn.microsoft.com/nl-nl/library/windows/apps/br241203 – ggg Nov 25 '14 at 15:54
  • There is one thing you forgot to suggest was: Restart the BLUETOOTH device ;) Now its working. But hang on. I have an other question, witch I'll create in a few minuts. – Jens Borrisholt Nov 25 '14 at 16:01
  • http://stackoverflow.com/questions/27131421/connect-to-bluetooth-device-with-ouit-modifying-the-manifest-file – Jens Borrisholt Nov 25 '14 at 16:04