瀏覽代碼

Bluecell BootLoader Protocol Add / Data Handler Class Add /File OPen Class 실수로 삭제함 ㅠㅠ / FileDownload Add

Serial str to hex 변환 공식 추가 / Serial Terminal Open Catch 했을 때 경우의 수 추가 / Serial Data Send 메서드 추가
YJ 6 年之前
父節點
當前提交
b10575590c

+ 3 - 1
Basic_Terminal/Basic_Terminal.csproj

@@ -46,7 +46,10 @@
46 46
     <Reference Include="System.Xml" />
47 47
   </ItemGroup>
48 48
   <ItemGroup>
49
+    <Compile Include="Func\Bluecell_BootProtocol.cs" />
49 50
     <Compile Include="Func\Crc16.cs" />
51
+    <Compile Include="Func\Data_Handler.cs" />
52
+    <Compile Include="Func\FileDownload.cs" />
50 53
     <Compile Include="Wnd\Debug.cs">
51 54
       <SubType>Form</SubType>
52 55
     </Compile>
@@ -59,7 +62,6 @@
59 62
     <Compile Include="Wnd\Download_bar.Designer.cs">
60 63
       <DependentUpon>Download_bar.cs</DependentUpon>
61 64
     </Compile>
62
-    <Compile Include="Func\File_Open.cs" />
63 65
     <Compile Include="Wnd\Main_Form.cs">
64 66
       <SubType>Form</SubType>
65 67
     </Compile>

+ 102 - 0
Basic_Terminal/Func/Bluecell_BootProtocol.cs

@@ -0,0 +1,102 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace Basic_Terminal
8
+{
9
+    public enum Bluepro_t
10
+    {
11
+        bluecell_header0 = 0,
12
+        bluecell_header1,
13
+        bluecell_header2,
14
+        bluecell_header3,
15
+        bluecell_type,
16
+        bluecell_length01,
17
+        bluecell_length02,
18
+    };
19
+    
20
+    class Bluecell_BootProtocol
21
+    {
22
+        Serial serial;
23
+        /*bluecell Header*/
24
+        public const byte Bluecell_Header0 = 0x42;//ASCII : B
25
+        public const byte Bluecell_Header1 = 0x4C;//ASCII : L
26
+        public const byte Bluecell_Header2 = 0x55;//ASCII : U
27
+        public const byte Bluecell_Header3 = 0x45;//ASCII : E
28
+        /*bluecell type*/
29
+        public const byte Bluecell_Reset = 0x52;//ASCII : R
30
+        public const byte Bluecell_Firmupdate_start    = 0x55;//ASCII : U
31
+        public const byte Bluecell_Firmupdate_sending  = 0x53;//ASCII : S
32
+        public const byte Bluecell_Firmupdate_end      = 0x65;//ASCII : e
33
+
34
+        public const int bluecell_Firmupdate_sendlength = 1024;
35
+        Crc16 crc16 = new Crc16();
36
+
37
+        public int Bluecell_Firmupdate_sendlength() {
38
+            return bluecell_Firmupdate_sendlength;
39
+        }
40
+
41
+        public byte[] Boot_Reset(object serial)
42
+        {
43
+            this.serial = (Serial)serial;
44
+            byte[] fix_data = new byte[8];
45
+            //Array.Clear(data, 0, data.Length);
46
+            fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
47
+            fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
48
+            fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
49
+            fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
50
+            fix_data[(int)Bluepro_t.bluecell_type]    = Bluecell_Reset;
51
+            fix_data[(int)Bluepro_t.bluecell_length01]  = 0;
52
+            fix_data[(int)Bluepro_t.bluecell_length02]  = 5;
53
+
54
+            fix_data[(int)Bluepro_t.bluecell_type + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0xFF00) >> 8);
55
+            fix_data[(int)Bluepro_t.bluecell_type + 2] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0x00FF));
56
+            this.serial.Serial_DataSend(fix_data, fix_data.Length);
57
+            return fix_data;            
58
+        }
59
+        public byte[] Boot_DataStart()
60
+        {
61
+            //Array.Clear(data, 0, data.Length);
62
+            byte[] fix_data = new byte[9];
63
+            fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
64
+            fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
65
+            fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
66
+            fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
67
+            fix_data[(int)Bluepro_t.bluecell_type]    = Bluecell_Firmupdate_start;
68
+            fix_data[(int)Bluepro_t.bluecell_length01]  = 0;
69
+            fix_data[(int)Bluepro_t.bluecell_length02]  = 3;
70
+            fix_data[(int)Bluepro_t.bluecell_type + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0xFF00) >> 8);
71
+            fix_data[(int)Bluepro_t.bluecell_type + 2] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0x00FF));
72
+            return fix_data;
73
+        }
74
+        public byte[] Boot_DataSending(byte[] data,int length)
75
+        {
76
+            //Array.Clear(data, 0, data.Length);
77
+            byte[] fix_data = new byte[5];
78
+            fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
79
+            fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
80
+            fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
81
+            fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
82
+            fix_data[(int)Bluepro_t.bluecell_type]    = Bluecell_Firmupdate_sending;
83
+            fix_data[(int)Bluepro_t.bluecell_length01] = Convert.ToByte((length & 0xFF00) >> 8);
84
+            fix_data[(int)Bluepro_t.bluecell_length02] = Convert.ToByte((length & 0x00FF));
85
+            return data;
86
+        }
87
+        public byte[] Boot_DataEnd()
88
+        {
89
+            //Array.Clear(data, 0, data.Length);
90
+            byte[] fix_data = new byte[5];
91
+            fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
92
+            fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
93
+            fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
94
+            fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
95
+            fix_data[(int)Bluepro_t.bluecell_type]    = Bluecell_Firmupdate_end;
96
+            fix_data[(int)Bluepro_t.bluecell_length01] = 0;
97
+            fix_data[(int)Bluepro_t.bluecell_length02] = 3;
98
+
99
+            return fix_data;
100
+        }
101
+    }
102
+}

+ 35 - 0
Basic_Terminal/Func/Data_Handler.cs

@@ -0,0 +1,35 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace Basic_Terminal
8
+{
9
+    class Data_Handler
10
+    {
11
+        public void Recv_dataCheck(byte[] data)
12
+        {
13
+            Boolean HeaderCheck = Serial_HeaderCheck(data);
14
+            int DataAckcnt = data[(int)Bluepro_t.bluecell_type + 1];
15
+            if (HeaderCheck == false)
16
+            {
17
+                return;
18
+            }
19
+            else
20
+            {
21
+                DataSeq seq = DataSeq.UpdateResetOK;
22
+                switch (seq)
23
+                {
24
+                    case DataSeq.UpdateSendingOK:
25
+                        UpdateFileSend(data, DataAckcnt);
26
+                        break;
27
+                    case DataSeq.UpdateEndOK:
28
+                        break;
29
+                    default:
30
+                        break;
31
+                }
32
+            }
33
+        }
34
+    }
35
+}

+ 119 - 0
Basic_Terminal/Func/FileDownload.cs

@@ -0,0 +1,119 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+using System.Windows.Forms;
8
+using System.IO;
9
+using System.IO.Ports;
10
+namespace Basic_Terminal
11
+{
12
+    enum DataSeq
13
+    {
14
+        UpdateResetOK = 0,
15
+        UpdateStartOK,
16
+        UpdateSendingOK,
17
+        UpdateEndOK,
18
+    }
19
+    class FileDownload
20
+    {
21
+        
22
+        Bluecell_BootProtocol Bluecell_BootProtocol = new Bluecell_BootProtocol();
23
+
24
+        /***
25
+         *Data File open
26
+        */
27
+        OpenFileDialog ofd;
28
+        Serial serial;
29
+        public string ShowFileOpenDialog(object serial,object ofd)
30
+        {
31
+            this.ofd = (OpenFileDialog)ofd;
32
+            this.serial = (Serial)serial;
33
+            this.ofd.Title = "업데이터 파일 탐색기";//파일오픈창 생성 및 설정
34
+            this.ofd.FileName = "*.bin";
35
+            //ofd.Filter = "bin 파일 (*.bin) | *.bin; | 모든 파일 (*.*) | *.*";
36
+            this.ofd.Filter = "bin 파일 (*.bin) | *.bin;";
37
+            DialogResult dr = this.ofd.ShowDialog();            //파일 오픈창 로드
38
+            if (dr == DialogResult.OK)//OK버튼 클릭시
39
+            {
40
+                string fileName = this.ofd.SafeFileName;                //File명과 확장자를 가지고 온다.
41
+                string fileFullName = this.ofd.FileName;//File경로와 File명을 모두 가지고 온다.
42
+                string filePath = fileFullName.Replace(fileName, "");//File경로만 가지고 온다.
43
+                Bluecell_BootProtocol.Boot_Reset(serial);
44
+                //UpdateFileSend(File.ReadAllBytes(this.ofd.FileName));
45
+                return fileFullName;
46
+            }
47
+            else if (dr == DialogResult.Cancel)//취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
48
+            {
49
+                return "";
50
+            }
51
+            return "";
52
+        }
53
+#if false
54
+        public void Recv_dataCheck(byte[] data)
55
+        {
56
+            Boolean HeaderCheck = Serial_HeaderCheck(data);
57
+            int DataAckcnt = data[(int)Bluepro_t.bluecell_type + 1];
58
+            if (HeaderCheck == false)
59
+            {
60
+                return;
61
+            }
62
+            else
63
+            {
64
+                DataSeq seq = DataSeq.UpdateResetOK;
65
+                switch (seq)
66
+                {
67
+                    case DataSeq.UpdateSendingOK:
68
+                        UpdateFileSend(data, DataAckcnt);
69
+                        break;
70
+                    case DataSeq.UpdateEndOK:
71
+                        break;
72
+                    default:
73
+                        break;
74
+                }
75
+            }
76
+        }
77
+#endif
78
+        private void UpdateFileSend(byte[] data,int cnt)
79
+        {
80
+            /*Define*/
81
+            int Quotient = 0,remainder = 0;
82
+            int sourceindex = 0;
83
+            byte[] updatedata = new byte[Bluecell_BootProtocol.bluecell_Firmupdate_sendlength];
84
+            /*Filse size */
85
+            Quotient = data.Length / Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
86
+            remainder = data.Length % Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
87
+            /*file copy*/
88
+            Array.Copy(data, sourceindex, updatedata, 0,Bluecell_BootProtocol.bluecell_Firmupdate_sendlength);
89
+            /*file write*/
90
+            if (remainder > 0 && cnt > Quotient)
91
+            {
92
+                this.serial.Serial_DataSend(data, remainder);
93
+            }
94
+            else
95
+            {
96
+                this.serial.Serial_DataSend(data, cnt * Bluecell_BootProtocol.bluecell_Firmupdate_sendlength);
97
+                /*send index modify*/
98
+                sourceindex = cnt * Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
99
+            }
100
+
101
+        }
102
+
103
+        public Boolean Serial_HeaderCheck(byte[] data)
104
+        {
105
+            Boolean ret = false;
106
+            if (data[(int)Bluepro_t.bluecell_header0] == Bluecell_BootProtocol.Bluecell_Header0
107
+                && data[(int)Bluepro_t.bluecell_header1] == Bluecell_BootProtocol.Bluecell_Header1
108
+                && data[(int)Bluepro_t.bluecell_header2] == Bluecell_BootProtocol.Bluecell_Header2
109
+                && data[(int)Bluepro_t.bluecell_header3] == Bluecell_BootProtocol.Bluecell_Header3
110
+                )/*모든 Header OK */
111
+            {
112
+                ret = true;
113
+            }
114
+            return ret;
115
+        }
116
+
117
+       
118
+    }
119
+}

+ 0 - 42
Basic_Terminal/Func/File_Open.cs

@@ -1,42 +0,0 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq;
4
-using System.Text;
5
-using System.Threading.Tasks;
6
-//Add code
7
-using System.Windows.Forms;
8
-using System.IO;
9
-using System.IO.Ports;
10
-namespace Basic_Terminal
11
-{
12
-    class File_Open
13
-    {
14
-        OpenFileDialog ofd = new OpenFileDialog();
15
-        public string ShowFileOpenDialog()
16
-        {
17
-            ofd.Title = "업데이터 파일 탐색기";//파일오픈창 생성 및 설정
18
-            ofd.FileName = "*.bin";
19
-            //ofd.Filter = "bin 파일 (*.bin) | *.bin; | 모든 파일 (*.*) | *.*";
20
-            ofd.Filter = "bin 파일 (*.bin) | *.bin;";
21
-            DialogResult dr = ofd.ShowDialog();            //파일 오픈창 로드
22
-            if (dr == DialogResult.OK)//OK버튼 클릭시
23
-            {
24
-                string fileName = ofd.SafeFileName;                //File명과 확장자를 가지고 온다.
25
-                string fileFullName = ofd.FileName;//File경로와 File명을 모두 가지고 온다.
26
-                string filePath = fileFullName.Replace(fileName, "");//File경로만 가지고 온다.
27
-                UpdateFileSend(File.ReadAllBytes(ofd.FileName));
28
-                return fileFullName;
29
-            }
30
-            else if (dr == DialogResult.Cancel)//취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
31
-            {
32
-                return "";
33
-            }
34
-            return "";
35
-        }
36
-        private void UpdateFileSend(byte[] data)
37
-        {
38
-
39
-        }
40
-
41
-    }
42
-}

+ 67 - 3
Basic_Terminal/Func/Serial.cs

@@ -13,9 +13,9 @@ namespace Basic_Terminal
13 13
     class Serial
14 14
     {
15 15
         private System.IO.Ports.SerialPort serialPort;
16
-
16
+        private Debug Debug = new Debug();    // Teminal Text Wnd Open
17 17
         public string Serial_Name { get => serialPort.PortName;  set => serialPort.PortName = value;}
18
-
18
+        Data_Handler data_Handler = new Data_Handler();
19 19
         public void Serial_Initialize(ref ComboBox cb_port)
20 20
         {
21 21
             
@@ -37,17 +37,51 @@ namespace Basic_Terminal
37 37
             serialPort.StopBits = StopBits.One;
38 38
 
39 39
         }
40
+        private delegate void StringSend(string Text);
41
+        private delegate void ByteSend(byte[] Text);
42
+
43
+        public string str2hex(string strData,Boolean Compotable)
44
+        {
45
+            string resultHex = string.Empty;
46
+            byte[] arr_byteStr = Encoding.Default.GetBytes(strData);
47
+
48
+            foreach (byte byteStr in arr_byteStr)
49
+            {
50
+                if(Compotable == true)
51
+                    resultHex += string.Format("{0:X2}", byteStr) + " ";
52
+                else
53
+                    resultHex += string.Format("{0:X2}", byteStr);
54
+            }
55
+
56
+            return resultHex;
57
+        }
58
+
59
+        static public byte[] str2bytes(string byteData)
60
+        {
61
+            System.Text.ASCIIEncoding asencoding = new System.Text.ASCIIEncoding();
62
+            return Encoding.Default.GetBytes(byteData);
63
+        }
64
+
40 65
         public void Serial_DataRecvFunction(object sender, SerialDataReceivedEventArgs e)
41 66
         {
67
+            
68
+            string data = serialPort.ReadExisting();
69
+            if(Debug.RadioButton_ascii.Checked == true)
70
+                Debug.Invoke(new StringSend(Debug.Data_Recv_Str), data);
71
+            else
72
+                Debug.Invoke(new StringSend(Debug.Data_Recv_Str), str2hex(data,true));
42 73
 
74
+            data_Handler.Recv_dataCheck(str2bytes(str2hex(data,false)));
43 75
         }
44
-        public void Serial_PortOpen(ref Button Btn_Portonoff)
76
+        public Boolean Serial_PortOpen(ref Button Btn_Portonoff)
45 77
         {
78
+            Boolean ret = false;
46 79
             try
47 80
             {
48 81
                 if (serialPort.IsOpen) { //When the port is open
49 82
                     serialPort.Close();
50 83
                     Btn_Portonoff.Text = "Port Open";
84
+                    ret = true;
51 85
                 }
52 86
                 else//When the port is close
53 87
                 {
@@ -60,6 +94,36 @@ namespace Basic_Terminal
60 94
                 MessageBox.Show("already port open " + Serial_Name);
61 95
                
62 96
             }
97
+            return ret;
98
+        }
99
+        public void Serial_TerminalOpen(object serial)
100
+        {
101
+            this.Debug.Serial_ClassSet(serial);
102
+            try
103
+            {
104
+                this.Debug.Show();
105
+            }
106
+            catch
107
+            {
108
+                Debug = new Debug();
109
+                this.Debug.Show();
110
+            }
111
+        }
112
+        public void Serial_DataSend(byte[] data)
113
+        {
114
+            try
115
+            {
116
+                serialPort.Write(data,0,data.Length);
117
+            }
118
+            catch (System.Exception ex)
119
+            {
120
+                MessageBox.Show(ex.Message);
121
+            }
122
+        }
123
+        public void Serial_DataSend(byte[] buffer, int count)
124
+        {
125
+            try { serialPort.Write(buffer, 0, count); }
126
+            catch { MessageBox.Show("Port Open Failed!!!"); }
63 127
         }
64 128
     }
65 129
 }

+ 120 - 16
Basic_Terminal/Wnd/Debug.Designer.cs

@@ -28,37 +28,141 @@
28 28
         /// </summary>
29 29
         private void InitializeComponent()
30 30
         {
31
-            this.tbReceived2 = new System.Windows.Forms.RichTextBox();
31
+            this.tbReceived = new System.Windows.Forms.RichTextBox();
32
+            this.groupBox1 = new System.Windows.Forms.GroupBox();
33
+            this.checkBox2 = new System.Windows.Forms.CheckBox();
34
+            this.checkBox1 = new System.Windows.Forms.CheckBox();
35
+            this.radioButton_ascii = new System.Windows.Forms.RadioButton();
36
+            this.radioButton_hex = new System.Windows.Forms.RadioButton();
37
+            this.button_Clear = new System.Windows.Forms.Button();
38
+            this.button_Send = new System.Windows.Forms.Button();
39
+            this.textBox_senddata = new System.Windows.Forms.TextBox();
40
+            this.groupBox1.SuspendLayout();
32 41
             this.SuspendLayout();
33 42
             // 
34
-            // tbReceived2
43
+            // tbReceived
35 44
             // 
36
-            this.tbReceived2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
37
-            this.tbReceived2.Dock = System.Windows.Forms.DockStyle.Fill;
38
-            this.tbReceived2.ForeColor = System.Drawing.SystemColors.Window;
39
-            this.tbReceived2.Location = new System.Drawing.Point(0, 0);
40
-            this.tbReceived2.MaxLength = 0;
41
-            this.tbReceived2.Name = "tbReceived2";
42
-            this.tbReceived2.ReadOnly = true;
43
-            this.tbReceived2.Size = new System.Drawing.Size(800, 450);
44
-            this.tbReceived2.TabIndex = 63;
45
-            this.tbReceived2.Text = "";
46
-            this.tbReceived2.WordWrap = false;
45
+            this.tbReceived.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
46
+            this.tbReceived.ForeColor = System.Drawing.SystemColors.Window;
47
+            this.tbReceived.Location = new System.Drawing.Point(0, 0);
48
+            this.tbReceived.MaxLength = 0;
49
+            this.tbReceived.Name = "tbReceived";
50
+            this.tbReceived.ReadOnly = true;
51
+            this.tbReceived.Size = new System.Drawing.Size(800, 403);
52
+            this.tbReceived.TabIndex = 63;
53
+            this.tbReceived.Text = "";
54
+            this.tbReceived.WordWrap = false;
55
+            // 
56
+            // groupBox1
57
+            // 
58
+            this.groupBox1.Controls.Add(this.checkBox2);
59
+            this.groupBox1.Controls.Add(this.checkBox1);
60
+            this.groupBox1.Controls.Add(this.radioButton_ascii);
61
+            this.groupBox1.Controls.Add(this.radioButton_hex);
62
+            this.groupBox1.Controls.Add(this.button_Clear);
63
+            this.groupBox1.Controls.Add(this.button_Send);
64
+            this.groupBox1.Controls.Add(this.textBox_senddata);
65
+            this.groupBox1.Location = new System.Drawing.Point(13, 410);
66
+            this.groupBox1.Name = "groupBox1";
67
+            this.groupBox1.Size = new System.Drawing.Size(787, 89);
68
+            this.groupBox1.TabIndex = 64;
69
+            this.groupBox1.TabStop = false;
70
+            this.groupBox1.Text = "보내는 문자열";
71
+            // 
72
+            // checkBox2
73
+            // 
74
+            this.checkBox2.AutoSize = true;
75
+            this.checkBox2.Location = new System.Drawing.Point(254, 20);
76
+            this.checkBox2.Name = "checkBox2";
77
+            this.checkBox2.Size = new System.Drawing.Size(116, 16);
78
+            this.checkBox2.TabIndex = 4;
79
+            this.checkBox2.Text = "수신 문자열 표시";
80
+            this.checkBox2.UseVisualStyleBackColor = true;
81
+            // 
82
+            // checkBox1
83
+            // 
84
+            this.checkBox1.AutoSize = true;
85
+            this.checkBox1.Location = new System.Drawing.Point(131, 20);
86
+            this.checkBox1.Name = "checkBox1";
87
+            this.checkBox1.Size = new System.Drawing.Size(116, 16);
88
+            this.checkBox1.TabIndex = 4;
89
+            this.checkBox1.Text = "송신 문자열 표시";
90
+            this.checkBox1.UseVisualStyleBackColor = true;
91
+            // 
92
+            // radioButton_ascii
93
+            // 
94
+            this.radioButton_ascii.AutoSize = true;
95
+            this.radioButton_ascii.Checked = true;
96
+            this.radioButton_ascii.Location = new System.Drawing.Point(71, 20);
97
+            this.radioButton_ascii.Name = "radioButton_ascii";
98
+            this.radioButton_ascii.Size = new System.Drawing.Size(54, 16);
99
+            this.radioButton_ascii.TabIndex = 3;
100
+            this.radioButton_ascii.TabStop = true;
101
+            this.radioButton_ascii.Text = "ASCII";
102
+            this.radioButton_ascii.UseVisualStyleBackColor = true;
103
+            // 
104
+            // radioButton_hex
105
+            // 
106
+            this.radioButton_hex.AutoSize = true;
107
+            this.radioButton_hex.Location = new System.Drawing.Point(7, 20);
108
+            this.radioButton_hex.Name = "radioButton_hex";
109
+            this.radioButton_hex.Size = new System.Drawing.Size(45, 16);
110
+            this.radioButton_hex.TabIndex = 3;
111
+            this.radioButton_hex.Text = "Hex";
112
+            this.radioButton_hex.UseVisualStyleBackColor = true;
113
+            // 
114
+            // button_Clear
115
+            // 
116
+            this.button_Clear.Location = new System.Drawing.Point(702, 20);
117
+            this.button_Clear.Name = "button_Clear";
118
+            this.button_Clear.Size = new System.Drawing.Size(71, 23);
119
+            this.button_Clear.TabIndex = 2;
120
+            this.button_Clear.Text = "삭제";
121
+            this.button_Clear.UseVisualStyleBackColor = true;
122
+            this.button_Clear.Click += new System.EventHandler(this.button_Clear_Click);
123
+            // 
124
+            // button_Send
125
+            // 
126
+            this.button_Send.Location = new System.Drawing.Point(702, 53);
127
+            this.button_Send.Name = "button_Send";
128
+            this.button_Send.Size = new System.Drawing.Size(71, 23);
129
+            this.button_Send.TabIndex = 1;
130
+            this.button_Send.Text = "보내기";
131
+            this.button_Send.UseVisualStyleBackColor = true;
132
+            this.button_Send.Click += new System.EventHandler(this.Button_Send_Click);
133
+            // 
134
+            // textBox_senddata
135
+            // 
136
+            this.textBox_senddata.Location = new System.Drawing.Point(7, 54);
137
+            this.textBox_senddata.Name = "textBox_senddata";
138
+            this.textBox_senddata.Size = new System.Drawing.Size(688, 21);
139
+            this.textBox_senddata.TabIndex = 0;
47 140
             // 
48 141
             // Debug
49 142
             // 
50 143
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
51 144
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
52
-            this.ClientSize = new System.Drawing.Size(800, 450);
53
-            this.Controls.Add(this.tbReceived2);
145
+            this.ClientSize = new System.Drawing.Size(802, 511);
146
+            this.Controls.Add(this.groupBox1);
147
+            this.Controls.Add(this.tbReceived);
54 148
             this.Name = "Debug";
55 149
             this.Text = "Debug";
150
+            this.groupBox1.ResumeLayout(false);
151
+            this.groupBox1.PerformLayout();
56 152
             this.ResumeLayout(false);
57 153
 
58 154
         }
59 155
 
60 156
         #endregion
61 157
 
62
-        public System.Windows.Forms.RichTextBox tbReceived2;
158
+        public System.Windows.Forms.RichTextBox tbReceived;
159
+        private System.Windows.Forms.GroupBox groupBox1;
160
+        private System.Windows.Forms.Button button_Send;
161
+        private System.Windows.Forms.TextBox textBox_senddata;
162
+        private System.Windows.Forms.Button button_Clear;
163
+        private System.Windows.Forms.CheckBox checkBox2;
164
+        private System.Windows.Forms.CheckBox checkBox1;
165
+        private System.Windows.Forms.RadioButton radioButton_ascii;
166
+        private System.Windows.Forms.RadioButton radioButton_hex;
63 167
     }
64 168
 }

+ 55 - 47
Basic_Terminal/Wnd/Debug.cs

@@ -16,17 +16,19 @@ namespace Basic_Terminal
16 16
         int LineLimit = 500;
17 17
         [DllImport("user32.dll")]
18 18
         public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
19
-        private const int WM_SETREDRAW = 255;
19
+        private const int WM_SETREDRAW = 11;
20
+        Serial serial;
21
+        public RadioButton RadioButton_ascii { get => radioButton_ascii; set => radioButton_ascii = value; }
22
+        public RadioButton RadioButton_hex { get => radioButton_hex; set => radioButton_hex = value; }
20 23
 
21 24
         public Debug()
22 25
         {
26
+            
23 27
             InitializeComponent();
28
+            
24 29
         }
25
-
26
-
27
-
28
-        TextBox temp_data = new TextBox();
29
-        public void Controller_TextLoad(string text)
30
+#if true
31
+        public void Data_Recv_Str(string text)
30 32
         {
31 33
             int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
32 34
             try
@@ -35,16 +37,16 @@ namespace Basic_Terminal
35 37
                 {
36 38
                     SendMessage(this.Handle, WM_SETREDRAW, false, 0);
37 39
                 }
38
-                catch { return; }
39
-                if (tbReceived2.Lines.Length > nLimitLines)
40
+                catch (Exception e) { MessageBox.Show(e.StackTrace); }
41
+                if (tbReceived.Lines.Length > nLimitLines)
40 42
                 {
41
-                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived2.Lines);
43
+                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
42 44
                     while ((tempLines.Count - nLimitLines) > 0)
43 45
                     {
44 46
                         tempLines.RemoveFirst();
45 47
                     }
46 48
 
47
-                    tbReceived2.Lines = tempLines.ToArray();
49
+                    tbReceived.Lines = tempLines.ToArray();
48 50
 
49 51
                 }
50 52
                 try
@@ -52,58 +54,49 @@ namespace Basic_Terminal
52 54
                     SendMessage(this.Handle, WM_SETREDRAW, true, 0);
53 55
                 }
54 56
                 catch { return; }
55
-                tbReceived2.AppendText(text);
56
-                tbReceived2.SelectionStart = tbReceived2.Text.Length;//맨 마지막 선택... 
57
-                tbReceived2.ScrollToCaret();
57
+                tbReceived.AppendText(text);
58
+                tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택... 
59
+                tbReceived.ScrollToCaret();
58 60
             }
59 61
             catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
60 62
         }
61
-        public void Controller_TextLoad(byte[] text)
63
+#endif
64
+#if false
65
+        public void Data_Recv_Hex(byte[] text)
62 66
         {
63
-            string AppendMessage = "\n[RX]";
64
-
65
-            int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
67
+           int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
66 68
             try
67 69
             {
68
-                for (int i = 0; i < text.Length; i++)
69
-                {
70
-                    AppendMessage += Convert.ToString(text[i], 16);
71
-                }
72
-                //string AppendMessage = DateTime.Now.ToString("hh:mm:ss.fff") + " " + text;
73
-                try
74
-                {
75
-                    tbReceived2.AppendText(AppendMessage);
76
-                }
77
-                catch { return; }
78 70
                 try
79 71
                 {
80 72
                     SendMessage(this.Handle, WM_SETREDRAW, false, 0);
81 73
                 }
82
-                catch { return; }
83
-                if (tbReceived2.Lines.Length > nLimitLines)
74
+                catch (Exception e) { MessageBox.Show(e.StackTrace); }
75
+                if (tbReceived.Lines.Length > nLimitLines)
84 76
                 {
85
-                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived2.Lines);
86
-
77
+                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
87 78
                     while ((tempLines.Count - nLimitLines) > 0)
88 79
                     {
89 80
                         tempLines.RemoveFirst();
90 81
                     }
91 82
 
92
-                    tbReceived2.Lines = tempLines.ToArray();
83
+                    tbReceived.Lines = tempLines.ToArray();
84
+
93 85
                 }
94 86
                 try
95 87
                 {
96 88
                     SendMessage(this.Handle, WM_SETREDRAW, true, 0);
97 89
                 }
98 90
                 catch { return; }
99
-                tbReceived2.Select(tbReceived2.Text.Length, 0);
100
-                tbReceived2.ScrollToCaret();
91
+                tbReceived.AppendText(text.ToString());
92
+                tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택... 
93
+                tbReceived.ScrollToCaret();
101 94
             }
102
-            finally { }
95
+            catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
103 96
 
104 97
         }
105
-
106
-        public void Controller_TX_TextLoad(byte[] text)
98
+#endif
99
+        public void Data_Send(byte[] text)
107 100
         {
108 101
             string AppendMessage = "\n[TX]";
109 102
 
@@ -114,43 +107,58 @@ namespace Basic_Terminal
114 107
                 {
115 108
                     AppendMessage += Convert.ToString(text[i], 16);
116 109
                 }
117
-                tbReceived2.AppendText(AppendMessage);
110
+                tbReceived.AppendText(AppendMessage);
118 111
                 try
119 112
                 {
120 113
                     SendMessage(this.Handle, WM_SETREDRAW, false, 0);
121 114
                 }
122 115
                 catch { return; }
123
-                if (tbReceived2.Lines.Length > nLimitLines)
116
+                if (tbReceived.Lines.Length > nLimitLines)
124 117
                 {
125
-                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived2.Lines);
118
+                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
126 119
 
127 120
                     while ((tempLines.Count - nLimitLines) > 0)
128 121
                     {
129 122
                         tempLines.RemoveFirst();
130 123
                     }
131 124
 
132
-                    tbReceived2.Lines = tempLines.ToArray();
125
+                    tbReceived.Lines = tempLines.ToArray();
133 126
                 }
134 127
                 try
135 128
                 {
136 129
                     SendMessage(this.Handle, WM_SETREDRAW, true, 0);
137 130
                 }
138 131
                 catch { return; }
139
-                tbReceived2.Select(tbReceived2.Text.Length, 0);
140
-                tbReceived2.ScrollToCaret();
132
+                tbReceived.Select(tbReceived.Text.Length, 0);
133
+                tbReceived.ScrollToCaret();
141 134
             }
142 135
             finally { }
143 136
 
144 137
         }
145
-        public void Controller_DebugBoxClear()
138
+    
139
+        public void Serial_ClassSet(object serial)
140
+        {
141
+            this.serial = (Serial)serial;
142
+        }
143
+        private void Button_Send_Click(object sender, EventArgs e)
146 144
         {
147 145
             try
148 146
             {
149
-                this.tbReceived2.Text = "";
147
+                this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
150 148
             }
151
-            finally { }
149
+            catch (System.Exception ex)
150
+            {
151
+                MessageBox.Show(ex.Message);
152
+            }
153
+        }
152 154
 
155
+        private void button_Clear_Click(object sender, EventArgs e)
156
+        {
157
+            try
158
+            {
159
+                this.tbReceived.Text = "";
160
+            }
161
+            finally { }
153 162
         }
154
-    
155 163
     }
156 164
 }

+ 4 - 4
Basic_Terminal/Wnd/Main_Form.Designer.cs

@@ -80,7 +80,7 @@
80 80
             this.button_terminal.TabIndex = 94;
81 81
             this.button_terminal.Text = "Terminal";
82 82
             this.button_terminal.UseVisualStyleBackColor = true;
83
-            this.button_terminal.Click += new System.EventHandler(this.button_terminal_Click);
83
+            this.button_terminal.Click += new System.EventHandler(this.Button_terminal_Click);
84 84
             // 
85 85
             // Ascii_checkBox
86 86
             // 
@@ -118,7 +118,7 @@
118 118
             this.button_PortOpen.TabIndex = 86;
119 119
             this.button_PortOpen.Text = "Port Open";
120 120
             this.button_PortOpen.UseVisualStyleBackColor = true;
121
-            this.button_PortOpen.Click += new System.EventHandler(this.button_PortOpen_Click);
121
+            this.button_PortOpen.Click += new System.EventHandler(this.Button_PortOpen_Click);
122 122
             // 
123 123
             // comboBox_Port
124 124
             // 
@@ -131,7 +131,7 @@
131 131
             this.comboBox_Port.Name = "comboBox_Port";
132 132
             this.comboBox_Port.Size = new System.Drawing.Size(101, 20);
133 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 135
             // 
136 136
             // cmBaudRate
137 137
             // 
@@ -193,7 +193,7 @@
193 193
             this.Controls.Add(this.Crc16_Check);
194 194
             this.Controls.Add(this.groupBox9);
195 195
             this.Name = "Main_Form";
196
-            this.Text = "Form1";
196
+            this.Text = "Terminal";
197 197
             this.groupBox9.ResumeLayout(false);
198 198
             this.groupBox9.PerformLayout();
199 199
             this.ResumeLayout(false);

+ 16 - 8
Basic_Terminal/Wnd/Main_Form.cs

@@ -16,7 +16,9 @@ namespace Basic_Terminal
16 16
     
17 17
     public partial class Main_Form : Form
18 18
     {
19
-        Serial serial = new Serial();
19
+        Serial serial = new Serial(); // Uart Open
20
+        OpenFileDialog ofd = new OpenFileDialog();
21
+
20 22
         public Main_Form()
21 23
         {
22 24
             InitializeComponent();
@@ -25,10 +27,10 @@ namespace Basic_Terminal
25 27
 
26 28
         private void Firmware_Update_Click(object sender, EventArgs e)
27 29
         {
28
-            File_Open file = new File_Open();
30
+            FileDownload file = new FileDownload();
29 31
             if (Ascii_checkBox.Checked == true)
30 32
                 Ascii_checkBox.Checked = false;
31
-            file.ShowFileOpenDialog();
33
+            file.ShowFileOpenDialog(serial, ofd);
32 34
         }
33 35
         private void Crc16_Check_Click(object sender, EventArgs e)
34 36
         {
@@ -37,19 +39,25 @@ namespace Basic_Terminal
37 39
             label1.Text = crc16.CRC16_Generate(tempdata, 11).ToString();
38 40
         }
39 41
 
40
-        private void button_PortOpen_Click(object sender, EventArgs e)
42
+        private void Button_PortOpen_Click(object sender, EventArgs e)
41 43
         {
42
-            serial.Serial_PortOpen(ref button_PortOpen);
44
+            Serial_connectiondisable(serial.Serial_PortOpen(ref button_PortOpen));
43 45
         }
44 46
 
45
-        private void comboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
47
+        private void ComboBox_Port_SelectedIndexChanged(object sender, EventArgs e)
46 48
         {
47 49
             serial.Serial_Name = comboBox_Port.SelectedItem.ToString();
48 50
         }
49 51
 
50
-        private void button_terminal_Click(object sender, EventArgs e)
52
+        private void Button_terminal_Click(object sender, EventArgs e)
51 53
         {
52
-
54
+            serial.Serial_TerminalOpen(serial);
53 55
         }
56
+        public void Serial_connectiondisable(Boolean on_off)
57
+        {
58
+            comboBox_Port.Enabled = on_off;
59
+            comboBox_baudrate.Enabled = on_off;
60
+        }
61
+
54 62
     }
55 63
 }