Here is what I have,
- A bluetooth wearable (MyoArm band).
- Windows Mobile 10 with anniversary update.
Both of them are paired properly.
Now, here is what I am trying to do,
- I am trying to enumerate the list of all services exposed by the bluetooth device connected to my windows mobile.
- I would then like to read input streams, if the service provides one.
I went though MSDN documentation and here is what I have done so far.
P.S. I have added Bluetooth access to the capabilities in the application manifest.
private async void OnReceiveClick(object sender, RoutedEventArgs e)
{
var devices = await DeviceInformation.FindAllAsync();
IList<DeviceInformation> myBluetoothDevices = new List<DeviceInformation>();
foreach (var device in devices)
{
if (device.Name.Contains("myo"))
{
var trace = string.Format("Name: {2} \t Paired: {3} \t Kind: {1} \t Id: {0}", device.Id, device.Kind, device.Name, device.Pairing?.IsPaired);
builder.AppendLine(trace);
myBluetoothDevices.Add(device);
}
}
foreach (var myBluetoothDevice in myBluetoothDevices)
{
try
{
if (myBluetoothDevice != null)
{
var service = await RfcommDeviceService.FromIdAsync(myBluetoothDevice.Id);
// TODO: Read input stream somehow here!!!
log.Text = builder.AppendLine(string.Format("Name: {0} \t Id: {1} \t Device Info Name: {2} \t Connection Host Name: {3} \t Service Id: {4}", service.Device.Name, service.Device.DeviceId, service.Device.DeviceInformation.Name, service.ConnectionHostName, service.ServiceId.Uuid)).ToString();
}
}
catch (Exception ex)
{
builder.AppendLine(ex.Message);
}
finally
{
log.Text = builder.ToString();
}
}
}
When I run the code and click the "Receive" button, I get an exception while calling the RfcommDeviceService.FromIdAsync method.
Exception: Element not found. (Exception from HRESULT: 0x80070490)
Am I missing something here? I am new to programming with bluetooth devices, so am I approaching the problem correctly?