Reputation: 6402
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.
Upvotes: 0
Views: 5698
Reputation: 961
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>
"any"
."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.
Upvotes: 1