title: get com port number of an USB adapter
body: <p>I am trying to write a program that uses an arduino mega and a FTDI-based USB to RS485 adapter.</p>
  
  <p>I want to make the program user-friendly, thus I don't wont the user to manually check the com port number, but I want to auto-detect it. Here's a snippet of the code</p>
  
  <pre><code>    ManagementScope scope = new ManagementScope();
      SelectQuery query = new SelectQuery("SELECT * FROM Win32_SerialPort");
      ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  
      try
      {
          foreach (ManagementObject item in searcher.Get())
          {
              String description = item["Description"].ToString();
              String deviceID = item["DeviceID"].ToString();
  
              Console.WriteLine("Porta " + description + " deviceID " + deviceID);
  
              if (description.Contains("USB Serial Port"))
                  return deviceID;
          }
      }
      catch (ManagementException)
      {
      }
  </code></pre>
  
  <p>The point that I am not able to understand is why I can find the USB Serial port of the Arduino (matching <code>description.Contains("Arduino")</code> ) but not the com port of the USB RS485 port.</p>
  
  <p>Do you have an idea why this could happen? is the query <code>SELECT * FROM Win32_SerialPort</code> wrong?</p>