首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IAsyncOperation<SerialDevice> FromIdAsync(string deviceId)返回null

IAsyncOperation<SerialDevice> FromIdAsync(string deviceId)返回null
EN

Stack Overflow用户
提问于 2019-03-13 13:10:09
回答 1查看 213关注 0票数 1

我有视窗IoT核心10 17744运行在覆盆子Pi 3。

我尝试使用以下代码从UWP应用程序初始化COM端口:

代码语言:javascript
复制
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变量的完全表示如下:

代码语言:javascript
复制
-       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操作之后,_serial_port中的值为null。

更新

即使我将Raspberry接口连接到工作节点,它也是null

第8针作为TX成对的RX线。

第10引脚为RX成对TX线。

更新

我在清单中有DeviceCapability

代码语言:javascript
复制
<DeviceCapability Name="serialcommunication">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-14 00:59:10

您需要在Package.appxmanifest中添加串行设备功能。

代码语言:javascript
复制
<DeviceCapability Name="serialcommunication">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>

即使我将Raspberry UART接口连接到工作节点:作为TX的第8引脚到成对的RX线,它也是空的。第10引脚为RX成对TX线。

这并不是SerialDevice.FromIdAsync()成功的必要条件。即使没有连接这些引脚,如果代码和设置正确,SerialDevice.FromIdAsync()也可以获得有效的设备。您可以参考串行UART样本

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55142683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档