..
This commit is contained in:
@@ -9,14 +9,14 @@ namespace ENIGProtocol.Tests
|
|||||||
public void TestCRC16Calculation()
|
public void TestCRC16Calculation()
|
||||||
{
|
{
|
||||||
// 테스트 데이터
|
// 테스트 데이터
|
||||||
byte[] testData = new byte[] { 0x02,0x00,0xFF };
|
byte[] testData = new byte[] { 0x02,0x00,0xFF }; //payload에는 stx, len, ... crc,etx 는 제외한다
|
||||||
|
|
||||||
// CRC16 계산
|
// CRC16 계산
|
||||||
var protocol = new EEProtocol();
|
var protocol = new EEProtocol();
|
||||||
ushort crc = protocol.CalculateCRC16(testData);
|
ushort crc = protocol.CalculateCRC16(testData);
|
||||||
|
|
||||||
// 예상 결과와 비교
|
// 예상 결과와 비교
|
||||||
Assert.Equal(0x1789, crc); // 실제 예상값으로 수정 필요
|
Assert.Equal(0x1789, crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -40,6 +40,7 @@ namespace ENIGProtocol.Tests
|
|||||||
{
|
{
|
||||||
// 패킷 파싱 테스트
|
// 패킷 파싱 테스트
|
||||||
var protocol = new EEProtocol();
|
var protocol = new EEProtocol();
|
||||||
|
|
||||||
//byte[] testPacket = new byte[] { 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x03 };
|
//byte[] testPacket = new byte[] { 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x03 };
|
||||||
byte[] testPacket = new byte[] { 0x02, 0x02, 0x00, 0xFF, 0x89, 0x17, 0x03 };
|
byte[] testPacket = new byte[] { 0x02, 0x02, 0x00, 0xFF, 0x89, 0x17, 0x03 };
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||||
<PackageReference Include="xunit" Version="2.9.3" />
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\enigprotocol\enigprotocol.csproj" />
|
<ProjectReference Include="..\enigprotocol\enigprotocol.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Xunit" />
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
149
sample/Form1.Designer.cs
generated
149
sample/Form1.Designer.cs
generated
@@ -45,18 +45,18 @@
|
|||||||
this.tbCmd = new System.Windows.Forms.TextBox();
|
this.tbCmd = new System.Windows.Forms.TextBox();
|
||||||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.panel1 = new System.Windows.Forms.Panel();
|
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.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.tabControl1 = new System.Windows.Forms.TabControl();
|
||||||
this.tabPage1 = new System.Windows.Forms.TabPage();
|
this.tabPage1 = new System.Windows.Forms.TabPage();
|
||||||
this.tabPage2 = 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.btSave = new System.Windows.Forms.Button();
|
||||||
|
this.btload = new System.Windows.Forms.Button();
|
||||||
|
this.rtCmd = new System.Windows.Forms.RichTextBox();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.tableLayoutPanel1.SuspendLayout();
|
this.tableLayoutPanel1.SuspendLayout();
|
||||||
this.panel1.SuspendLayout();
|
this.panel1.SuspendLayout();
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
this.rtRx.Location = new System.Drawing.Point(4, 5);
|
this.rtRx.Location = new System.Drawing.Point(4, 5);
|
||||||
this.rtRx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
this.rtRx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
this.rtRx.Name = "rtRx";
|
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.TabIndex = 0;
|
||||||
this.rtRx.Text = "";
|
this.rtRx.Text = "";
|
||||||
//
|
//
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
this.rtTx.Location = new System.Drawing.Point(474, 5);
|
this.rtTx.Location = new System.Drawing.Point(474, 5);
|
||||||
this.rtTx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
this.rtTx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
this.rtTx.Name = "rtTx";
|
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.TabIndex = 1;
|
||||||
this.rtTx.Text = "";
|
this.rtTx.Text = "";
|
||||||
//
|
//
|
||||||
@@ -198,11 +198,13 @@
|
|||||||
//
|
//
|
||||||
// rtMsg
|
// rtMsg
|
||||||
//
|
//
|
||||||
this.rtMsg.Dock = System.Windows.Forms.DockStyle.Bottom;
|
this.rtMsg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
|
||||||
this.rtMsg.Location = new System.Drawing.Point(3, 331);
|
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.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
this.rtMsg.Name = "rtMsg";
|
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.TabIndex = 10;
|
||||||
this.rtMsg.Text = "";
|
this.rtMsg.Text = "";
|
||||||
//
|
//
|
||||||
@@ -223,14 +225,16 @@
|
|||||||
this.tableLayoutPanel1.ColumnCount = 2;
|
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.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.rtRx, 0, 0);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.rtTx, 1, 0);
|
this.tableLayoutPanel1.Controls.Add(this.rtTx, 1, 0);
|
||||||
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
|
this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
|
||||||
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
this.tableLayoutPanel1.RowCount = 1;
|
this.tableLayoutPanel1.RowCount = 2;
|
||||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 70F));
|
||||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(940, 328);
|
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;
|
this.tableLayoutPanel1.TabIndex = 12;
|
||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
@@ -250,6 +254,39 @@
|
|||||||
this.panel1.Size = new System.Drawing.Size(954, 52);
|
this.panel1.Size = new System.Drawing.Size(954, 52);
|
||||||
this.panel1.TabIndex = 13;
|
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
|
// panel2
|
||||||
//
|
//
|
||||||
this.panel2.Controls.Add(this.tbbaud);
|
this.panel2.Controls.Add(this.tbbaud);
|
||||||
@@ -264,16 +301,6 @@
|
|||||||
this.panel2.Size = new System.Drawing.Size(954, 46);
|
this.panel2.Size = new System.Drawing.Size(954, 46);
|
||||||
this.panel2.TabIndex = 14;
|
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
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.Dock = System.Windows.Forms.DockStyle.Left;
|
this.label2.Dock = System.Windows.Forms.DockStyle.Left;
|
||||||
@@ -284,38 +311,15 @@
|
|||||||
this.label2.Text = "baud";
|
this.label2.Text = "baud";
|
||||||
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// label3
|
// label1
|
||||||
//
|
//
|
||||||
this.label3.Dock = System.Windows.Forms.DockStyle.Left;
|
this.label1.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.label1.Location = new System.Drawing.Point(3, 3);
|
||||||
this.label3.Location = new System.Drawing.Point(5, 5);
|
this.label1.Name = "label1";
|
||||||
this.label3.Name = "label3";
|
this.label1.Size = new System.Drawing.Size(55, 40);
|
||||||
this.label3.Size = new System.Drawing.Size(55, 42);
|
this.label1.TabIndex = 7;
|
||||||
this.label3.TabIndex = 12;
|
this.label1.Text = "port";
|
||||||
this.label3.Text = "ID\r\n(1)";
|
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
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;
|
|
||||||
//
|
//
|
||||||
// tabControl1
|
// tabControl1
|
||||||
//
|
//
|
||||||
@@ -331,7 +335,6 @@
|
|||||||
// tabPage1
|
// tabPage1
|
||||||
//
|
//
|
||||||
this.tabPage1.Controls.Add(this.tableLayoutPanel1);
|
this.tabPage1.Controls.Add(this.tableLayoutPanel1);
|
||||||
this.tabPage1.Controls.Add(this.rtMsg);
|
|
||||||
this.tabPage1.Location = new System.Drawing.Point(4, 29);
|
this.tabPage1.Location = new System.Drawing.Point(4, 29);
|
||||||
this.tabPage1.Name = "tabPage1";
|
this.tabPage1.Name = "tabPage1";
|
||||||
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
|
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
|
||||||
@@ -353,15 +356,15 @@
|
|||||||
this.tabPage2.Text = "Command";
|
this.tabPage2.Text = "Command";
|
||||||
this.tabPage2.UseVisualStyleBackColor = true;
|
this.tabPage2.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// rtCmd
|
// btSave
|
||||||
//
|
//
|
||||||
this.rtCmd.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.btSave.Location = new System.Drawing.Point(820, 50);
|
||||||
this.rtCmd.Location = new System.Drawing.Point(3, 3);
|
this.btSave.Name = "btSave";
|
||||||
this.rtCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
this.btSave.Size = new System.Drawing.Size(113, 29);
|
||||||
this.rtCmd.Name = "rtCmd";
|
this.btSave.TabIndex = 13;
|
||||||
this.rtCmd.Size = new System.Drawing.Size(940, 446);
|
this.btSave.Text = "Save";
|
||||||
this.rtCmd.TabIndex = 11;
|
this.btSave.UseVisualStyleBackColor = true;
|
||||||
this.rtCmd.Text = "";
|
this.btSave.Click += new System.EventHandler(this.btSave_Click);
|
||||||
//
|
//
|
||||||
// btload
|
// btload
|
||||||
//
|
//
|
||||||
@@ -373,15 +376,15 @@
|
|||||||
this.btload.UseVisualStyleBackColor = true;
|
this.btload.UseVisualStyleBackColor = true;
|
||||||
this.btload.Click += new System.EventHandler(this.btload_Click);
|
this.btload.Click += new System.EventHandler(this.btload_Click);
|
||||||
//
|
//
|
||||||
// btSave
|
// rtCmd
|
||||||
//
|
//
|
||||||
this.btSave.Location = new System.Drawing.Point(820, 50);
|
this.rtCmd.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.btSave.Name = "btSave";
|
this.rtCmd.Location = new System.Drawing.Point(3, 3);
|
||||||
this.btSave.Size = new System.Drawing.Size(113, 29);
|
this.rtCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
this.btSave.TabIndex = 13;
|
this.rtCmd.Name = "rtCmd";
|
||||||
this.btSave.Text = "Save";
|
this.rtCmd.Size = new System.Drawing.Size(940, 446);
|
||||||
this.btSave.UseVisualStyleBackColor = true;
|
this.rtCmd.TabIndex = 11;
|
||||||
this.btSave.Click += new System.EventHandler(this.btSave_Click);
|
this.rtCmd.Text = "";
|
||||||
//
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.ComponentModel;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@@ -76,7 +77,7 @@ namespace SampleProject
|
|||||||
|
|
||||||
void AddMessage(string msg, messageType type = messageType.normal)
|
void AddMessage(string msg, messageType type = messageType.normal)
|
||||||
{
|
{
|
||||||
if(this.InvokeRequired)
|
if (this.InvokeRequired)
|
||||||
{
|
{
|
||||||
this.BeginInvoke(new Action(() => AddMessage(msg, type)));
|
this.BeginInvoke(new Action(() => AddMessage(msg, type)));
|
||||||
return;
|
return;
|
||||||
@@ -106,8 +107,10 @@ namespace SampleProject
|
|||||||
{
|
{
|
||||||
cmbport.Items.Add(item);
|
cmbport.Items.Add(item);
|
||||||
}
|
}
|
||||||
cmbport.Text = "COM11";
|
if (Pub.Setting.LastPort.isEmpty() == false) cmbport.Text = Pub.Setting.LastPort;
|
||||||
if (cmbport.Items.Count > 0) cmbport.SelectedIndex = 0;
|
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;
|
if (cmbid.Items.Count > 0) cmbid.SelectedIndex = 0;
|
||||||
LoadCmds();
|
LoadCmds();
|
||||||
this.timer1.Start();
|
this.timer1.Start();
|
||||||
@@ -116,8 +119,14 @@ namespace SampleProject
|
|||||||
private void btconnect_Click(object sender, EventArgs e)
|
private void btconnect_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var port = cmbport.Text.Trim();
|
var port = cmbport.Text.Trim();
|
||||||
var buid = tbbaud.Text.toInt();
|
var baud = tbbaud.Text.toInt();
|
||||||
if(dev.IsOpen)
|
|
||||||
|
//setting save
|
||||||
|
Pub.Setting.LastPort = port;
|
||||||
|
Pub.Setting.LastBaud = baud.ToString();
|
||||||
|
Pub.Setting.Save();
|
||||||
|
|
||||||
|
if (dev.IsOpen)
|
||||||
{
|
{
|
||||||
dev.Close();
|
dev.Close();
|
||||||
AddMessage("port closed");
|
AddMessage("port closed");
|
||||||
@@ -127,7 +136,7 @@ namespace SampleProject
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.dev.PortName = port;
|
this.dev.PortName = port;
|
||||||
this.dev.BaudRate = buid;
|
this.dev.BaudRate = baud;
|
||||||
dev.Open();
|
dev.Open();
|
||||||
AddMessage("port opened");
|
AddMessage("port opened");
|
||||||
}
|
}
|
||||||
@@ -136,8 +145,8 @@ namespace SampleProject
|
|||||||
AddMessage(ex.Message, messageType.error);
|
AddMessage(ex.Message, messageType.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timer1_Tick(object sender, EventArgs e)
|
private void timer1_Tick(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace SampleProject
|
|||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Pub.init();
|
||||||
Application.Run(new Form1());
|
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>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Pub.cs" />
|
||||||
|
<Compile Include="Settings.cs" />
|
||||||
<EmbeddedResource Include="Form1.resx">
|
<EmbeddedResource Include="Form1.resx">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</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