Identifiy serial port

Trying to find similar code:


List<string> ComPortNames(String VID, String PID)
{


String pattern = String.Format("^VID_{0}.PID_{1}", VID, PID);
Regex _rx = new Regex(pattern, RegexOptions.IgnoreCase);
List<string> comports = new List<string>();
RegistryKey rk1 = Registry.LocalMachine;
RegistryKey rk2 = rk1.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum");
foreach (String s3 in rk2.GetSubKeyNames())
{
tbxDateTime.Text = ("1");
RegistryKey rk3 = rk2.OpenSubKey(s3);
foreach (String s in rk3.GetSubKeyNames())
{
if (_rx.Match(s).Success)
{
tbxDateTime.Text = ("2");
RegistryKey rk4 = rk3.OpenSubKey(s);
foreach (String s2 in rk4.GetSubKeyNames())
{
tbxDateTime.Text = ("3");
RegistryKey rk5 = rk4.OpenSubKey(s2);
RegistryKey rk6 = rk5.OpenSubKey("Device Parameters");
comports.Add((string)rk6.GetValue("PortName"));
}
}
}
}
//tbxDateTime.Text = ("out");
return comports;
}







List<string> names = ComPortNames("2008", "1001");
if (names.Count > 0)
{
foreach (String s in SerialPort.GetPortNames())
{

if (names.Contains(s))
// Console.WriteLine("My TransCORE port is " + s + "and is" + m);
tbxOpenStat.Text = ("My TransCORE port is " + s);

}
}
else

//Console.WriteLine("No COM ports found");

tbxOpenStat.Text = ("No COM ports found");


in C++
Topic archived. No new replies allowed.