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](https://stackoverflow.com/questions/46877283/uwp-bluetooth-rfcomm-connectasync-problems) (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 want to implement that.
From [this](https://stackoverflow.com/questions/65143649/unable-to-discover-bluetooth-devices-in-uwp-application-but-works-in-wpf-applica) SO answer, I discovered that Microsoft recommends to use a DeviceWatcher to find all connected Bluetooth devices, so I coded a DeviceWatcher, and it works without a problem. I get a full list of Bluetooth devices as DeviceInformation objects.
However, when I 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
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:
<Function Type="name:serialPort" />
Are the manifest capabilities correct? How can I successfully get a SerialDevice object for the Bluetooth device?
Edit 1: DeviceCapability Name changed to "serialcommunication" but I still get the same exception.
Edit 2: The Bluetooth device with which I am trying to connect exposes COM ports as follows:
I figured out what the problem was. I had not realised that the `Id` field of the `DeviceInformation` class holds different values, according to the value of the `Kind` field.
So I was getting the `AEP` kind of DeviceInformation for the Bluetooth device, but I needed to be getting the `DeviceInterface` kind instead.
The `Id` field for the `DeviceInterface` kind of DeviceInformation is the correct parameter for `SerialDevice.FromIdAsync(string id)`.