Loading...
Pages: [1]   Go Down
Author Topic: Getting Arduino Com Ports With C#  (Read 356 times)
0 Members and 1 Guest are viewing this topic.
Adana / Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Tesla Member
***
Karma: 50
Posts: 6536
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Why I like my 2005 rio yellow Honda S2000 with the top down, and more!
GOOGLE ADVANCED FORUM SEARCH BELOW!  
Go to:  http://www.google.com/advanced_search?hl=en
put in key search words,
use site or domain:  http://arduino.cc/forum
or in a google search box put key words site:http://arduino.cc/forum

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6313
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Adana / Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I Found smiley-grin

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 smiley
Logged

Pages: [1]   Go Up
Print
 
Jump to: