Search code examples
raspberry-pi3uartwindows-iot-core-10

IAsyncOperation<SerialDevice> FromIdAsync(string deviceId) returns null


I have Windows IoT Core 10 17744 running over Raspberry Pi 3.
I try to initialize COM port from UWP application using following code:

string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
_serial_port = await SerialDevice.FromIdAsync(di.Id);

I have di.Id -> \\?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
Full represintation of di variable as follow:

-       di  {Windows.Devices.Enumeration.DeviceInformation} Windows.Devices.Enumeration.DeviceInformation
        EnclosureLocation   null    Windows.Devices.Enumeration.EnclosureLocation
        Id  "\\\\?\\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}"  string
        IsDefault   false   bool
        IsEnabled   true    bool
        Kind    DeviceInterface Windows.Devices.Enumeration.DeviceInformationKind
        Name    "MINWINPC"  string
-       Pairing {Windows.Devices.Enumeration.DeviceInformationPairing}  Windows.Devices.Enumeration.DeviceInformationPairing
        CanPair false   bool
+       Custom  {Windows.Devices.Enumeration.DeviceInformationCustomPairing}    Windows.Devices.Enumeration.DeviceInformationCustomPairing
        IsPaired    false   bool
        ProtectionLevel None    Windows.Devices.Enumeration.DevicePairingProtectionLevel
        Native View To inspect the native object, enable native code debugging. 
+       Properties  {System.__ComObject}    System.Collections.Generic.IReadOnlyDictionary<string, object> {System.__ComObject}
        Native View To inspect the native object, enable native code debugging. 

But after await operation I have null in _serial_port.

UPDATE

It is null even if I connect Raspberry UART interface to working node:
8th pin as TX to paired RX line.
10th pin as RX to paired TX line.

UPDATE

I have DeviceCapability in manifest:

<DeviceCapability Name="serialcommunication">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>

Solution

  • You need add serial device capability in the Package.appxmanifest:

    <DeviceCapability Name="serialcommunication">
      <Device Id="any">
        <Function Type="name:serialPort" />
      </Device>
    </DeviceCapability>
    

    It is null even if I connect Raspberry UART interface to working node: 8th pin as TX to paired RX line. 10th pin as RX to paired TX line.

    This is not required for SerialDevice.FromIdAsync() success. Even if you don't connect these pins the SerialDevice.FromIdAsync() can get the valid device if the code and setting correctly. You can refer to Serial UART Sample.