Browse Source

Serial Refresh 기능 추가

YJ 6 years ago
parent
commit
0efbdf9c07

+ 23 - 0
Basic_Terminal/Func/Serial.cs

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

+ 1 - 0
Basic_Terminal/Wnd/Main_Form.Designer.cs

@@ -363,6 +363,7 @@
363 363
             this.comboBox_Port.Size = new System.Drawing.Size(101, 20);
364 364
             this.comboBox_Port.TabIndex = 88;
365 365
             this.comboBox_Port.SelectedIndexChanged += new System.EventHandler(this.ComboBox_Port_SelectedIndexChanged);
366
+            this.comboBox_Port.MouseDown += new System.Windows.Forms.MouseEventHandler(this.comboBox_Port_MouseDown);
366 367
             // 
367 368
             // cmBaudRate
368 369
             // 

+ 5 - 0
Basic_Terminal/Wnd/Main_Form.cs

@@ -774,5 +774,10 @@ namespace RF_TRIO_PLL_ZIG
774 774
                     MessageBoxDefaultButton.Button1,
775 775
                     MessageBoxOptions.DefaultDesktopOnly);
776 776
         }
777
+
778
+        private void comboBox_Port_MouseDown(object sender, MouseEventArgs e)
779
+        {
780
+            serial.SetPortNameValues(comboBox_Port);
781
+        }
777 782
     }
778 783
 }