C#UWP串行通信未连接

问题描述 投票:0回答:2

我正在使用UWP创建串行通信程序..

串行通信未连接..未捕获“设备”。返回null。

代码在这里。

//从给定的端口名称字符串选择器= SerialDevice.GetDeviceSelector(portName)获取设备选择器;

        // Get a list of devices that match the given name
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector, null);

        // If any device found...
        if (devices.Any())

然后,我在UWP项目的Package.appxmanifest中添加了该代码。

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

但它不起作用..

但是,我正在类库中创建串行通信模块。

uwp
2个回答
1
投票

在类库中编写代码与在UWP项目中编写代码相同。您应该首先使用官方sample自行检查问题。尝试此示例并将您的设备与此示例连接。如果官方样本没有问题,那么这意味着您的设备没有任何问题。您需要检查项目和官方样本之间的差异。例如,Did初始化了deviceWatcher?你开始了吗?

如果您需要进一步的帮助,可能需要详细说明您的设备并阅读此How to create a Minimal, Complete, and Verifiable example以向我们展示样品。


0
投票

这对我有用:

using (SerialDevice serialDevice = await SerialDevice.FromIdAsync(item.Id))
{

}
© www.soinside.com 2019 - 2024. All rights reserved.