Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{csproj,slnx,yml,json}]
indent_size = 2

[*.cs]
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
70 changes: 8 additions & 62 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,63 +1,9 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
*.cs text eol=lf
*.csproj text eol=lf
*.props text eol=lf
*.targets text eol=lf
*.slnx text eol=lf
*.md text eol=lf
*.json text eol=lf
*.yml text eol=lf
23 changes: 23 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: .NET 10

on: [push, pull_request]

permissions:
contents: read

jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: '10.0.x'
- run: dotnet restore EasyModbus.slnx
- run: dotnet build EasyModbus.slnx --configuration Release --no-restore
- run: dotnet test EasyModbus.slnx --configuration Release --no-build --no-restore --blame-hang-timeout 30s
- run: dotnet run --project ConsoleAppStd --configuration Release --no-build
12 changes: 6 additions & 6 deletions ConsoleAppStd/ConsoleAppStd.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyModbus_NET5\EasyModbus_V5.0.csproj" />
<ProjectReference Include="../EasyModbus/EasyModbus.csproj" />
</ItemGroup>

</Project>
46 changes: 29 additions & 17 deletions ConsoleAppStd/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
using System;
using System.Globalization;
using System.Net;
using EasyModbus;

namespace ConsoleAppStd
if (args.Length > 2)
{
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Hello World!");

EasyModbus.ModbusClient modbusClient = new EasyModbus.ModbusClient();
modbusClient.Connect("127.0.0.1", 502);
bool[] response = modbusClient.ReadDiscreteInputs(0, 2);
Console.Error.WriteLine("Usage: ConsoleAppStd [host [port]]");
return 1;
}

modbusClient.Disconnect();
Console.WriteLine("Value of Discrete Input #1: " + response[0].ToString());
Console.WriteLine("Value of Discrete Input #2: " + response[1].ToString());
Console.ReadKey();
}
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
await using var server = args.Length == 0 ? new ModbusServer { LocalIPAddress = IPAddress.Loopback, Port = 0 } : null;
try
{
if (server is not null)
{
server.holdingRegisters[1] = 123;
server.holdingRegisters[2] = 456;
server.Listen();
}
var host = args.Length > 0 ? args[0] : "127.0.0.1";
var port = args.Length > 1 ? int.Parse(args[1], CultureInfo.InvariantCulture) : server?.Port ?? 502;
await using var client = new ModbusClient(host, port);
await client.ConnectAsync(timeout.Token);
var values = await client.ReadHoldingRegistersAsync(0, 2, timeout.Token);
Console.WriteLine($"Holding registers 0 and 1: {string.Join(", ", values)}");
return 0;
}
catch (Exception exception) when (exception is IOException or System.Net.Sockets.SocketException or OperationCanceledException or
EasyModbus.Exceptions.ModbusException or ArgumentException or FormatException or OverflowException)
{
Console.Error.WriteLine(exception.Message);
return 1;
}
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<!-- Keep this repository independent of a consuming solution's build settings. -->
</Project>
3 changes: 3 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<!-- Do not inherit a consuming solution's versioning or deployment targets. -->
</Project>
Loading