main
syneffort 3 years ago
parent b25cf87a7f
commit 3fa0ff0ede
  1. 2
      ModbusStudy/CommClient/Client/ICommClient.cs
  2. 106
      ModbusStudy/CommClient/Client/ModbusMaster.cs
  3. BIN
      ModbusStudy/CommClient/Graphicloads-100-Flat-2-Arrow-next.ico
  4. 108
      ModbusStudy/CommClient/MainForm.Designer.cs
  5. 120
      ModbusStudy/CommClient/MainForm.cs
  6. 2811
      ModbusStudy/CommClient/MainForm.resx
  7. 6
      ModbusStudy/CommClient/MasterClient.csproj
  8. 2
      ModbusStudy/CommClient/Program.cs
  9. 2
      ModbusStudy/CommClient/Properties/Resources.Designer.cs
  10. 2
      ModbusStudy/CommClient/Properties/Settings.Designer.cs
  11. BIN
      ModbusStudy/ModbusSlave/Graphicloads-100-Flat-2-Arrow-previous.ico
  12. 50
      ModbusStudy/ModbusSlave/MainForm.Designer.cs
  13. 9
      ModbusStudy/ModbusSlave/MainForm.cs
  14. 2817
      ModbusStudy/ModbusSlave/MainForm.resx
  15. 6
      ModbusStudy/ModbusSlave/ModbusSlave.csproj
  16. 2
      ModbusStudy/ModbusStudy.sln
  17. BIN
      Resource/Icon/Graphicloads-100-Flat-2-Arrow-next.ico
  18. BIN
      Resource/Icon/Graphicloads-100-Flat-2-Arrow-previous.ico

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommClient.Client
namespace MasterClient.Client
{
interface ICommClient
{

@ -5,46 +5,134 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommClient.Client
namespace MasterClient.Client
{
class ModbusMaster : ICommClient
{
private ModbusClient client;
private int UINIT_IDENTIFIER = 1;
public ModbusMaster()
public byte identifier = 1;
public ModbusMaster(byte identifier = 1)
{
client = new ModbusClient();
this.identifier = identifier;
}
public void Connect()
{
throw new NotImplementedException();
try
{
if (client.Connected)
client.Disconnect();
client.Connect();
}
catch (Exception ex)
{
throw ex;
}
}
public void Disconnect()
{
throw new NotImplementedException();
try
{
client.Disconnect();
}
catch (Exception ex)
{
throw ex;
}
}
public bool GetStatus()
{
throw new NotImplementedException();
if (client == null)
return false;
return client.Connected;
}
public string ReadValue(string name)
{
throw new NotImplementedException();
if (!client.Connected)
throw new Exception("Disconnected status");
try
{
int address;
if (!int.TryParse(name, out address))
throw new Exception("cannot parse as int");
string value = "";
if (address >= 40001 && address < 50000)
value = client.ReadHoldingRegisters(address - 40001, 1)[0].ToString();
else if (address >= 30001 && address < 40000)
value = client.ReadInputRegisters(address - 30001, 1)[0].ToString();
else if (address >= 10001 && address < 20000)
value = client.ReadInputRegisters(address - 10001, 1)[0].ToString();
else if (address >= 1 && address < 10000)
value = client.ReadCoils(address - 1, 1)[0].ToString();
else
throw new Exception("Address is unavailable. (0x, 1x, 3x, 4x only)");
return value;
}
catch (Exception ex)
{
throw ex;
}
}
public void SetServer(string ip, int port)
{
throw new NotImplementedException();
client.IPAddress = ip;
client.Port = port;
client.UnitIdentifier = this.identifier;
}
public void WriteValue(string name, string value)
{
throw new NotImplementedException();
if (!client.Connected)
throw new Exception("Disconnected status");
try
{
// 0x, 4x 만 쓰기 가능
int address;
if (!int.TryParse(name, out address))
throw new Exception("Cannot parse as int");
if (address >= 40001 && address < 50000)
{
int parsed = 0;
if (!int.TryParse(value, out parsed))
throw new Exception("Value is not integer");
client.WriteSingleRegister(address - 40001, parsed);
}
else if (address >= 1 && address < 10000)
{
bool parsed = false;
if (value == "0")
parsed = false;
else if (value == "1")
parsed = true;
else if (!bool.TryParse(value, out parsed))
throw new Exception("Value is not boolean");
client.WriteSingleCoil(address - 1, parsed);
}
else
throw new Exception("Address is unavailable (0x, 4x only)");
}
catch (Exception ex)
{
throw ex;
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

@ -1,5 +1,5 @@

namespace CommClient
namespace MasterClient
{
partial class MainForm
{
@ -29,11 +29,14 @@ namespace CommClient
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
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.nudIdentifier = new System.Windows.Forms.NumericUpDown();
this.nudPort = new System.Windows.Forms.NumericUpDown();
this.label7 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tbStatus = new System.Windows.Forms.TextBox();
@ -52,19 +55,17 @@ namespace CommClient
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.gbMode = new System.Windows.Forms.GroupBox();
this.chkSdk = new System.Windows.Forms.RadioButton();
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.nudIdentifier)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).BeginInit();
this.groupBox5.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).BeginInit();
this.gbMode.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
@ -72,7 +73,7 @@ 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.nudIdentifier);
this.groupBox1.Controls.Add(this.nudPort);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.label3);
@ -120,6 +121,25 @@ namespace CommClient
this.btnConnect.Text = "Connect";
this.btnConnect.UseVisualStyleBackColor = true;
this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
//
// nudIdentifier
//
this.nudIdentifier.Location = new System.Drawing.Point(78, 123);
this.nudIdentifier.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.nudIdentifier.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.nudIdentifier.Name = "nudIdentifier";
this.nudIdentifier.Size = new System.Drawing.Size(156, 23);
this.nudIdentifier.TabIndex = 9;
this.nudIdentifier.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudIdentifier.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// nudPort
//
@ -139,6 +159,15 @@ namespace CommClient
0,
0,
0});
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(4, 129);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(54, 15);
this.label7.TabIndex = 5;
this.label7.Text = "Identifier";
//
// label3
//
@ -340,19 +369,19 @@ namespace CommClient
this.label5.TabIndex = 6;
this.label5.Text = "Tag name/Id";
//
// groupBox4
// gbMode
//
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";
this.gbMode.Controls.Add(this.chkSdk);
this.gbMode.Controls.Add(this.chkOPCUA);
this.gbMode.Controls.Add(this.chkModbus);
this.gbMode.Location = new System.Drawing.Point(13, 453);
this.gbMode.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.gbMode.Name = "gbMode";
this.gbMode.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.gbMode.Size = new System.Drawing.Size(240, 64);
this.gbMode.TabIndex = 0;
this.gbMode.TabStop = false;
this.gbMode.Text = "Mode";
//
// chkSdk
//
@ -388,34 +417,6 @@ namespace CommClient
this.chkModbus.TabStop = true;
this.chkModbus.Text = "Modbus";
this.chkModbus.UseVisualStyleBackColor = true;
//
// label7
//
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";
//
// nudAddress
//
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
//
@ -424,17 +425,19 @@ namespace CommClient
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(690, 528);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.gbMode);
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.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
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.nudIdentifier)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).EndInit();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
@ -442,9 +445,8 @@ namespace CommClient
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).EndInit();
this.gbMode.ResumeLayout(false);
this.gbMode.PerformLayout();
this.ResumeLayout(false);
}
@ -461,7 +463,7 @@ namespace CommClient
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.GroupBox gbMode;
private System.Windows.Forms.Button btnRead;
private System.Windows.Forms.TextBox tbReadName;
private System.Windows.Forms.Label label4;
@ -478,7 +480,7 @@ 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.NumericUpDown nudIdentifier;
private System.Windows.Forms.Label label7;
}
}

@ -1,4 +1,4 @@
using CommClient.Client;
using MasterClient.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -9,7 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CommClient
namespace MasterClient
{
public partial class MainForm : Form
{
@ -19,50 +19,22 @@ namespace CommClient
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)
{
btnConnect.Enabled = !status;
tbIP.Enabled = !status;
nudPort.Enabled = !status;
nudIdentifier.Enabled = !status;
btnDisconnect.Enabled = status;
tbStatus.Text = status ? "Connected" : "Disconnected";
tbStatus.BackColor = status ? Color.Lime : Color.Silver;
gbMode.Enabled = !status;
Log(status ? "--- Connected ---" : "--- Disconnected ---");
}
private void Log(string text)
@ -91,22 +63,88 @@ namespace CommClient
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
InitServer();
client.SetServer(tbIP.Text, (int)nudPort.Value);
client.Connect();
ChangeStatus(true);
}
catch (Exception ex)
{
Log($"[ERROR] {ex.Message}");
}
}
private void InitServer()
{
if (client != null && client.GetStatus())
{
Log("--- Disconnect previous connection ---");
btnDisconnect_Click(null, null);
}
if (chkModbus.Checked)
{
client = new Client.ModbusMaster((byte)nudIdentifier.Value);
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 btnDisconnect_Click(object sender, EventArgs e)
{
try
{
client.Disconnect();
ChangeStatus(false);
}
catch (Exception ex)
{
Log($"[ERROR] {ex.Message}");
}
}
private void btnRead_Click(object sender, EventArgs e)
{
try
{
if (!client.GetStatus())
throw new Exception("Disconneced");
string value = client.ReadValue(tbReadName.Text);
Log($"[READ] {tbReadName.Text}:{value}");
}
catch (Exception ex)
{
Log($"[ERROR] {ex.Message}");
}
}
private void btnWrite_Click(object sender, EventArgs e)
{
try
{
if (!client.GetStatus())
throw new Exception("Disconneced");
client.WriteValue(tbWriteName.Text, tbWriteValue.Text);
Log($"[WRITE] {tbWriteName.Text}:{tbWriteValue.Text}");
}
catch (Exception ex)
{
Log($"[ERROR] {ex.Message}");
}
}
private void btnClear_Click(object sender, EventArgs e)

File diff suppressed because it is too large Load Diff

@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Graphicloads-100-Flat-2-Arrow-next.ico</ApplicationIcon>
</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>
@ -85,5 +88,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Graphicloads-100-Flat-2-Arrow-next.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -4,7 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CommClient
namespace MasterClient
{
static class Program
{

@ -9,7 +9,7 @@
//------------------------------------------------------------------------------
namespace CommClient.Properties
namespace MasterClient.Properties
{
/// <summary>
/// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.

@ -9,7 +9,7 @@
//------------------------------------------------------------------------------
namespace CommClient.Properties
namespace MasterClient.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

@ -29,10 +29,11 @@ namespace ModbusSlave
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnStop = new System.Windows.Forms.Button();
this.btnRun = new System.Windows.Forms.Button();
this.nudAddress = new System.Windows.Forms.NumericUpDown();
this.nudIdentifier = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.nudPort = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
@ -60,7 +61,7 @@ namespace ModbusSlave
this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudIdentifier)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).BeginInit();
this.groupBox2.SuspendLayout();
this.tabLv.SuspendLayout();
@ -74,7 +75,7 @@ namespace ModbusSlave
//
this.groupBox1.Controls.Add(this.btnStop);
this.groupBox1.Controls.Add(this.btnRun);
this.groupBox1.Controls.Add(this.nudAddress);
this.groupBox1.Controls.Add(this.nudIdentifier);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.nudPort);
this.groupBox1.Controls.Add(this.label2);
@ -113,15 +114,15 @@ namespace ModbusSlave
this.btnRun.UseVisualStyleBackColor = true;
this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
//
// nudAddress
// nudIdentifier
//
this.nudAddress.Location = new System.Drawing.Point(81, 90);
this.nudAddress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.nudAddress.Name = "nudAddress";
this.nudAddress.Size = new System.Drawing.Size(156, 23);
this.nudAddress.TabIndex = 2;
this.nudAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudAddress.Value = new decimal(new int[] {
this.nudIdentifier.Location = new System.Drawing.Point(81, 90);
this.nudIdentifier.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.nudIdentifier.Name = "nudIdentifier";
this.nudIdentifier.Size = new System.Drawing.Size(156, 23);
this.nudIdentifier.TabIndex = 2;
this.nudIdentifier.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.nudIdentifier.Value = new decimal(new int[] {
1,
0,
0,
@ -132,9 +133,9 @@ namespace ModbusSlave
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 95);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(49, 15);
this.label3.Size = new System.Drawing.Size(54, 15);
this.label3.TabIndex = 0;
this.label3.Text = "Address";
this.label3.Text = "Identifier";
//
// nudPort
//
@ -255,11 +256,11 @@ namespace ModbusSlave
// tabPage1
//
this.tabPage1.Controls.Add(this.lv0x);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Location = new System.Drawing.Point(4, 24);
this.tabPage1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage1.Size = new System.Drawing.Size(255, 426);
this.tabPage1.Size = new System.Drawing.Size(255, 424);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "0x";
this.tabPage1.UseVisualStyleBackColor = true;
@ -276,7 +277,7 @@ namespace ModbusSlave
this.lv0x.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lv0x.MultiSelect = false;
this.lv0x.Name = "lv0x";
this.lv0x.Size = new System.Drawing.Size(249, 418);
this.lv0x.Size = new System.Drawing.Size(249, 416);
this.lv0x.TabIndex = 0;
this.lv0x.UseCompatibleStateImageBehavior = false;
this.lv0x.View = System.Windows.Forms.View.Details;
@ -294,11 +295,11 @@ namespace ModbusSlave
// tabPage2
//
this.tabPage2.Controls.Add(this.lv1x);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Location = new System.Drawing.Point(4, 24);
this.tabPage2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage2.Size = new System.Drawing.Size(255, 426);
this.tabPage2.Size = new System.Drawing.Size(255, 424);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "1x";
this.tabPage2.UseVisualStyleBackColor = true;
@ -315,7 +316,7 @@ namespace ModbusSlave
this.lv1x.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lv1x.MultiSelect = false;
this.lv1x.Name = "lv1x";
this.lv1x.Size = new System.Drawing.Size(249, 418);
this.lv1x.Size = new System.Drawing.Size(249, 416);
this.lv1x.TabIndex = 1;
this.lv1x.UseCompatibleStateImageBehavior = false;
this.lv1x.View = System.Windows.Forms.View.Details;
@ -333,11 +334,11 @@ namespace ModbusSlave
// tabPage3
//
this.tabPage3.Controls.Add(this.lv3x);
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Location = new System.Drawing.Point(4, 24);
this.tabPage3.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabPage3.Size = new System.Drawing.Size(255, 426);
this.tabPage3.Size = new System.Drawing.Size(255, 424);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "3x";
this.tabPage3.UseVisualStyleBackColor = true;
@ -354,7 +355,7 @@ namespace ModbusSlave
this.lv3x.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lv3x.MultiSelect = false;
this.lv3x.Name = "lv3x";
this.lv3x.Size = new System.Drawing.Size(249, 418);
this.lv3x.Size = new System.Drawing.Size(249, 416);
this.lv3x.TabIndex = 1;
this.lv3x.UseCompatibleStateImageBehavior = false;
this.lv3x.View = System.Windows.Forms.View.Details;
@ -419,12 +420,13 @@ namespace ModbusSlave
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.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "MainForm";
this.Text = "Modbus Slave";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudAddress)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudIdentifier)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPort)).EndInit();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
@ -442,7 +444,7 @@ namespace ModbusSlave
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.NumericUpDown nudAddress;
private System.Windows.Forms.NumericUpDown nudIdentifier;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown nudPort;
private System.Windows.Forms.Label label2;

@ -17,7 +17,7 @@ namespace ModbusSlave
public partial class MainForm : Form
{
private readonly int DATA_COUNT = 20;
private ModbusServer server;
private ModbusServer server = new ModbusServer();
private System.Timers.Timer updateTimer;
private bool isFirstLog = true;
@ -32,8 +32,9 @@ namespace ModbusSlave
{
try
{
server = new ModbusServer();
server.Port = (int)nudPort.Value;
server.UnitIdentifier = Convert.ToByte(nudAddress.Value);
server.UnitIdentifier = Convert.ToByte(nudIdentifier.Value);
if (!CheckPortInUse(server.Port))
{
@ -45,7 +46,7 @@ namespace ModbusSlave
Log("--- Server start ---");
btnRun.Enabled = false;
nudAddress.Enabled = false;
nudIdentifier.Enabled = false;
nudPort.Enabled = false;
tbStatus.Text = "Run";
@ -67,7 +68,7 @@ namespace ModbusSlave
Log("--- Server stop ---");
btnRun.Enabled = true;
nudAddress.Enabled = true;
nudIdentifier.Enabled = true;
nudPort.Enabled = true;
tbStatus.Text = "Stop";

File diff suppressed because it is too large Load Diff

@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Graphicloads-100-Flat-2-Arrow-previous.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyModbus, Version=5.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll</HintPath>
@ -92,5 +95,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Graphicloads-100-Flat-2-Arrow-previous.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.32630.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusSlave", "ModbusSlave\ModbusSlave.csproj", "{439FCE65-14FD-4495-96CF-C4473455249D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommClient", "CommClient\CommClient.csproj", "{F47D20AF-4D05-4AA5-9160-401599079F1A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasterClient", "CommClient\MasterClient.csproj", "{F47D20AF-4D05-4AA5-9160-401599079F1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Loading…
Cancel
Save