public static List <VCom> GetComList() { Dictionary <String, String> cncalist = new Dictionary <string, string>(); List <VCom> list = new List <VCom>(); string cmd = String.Format("list"); ArrayList output; int ret = exec(cmd, out output); if (ret == 0) { foreach (string line in output) { Regex reg = new Regex("(CNCA|CNCB)(\\d+) PortName=(\\w+)"); Match match = reg.Match(line.Trim()); if (match.Success && match.Groups.Count > 3) { string value1 = match.Groups[1].Value; string value2 = match.Groups[2].Value; string value3 = match.Groups[3].Value; if (value1.CompareTo("CNCA") == 0 && !cncalist.ContainsKey(value2)) { cncalist.Add(value2, value3); } else if (value1.CompareTo("CNCB") == 0 && cncalist.ContainsKey(value2)) { string portname; if (cncalist.TryGetValue(value2, out portname)) { string strid = Regex.Replace(portname, @"COM", ""); int id = 0; if (Int32.TryParse(strid, out id)) { VCom vcom = new VCom(); vcom.Id = id; vcom.VComName = portname; vcom.VComName4Socket = value3; list.Add(vcom); } } } } } } list.Sort(); return(list); }
public int CompareTo(object obj) { int res = 0; try { VCom vcom = (VCom)obj; if (this.Id > vcom.Id) { res = 1; } else if (this.Id < vcom.Id) { res = -1; } } catch (Exception ex) { throw new Exception("比较异常", ex.InnerException); } return(res); }