Go Down

Topic: Getting Arduino Com Ports With C# (Read 2086 times) previous topic - next topic


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

string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)

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?


Usually something is sent to the available comport, and if the arduino is attached to that port and recognizes what is sent, ti would send a response back to the pc.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


There may be a better way to do this by looking at attributes of the virtual COM port, but one approach is to look at the "Ports (COM & LPT)" class in the registry. This has a key for each COM port, and you could tell from the DriverDesc value whether this is a virtual COM port provided by the Arduino USB driver.


I Found :D

here is code

                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_PnPEntity");

                foreach (ManagementObject queryObj in searcher.Get())
                    if (queryObj["Caption"].ToString().Contains("Arduino"))

            catch (ManagementException e)

dont forget add reference System.Management :)

Go Up