Skip to content

Commit b82e806

Browse files
Alpha Version of .NET5 integration and complete redesign
1 parent a68fd87 commit b82e806

15 files changed

+1485
-298
lines changed

ConsoleAppStd/ConsoleAppStd.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\EasyModbusStd\EasyModbus_V5.0.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

ConsoleAppStd/Program.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace ConsoleAppStd
4+
{
5+
class Program
6+
{
7+
8+
static void Main(string[] args)
9+
{
10+
Console.WriteLine("Hello World!");
11+
12+
EasyModbus.ModbusClient modbusClient = new EasyModbus.ModbusClient();
13+
modbusClient.Connect("127.0.0.1", 502);
14+
bool[] response = modbusClient.ReadDiscreteInputs(0, 2);
15+
16+
modbusClient.Disconnect();
17+
Console.WriteLine("Value of Discrete Input #1: " + response[0].ToString());
18+
Console.WriteLine("Value of Discrete Input #2: " + response[1].ToString());
19+
Console.ReadKey();
20+
}
21+
}
22+
}

ConsoleApplication1/ConsoleApplication1.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="EasyModbus, Version=4.4.1.0, Culture=neutral, processorArchitecture=MSIL">
37-
<HintPath>..\packages\EasyModbusTCP.4.5.1\lib\EasyModbus.dll</HintPath>
38-
</Reference>
3936
<Reference Include="System" />
4037
<Reference Include="System.Core" />
4138
<Reference Include="System.Xml.Linq" />
@@ -53,6 +50,12 @@
5350
<None Include="App.config" />
5451
<None Include="packages.config" />
5552
</ItemGroup>
53+
<ItemGroup>
54+
<ProjectReference Include="..\EasyModbusStd\EasyModbusStd.csproj">
55+
<Project>{723f8a8c-55aa-44ea-b595-db10dfd24e74}</Project>
56+
<Name>EasyModbusStd</Name>
57+
</ProjectReference>
58+
</ItemGroup>
5659
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5760
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
5861
Other similar extension points exist, see Microsoft.Common.targets.

ConsoleApplication1/Program.cs

-58
Original file line numberDiff line numberDiff line change
@@ -14,65 +14,7 @@ class Program
1414
{
1515
static void Main(string[] args)
1616
{
17-
// int[] registers = EasyModbus.ModbusClient.ConvertStringToRegisters("hello");
18-
// SerialPort serialport = new SerialPort("COM3");
19-
/* serialport.PortName = "COM3";
20-
serialport.BaudRate = 9600;
21-
serialport.Parity = Parity.None;
22-
serialport.StopBits = StopBits.One;
23-
byte[] buffer = new byte[50];
24-
serialport.Open();
25-
byte[] bufferout = new byte[50];
26-
int numberOfBytesRead = 0;
27-
do
28-
{
29-
int quantity = serialport.Read(buffer, 0, 15);
30-
Buffer.BlockCopy(buffer, 0, bufferout, numberOfBytesRead, quantity);
31-
numberOfBytesRead = numberOfBytesRead + quantity;
32-
}
33-
while (numberOfBytesRead < 5);
34-
for (int i = 0; i < 15; i++)
35-
Console.WriteLine(bufferout[i].ToString());
36-
serialport.Write("ddddddddd");*/
37-
EasyModbus.ModbusClient modbusClient = new EasyModbus.ModbusClient("COM3");
38-
modbusClient.Baudrate = 19200;
39-
//modbusClient.SerialPort = "COM3";
40-
//EasyModbus.ModbusClient modbusClient = new EasyModbus.ModbusClient("127.0.0.1", 502);
41-
//modbusClient.LogFileFilename = "logfile.txt";
42-
modbusClient.UnitIdentifier = 247;
43-
modbusClient.Connect();
44-
while (true)
45-
{
4617

47-
48-
// Console.WriteLine("Execute FC5");
49-
// modbusClient.WriteSingleCoil(0, true);
50-
// Console.WriteLine("Execute FC6");
51-
// modbusClient.WriteSingleRegister(0, 1234);
52-
// Console.WriteLine("Execute FC15");
53-
// modbusClient.WriteMultipleCoils(0, new bool[] { true, false, true, false, true, false, true });
54-
//Console.WriteLine("Execute FC16");
55-
//modbusClient.WriteMultipleRegisters(0, EasyModbus.ModbusClient.ConvertStringToRegisters("hallo2"));
56-
//modbusClient.Disconnect();
57-
//System.Threading.Thread.Sleep(100);
58-
//modbusClient.Connect();
59-
60-
//Console.WriteLine("Execute FC3");
61-
//Console.WriteLine("Value of Holding Register 1000: " + modbusClient.ReadHoldingRegisters(1000, 1)[0]);
62-
63-
DateTime datetimeStart = DateTime.Now;
64-
for (int i = 1; i < 125; i++)
65-
{
66-
modbusClient.WriteSingleRegister(i,i);
67-
Console.WriteLine(modbusClient.ReadInputRegisters(i, 125)[0]);
68-
}
69-
DateTime datetimeEnd = DateTime.Now;
70-
71-
Console.WriteLine("Time elapsed: " + (datetimeEnd - datetimeStart));
72-
73-
// System.Threading.Thread.Sleep(1000);
74-
}
75-
modbusClient.Disconnect();
7618
Console.ReadKey();
7719
}
7820
}

0 commit comments

Comments
 (0)