SerialDevice.FromIdAsync() throws Invalid Data exception


I am trying to program a uwp app in C#, that must connect to any bluetooth device (not LE) that will be paired with the computer.

I started by copying the Microsoft RFComm Chat sample app, but ran into the problem described here (it was too slow, and sometimes dropped the connection for no reason). This SO user solved the problem by using a SerialDevice approach, so I implemented that.

From this SO answer, I discovered that Microsoft recommends to use a DeviceWatcher to find all connected Bluetooth devices, so I implemented that, and it works without a problem. I get a full list of Bluetooth devices as DeviceInformation objects.

However, I then try to use a selected DeviceInformation object to create a SerialDevice, it always fails with "Data is invalid" exception.

SerialDevice sd = await SerialDevice.FromIdAsync(myDeviceInfo.Id);


"Die Daten sind unzulässig. (Exception from HRESULT: 0x8007000D)"

("the data are invalid")

The contents of myDeviceInfo.Id are Bluetooth#Bluetoothc0:b6:f9:c1:62:62-00:80:25:40:95:7b

I have also tried giving this string in directly as a string parameter, with the same result. The device is already paired with the computer, and was used many times successfully with this Id string and the RfcommService code.

In the manifest, I added the following lines:

<DeviceCapability Name="bluetooth.rfcomm">
  <Device Id="any">
    <Function Type="name:serialPort" />

How can I successfully get a SerialDevice object for the Bluetooth device?

EDIT 1: Corrected the name of the DeviceCapability to "serialcommunication". I still get the same exception.

EDIT 2: The device exposes incoming and outgoing COM ports as follows: enter image description here

asked on Stack Overflow Mar 27, 2021 by user1725145 • edited Mar 30, 2021 by user1725145

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0