COM port number from Windows.Devices.Enumeration.DeviceInformation

Is there a way to get the COM port number for a device through DeviceInformation ? I can see COM port numbers when I look at them through the device manager.

I just came across several devices that do not list the COM port number as part of the Name property. I included them in two, and there is no way to distinguish them from each other. Ideally, I would like to see a COM port. Is there any other way to get this information?

 string _serialSelector = SerialDevice.GetDeviceSelector(); DeviceInformationCollection tempInfo = await DeviceInformation.FindAllAsync(_serialSelector); if (tempInfo.Count > 0) { foreach (var efefe in tempInfo) { if (efefe.Kind.Equals(DeviceInformationKind.DeviceInterface)) { //efefe.Name } } } 
+2
c # uwp
source share
1 answer

You have completed most of the task, then you will need to use your efefe identifier to get the SerialDevice object using SerialDevice.FromIdAsync | fromIdAsync .

Here is a demo:

 string _serialSelector = SerialDevice.GetDeviceSelector(); var infos = await DeviceInformation.FindAllAsync(_serialSelector); foreach (var info in infos) { var serialDevice = await SerialDevice.FromIdAsync(info.Id); if (serialDevice != null) { var port = serialDevice.PortName; Debug.WriteLine(port.ToString()); } } 

And don't forget to add DeviceCapability to the manifest:

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

All Articles