要在UWP文件中生成串口监听,但是当运行SerialDevice.FromIdAsync(dis[0].Id)之后,获取的serialport依然为空,然后曝出”object reference not set to an insance”异常。
查了一下,其实在应用程序清单GUI中进行串行通信是需要在manifest文件中表明的。
将下列内容加入到Package.appxmanifest的项下即可:
<Capabilities>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>