public static void FindChild(string rootName, Transform trans, List <ComItem> list) { string name = trans.name; int lastUnderLine = name.LastIndexOf('_'); if (lastUnderLine > 0) { string comName = name.Substring(0, lastUnderLine); string comType = name.Substring(lastUnderLine + 1); if (comType != "" && checkComType(comType)) { ComItem item = new ComItem(); if (comName.Length > 1) { string firstLetter = comName[0].ToString(); string lastLatters = comName.Substring(1); item.com_var_name = string.Format("{0}{1}", firstLetter.ToLower(), lastLatters); } else { item.com_var_name = comName.ToLower(); } item.com_type_name = comType; item.com_path_name = GetTransPath(rootName, trans); list.Add(item); } } for (int i = 0; i < trans.childCount; i++) { FindChild(rootName, trans.GetChild(i), list); } }
public static ComItem GetComNum() { ComItem comItem = new ComItem(); comItem.ComNum = -1; comItem.ComName = ""; int comNum = -1; string[] strArr = GetHarewareInfo(HardwareEnum.Win32_PnPEntity, "Name"); foreach (string s in strArr) { if (s.Length >= 23 && s.Contains("CH340")) { int start = s.IndexOf("(") + 3; int end = s.IndexOf(")"); comNum = Convert.ToInt32(s.Substring(start + 1, end - start - 1)); Console.WriteLine(s); comItem.ComNum = comNum; comItem.ComName = s; } } return(comItem); }