C#UWP串行通信未连接

C#UWP串行通信未连接,c#,uwp,serial-port,C#,Uwp,Serial Port,我正在使用UWP创建串行通信程序 串行通信无法连接。 未捕获“设备”。返回null 代码在这里 // Get a device selector from the given port name string selector = SerialDevice.GetDeviceSelector(portName); // Get a list of devices that match the given name DeviceInformationCollection devices = aw

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

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

代码在这里

// Get a device selector from the given port name
string selector = 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项目中编写代码相同。您应该首先亲自与官方人员检查问题。尝试此示例并将您的设备与此示例连接。如果官方示例工作正常,则表示您的设备没有任何问题。您需要检查您的项目与官方示例之间的差异。例如,是否初始化了deviceWatcher?是你开始的吗

如果您需要进一步的帮助,也许您需要详细说明您的设备,并阅读本文以向我们展示一个示例