diff --git a/ENIGProtocol.Tests/EEProtocolTests.cs b/ENIGProtocol.Tests/EEProtocolTests.cs
index f54a8d7..6f058bd 100644
--- a/ENIGProtocol.Tests/EEProtocolTests.cs
+++ b/ENIGProtocol.Tests/EEProtocolTests.cs
@@ -9,14 +9,14 @@ namespace ENIGProtocol.Tests
public void TestCRC16Calculation()
{
// 테스트 데이터
- byte[] testData = new byte[] { 0x02,0x00,0xFF };
+ byte[] testData = new byte[] { 0x02,0x00,0xFF }; //payload에는 stx, len, ... crc,etx 는 제외한다
// CRC16 계산
var protocol = new EEProtocol();
ushort crc = protocol.CalculateCRC16(testData);
// 예상 결과와 비교
- Assert.Equal(0x1789, crc); // 실제 예상값으로 수정 필요
+ Assert.Equal(0x1789, crc);
}
[Fact]
@@ -40,6 +40,7 @@ namespace ENIGProtocol.Tests
{
// 패킷 파싱 테스트
var protocol = new EEProtocol();
+
//byte[] testPacket = new byte[] { 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x03 };
byte[] testPacket = new byte[] { 0x02, 0x02, 0x00, 0xFF, 0x89, 0x17, 0x03 };
diff --git a/ENIGProtocol.Tests/ENIGProtocol.Tests.csproj b/ENIGProtocol.Tests/ENIGProtocol.Tests.csproj
index fcb8f69..860d897 100644
--- a/ENIGProtocol.Tests/ENIGProtocol.Tests.csproj
+++ b/ENIGProtocol.Tests/ENIGProtocol.Tests.csproj
@@ -1,33 +1,33 @@
-
-
-
- net6.0
- enable
- enable
-
- false
- true
-
-
-
-
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net6.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sample/Form1.Designer.cs b/sample/Form1.Designer.cs
index ab4bb62..26512e2 100644
--- a/sample/Form1.Designer.cs
+++ b/sample/Form1.Designer.cs
@@ -45,18 +45,18 @@
this.tbCmd = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel1 = new System.Windows.Forms.Panel();
- this.panel2 = new System.Windows.Forms.Panel();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
+ this.label4 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.panel2 = new System.Windows.Forms.Panel();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
- this.rtCmd = new System.Windows.Forms.RichTextBox();
- this.btload = new System.Windows.Forms.Button();
this.btSave = new System.Windows.Forms.Button();
+ this.btload = new System.Windows.Forms.Button();
+ this.rtCmd = new System.Windows.Forms.RichTextBox();
this.statusStrip1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout();
@@ -73,7 +73,7 @@
this.rtRx.Location = new System.Drawing.Point(4, 5);
this.rtRx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.rtRx.Name = "rtRx";
- this.rtRx.Size = new System.Drawing.Size(462, 318);
+ this.rtRx.Size = new System.Drawing.Size(462, 302);
this.rtRx.TabIndex = 0;
this.rtRx.Text = "";
//
@@ -84,7 +84,7 @@
this.rtTx.Location = new System.Drawing.Point(474, 5);
this.rtTx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.rtTx.Name = "rtTx";
- this.rtTx.Size = new System.Drawing.Size(462, 318);
+ this.rtTx.Size = new System.Drawing.Size(462, 302);
this.rtTx.TabIndex = 1;
this.rtTx.Text = "";
//
@@ -198,11 +198,13 @@
//
// rtMsg
//
- this.rtMsg.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.rtMsg.Location = new System.Drawing.Point(3, 331);
+ this.rtMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
+ this.tableLayoutPanel1.SetColumnSpan(this.rtMsg, 2);
+ this.rtMsg.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.rtMsg.Location = new System.Drawing.Point(4, 317);
this.rtMsg.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.rtMsg.Name = "rtMsg";
- this.rtMsg.Size = new System.Drawing.Size(940, 118);
+ this.rtMsg.Size = new System.Drawing.Size(932, 124);
this.rtMsg.TabIndex = 10;
this.rtMsg.Text = "";
//
@@ -223,14 +225,16 @@
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel1.Controls.Add(this.rtMsg, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.rtRx, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.rtTx, 1, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
- this.tableLayoutPanel1.RowCount = 1;
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
- this.tableLayoutPanel1.Size = new System.Drawing.Size(940, 328);
+ this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 70F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(940, 446);
this.tableLayoutPanel1.TabIndex = 12;
//
// panel1
@@ -250,6 +254,39 @@
this.panel1.Size = new System.Drawing.Size(954, 52);
this.panel1.TabIndex = 13;
//
+ // label5
+ //
+ this.label5.Dock = System.Windows.Forms.DockStyle.Left;
+ this.label5.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.label5.Location = new System.Drawing.Point(381, 5);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(55, 42);
+ this.label5.TabIndex = 14;
+ this.label5.Text = "DATA\r\n(n)";
+ this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // label4
+ //
+ this.label4.Dock = System.Windows.Forms.DockStyle.Left;
+ this.label4.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.label4.Location = new System.Drawing.Point(243, 5);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(55, 42);
+ this.label4.TabIndex = 13;
+ this.label4.Text = "CMD\r\n(1)";
+ this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
+ // label3
+ //
+ this.label3.Dock = System.Windows.Forms.DockStyle.Left;
+ this.label3.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.label3.Location = new System.Drawing.Point(5, 5);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(55, 42);
+ this.label3.TabIndex = 12;
+ this.label3.Text = "ID\r\n(1)";
+ this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ //
// panel2
//
this.panel2.Controls.Add(this.tbbaud);
@@ -264,16 +301,6 @@
this.panel2.Size = new System.Drawing.Size(954, 46);
this.panel2.TabIndex = 14;
//
- // label1
- //
- this.label1.Dock = System.Windows.Forms.DockStyle.Left;
- this.label1.Location = new System.Drawing.Point(3, 3);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(55, 40);
- this.label1.TabIndex = 7;
- this.label1.Text = "port";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
// label2
//
this.label2.Dock = System.Windows.Forms.DockStyle.Left;
@@ -284,38 +311,15 @@
this.label2.Text = "baud";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
- // label3
+ // label1
//
- this.label3.Dock = System.Windows.Forms.DockStyle.Left;
- this.label3.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label3.Location = new System.Drawing.Point(5, 5);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(55, 42);
- this.label3.TabIndex = 12;
- this.label3.Text = "ID\r\n(1)";
- this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // label4
- //
- this.label4.Dock = System.Windows.Forms.DockStyle.Left;
- this.label4.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label4.Location = new System.Drawing.Point(243, 5);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(55, 42);
- this.label4.TabIndex = 13;
- this.label4.Text = "CMD\r\n(1)";
- this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // label5
- //
- this.label5.Dock = System.Windows.Forms.DockStyle.Left;
- this.label5.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label5.Location = new System.Drawing.Point(381, 5);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(55, 42);
- this.label5.TabIndex = 14;
- this.label5.Text = "DATA\r\n(n)";
- this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ this.label1.Dock = System.Windows.Forms.DockStyle.Left;
+ this.label1.Location = new System.Drawing.Point(3, 3);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(55, 40);
+ this.label1.TabIndex = 7;
+ this.label1.Text = "port";
+ this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// tabControl1
//
@@ -331,7 +335,6 @@
// tabPage1
//
this.tabPage1.Controls.Add(this.tableLayoutPanel1);
- this.tabPage1.Controls.Add(this.rtMsg);
this.tabPage1.Location = new System.Drawing.Point(4, 29);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
@@ -353,15 +356,15 @@
this.tabPage2.Text = "Command";
this.tabPage2.UseVisualStyleBackColor = true;
//
- // rtCmd
+ // btSave
//
- this.rtCmd.Dock = System.Windows.Forms.DockStyle.Fill;
- this.rtCmd.Location = new System.Drawing.Point(3, 3);
- this.rtCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.rtCmd.Name = "rtCmd";
- this.rtCmd.Size = new System.Drawing.Size(940, 446);
- this.rtCmd.TabIndex = 11;
- this.rtCmd.Text = "";
+ this.btSave.Location = new System.Drawing.Point(820, 50);
+ this.btSave.Name = "btSave";
+ this.btSave.Size = new System.Drawing.Size(113, 29);
+ this.btSave.TabIndex = 13;
+ this.btSave.Text = "Save";
+ this.btSave.UseVisualStyleBackColor = true;
+ this.btSave.Click += new System.EventHandler(this.btSave_Click);
//
// btload
//
@@ -373,15 +376,15 @@
this.btload.UseVisualStyleBackColor = true;
this.btload.Click += new System.EventHandler(this.btload_Click);
//
- // btSave
+ // rtCmd
//
- this.btSave.Location = new System.Drawing.Point(820, 50);
- this.btSave.Name = "btSave";
- this.btSave.Size = new System.Drawing.Size(113, 29);
- this.btSave.TabIndex = 13;
- this.btSave.Text = "Save";
- this.btSave.UseVisualStyleBackColor = true;
- this.btSave.Click += new System.EventHandler(this.btSave_Click);
+ this.rtCmd.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.rtCmd.Location = new System.Drawing.Point(3, 3);
+ this.rtCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.rtCmd.Name = "rtCmd";
+ this.rtCmd.Size = new System.Drawing.Size(940, 446);
+ this.rtCmd.TabIndex = 11;
+ this.rtCmd.Text = "";
//
// Form1
//
diff --git a/sample/Form1.cs b/sample/Form1.cs
index e74cee2..75eb813 100644
--- a/sample/Form1.cs
+++ b/sample/Form1.cs
@@ -6,6 +6,7 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
+using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -76,7 +77,7 @@ namespace SampleProject
void AddMessage(string msg, messageType type = messageType.normal)
{
- if(this.InvokeRequired)
+ if (this.InvokeRequired)
{
this.BeginInvoke(new Action(() => AddMessage(msg, type)));
return;
@@ -106,8 +107,10 @@ namespace SampleProject
{
cmbport.Items.Add(item);
}
- cmbport.Text = "COM11";
- if (cmbport.Items.Count > 0) cmbport.SelectedIndex = 0;
+ if (Pub.Setting.LastPort.isEmpty() == false) cmbport.Text = Pub.Setting.LastPort;
+ else if (cmbport.Items.Count > 0) cmbport.SelectedIndex = 0;
+
+ if (Pub.Setting.LastBaud.isEmpty() == false) tbbaud.Text = Pub.Setting.LastBaud;
if (cmbid.Items.Count > 0) cmbid.SelectedIndex = 0;
LoadCmds();
this.timer1.Start();
@@ -116,8 +119,14 @@ namespace SampleProject
private void btconnect_Click(object sender, EventArgs e)
{
var port = cmbport.Text.Trim();
- var buid = tbbaud.Text.toInt();
- if(dev.IsOpen)
+ var baud = tbbaud.Text.toInt();
+
+ //setting save
+ Pub.Setting.LastPort = port;
+ Pub.Setting.LastBaud = baud.ToString();
+ Pub.Setting.Save();
+
+ if (dev.IsOpen)
{
dev.Close();
AddMessage("port closed");
@@ -127,7 +136,7 @@ namespace SampleProject
try
{
this.dev.PortName = port;
- this.dev.BaudRate = buid;
+ this.dev.BaudRate = baud;
dev.Open();
AddMessage("port opened");
}
@@ -136,8 +145,8 @@ namespace SampleProject
AddMessage(ex.Message, messageType.error);
}
}
-
-
+
+
}
private void timer1_Tick(object sender, EventArgs e)
diff --git a/sample/Program.cs b/sample/Program.cs
index b43a18e..17f8db2 100644
--- a/sample/Program.cs
+++ b/sample/Program.cs
@@ -16,6 +16,7 @@ namespace SampleProject
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
+ Pub.init();
Application.Run(new Form1());
}
}
diff --git a/sample/Pub.cs b/sample/Pub.cs
new file mode 100644
index 0000000..5cce371
--- /dev/null
+++ b/sample/Pub.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SampleProject
+{
+ public static class Pub
+ {
+ public static Settings Setting { get; set; }
+ public static void init()
+ {
+ Setting = new Settings();
+ Setting.Load();
+ }
+
+
+ }
+}
diff --git a/sample/SampleProject.csproj b/sample/SampleProject.csproj
index ada82a2..6a6bb90 100644
--- a/sample/SampleProject.csproj
+++ b/sample/SampleProject.csproj
@@ -57,6 +57,8 @@
+
+
Form1.cs
diff --git a/sample/Settings.cs b/sample/Settings.cs
new file mode 100644
index 0000000..96171b0
--- /dev/null
+++ b/sample/Settings.cs
@@ -0,0 +1,25 @@
+using AR;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SampleProject
+{
+ public class Settings : AR.Setting
+ {
+ public string LastPort { get; set; }
+ public string LastBaud { get; set; }
+ public override void AfterLoad()
+ {
+ // throw new NotImplementedException();
+ if (LastBaud.isEmpty()) LastBaud = "9600";
+ }
+
+ public override void AfterSave()
+ {
+ // throw new NotImplementedException();
+ }
+ }
+}