gpt4 book ai didi

UWP 链接到串口

转载 作者:行者123 更新时间:2023-12-04 21:51:24 25 4
gpt4 key购买 nike

我想创建一个 UWP 应用程序来接收 Waspmote 板发送的信息。

在 WindowsForms 中,使用 System.IO.Ports; 它可以工作

但在 UWP 中,它向我显示此错误: enter image description here

如何解决这个问题,并且能够从串口接收到消息

最佳答案

您正在尝试使用 UWP 应用无法访问的旧 API。

使用Windows.Devices.SerialCommunication中的类可以实现串口通信.

您将使用的类是 SerialDevice这将允许您枚举、打开设备并执行 I/O 操作。

为了使用 API,您需要在您的应用程序 list 中添加串行端口功能。 UWP 应用程序只能访问声明的硬件资源。

<DeviceCapability Name="serialcommunication">
<Device Id="vidpid:045E 0610">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>

或者如果您想访问任何硬件:

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

您会找到完整的 serial port sample作为 UWP 示例集合的一部分。

关于UWP 链接到串口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47791149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com