Explorar o código

Serial Refresh 기능추가 / Byte Recv 시 data 그리기 delay 삭제 / Debug Design 크기 변경

YJ %!s(int64=6) %!d(string=hai) anos
pai
achega
dd13706c70

+ 27 - 0
Basic_Terminal/Func/Serial.cs

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

+ 8 - 8
Basic_Terminal/Wnd/Debug.Designer.cs

@@ -49,7 +49,7 @@
49
             this.tbReceived.Name = "tbReceived";
49
             this.tbReceived.Name = "tbReceived";
50
             this.tbReceived.ReadOnly = true;
50
             this.tbReceived.ReadOnly = true;
51
             this.tbReceived.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
51
             this.tbReceived.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
52
-            this.tbReceived.Size = new System.Drawing.Size(800, 403);
52
+            this.tbReceived.Size = new System.Drawing.Size(1230, 403);
53
             this.tbReceived.TabIndex = 63;
53
             this.tbReceived.TabIndex = 63;
54
             this.tbReceived.Text = "";
54
             this.tbReceived.Text = "";
55
             // 
55
             // 
@@ -64,7 +64,7 @@
64
             this.groupBox1.Controls.Add(this.textBox_senddata);
64
             this.groupBox1.Controls.Add(this.textBox_senddata);
65
             this.groupBox1.Location = new System.Drawing.Point(13, 410);
65
             this.groupBox1.Location = new System.Drawing.Point(13, 410);
66
             this.groupBox1.Name = "groupBox1";
66
             this.groupBox1.Name = "groupBox1";
67
-            this.groupBox1.Size = new System.Drawing.Size(787, 89);
67
+            this.groupBox1.Size = new System.Drawing.Size(1217, 89);
68
             this.groupBox1.TabIndex = 64;
68
             this.groupBox1.TabIndex = 64;
69
             this.groupBox1.TabStop = false;
69
             this.groupBox1.TabStop = false;
70
             this.groupBox1.Text = "보내는 문자열";
70
             this.groupBox1.Text = "보내는 문자열";
@@ -113,7 +113,7 @@
113
             // 
113
             // 
114
             // button_Clear
114
             // button_Clear
115
             // 
115
             // 
116
-            this.button_Clear.Location = new System.Drawing.Point(702, 20);
116
+            this.button_Clear.Location = new System.Drawing.Point(1140, 19);
117
             this.button_Clear.Name = "button_Clear";
117
             this.button_Clear.Name = "button_Clear";
118
             this.button_Clear.Size = new System.Drawing.Size(71, 23);
118
             this.button_Clear.Size = new System.Drawing.Size(71, 23);
119
             this.button_Clear.TabIndex = 2;
119
             this.button_Clear.TabIndex = 2;
@@ -123,7 +123,7 @@
123
             // 
123
             // 
124
             // button_Send
124
             // button_Send
125
             // 
125
             // 
126
-            this.button_Send.Location = new System.Drawing.Point(702, 53);
126
+            this.button_Send.Location = new System.Drawing.Point(1140, 52);
127
             this.button_Send.Name = "button_Send";
127
             this.button_Send.Name = "button_Send";
128
             this.button_Send.Size = new System.Drawing.Size(71, 23);
128
             this.button_Send.Size = new System.Drawing.Size(71, 23);
129
             this.button_Send.TabIndex = 1;
129
             this.button_Send.TabIndex = 1;
@@ -135,14 +135,14 @@
135
             // 
135
             // 
136
             this.textBox_senddata.Location = new System.Drawing.Point(7, 54);
136
             this.textBox_senddata.Location = new System.Drawing.Point(7, 54);
137
             this.textBox_senddata.Name = "textBox_senddata";
137
             this.textBox_senddata.Name = "textBox_senddata";
138
-            this.textBox_senddata.Size = new System.Drawing.Size(688, 21);
138
+            this.textBox_senddata.Size = new System.Drawing.Size(1115, 21);
139
             this.textBox_senddata.TabIndex = 0;
139
             this.textBox_senddata.TabIndex = 0;
140
             // 
140
             // 
141
             // Debug
141
             // Debug
142
             // 
142
             // 
143
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
143
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
144
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
144
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
145
-            this.ClientSize = new System.Drawing.Size(802, 511);
145
+            this.ClientSize = new System.Drawing.Size(1242, 511);
146
             this.Controls.Add(this.groupBox1);
146
             this.Controls.Add(this.groupBox1);
147
             this.Controls.Add(this.tbReceived);
147
             this.Controls.Add(this.tbReceived);
148
             this.Name = "Debug";
148
             this.Name = "Debug";
@@ -162,7 +162,7 @@
162
         private System.Windows.Forms.Button button_Clear;
162
         private System.Windows.Forms.Button button_Clear;
163
         private System.Windows.Forms.CheckBox checkBox2;
163
         private System.Windows.Forms.CheckBox checkBox2;
164
         private System.Windows.Forms.CheckBox checkBox1;
164
         private System.Windows.Forms.CheckBox checkBox1;
165
-        private System.Windows.Forms.RadioButton radioButton_ascii;
166
-        private System.Windows.Forms.RadioButton radioButton_hex;
165
+        public System.Windows.Forms.RadioButton radioButton_ascii;
166
+        public System.Windows.Forms.RadioButton radioButton_hex;
167
     }
167
     }
168
 }
168
 }

+ 48 - 0
Basic_Terminal/Wnd/Debug.cs

@@ -13,6 +13,7 @@ namespace Basic_Terminal
13
 {
13
 {
14
     public partial class Debug : Form
14
     public partial class Debug : Form
15
     {
15
     {
16
+        Main_Form main_form;
16
         int LineLimit = 500;
17
         int LineLimit = 500;
17
         [DllImport("user32.dll")]
18
         [DllImport("user32.dll")]
18
         public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
19
         public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
@@ -30,6 +31,7 @@ namespace Basic_Terminal
30
 #if true
31
 #if true
31
         public void Data_Recv_Str(string text)
32
         public void Data_Recv_Str(string text)
32
         {
33
         {
34
+           
33
             int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
35
             int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
34
             try
36
             try
35
             {
37
             {
@@ -96,6 +98,48 @@ namespace Basic_Terminal
96
 
98
 
97
         }
99
         }
98
 #endif
100
 #endif
101
+        public void Data_Recv_Hex(byte[] text)
102
+        {
103
+            string AppendMessage = "";
104
+            
105
+            int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
106
+            try
107
+            {/*
108
+                try
109
+                {
110
+                    SendMessage(this.Handle, WM_SETREDRAW, false, 0);
111
+                }
112
+                catch (Exception e) { MessageBox.Show(e.StackTrace); }*/
113
+                for (int i = 0; i < text.Length; i++)
114
+                {
115
+                    AppendMessage += Convert.ToString(text[i], 16);
116
+                    AppendMessage += " ";
117
+                }
118
+                AppendMessage += "\r\n";
119
+                tbReceived.AppendText(AppendMessage);
120
+               
121
+                if (tbReceived.Lines.Length > nLimitLines)
122
+                {
123
+                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
124
+
125
+                    while ((tempLines.Count - nLimitLines) > 0)
126
+                    {
127
+                        tempLines.RemoveFirst();
128
+                    }
129
+
130
+                    tbReceived.Lines = tempLines.ToArray();
131
+                }
132
+                try
133
+                {
134
+                    SendMessage(this.Handle, WM_SETREDRAW, true, 0);
135
+                }
136
+                catch { return; }
137
+                tbReceived.Select(tbReceived.Text.Length, 0);
138
+                tbReceived.ScrollToCaret();
139
+            }
140
+            catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
141
+
142
+        }
99
         public void Data_Send(byte[] text)
143
         public void Data_Send(byte[] text)
100
         {
144
         {
101
             string AppendMessage = "\n[TX]";
145
             string AppendMessage = "\n[TX]";
@@ -170,5 +214,9 @@ namespace Basic_Terminal
170
             radioButton_ascii.Checked = true;
214
             radioButton_ascii.Checked = true;
171
             radioButton_hex.Checked = false;
215
             radioButton_hex.Checked = false;
172
         }
216
         }
217
+        public void Debug_Main_Form_Get(object frm)
218
+        {
219
+            this.main_form = (Main_Form)frm;
220
+        }
173
     }
221
     }
174
 }
222
 }

+ 1 - 1
Basic_Terminal/Wnd/Download_bar.cs

@@ -45,7 +45,7 @@ namespace Basic_Terminal
45
         public void Update_Percent(String val)
45
         public void Update_Percent(String val)
46
         {
46
         {
47
             CheckForIllegalCrossThreadCalls = false;
47
             CheckForIllegalCrossThreadCalls = false;
48
-            Firm_Progressbar.PerformStep();
48
+            //Firm_Progressbar.PerformStep();
49
             try
49
             try
50
             {
50
             {
51
                 Update_label.Text = val + "%";
51
                 Update_label.Text = val + "%";

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

@@ -132,6 +132,7 @@
132
             this.comboBox_Port.Size = new System.Drawing.Size(101, 20);
132
             this.comboBox_Port.Size = new System.Drawing.Size(101, 20);
133
             this.comboBox_Port.TabIndex = 88;
133
             this.comboBox_Port.TabIndex = 88;
134
             this.comboBox_Port.SelectedIndexChanged += new System.EventHandler(this.ComboBox_Port_SelectedIndexChanged);
134
             this.comboBox_Port.SelectedIndexChanged += new System.EventHandler(this.ComboBox_Port_SelectedIndexChanged);
135
+            this.comboBox_Port.MouseDown += new System.Windows.Forms.MouseEventHandler(this.comboBox_Port_MouseDown);
135
             // 
136
             // 
136
             // cmBaudRate
137
             // cmBaudRate
137
             // 
138
             // 

+ 6 - 1
Basic_Terminal/Wnd/Main_Form.cs

@@ -50,7 +50,8 @@ namespace Basic_Terminal
50
 
50
 
51
         private void ComboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
51
         private void ComboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
52
         {
52
         {
53
-            serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
53
+            
54
+            //serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
54
         }
55
         }
55
 
56
 
56
         private void Button_terminal_Click(object sender, EventArgs e)
57
         private void Button_terminal_Click(object sender, EventArgs e)
@@ -63,5 +64,9 @@ namespace Basic_Terminal
63
             comboBox_baudrate.Enabled = on_off;
64
             comboBox_baudrate.Enabled = on_off;
64
         }
65
         }
65
 
66
 
67
+        private void comboBox_Port_MouseDown(object sender, MouseEventArgs e)
68
+        {
69
+            serial.SetPortNameValues(comboBox_Port);
70
+        }
66
     }
71
     }
67
 }
72
 }