Skip to content

Commit 8b02bdb

Browse files
Changes Modbus RTU CRC Check
1 parent 8bfdcdc commit 8b02bdb

File tree

7 files changed

+109
-19
lines changed

7 files changed

+109
-19
lines changed

EasyModbusAdvancedClient/AddConnectionForm.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,27 @@ void Button1Click(object sender, EventArgs e)
7373
}
7474
}
7575

76+
public enum ModbusType
77+
{
78+
ModbusTCP = 0,
79+
ModbusRTU = 1
80+
}
81+
7682
public class ConnectionProperties
7783
{
84+
85+
ModbusType modbusType;
86+
87+
[Browsable(true)]
88+
[Category("Modbus Type")]
89+
[Description("Modbus TCP or Modbus RTU")]
90+
[DisplayName("Modbus Type")]
91+
public ModbusType ModbusTypeProperty
92+
{
93+
get { return modbusType; }
94+
set { modbusType = value; }
95+
}
96+
7897
string connectionName = "Connection #1";
7998

8099
[Browsable(true)]
@@ -86,7 +105,7 @@ public string ConnectionName
86105
get { return connectionName; }
87106
set { connectionName = value; }
88107
}
89-
108+
90109
string modbusTCPAddress = "127.0.0.1";
91110

92111
[Browsable(true)]

EasyModbusClientExample/MainForm.Designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyModbusClientExample/MainForm.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ void BtnReadCoilsClick(object sender, EventArgs e)
8888
{
8989
MessageBox.Show(exc.Message,"Exception Reading values from Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
9090
}
91+
finally
92+
{
93+
modbusClient.Disconnect();
94+
}
9195
}
9296

9397
private void btnReadDiscreteInputs_Click(object sender, EventArgs e)
@@ -111,6 +115,10 @@ private void btnReadDiscreteInputs_Click(object sender, EventArgs e)
111115
{
112116
MessageBox.Show(exc.Message, "Exception Reading values from Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
113117
}
118+
finally
119+
{
120+
modbusClient.Disconnect();
121+
}
114122
}
115123

116124
private void btnReadHoldingRegisters_Click(object sender, EventArgs e)
@@ -138,6 +146,10 @@ private void btnReadHoldingRegisters_Click(object sender, EventArgs e)
138146
{
139147
MessageBox.Show(exc.Message, "Exception Reading values from Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
140148
}
149+
finally
150+
{
151+
modbusClient.Disconnect();
152+
}
141153
}
142154

143155
private void btnReadInputRegisters_Click(object sender, EventArgs e)
@@ -163,6 +175,10 @@ private void btnReadInputRegisters_Click(object sender, EventArgs e)
163175
{
164176
MessageBox.Show(exc.Message, "Exception Reading values from Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
165177
}
178+
finally
179+
{
180+
modbusClient.Disconnect();
181+
}
166182
}
167183

168184
private void pictureBox1_Click(object sender, EventArgs e)
@@ -265,6 +281,10 @@ private void btnWriteSingleCoil_Click(object sender, EventArgs e)
265281
{
266282
MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
267283
}
284+
finally
285+
{
286+
modbusClient.Disconnect();
287+
}
268288
}
269289

270290
private void btnWriteSingleRegister_Click(object sender, EventArgs e)
@@ -289,6 +309,10 @@ private void btnWriteSingleRegister_Click(object sender, EventArgs e)
289309
{
290310
MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
291311
}
312+
finally
313+
{
314+
modbusClient.Disconnect();
315+
}
292316
}
293317

294318
private void btnWriteMultipleCoils_Click(object sender, EventArgs e)
@@ -317,6 +341,10 @@ private void btnWriteMultipleCoils_Click(object sender, EventArgs e)
317341
{
318342
MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
319343
}
344+
finally
345+
{
346+
modbusClient.Disconnect();
347+
}
320348
}
321349

322350
private void btnWriteMultipleRegisters_Click(object sender, EventArgs e)
@@ -345,6 +373,10 @@ private void btnWriteMultipleRegisters_Click(object sender, EventArgs e)
345373
{
346374
MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
347375
}
376+
finally
377+
{
378+
modbusClient.Disconnect();
379+
}
348380
}
349381

350382
private void lsbAnswerFromServer_DoubleClick(object sender, EventArgs e)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<OpenCoverSettings />

EasyModbusServerSimulator/EasyModbusServerSimulator.csproj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,24 @@
3131
<IsWebBootstrapper>false</IsWebBootstrapper>
3232
<UseApplicationTrust>false</UseApplicationTrust>
3333
<BootstrapperEnabled>true</BootstrapperEnabled>
34+
<NoWin32Manifest>False</NoWin32Manifest>
35+
<SignAssembly>False</SignAssembly>
36+
<DelaySign>False</DelaySign>
37+
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
38+
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
39+
<NoStdLib>False</NoStdLib>
40+
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
41+
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
42+
<WarningLevel>4</WarningLevel>
43+
<RunCodeAnalysis>False</RunCodeAnalysis>
44+
<SourceAnalysisOverrideSettingsFile>C:\Users\srossmann.CARPENTIER\AppData\Roaming\ICSharpCode\SharpDevelop5\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
3445
</PropertyGroup>
3546
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
3647
<PlatformTarget>x86</PlatformTarget>
48+
<BaseAddress>4194304</BaseAddress>
49+
<RegisterForComInterop>False</RegisterForComInterop>
50+
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
51+
<FileAlignment>4096</FileAlignment>
3752
</PropertyGroup>
3853
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
3954
<OutputPath>bin\Debug\</OutputPath>
@@ -42,6 +57,8 @@
4257
<Optimize>False</Optimize>
4358
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
4459
<DefineConstants>DEBUG;TRACE</DefineConstants>
60+
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
61+
<StartAction>Project</StartAction>
4562
</PropertyGroup>
4663
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
4764
<OutputPath>bin\Release\</OutputPath>
@@ -51,9 +68,6 @@
5168
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
5269
<DefineConstants>TRACE</DefineConstants>
5370
</PropertyGroup>
54-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
55-
<Prefer32Bit>false</Prefer32Bit>
56-
</PropertyGroup>
5771
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
5872
<Prefer32Bit>false</Prefer32Bit>
5973
</PropertyGroup>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Properties />
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
#region Using directives
2-
1+
#region Using directives
32
using System;
43
using System.Reflection;
54
using System.Runtime.InteropServices;
65

76
#endregion
8-
97
// General Information about an assembly is controlled through the following
108
// set of attributes. Change these attribute values to modify the information
119
// associated with an assembly.
12-
[assembly: AssemblyTitle("EasyModbusServerSimulator")]
13-
[assembly: AssemblyDescription("")]
14-
[assembly: AssemblyConfiguration("")]
15-
[assembly: AssemblyCompany("Stefan Rossmann Engineering Solutions")]
16-
[assembly: AssemblyProduct("EasyModbusServerSimulator")]
17-
[assembly: AssemblyCopyright("Copyright 2016")]
18-
[assembly: AssemblyTrademark("")]
19-
[assembly: AssemblyCulture("")]
20-
10+
[assembly: AssemblyTitle ("EasyModbusServerSimulator")]
11+
[assembly: AssemblyDescription ("")]
12+
[assembly: AssemblyConfiguration ("")]
13+
[assembly: AssemblyCompany ("Stefan Rossmann Engineering Solutions")]
14+
[assembly: AssemblyProduct ("EasyModbusServerSimulator")]
15+
[assembly: AssemblyCopyright ("Copyright 2016")]
16+
[assembly: AssemblyTrademark ("")]
17+
[assembly: AssemblyCulture ("")]
2118
// This sets the default COM visibility of types in the assembly to invisible.
2219
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
23-
[assembly: ComVisible(false)]
24-
20+
[assembly: ComVisible (false)]
2521
// The assembly version has following format :
2622
//
2723
// Major.Minor.Build.Revision
2824
//
2925
// You can specify all the values or you can use the default the Revision and
3026
// Build Numbers by using the '*' as shown below:
31-
[assembly: AssemblyVersion("2.6.*")]
27+
[assembly: AssemblyVersion ("2.6.*")]

0 commit comments

Comments
 (0)