【问题标题】:Unable to open UART port on Windows IoT with Raspberry Pi 3无法使用 Raspberry Pi 3 在 Windows IoT 上打开 UART 端口
【发布时间】:2019-07-06 01:28:57
【问题描述】:

在运行在 Raspberry Pi 3 上的 Windows IoT Core 10 上用 C# 打开 SerialDevice 后,串口中有 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);

serialPortnull

di.Id 等于:Id "\\\\?\\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string

list.Count等于1

这里有两条来自/api/devicemanager/devicesGET请求的记录与UART相关:

{
  "Class": "Ports",
  "Description": "BCM283x Mini UART Serial Device",
  "ID": "ACPI\\BCM2836\\0",
  "Manufacturer": "Microsoft",
  "ParentID": "ACPI_HAL\\PNP0C08\\0",
  "ProblemCode": 0,
  "StatusCode": 25182218
},
{
  "Class": "System",
  "Description": "ARM PL011 UART Device Driver",
  "ID": "ACPI\\BCM2837\\4",
  "Manufacturer": "Microsoft",
  "ParentID": "ACPI_HAL\\PNP0C08\\0",
  "ProblemCode": 0,
  "StatusCode": 25165834
},

我尝试将 Rx 和 Tx 都短接,并且不短接,它不起作用...

更新

如果我拆分给定的 ID,我有 Invalid data 异常。

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; }

输出:

抛出异常:mscorlib.ni.dll 中的“System.Exception”
数据无效。 (来自 HRESULT 的异常:0x8007000D)
数据无效。 (来自 HRESULT 的异常:0x8007000D)
没有设备

【问题讨论】:

标签: c# raspberry-pi uart windows-iot-core-10


【解决方案1】:

正如Grim所说,解决方案在这里:SerialDevice.FromIdAsync() yields a null serial port

需要补充:

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

Package.appxmanifest 文件中的&lt;Capabilities&gt; 标记中。

【讨论】:

    猜你喜欢
    • 2021-02-17
    • 2021-07-10
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多