C# 无法使用Raspberry Pi 3打开Windows IoT上的UART端口

C# 无法使用Raspberry Pi 3打开Windows IoT上的UART端口,c#,raspberry-pi,uart,windows-iot-core-10,C#,Raspberry Pi,Uart,Windows Iot Core 10,在Raspberry Pi 3上运行的Windows IoT Core 10上的C#中打开串行设备后,串行端口中出现null 代码如下: string aqs = SerialDevice.GetDeviceSelector(); DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs); List<DeviceInformation> list = devices.ToList()

在Raspberry Pi 3上运行的Windows IoT Core 10上的C#中打开串行设备后,串行端口中出现null

代码如下:

string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
serialPort = await SerialDevice.FromIdAsync(di.Id);
我试着把Rx和Tx都短路了,但并没有马上短路,它不起作用

更新

如果我分割给定的ID,我有
无效数据
异常

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

string id = "{86e0d1e0-8089-11d0-9ce4-08003e301f73}";
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
id = "\\\\?\\ACPI#BCM2836#0#";
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
id = di.Id;
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
if (serialPort == null) { Debug.WriteLine("No device"); return; }
string aqs=SerialDevice.GetDeviceSelector();
DeviceInformation Collection devices=等待DeviceInformation.FindAllAsync(aqs);
List=devices.ToList();
DeviceInformation di=list.First();
字符串id=“{86e0d1e0-8089-11d0-9ce4-08003e301f73}”;
请尝试{serialPort=wait SerialDevice.FromIdAsync(id);}catch(异常e){Debug.WriteLine(e.Message);}
id=“\\\?\\ACPI”BCM2836“0”;
请尝试{serialPort=wait SerialDevice.FromIdAsync(id);}catch(异常e){Debug.WriteLine(e.Message);}
id=di.id;
请尝试{serialPort=wait SerialDevice.FromIdAsync(id);}catch(异常e){Debug.WriteLine(e.Message);}
if(serialPort==null){Debug.WriteLine(“无设备”);return;}
输出:

引发异常:mscorlib.ni.dll中的“System.Exception”
数据无效。(HRESULT的例外:0x8007000D)
数据无效。(HRESULT的例外:0x8007000D)
没有装置

如前所述,解决方案如下:

有必要补充:

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


Package.appxmanifest
文件中的
标记中,

很明显,您找到的di.Id字符串比存储在设备记录中的Id长,即在末尾包含GUID。也许它找不到你要求它查找的ID?你错了,请查看我的更新。我怎么错了?!“ACPI\\BCM2836\\0”!=“\\\?\\ACPI#BCM2836#0#”。。。请看一看这个
<DeviceCapability Name="serialcommunication">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>