// 시리얼 설정 부분 선택지 private void Serial_Combo_Init() { // 시리얼 옵션 콤보박스 초기화 this.Serial_Combo_Port.DropDownStyle = ComboBoxStyle.DropDownList; this.Serial_Combo_Baud.DropDownStyle = ComboBoxStyle.DropDownList; this.Serial_Combo_Data.DropDownStyle = ComboBoxStyle.DropDownList; this.Serial_Combo_FlowCon.DropDownStyle = ComboBoxStyle.DropDownList; this.Serial_Combo_Parity.DropDownStyle = ComboBoxStyle.DropDownList; this.Serial_Combo_StopBit.DropDownStyle = ComboBoxStyle.DropDownList; // 이 부분에서 포트 없는 상태에서 불러올때마다 에러생기는 듯. 조건식 필요~! List <string> data = new List <string>(); foreach (string s in SerialPort.GetPortNames()) { data.Add(s); } Serial_Combo_Port.Items.AddRange(data.Cast <object>().ToArray()); using (var searcher = new ManagementObjectSearcher ("SELECT * FROM WIN32_SerialPort")) { string[] portnames = SerialPort.GetPortNames(); var ports = searcher.Get().Cast <ManagementBaseObject>().ToList(); //상세한 이름 가져오기 var tList = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select " - " + p["Caption"]).ToList(); //지원하는 포트 이름만 가져오기(비교해서 위에 있는 놈 붙여넣으려고) var cmpList = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select n).ToList(); //usb이름 가져오는 녀석 foreach (string s in cmpList) { for (int i = 0; i < Serial_Combo_Port.Items.Count; i++) { try { int a = Serial_Combo_Port.Items.IndexOf(s); Serial_Combo_Port.Items[a] += tList[i]; } catch (ArgumentException e) { } } } //comport 이름 가져오는 녀석 foreach (COMPortInfo comPort in COMPortInfo.GetCOMPortsInfo()) { string[] comportName = comPort.Name.Split('-'); int a = Serial_Combo_Port.Items.IndexOf(comportName[0]); Serial_Combo_Port.Items[a] += " - " + comPort.Description; } } if (Serial_Combo_Port.Items.Count != 0) { Serial_Combo_Port.SelectedIndex = 0; } Serial_Combo_Port.SelectedIndex = 0; List <string> data2 = new List <string>(); string[] Baud = { "4800", "9600", "14400", "19200" }; foreach (string s in Baud) { data2.Add(s); } Serial_Combo_Baud.Items.AddRange(data2.Cast <object>().ToArray()); Serial_Combo_Baud.SelectedIndex = 0; List <string> data3 = new List <string>(); string[] Data = { "7", "8" }; foreach (string s in Data) { data3.Add(s); } Serial_Combo_Data.Items.AddRange(data3.Cast <object>().ToArray()); Serial_Combo_Data.SelectedIndex = 1; List <string> data4 = new List <string>(); string[] Parity = { "none", "odd", "even", "mark", "space" }; foreach (string s in Parity) { data4.Add(s); } Serial_Combo_Parity.Items.AddRange(data4.Cast <object>().ToArray()); Serial_Combo_Parity.SelectedIndex = 0; List <string> data5 = new List <string>(); string[] Stopbit = { "none", "1 bit", "2 bit", "1.5 bit" }; foreach (string s in Stopbit) { data5.Add(s); } Serial_Combo_StopBit.Items.AddRange(data5.Cast <object>().ToArray()); Serial_Combo_StopBit.SelectedIndex = 1; List <string> data6 = new List <string>(); string[] FlowCon = { "none", "Xon/Xoff", "hardware" }; foreach (string s in FlowCon) { data6.Add(s); } Serial_Combo_FlowCon.Items.AddRange(data6.Cast <object>().ToArray()); Serial_Combo_FlowCon.SelectedIndex = 0; }