Getting Arduino Com Ports With C#

Hi I use this code for getting available com ports from computer with C#

string ports = SerialPort.GetPortNames();

foreach (string port in ports)

{

comboBox1.Items.Add(port);

}

My question is that How can I get only Arduino port because I get all ports and I take exception on my desktop program. I want to take only arduino ports.

Anybody have idea?

I Found :smiley:

here is code

try

{

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(“root\CIMV2”,

“SELECT * FROM Win32_PnPEntity”);

foreach (ManagementObject queryObj in searcher.Get())

{

if (queryObj[“Caption”].ToString().Contains(“Arduino”))

{

Console.WriteLine(queryObj[“Caption”]);

}

}

Console.ReadLine();

}

catch (ManagementException e)

{

Console.WriteLine(e.Message);

}

dont forget add reference System.Management :slight_smile: