Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I finally got this sorted out myself a couple days ago. There are two parts, one to check the registry and another to check the vid/pid of the device.</p> <p>The registry method I use just to make sure I don't capture a null modem emulator like com0com.</p> <pre><code> /// &lt;summary&gt; /// Removes any comm ports that are not explicitly defined as allowed in ALLOWED_TYPES /// &lt;/summary&gt; /// &lt;param name="allPorts"&gt;reference to List that will be checked&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; private static void nullModemCheck(ref List&lt;string&gt; allPorts) { // Open registry to get the COM Ports available with the system RegistryKey regKey = Registry.LocalMachine; // Defined as: private const string REG_COM_STRING ="HARDWARE\DEVICEMAP\SERIALCOMM"; regKey = regKey.OpenSubKey(REG_COM_STRING); Dictionary&lt;string, string&gt; tempDict = new Dictionary&lt;string, string&gt;(); foreach (string p in allPorts) tempDict.Add(p, p); // This holds any matches we may find string match = ""; foreach (string subKey in regKey.GetValueNames()) { // Name must contain either VCP or Seial to be valid. Process any entries NOT matching // Compare to subKey (name of RegKey entry) if (!(subKey.Contains("Serial") || subKey.Contains("VCP"))) { // Okay, this might be an illegal port. // Peek in the dictionary, do we have this key? Compare to regKey.GetValue(subKey) if(tempDict.TryGetValue(regKey.GetValue(subKey).ToString(), out match)) { // Kill it! allPorts.Remove(match); // Reset our output string match = ""; } } } regKey.Close(); } </code></pre> <p>The vid/pid portion was gleaned from <a href="http://t6953.techinpro.us/q/508141744f1eba38a4429885" rel="nofollow noreferrer" title="here">techinpro</a></p> <pre><code> /// &lt;summary&gt; /// Compile an array of COM port names associated with given VID and PID /// &lt;/summary&gt; /// &lt;param name="VID"&gt;string representing the vendor id of the USB/Serial convertor&lt;/param&gt; /// &lt;param name="PID"&gt;string representing the product id of the USB/Serial convertor&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; private static List&lt;string&gt; getPortByVPid(String VID, String PID) { String pattern = String.Format("^VID_{0}.PID_{1}", VID, PID); Regex _rx = new Regex(pattern, RegexOptions.IgnoreCase); List&lt;string&gt; comports = new List&lt;string&gt;(); RegistryKey rk1 = Registry.LocalMachine; RegistryKey rk2 = rk1.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum"); foreach (String s3 in rk2.GetSubKeyNames()) { RegistryKey rk3 = rk2.OpenSubKey(s3); foreach (String s in rk3.GetSubKeyNames()) { if (_rx.Match(s).Success) { RegistryKey rk4 = rk3.OpenSubKey(s); foreach (String s2 in rk4.GetSubKeyNames()) { RegistryKey rk5 = rk4.OpenSubKey(s2); RegistryKey rk6 = rk5.OpenSubKey("Device Parameters"); comports.Add((string)rk6.GetValue("PortName")); } } } } return comports; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload