..
This commit is contained in:
@@ -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 };
|
||||
|
||||
|
||||
149
sample/Form1.Designer.cs
generated
149
sample/Form1.Designer.cs
generated
@@ -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
|
||||
//
|
||||
|
||||
@@ -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;
|
||||
@@ -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,7 +119,13 @@ namespace SampleProject
|
||||
private void btconnect_Click(object sender, EventArgs e)
|
||||
{
|
||||
var port = cmbport.Text.Trim();
|
||||
var buid = tbbaud.Text.toInt();
|
||||
var baud = tbbaud.Text.toInt();
|
||||
|
||||
//setting save
|
||||
Pub.Setting.LastPort = port;
|
||||
Pub.Setting.LastBaud = baud.ToString();
|
||||
Pub.Setting.Save();
|
||||
|
||||
if (dev.IsOpen)
|
||||
{
|
||||
dev.Close();
|
||||
@@ -127,7 +136,7 @@ namespace SampleProject
|
||||
try
|
||||
{
|
||||
this.dev.PortName = port;
|
||||
this.dev.BaudRate = buid;
|
||||
this.dev.BaudRate = baud;
|
||||
dev.Open();
|
||||
AddMessage("port opened");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace SampleProject
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Pub.init();
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
|
||||
21
sample/Pub.cs
Normal file
21
sample/Pub.cs
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Pub.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
25
sample/Settings.cs
Normal file
25
sample/Settings.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user