In this article, I explain connect to virtual COM port from UWP app.
In Windows 10 APIs, there are some classes to access serial device, one of those is Windows.Devices.SerialCommunication.SerialDevice class.
After define following capability to Pakcage.appxmanifest:
<DeviceCapability Name="serialCommunication"> <Device Id="any"> <Function Type="name:serialPort" /> </Device> </DeviceCapability>
It works fine to access to COM port, but it doesn't works for virtual COM port.
If you tried to get SerialDevice instance of virtual COM port, you would not get, SerialDevice.FromIdAsync method would return null.
var deviceColletion = await DeviceInformation.FindAllAsync("COM3"); if (deviceColletion.Any()) { var device = deviceColletion.First(); var s = await SerialDevice.FromIdAsync(device.Id); // return null }
If you want to write/read to virtual COM port, you can use System.IO.Ports.SerialPort class.
It can Open virtual COM ports, and write / read data to the virtual COM port.
But, there is a limitation. SerialPort class on UWP can't list ports using GetPortNames method. If the method was used, then PlatformNotSupportedException would be occurred.
So, I created a sample app using it.
The sample app writes / reads to virtual COM port COM3 for reading and COM4 for writing.
I tested the app on an environment that is set up using com0com, like following:
The result of the app is as below:
The source code is on following GitHub repository.
https://github.com/runceel/VirtualCOMPortApp
Next article: Get list of virtual serial COM port from UWP app
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.