UWP 链接到串口 [英] UWP link to serial port

查看:63
本文介绍了UWP 链接到串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create an UWP application to receive information sent by Waspmote board.

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

in WindowsForms, it's using System.IO.Ports; it can work

但是在 UWP 中,它显示了这个错误:

but in UWP, it show me this error:

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

how can I solve this problem, and be able to receive the message from serial port

推荐答案

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

You're trying to use an old API which is not accessible to UWP apps.

串行通信可以通过使用来自 Windows 的类来实现.Devices.SerialCommunication.

Serial communication can be achieved by using the classes from Windows.Devices.SerialCommunication.

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

The class you'll use is SerialDevice which will allow you to enumerate, open the device and perform I/O operations.

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

In order to use the API, you will need to add the serial port capability in your application manifest. UWP applications can only access to declared hardware resources.

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

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

or if you want to access any hardware:

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

您会找到完整的串口示例作为 UWP 示例集合的一部分.

You will find a full serial port sample as part of the UWP sample collection.

这篇关于UWP 链接到串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆