modbus master I

main
syneffort 3 years ago
parent 352e655814
commit b25cf87a7f
  1. 23
      ModbusStudy/CommClient/Client/ICommClient.cs
  2. 50
      ModbusStudy/CommClient/Client/ModbusMaster.cs
  3. 6
      ModbusStudy/CommClient/CommClient.csproj
  4. 521
      ModbusStudy/CommClient/MainForm.Designer.cs
  5. 99
      ModbusStudy/CommClient/MainForm.cs
  6. 4
      ModbusStudy/CommClient/packages.config

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommClient.Client
{
interface ICommClient
{
void SetServer(string ip, int port);
void Connect();
void Disconnect();
string ReadValue(string name);
void WriteValue(string name, string value);
bool GetStatus();
}
}

@ -0,0 +1,50 @@
using EasyModbus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommClient.Client
{
class ModbusMaster : ICommClient
{
private ModbusClient client;
private int UINIT_IDENTIFIER = 1;
public ModbusMaster()
{
client = new ModbusClient();
}
public void Connect()
{
throw new NotImplementedException();
}
public void Disconnect()
{
throw new NotImplementedException();
}
public bool GetStatus()
{
throw new NotImplementedException();
}
public string ReadValue(string name)
{
throw new NotImplementedException();
}
public void SetServer(string ip, int port)
{
throw new NotImplementedException();
}
public void WriteValue(string name, string value)
{
throw new NotImplementedException();
}
}
}

@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyModbus, Version=5.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\hima.lib.easymodbus.5.6.0\lib\EasyModbus.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -46,6 +49,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client\ICommClient.cs" />
<Compile Include="Client\ModbusMaster.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
@ -66,6 +71,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

@ -30,38 +30,41 @@ namespace CommClient
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnDisconnect = new System.Windows.Forms.Button();
this.tbIP = new System.Windows.Forms.TextBox();
this.btnConnect = new System.Windows.Forms.Button();
this.nudPort = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tbStatus = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.chkAutoScroll = new System.Windows.Forms.CheckBox();
this.btnClear = new System.Windows.Forms.Button();
this.rtbLog = new System.Windows.Forms.RichTextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.tbStatus = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.nudPort = new System.Windows.Forms.NumericUpDown();
this.btnConnect = new System.Windows.Forms.Button();
this.btnDisconnect = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.tbName = new System.Windows.Forms.TextBox();
this.btnRead = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.tbWriteName = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.tbWriteValue = new System.Windows.Forms.TextBox();
this.tbReadName = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.btnWrite = new System.Windows.Forms.Button();
this.chkModbus = new System.Windows.Forms.RadioButton();
this.chkOPCUA = new System.Windows.Forms.RadioButton();
this.tbWriteValue = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.tbWriteName = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.chkSdk = new System.Windows.Forms.RadioButton();
this.rtbLog = new System.Windows.Forms.RichTextBox();
this.chkAutoScroll = new System.Windows.Forms.CheckBox();
this.btnClear = new System.Windows.Forms.Button();
this.tbIP = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.chkOPCUA = new System.Windows.Forms.RadioButton();
this.chkModbus = new System.Windows.Forms.RadioButton();
this.label7 = new System.Windows.Forms.Label();
this.nudAddress = new System.Windows.Forms.NumericUpDown();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).BeginInit();
this.groupBox5.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).BeginInit();
this.SuspendLayout();
//
// groupBox1
@ -69,306 +72,370 @@ namespace CommClient
this.groupBox1.Controls.Add(this.btnDisconnect);
this.groupBox1.Controls.Add(this.tbIP);
this.groupBox1.Controls.Add(this.btnConnect);
this.groupBox1.Controls.Add(this.nudAddress);
this.groupBox1.Controls.Add(this.nudPort);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.tbStatus);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Location = new System.Drawing.Point(13, 16);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(240, 135);
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Size = new System.Drawing.Size(240, 196);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server";
//
// groupBox5
// btnDisconnect
//
this.groupBox5.Controls.Add(this.chkAutoScroll);
this.groupBox5.Controls.Add(this.btnClear);
this.groupBox5.Controls.Add(this.rtbLog);
this.groupBox5.Location = new System.Drawing.Point(259, 13);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(417, 384);
this.groupBox5.TabIndex = 0;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Log";
this.btnDisconnect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDisconnect.Location = new System.Drawing.Point(152, 154);
this.btnDisconnect.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnDisconnect.Name = "btnDisconnect";
this.btnDisconnect.Size = new System.Drawing.Size(82, 29);
this.btnDisconnect.TabIndex = 10;
this.btnDisconnect.Text = "Disconnect";
this.btnDisconnect.UseVisualStyleBackColor = true;
this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);
//
// groupBox2
// tbIP
//
this.groupBox2.Controls.Add(this.btnRead);
this.groupBox2.Controls.Add(this.tbName);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Location = new System.Drawing.Point(13, 154);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(240, 75);
this.groupBox2.TabIndex = 0;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Read Config";
this.tbIP.Location = new System.Drawing.Point(78, 59);
this.tbIP.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tbIP.Name = "tbIP";
this.tbIP.Size = new System.Drawing.Size(156, 23);
this.tbIP.TabIndex = 7;
this.tbIP.Text = "127.0.0.1";
//
// groupBox3
// btnConnect
//
this.groupBox3.Controls.Add(this.btnWrite);
this.groupBox3.Controls.Add(this.tbWriteValue);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.tbWriteName);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Location = new System.Drawing.Point(13, 235);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(240, 105);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Write Config";
this.btnConnect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnConnect.Location = new System.Drawing.Point(78, 154);
this.btnConnect.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnConnect.Name = "btnConnect";
this.btnConnect.Size = new System.Drawing.Size(68, 29);
this.btnConnect.TabIndex = 11;
this.btnConnect.Text = "Connect";
this.btnConnect.UseVisualStyleBackColor = true;
this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
//
// groupBox4
// nudPort
//
this.groupBox4.Controls.Add(this.chkSdk);
this.groupBox4.Controls.Add(this.chkOPCUA);
this.groupBox4.Controls.Add(this.chkModbus);
this.groupBox4.Location = new System.Drawing.Point(13, 346);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(240, 51);
this.groupBox4.TabIndex = 0;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Mode";
this.nudPort.Location = new System.Drawing.Point(78, 92);
this.nudPort.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.nudPort.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.nudPort.Name = "nudPort";
this.nudPort.Size = new System.Drawing.Size(156, 23);
this.nudPort.TabIndex = 9;
this.nudPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudPort.Value = new decimal(new int[] {
502,
0,
0,
0});
//
// label1
// label3
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(4, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 12);
this.label1.TabIndex = 6;
this.label1.Text = "Status";
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(4, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Server IP";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(4, 98);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 15);
this.label2.TabIndex = 5;
this.label2.Text = "TCP port";
//
// tbStatus
//
this.tbStatus.BackColor = System.Drawing.Color.Silver;
this.tbStatus.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbStatus.Location = new System.Drawing.Point(78, 20);
this.tbStatus.Location = new System.Drawing.Point(78, 25);
this.tbStatus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tbStatus.Name = "tbStatus";
this.tbStatus.ReadOnly = true;
this.tbStatus.Size = new System.Drawing.Size(156, 21);
this.tbStatus.Size = new System.Drawing.Size(156, 23);
this.tbStatus.TabIndex = 7;
this.tbStatus.Text = "Disconnected";
this.tbStatus.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label2
// label1
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(4, 78);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(55, 12);
this.label2.TabIndex = 5;
this.label2.Text = "TCP port";
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(4, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 15);
this.label1.TabIndex = 6;
this.label1.Text = "Status";
//
// nudPort
// groupBox5
//
this.nudPort.Location = new System.Drawing.Point(78, 74);
this.nudPort.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.nudPort.Name = "nudPort";
this.nudPort.Size = new System.Drawing.Size(156, 21);
this.nudPort.TabIndex = 9;
this.nudPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudPort.Value = new decimal(new int[] {
502,
0,
0,
0});
this.groupBox5.Controls.Add(this.chkAutoScroll);
this.groupBox5.Controls.Add(this.btnClear);
this.groupBox5.Controls.Add(this.rtbLog);
this.groupBox5.Location = new System.Drawing.Point(259, 16);
this.groupBox5.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox5.Size = new System.Drawing.Size(417, 501);
this.groupBox5.TabIndex = 0;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Log";
//
// btnConnect
// chkAutoScroll
//
this.btnConnect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnConnect.Location = new System.Drawing.Point(78, 101);
this.btnConnect.Name = "btnConnect";
this.btnConnect.Size = new System.Drawing.Size(68, 23);
this.btnConnect.TabIndex = 11;
this.btnConnect.Text = "Connect";
this.btnConnect.UseVisualStyleBackColor = true;
this.chkAutoScroll.AutoSize = true;
this.chkAutoScroll.Checked = true;
this.chkAutoScroll.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkAutoScroll.Location = new System.Drawing.Point(6, 472);
this.chkAutoScroll.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.chkAutoScroll.Name = "chkAutoScroll";
this.chkAutoScroll.Size = new System.Drawing.Size(84, 19);
this.chkAutoScroll.TabIndex = 4;
this.chkAutoScroll.Text = "Auto scroll";
this.chkAutoScroll.UseVisualStyleBackColor = true;
//
// btnDisconnect
// btnClear
//
this.btnDisconnect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDisconnect.Location = new System.Drawing.Point(152, 101);
this.btnDisconnect.Name = "btnDisconnect";
this.btnDisconnect.Size = new System.Drawing.Size(82, 23);
this.btnDisconnect.TabIndex = 10;
this.btnDisconnect.Text = "Disconnect";
this.btnDisconnect.UseVisualStyleBackColor = true;
this.btnClear.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClear.Location = new System.Drawing.Point(336, 464);
this.btnClear.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(75, 29);
this.btnClear.TabIndex = 5;
this.btnClear.Text = "Clear log";
this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// label4
// rtbLog
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 17);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(79, 12);
this.label4.TabIndex = 6;
this.label4.Text = "Tag name/Id";
this.rtbLog.BackColor = System.Drawing.Color.Black;
this.rtbLog.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rtbLog.ForeColor = System.Drawing.Color.Lime;
this.rtbLog.Location = new System.Drawing.Point(6, 25);
this.rtbLog.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.rtbLog.Name = "rtbLog";
this.rtbLog.ReadOnly = true;
this.rtbLog.Size = new System.Drawing.Size(405, 431);
this.rtbLog.TabIndex = 1;
this.rtbLog.Text = "";
//
// tbName
// groupBox2
//
this.tbName.Location = new System.Drawing.Point(91, 13);
this.tbName.Name = "tbName";
this.tbName.Size = new System.Drawing.Size(143, 21);
this.tbName.TabIndex = 7;
this.tbName.Text = "00001";
this.groupBox2.Controls.Add(this.btnRead);
this.groupBox2.Controls.Add(this.tbReadName);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Location = new System.Drawing.Point(13, 220);
this.groupBox2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox2.Size = new System.Drawing.Size(240, 86);
this.groupBox2.TabIndex = 0;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Read Config";
//
// btnRead
//
this.btnRead.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRead.Location = new System.Drawing.Point(159, 40);
this.btnRead.Location = new System.Drawing.Point(159, 50);
this.btnRead.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnRead.Name = "btnRead";
this.btnRead.Size = new System.Drawing.Size(75, 23);
this.btnRead.Size = new System.Drawing.Size(75, 29);
this.btnRead.TabIndex = 10;
this.btnRead.Text = "Read";
this.btnRead.UseVisualStyleBackColor = true;
this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
//
// label5
// tbReadName
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(79, 12);
this.label5.TabIndex = 6;
this.label5.Text = "Tag name/Id";
//
// tbWriteName
//
this.tbWriteName.Location = new System.Drawing.Point(91, 20);
this.tbWriteName.Name = "tbWriteName";
this.tbWriteName.Size = new System.Drawing.Size(143, 21);
this.tbWriteName.TabIndex = 7;
this.tbWriteName.Text = "00001";
this.tbReadName.Location = new System.Drawing.Point(91, 16);
this.tbReadName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tbReadName.Name = "tbReadName";
this.tbReadName.Size = new System.Drawing.Size(143, 23);
this.tbReadName.TabIndex = 7;
this.tbReadName.Text = "00001";
//
// label6
// label4
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(6, 51);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(66, 12);
this.label6.TabIndex = 6;
this.label6.Text = "Write value";
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 21);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(75, 15);
this.label4.TabIndex = 6;
this.label4.Text = "Tag name/Id";
//
// tbWriteValue
// groupBox3
//
this.tbWriteValue.Location = new System.Drawing.Point(91, 47);
this.tbWriteValue.Name = "tbWriteValue";
this.tbWriteValue.Size = new System.Drawing.Size(143, 21);
this.tbWriteValue.TabIndex = 7;
this.tbWriteValue.Text = "0";
this.groupBox3.Controls.Add(this.btnWrite);
this.groupBox3.Controls.Add(this.tbWriteValue);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.tbWriteName);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Location = new System.Drawing.Point(13, 314);
this.groupBox3.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox3.Size = new System.Drawing.Size(240, 131);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Write Config";
//
// btnWrite
//
this.btnWrite.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnWrite.Location = new System.Drawing.Point(159, 74);
this.btnWrite.Location = new System.Drawing.Point(159, 92);
this.btnWrite.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnWrite.Name = "btnWrite";
this.btnWrite.Size = new System.Drawing.Size(75, 23);
this.btnWrite.Size = new System.Drawing.Size(75, 29);
this.btnWrite.TabIndex = 10;
this.btnWrite.Text = "Write";
this.btnWrite.UseVisualStyleBackColor = true;
this.btnWrite.Click += new System.EventHandler(this.btnWrite_Click);
//
// chkModbus
// tbWriteValue
//
this.chkModbus.AutoSize = true;
this.chkModbus.Checked = true;
this.chkModbus.Location = new System.Drawing.Point(8, 21);
this.chkModbus.Name = "chkModbus";
this.chkModbus.Size = new System.Drawing.Size(69, 16);
this.chkModbus.TabIndex = 0;
this.chkModbus.TabStop = true;
this.chkModbus.Text = "Modbus";
this.chkModbus.UseVisualStyleBackColor = true;
this.tbWriteValue.Location = new System.Drawing.Point(91, 59);
this.tbWriteValue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tbWriteValue.Name = "tbWriteValue";
this.tbWriteValue.Size = new System.Drawing.Size(143, 23);
this.tbWriteValue.TabIndex = 7;
this.tbWriteValue.Text = "0";
//
// chkOPCUA
// label6
//
this.chkOPCUA.AutoSize = true;
this.chkOPCUA.Location = new System.Drawing.Point(91, 21);
this.chkOPCUA.Name = "chkOPCUA";
this.chkOPCUA.Size = new System.Drawing.Size(69, 16);
this.chkOPCUA.TabIndex = 0;
this.chkOPCUA.Text = "OPC UA";
this.chkOPCUA.UseVisualStyleBackColor = true;
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(6, 64);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(67, 15);
this.label6.TabIndex = 6;
this.label6.Text = "Write value";
//
// tbWriteName
//
this.tbWriteName.Location = new System.Drawing.Point(91, 25);
this.tbWriteName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tbWriteName.Name = "tbWriteName";
this.tbWriteName.Size = new System.Drawing.Size(143, 23);
this.tbWriteName.TabIndex = 7;
this.tbWriteName.Text = "00001";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 30);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(75, 15);
this.label5.TabIndex = 6;
this.label5.Text = "Tag name/Id";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.chkSdk);
this.groupBox4.Controls.Add(this.chkOPCUA);
this.groupBox4.Controls.Add(this.chkModbus);
this.groupBox4.Location = new System.Drawing.Point(13, 453);
this.groupBox4.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox4.Size = new System.Drawing.Size(240, 64);
this.groupBox4.TabIndex = 0;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Mode";
//
// chkSdk
//
this.chkSdk.AutoSize = true;
this.chkSdk.Location = new System.Drawing.Point(174, 21);
this.chkSdk.Location = new System.Drawing.Point(174, 26);
this.chkSdk.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.chkSdk.Name = "chkSdk";
this.chkSdk.Size = new System.Drawing.Size(47, 16);
this.chkSdk.Size = new System.Drawing.Size(48, 19);
this.chkSdk.TabIndex = 0;
this.chkSdk.Text = "SDK";
this.chkSdk.UseVisualStyleBackColor = true;
//
// rtbLog
//
this.rtbLog.BackColor = System.Drawing.Color.Black;
this.rtbLog.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rtbLog.ForeColor = System.Drawing.Color.Lime;
this.rtbLog.Location = new System.Drawing.Point(6, 20);
this.rtbLog.Name = "rtbLog";
this.rtbLog.ReadOnly = true;
this.rtbLog.Size = new System.Drawing.Size(405, 329);
this.rtbLog.TabIndex = 1;
this.rtbLog.Text = "";
//
// chkAutoScroll
// chkOPCUA
//
this.chkAutoScroll.AutoSize = true;
this.chkAutoScroll.Checked = true;
this.chkAutoScroll.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkAutoScroll.Location = new System.Drawing.Point(6, 362);
this.chkAutoScroll.Name = "chkAutoScroll";
this.chkAutoScroll.Size = new System.Drawing.Size(84, 16);
this.chkAutoScroll.TabIndex = 4;
this.chkAutoScroll.Text = "Auto scroll";
this.chkAutoScroll.UseVisualStyleBackColor = true;
this.chkOPCUA.AutoSize = true;
this.chkOPCUA.Location = new System.Drawing.Point(91, 26);
this.chkOPCUA.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.chkOPCUA.Name = "chkOPCUA";
this.chkOPCUA.Size = new System.Drawing.Size(69, 19);
this.chkOPCUA.TabIndex = 0;
this.chkOPCUA.Text = "OPC UA";
this.chkOPCUA.UseVisualStyleBackColor = true;
//
// btnClear
// chkModbus
//
this.btnClear.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClear.Location = new System.Drawing.Point(336, 355);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(75, 23);
this.btnClear.TabIndex = 5;
this.btnClear.Text = "Clear log";
this.btnClear.UseVisualStyleBackColor = true;
this.chkModbus.AutoSize = true;
this.chkModbus.Checked = true;
this.chkModbus.Location = new System.Drawing.Point(8, 26);
this.chkModbus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.chkModbus.Name = "chkModbus";
this.chkModbus.Size = new System.Drawing.Size(69, 19);
this.chkModbus.TabIndex = 0;
this.chkModbus.TabStop = true;
this.chkModbus.Text = "Modbus";
this.chkModbus.UseVisualStyleBackColor = true;
//
// tbIP
// label7
//
this.tbIP.Location = new System.Drawing.Point(78, 47);
this.tbIP.Name = "tbIP";
this.tbIP.Size = new System.Drawing.Size(156, 21);
this.tbIP.TabIndex = 7;
this.tbIP.Text = "127.0.0.1";
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(4, 129);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(49, 15);
this.label7.TabIndex = 5;
this.label7.Text = "Address";
//
// label3
// nudAddress
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(4, 51);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 12);
this.label3.TabIndex = 5;
this.label3.Text = "Server IP";
this.nudAddress.Location = new System.Drawing.Point(78, 123);
this.nudAddress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.nudAddress.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.nudAddress.Name = "nudAddress";
this.nudAddress.Size = new System.Drawing.Size(156, 23);
this.nudAddress.TabIndex = 9;
this.nudAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudAddress.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(690, 407);
this.ClientSize = new System.Drawing.Size(690, 528);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Font = new System.Drawing.Font("맑은 고딕", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "MainForm";
this.Text = "Comm Client";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).EndInit();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
this.groupBox2.ResumeLayout(false);
@ -377,7 +444,7 @@ namespace CommClient
this.groupBox3.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).EndInit();
this.ResumeLayout(false);
}
@ -396,7 +463,7 @@ namespace CommClient
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button btnRead;
private System.Windows.Forms.TextBox tbName;
private System.Windows.Forms.TextBox tbReadName;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnWrite;
private System.Windows.Forms.TextBox tbWriteValue;
@ -411,6 +478,8 @@ namespace CommClient
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.TextBox tbIP;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown nudAddress;
private System.Windows.Forms.Label label7;
}
}

@ -1,4 +1,5 @@
using System;
using CommClient.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -12,9 +13,105 @@ namespace CommClient
{
public partial class MainForm : Form
{
private bool isFirstLog = true;
private ICommClient client;
public MainForm()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
chkModbus.CheckedChanged += Chk_CheckedChanged;
chkOPCUA.CheckedChanged += Chk_CheckedChanged;
chkSdk.CheckedChanged += Chk_CheckedChanged;
}
private void Chk_CheckedChanged(object sender, EventArgs e)
{
if (!(sender as RadioButton).Checked)
return;
InitClient();
}
private void InitClient()
{
if (client != null && client.GetStatus())
{
Log("--- Disconnect previous connection ---");
btnDisconnect_Click(null, null);
}
if (chkModbus.Checked)
{
client = new ModbusMaster();
Log("--- Run as Modbus mode ---");
}
else if (chkOPCUA.Checked)
{
Log("--- Run as OPCUA mode ---");
}
else if (chkSdk.Checked)
{
Log("--- Run as SDK mode ---");
}
}
private void ChangeStatus(bool status)
{
}
private void Log(string text)
{
rtbLog.AppendText((isFirstLog ? "" : Environment.NewLine) + text);
isFirstLog = false;
ScrollToEnd();
}
private void ScrollToEnd()
{
if (!chkAutoScroll.Checked)
return;
rtbLog.SelectionStart = rtbLog.Text.Length;
rtbLog.ScrollToCaret();
}
private void ClearLog()
{
rtbLog.Clear();
isFirstLog = true;
ScrollToEnd();
}
private void btnConnect_Click(object sender, EventArgs e)
{
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
}
private void btnRead_Click(object sender, EventArgs e)
{
}
private void btnWrite_Click(object sender, EventArgs e)
{
}
private void btnClear_Click(object sender, EventArgs e)
{
ClearLog();
}
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="hima.lib.easymodbus" version="5.6.0" targetFramework="net481" />
</packages>
Loading…
Cancel
Save