Soyez le premier à donner votre avis sur cette source.
Snippet vu 5 841 fois - Téléchargée 19 fois
public string[] GetPortCOM(out string[] strType) { int index = 0; string strRECO = ""; strType = new string[0]; string[] LstCOM = new string[0]; RegistryKey bt = Registry.LocalMachine; RegistryKey rk = Registry.LocalMachine; //--------------------------------------------------// bt = bt.OpenSubKey("SYSTEM\\ControlSet001\\Enum\\BTHENUM"); if (bt != null) { string[] bth_names = bt.GetSubKeyNames(); foreach (string str_key in bth_names) { if(!str_key.Contains("_vid")) { bt = bt.OpenSubKey(str_key); string[] bth_key = bt.GetSubKeyNames(); LstCOM = new string[bth_key.Length + 1]; index = 0; foreach (string str_subkey in bth_key) { if (!str_subkey.Contains("00_00")) { RegistryKey btx = bt.OpenSubKey(str_subkey + "\\Device Parameters"); LstCOM[index++] = (string)btx.GetValue("PortName"); btx.Close(); btx = null; } } break; } } } if (LstCOM.Length > 0) strRECO = string.Join(",", LstCOM); //--------------------------------------------------// rk = rk.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM"); if (rk == null) return new string[0]; string[] names = rk.GetValueNames(); //--------------------------------------------------// index = 0; strType = new string[names.Length]; string[] ValRet = new string[names.Length]; foreach (string name in names) { strType[index] = ""; if (name.ToLower().Contains("bth")) strType[index] = "BLUE"; else if (name.ToLower().Contains("serial")) strType[index] = "HARD"; else if (name.ToLower().Contains("vcp")) strType[index] = "VIRT"; if (strType[index].Length > 0) { string val = (string)rk.GetValue(name); for (int i = 3; i < val.Length; i++) // 3 = len -> COM prefix if (!char.IsDigit(val, i)) { val = val.Substring(0, i); break; } if (strType[index] == "BLUE" && !strRECO.Contains(val + ",")) { val = ""; strType[index] = ""; } else ValRet[index++] = val; } } if (bt != null) { bt.Close(); bt = null; } if (rk != null) { rk.Close(); rk = null; } Array.Resize(ref ValRet, index); Array.Resize(ref strType, index); return ValRet; }
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.