Reputation: 801
UWP app, To connect with Serial device ( like COM3 ), I success to get all available device list with below code. But One point is strange. My Device has no VID, no PID.
Why ??
First is test code.
public MainPage()
{
this.InitializeComponent();
Task.Run(() => this.test()).Wait();
}
public async Task test()
{
try
{
// Not Work
// var DeviceSelector = SerialDevice.GetDeviceSelectorFromUsbVidPid(0x0403, 0x6001); //
// Work
var DeviceSelector = SerialDevice.GetDeviceSelector();
var DeviceInformations = await DeviceInformation.FindAllAsync(DeviceSelector);
for (int i = 0; i < DeviceInformations.Count; i++)
{
var d = DeviceInformations[i];
SerialDevice port = await SerialDevice.FromIdAsync(d.Id);
Debug.WriteLine(String.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n---------------------",
d.Name,
d.Id,
d.IsEnabled,
port?.PortName,
port?.UsbProductId.ToString("X4"),
port?.UsbVendorId.ToString("X4")
));
}
}
catch (Exception ex)
{
Debug.WriteLine("SerialController/ListAvailablePorts/Exception/" + ex.Message);
}
return;
}
Package.appxmanifest must has this too.
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
</Package>
and Here is result with GetDeviceSelector.
FT232R USB UART
\\?\FTDIBUS#VID_0403+PID_6001+AL03INW7A#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
True
COM12
0000
0000
see last two Zero value. VID, PID look like zero. What is wrong ?
Update1 :
with Advice of Sunteen Wu (thank you), I tried to use other device. Next device is RS232-USB device. Both device is Virtual COM port. I tried same code. 2nd Device has Vid, Pid !! Hmm..... My device was wrong.....
ATEN USB to Serial Bridge (COM13)
\\?\USB#VID_0557&PID_2008#8&1d38065f&1&4#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
System.Runtime.InteropServices.WindowsRuntime.ReadOnlyDictionaryValueCollection`2[System.String,System.Object]
COM13
2008
0557
Upvotes: 0
Views: 596
Reputation: 801
It is my device fault. I reported it to manufacture. I hope They will add Vid, Pid future. about detail, Please read "update" in my Question.
Before purchase, There is no way to know it... : (
I like their product. It's very good.
Upvotes: 1