浏览代码

Port 새로고침 사용 안함 버그로인한 주석처리

YJ 5 年之前
父节点
当前提交
cbd1ec0042
共有 2 个文件被更改,包括 27 次插入1 次删除
  1. 22 0
      Basic_Terminal/Func/Serial.cs
  2. 5 1
      Basic_Terminal/Wnd/Main_Form.cs

+ 22 - 0
Basic_Terminal/Func/Serial.cs

@@ -19,6 +19,28 @@ namespace RF_TRIO_PLL_ZIG
19 19
         Data_Handler data_Handler = new Data_Handler();
20 20
         //FileDownload fileDownload;
21 21
         Update_Serial fileDownload = null;
22
+        public void SetPortNameValues(object obj)
23
+        {
24
+            string[] ports = SerialPort.GetPortNames(); // load all name of com ports to string
25
+            try
26
+            {
27
+                ((ComboBox)obj).Items.Clear(); //delete previous names in combobox items
28
+            }
29
+            catch { }
30
+           ((ComboBox)obj).DataSource = null;
31
+            foreach (string port in ports) //add this names to comboboxPort items
32
+            {
33
+                ((ComboBox)obj).Items.Add(port); //if there are some com ports ,select first
34
+            }
35
+            if (((ComboBox)obj).Items.Count > 0)
36
+            {
37
+                ((ComboBox)obj).SelectedIndex = 0;
38
+            }
39
+            else
40
+            {
41
+                ((ComboBox)obj).Text = " "; //if there are no com ports ,write Empty
42
+            }
43
+        }
22 44
         public void Serial_Initialize(ref ComboBox cb_port)
23 45
         {
24 46
             

+ 5 - 1
Basic_Terminal/Wnd/Main_Form.cs

@@ -68,7 +68,7 @@ namespace RF_TRIO_PLL_ZIG
68 68
 
69 69
         private void ComboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
70 70
         {
71
-            serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
71
+           // serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
72 72
         }
73 73
 
74 74
         private void Button_terminal_Click(object sender, EventArgs e)
@@ -774,5 +774,9 @@ namespace RF_TRIO_PLL_ZIG
774 774
                     MessageBoxDefaultButton.Button1,
775 775
                     MessageBoxOptions.DefaultDesktopOnly);
776 776
         }
777
+        private void comboBox_Port_MouseDown(object sender, MouseEventArgs e)
778
+        {
779
+            serial.SetPortNameValues(comboBox_Port);
780
+        }
777 781
     }
778 782
 }