UWP 链接到串口

标签 uwp

我想创建一个 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/

相关文章:

c# - DEP0600 部署 UWP 项目时出错

c# - 将 Array 的元素绑定(bind)到 xaml 属性

c# - 如何在 UWP MVVM 中使用 CalenderView

c# - 从 View 模型更新记录的正确方法是什么?

xaml - x :Bind compare with the classical Binding, 怎么写尽量简洁?

C++ 智能卡通信

android - 你如何管理你的 Assets ?

c# - uwp 解析或反序列化 httpclient 响应

xaml - 您能否在 UWP XAML 中定义一个 Thickness 静态资源,该资源引用另一个静态资源( double )作为其值之一?

c# - UWP SQLite 查询结果类包含另一个类