浏览代码

CRC16 Lib 추가 / File Dialog Lib 추가 / Serial Lib 추가

YJ 6 年之前
父节点
当前提交
373fd861e5

+ 2 - 0
Basic_Terminal/Basic_Terminal.csproj

@@ -53,6 +53,7 @@
53 53
     <Compile Include="Download_bar.Designer.cs">
54 54
       <DependentUpon>Download_bar.cs</DependentUpon>
55 55
     </Compile>
56
+    <Compile Include="File_Open.cs" />
56 57
     <Compile Include="Main_Form.cs">
57 58
       <SubType>Form</SubType>
58 59
     </Compile>
@@ -61,6 +62,7 @@
61 62
     </Compile>
62 63
     <Compile Include="Program.cs" />
63 64
     <Compile Include="Properties\AssemblyInfo.cs" />
65
+    <Compile Include="Serial.cs" />
64 66
     <EmbeddedResource Include="Download_bar.resx">
65 67
       <DependentUpon>Download_bar.cs</DependentUpon>
66 68
     </EmbeddedResource>

+ 4 - 4
Basic_Terminal/Crc16.cs

@@ -10,7 +10,7 @@ namespace Basic_Terminal
10 10
 
11 11
     class Crc16
12 12
     {
13
-        private ushort[] Table_CRC16 = {
13
+        private readonly ushort[] Table_CRC16 = {
14 14
             0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
15 15
             0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
16 16
             0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
@@ -45,7 +45,7 @@ namespace Basic_Terminal
45 45
             0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
46 46
         };
47 47
 
48
-        public enum etError
48
+        public enum EtError
49 49
         {
50 50
             CHECKSUM_ERROR = 0,
51 51
             NO_ERROR
@@ -87,7 +87,7 @@ namespace Basic_Terminal
87 87
             return (crc16);
88 88
         }
89 89
 
90
-        etError CRC16_Check(byte[] buf_ptr, int len, ushort checksum)
90
+        EtError CRC16_Check(byte[] buf_ptr, int len, ushort checksum)
91 91
         {
92 92
             byte dt = 0;
93 93
             ushort crc16 = 0;
@@ -119,7 +119,7 @@ namespace Basic_Terminal
119 119
                     dt = (byte)(dt << 1);
120 120
                 }
121 121
             }
122
-            return (crc16 == checksum ? etError.CHECKSUM_ERROR : etError.NO_ERROR);
122
+            return (crc16 == checksum ? EtError.CHECKSUM_ERROR : EtError.NO_ERROR);
123 123
         }
124 124
     }
125 125
 }

+ 42 - 0
Basic_Terminal/File_Open.cs

@@ -0,0 +1,42 @@
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
+}

+ 45 - 45
Basic_Terminal/Main_Form.Designer.cs

@@ -33,11 +33,11 @@
33 33
             this.Start_button = new System.Windows.Forms.Button();
34 34
             this.Ascii_checkBox = new System.Windows.Forms.CheckBox();
35 35
             this.cmCom_Port = new System.Windows.Forms.Label();
36
-            this.button1 = new System.Windows.Forms.Button();
37
-            this.PortClose_button = new System.Windows.Forms.Button();
38
-            this.comboBox1 = new System.Windows.Forms.ComboBox();
36
+            this.button_PortOpen = new System.Windows.Forms.Button();
37
+            this.button_PortClose = new System.Windows.Forms.Button();
38
+            this.comboBox_Port = new System.Windows.Forms.ComboBox();
39 39
             this.cmBaudRate = new System.Windows.Forms.Label();
40
-            this.comboBox2 = new System.Windows.Forms.ComboBox();
40
+            this.comboBox_baudrate = new System.Windows.Forms.ComboBox();
41 41
             this.Crc16_Check = new System.Windows.Forms.Button();
42 42
             this.label1 = new System.Windows.Forms.Label();
43 43
             this.groupBox9.SuspendLayout();
@@ -52,11 +52,11 @@
52 52
             this.groupBox9.Controls.Add(this.Start_button);
53 53
             this.groupBox9.Controls.Add(this.Ascii_checkBox);
54 54
             this.groupBox9.Controls.Add(this.cmCom_Port);
55
-            this.groupBox9.Controls.Add(this.button1);
56
-            this.groupBox9.Controls.Add(this.PortClose_button);
57
-            this.groupBox9.Controls.Add(this.comboBox1);
55
+            this.groupBox9.Controls.Add(this.button_PortOpen);
56
+            this.groupBox9.Controls.Add(this.button_PortClose);
57
+            this.groupBox9.Controls.Add(this.comboBox_Port);
58 58
             this.groupBox9.Controls.Add(this.cmBaudRate);
59
-            this.groupBox9.Controls.Add(this.comboBox2);
59
+            this.groupBox9.Controls.Add(this.comboBox_baudrate);
60 60
             this.groupBox9.Location = new System.Drawing.Point(12, 23);
61 61
             this.groupBox9.Name = "groupBox9";
62 62
             this.groupBox9.Size = new System.Drawing.Size(225, 223);
@@ -108,41 +108,41 @@
108 108
             this.cmCom_Port.TabIndex = 89;
109 109
             this.cmCom_Port.Text = "Com Port";
110 110
             // 
111
-            // button1
111
+            // button_PortOpen
112 112
             // 
113
-            this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
113
+            this.button_PortOpen.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
114 114
             | System.Windows.Forms.AnchorStyles.Left) 
115 115
             | System.Windows.Forms.AnchorStyles.Right)));
116
-            this.button1.Location = new System.Drawing.Point(13, 95);
117
-            this.button1.Name = "button1";
118
-            this.button1.Size = new System.Drawing.Size(93, 34);
119
-            this.button1.TabIndex = 86;
120
-            this.button1.Text = "Port Open";
121
-            this.button1.UseVisualStyleBackColor = true;
116
+            this.button_PortOpen.Location = new System.Drawing.Point(19, 95);
117
+            this.button_PortOpen.Name = "button_PortOpen";
118
+            this.button_PortOpen.Size = new System.Drawing.Size(93, 34);
119
+            this.button_PortOpen.TabIndex = 86;
120
+            this.button_PortOpen.Text = "Port Open";
121
+            this.button_PortOpen.UseVisualStyleBackColor = true;
122 122
             // 
123
-            // PortClose_button
123
+            // button_PortClose
124 124
             // 
125
-            this.PortClose_button.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
125
+            this.button_PortClose.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
126 126
             | System.Windows.Forms.AnchorStyles.Left) 
127 127
             | System.Windows.Forms.AnchorStyles.Right)));
128
-            this.PortClose_button.Location = new System.Drawing.Point(118, 95);
129
-            this.PortClose_button.Name = "PortClose_button";
130
-            this.PortClose_button.Size = new System.Drawing.Size(93, 34);
131
-            this.PortClose_button.TabIndex = 87;
132
-            this.PortClose_button.Text = "Port Closed";
133
-            this.PortClose_button.UseVisualStyleBackColor = true;
128
+            this.button_PortClose.Location = new System.Drawing.Point(118, 95);
129
+            this.button_PortClose.Name = "button_PortClose";
130
+            this.button_PortClose.Size = new System.Drawing.Size(93, 34);
131
+            this.button_PortClose.TabIndex = 87;
132
+            this.button_PortClose.Text = "Port Closed";
133
+            this.button_PortClose.UseVisualStyleBackColor = true;
134 134
             // 
135
-            // comboBox1
135
+            // comboBox_Port
136 136
             // 
137
-            this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
137
+            this.comboBox_Port.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
138 138
             | System.Windows.Forms.AnchorStyles.Left) 
139 139
             | System.Windows.Forms.AnchorStyles.Right)));
140
-            this.comboBox1.Cursor = System.Windows.Forms.Cursors.Default;
141
-            this.comboBox1.FormattingEnabled = true;
142
-            this.comboBox1.Location = new System.Drawing.Point(109, 15);
143
-            this.comboBox1.Name = "comboBox1";
144
-            this.comboBox1.Size = new System.Drawing.Size(101, 20);
145
-            this.comboBox1.TabIndex = 88;
140
+            this.comboBox_Port.Cursor = System.Windows.Forms.Cursors.Default;
141
+            this.comboBox_Port.FormattingEnabled = true;
142
+            this.comboBox_Port.Location = new System.Drawing.Point(109, 15);
143
+            this.comboBox_Port.Name = "comboBox_Port";
144
+            this.comboBox_Port.Size = new System.Drawing.Size(101, 20);
145
+            this.comboBox_Port.TabIndex = 88;
146 146
             // 
147 147
             // cmBaudRate
148 148
             // 
@@ -156,13 +156,13 @@
156 156
             this.cmBaudRate.TabIndex = 90;
157 157
             this.cmBaudRate.Text = "Baud Rate(bps)";
158 158
             // 
159
-            // comboBox2
159
+            // comboBox_baudrate
160 160
             // 
161
-            this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
161
+            this.comboBox_baudrate.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
162 162
             | System.Windows.Forms.AnchorStyles.Left) 
163 163
             | System.Windows.Forms.AnchorStyles.Right)));
164
-            this.comboBox2.FormattingEnabled = true;
165
-            this.comboBox2.Items.AddRange(new object[] {
164
+            this.comboBox_baudrate.FormattingEnabled = true;
165
+            this.comboBox_baudrate.Items.AddRange(new object[] {
166 166
             "9600",
167 167
             "14400",
168 168
             "19200",
@@ -170,11 +170,11 @@
170 170
             "57600",
171 171
             "115200",
172 172
             "128000"});
173
-            this.comboBox2.Location = new System.Drawing.Point(110, 45);
174
-            this.comboBox2.Name = "comboBox2";
175
-            this.comboBox2.Size = new System.Drawing.Size(101, 20);
176
-            this.comboBox2.TabIndex = 91;
177
-            this.comboBox2.Text = "115200";
173
+            this.comboBox_baudrate.Location = new System.Drawing.Point(110, 45);
174
+            this.comboBox_baudrate.Name = "comboBox_baudrate";
175
+            this.comboBox_baudrate.Size = new System.Drawing.Size(101, 20);
176
+            this.comboBox_baudrate.TabIndex = 91;
177
+            this.comboBox_baudrate.Text = "115200";
178 178
             // 
179 179
             // Crc16_Check
180 180
             // 
@@ -219,13 +219,13 @@
219 219
         private System.Windows.Forms.Button Start_button;
220 220
         private System.Windows.Forms.CheckBox Ascii_checkBox;
221 221
         private System.Windows.Forms.Label cmCom_Port;
222
-        private System.Windows.Forms.Button button1;
223
-        private System.Windows.Forms.Button PortClose_button;
224
-        private System.Windows.Forms.ComboBox comboBox1;
222
+        private System.Windows.Forms.Button button_PortOpen;
223
+        private System.Windows.Forms.Button button_PortClose;
225 224
         private System.Windows.Forms.Label cmBaudRate;
226
-        private System.Windows.Forms.ComboBox comboBox2;
225
+        private System.Windows.Forms.ComboBox comboBox_baudrate;
227 226
         private System.Windows.Forms.Button Crc16_Check;
228 227
         private System.Windows.Forms.Label label1;
228
+        public System.Windows.Forms.ComboBox comboBox_Port;
229 229
     }
230 230
 }
231 231
 

+ 12 - 32
Basic_Terminal/Main_Form.cs

@@ -10,55 +10,35 @@ using System.Windows.Forms;
10 10
 //Add code
11 11
 
12 12
 using System.IO;
13
+using System.IO.Ports;
13 14
 namespace Basic_Terminal
14 15
 {
16
+    
15 17
     public partial class Main_Form : Form
16 18
     {
17
-        OpenFileDialog ofd = new OpenFileDialog();
18
-      
19
+        
20
+        public delegate void Serial_EventFunction(object sender, SerialDataReceivedEventArgs e);
19 21
         public Main_Form()
20 22
         {
23
+            Serial serial = new Serial();
24
+
21 25
             InitializeComponent();
26
+            serial.Serial_Initialize(ref comboBox_Port);
22 27
         }
23 28
 
24 29
         private void Firmware_Update_Click(object sender, EventArgs e)
25 30
         {
31
+            File_Open file = new File_Open();
26 32
             if (Ascii_checkBox.Checked == true)
27 33
                 Ascii_checkBox.Checked = false;
28
-                ShowFileOpenDialog();
29
-        }
30
-        private string ShowFileOpenDialog()
31
-        {
32
-            byte[] tempdata = new byte[5];
33
-            ofd.Title = "업데이터 파일 탐색기";//파일오픈창 생성 및 설정
34
-            ofd.FileName = "*.bin";
35
-            //ofd.Filter = "bin 파일 (*.bin) | *.bin; | 모든 파일 (*.*) | *.*";
36
-            ofd.Filter = "bin 파일 (*.bin) | *.bin;";
37
-            DialogResult dr = ofd.ShowDialog();            //파일 오픈창 로드
38
-            if (dr == DialogResult.OK)//OK버튼 클릭시
39
-            {
40
-                string fileName = ofd.SafeFileName;                //File명과 확장자를 가지고 온다.
41
-                string fileFullName = ofd.FileName;//File경로와 File명을 모두 가지고 온다.
42
-                string filePath = fileFullName.Replace(fileName, "");//File경로만 가지고 온다.
43
-                UpdateFileSend(File.ReadAllBytes(ofd.FileName));
44
-                return fileFullName;
45
-            }
46
-            else if (dr == DialogResult.Cancel)//취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
47
-            {
48
-                return "";
49
-            }
50
-            return "";
51
-        }
52
-        private void UpdateFileSend(byte[] data)
53
-        {
54
-
34
+            file.ShowFileOpenDialog();
55 35
         }
56
-
57 36
         private void Crc16_Check_Click(object sender, EventArgs e)
58 37
         {
59 38
             Crc16 crc16 = new Crc16();
60
-            byte[] tempdata = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
61
-            label1.Text = crc16.CRC16_Generate(tempdata, 10).ToString();
39
+            byte[] tempdata = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,0x0A };
40
+            label1.Text = crc16.CRC16_Generate(tempdata, 11).ToString();
62 41
         }
42
+
63 43
     }
64 44
 }

+ 37 - 0
Basic_Terminal/Serial.cs

@@ -0,0 +1,37 @@
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
+
11
+namespace Basic_Terminal
12
+{
13
+    class Serial
14
+    {
15
+        private System.IO.Ports.SerialPort serialPort;
16
+
17
+        public void Serial_Initialize(ref ComboBox cb_port)
18
+        {
19
+            
20
+            this.serialPort = new System.IO.Ports.SerialPort();
21
+            this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.Serial_DataRecvFunction);
22
+
23
+            cb_port.BeginUpdate();
24
+            foreach (string comport in SerialPort.GetPortNames())//foreach (string comport in SerialPort_TestProgram.GetPortNames())
25
+            {
26
+                cb_port.Items.Add(comport);
27
+            }
28
+            cb_port.EndUpdate();
29
+            //SerialPort 초기 설정.
30
+            cb_port.DataSource = SerialPort.GetPortNames();
31
+        }
32
+        public void Serial_DataRecvFunction(object sender, SerialDataReceivedEventArgs e)
33
+        {
34
+
35
+        }
36
+    }
37
+}