I tried like as:
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("PortName: {0}", queryObj["PortName"]);
}
It gives me not found in console
I tried like as:
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("PortName: {0}", queryObj["PortName"]);
}
It gives me not found in console
This should do the trick, or at least get you pointed in the right direction:
ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");
foreach (ManagementObject service in comPortSearcher.Get())
{
Console.WriteLine(service.ToString());
}
Baically you need to specify the right query.
\\TMOM-PC\root\CIMV2:Win32_PnPEntity.DeviceID="USB\\VID_0403&PID_6001\\A900ER2T"Use this query
string[] portnames = SerialPort.GetPortNames();
foreach( string port in portnames)
{
Console.WriteLine(port);
}
ManagementObjectSearcher in your code if you use SerialPort.GetPortNames?