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> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -46,6 +49,8 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Client\ICommClient.cs" />
<Compile Include="Client\ModbusMaster.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -66,6 +71,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

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