raspberry-pi3 - IAsync 操作FromIdAsync(string deviceId) 返回 null
问题描述
我在 Raspberry Pi 3 上运行 Windows IoT Core 10 17744。
我尝试使用以下代码从 UWP 应用程序初始化 COM 端口:
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);
我有di.Id
->变量的\\?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
完整表示di
如下:
- 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.
但await
手术后我有 null in _serial_port
。
更新
null
即使我将 Raspberry UART 接口连接到工作节点:第
8 个引脚作为 TX 到配对的 RX 线也是如此。
第 10 个引脚作为 RX 到配对的 TX 线。
更新
我有DeviceCapability
清单:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
解决方案
您需要在Package.appxmanifest中添加串行设备功能:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
即使我将 Raspberry UART 接口连接到工作节点,它也是空的:第 8 个引脚作为 TX 到配对的 RX 线。第 10 个引脚作为 RX 到配对的 TX 线。
这不是 SerialDevice.FromIdAsync() 成功所必需的。即使您不连接这些引脚,如果代码和设置正确,SerialDevice.FromIdAsync() 也可以获取有效设备。您可以参考串行 UART 示例。
推荐阅读
- git - 在自托管 git repo 上使用 git pull 请求的工作流程
- javascript - 窗口未定义,Vue 平滑滚动 - Nuxt.js
- firefox - Createjs 和 Firefox 72
- python - 是否有一种有效的方法来测试 .onion 链接是否有效
- python - MongoDB 不尊重上限集合的最大值
- android - Renderscript 如何从 2d 浮点数组初始化缓冲区以进行分配
- excel - Excel Tick Marks 改变数据显示
- jquery - 如何使用 jQuery 动态创建包含数据列表的 HTML 输入?
- sql - IBM DB2 SQL Count 总是返回 1 和多行
- python - 如何使用决策边界分隔散点图?