Skip to content

Commit

Permalink
Merge pull request #64 from ChrisPulman/UpdateBuild
Browse files Browse the repository at this point in the history
Update Build gated release
  • Loading branch information
ChrisPulman authored Dec 31, 2023
2 parents 887a1ab + 93aa3e7 commit f5dee85
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 79 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/BuildOnly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ name: ModbusRx CI-BuildOnly

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches-ignore:
- main

jobs:
build-and-release:

runs-on: windows-2022

windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -20,7 +18,10 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Add MSBuild to PATH
uses: glennawatson/setup-msbuild@v1.0.3
Expand Down
33 changes: 20 additions & 13 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ name: ModbusRx CI-Build

on:
push:
branches: [ "main" ]
branches:
- main

jobs:
build-and-release:

runs-on: windows-2022

windows-latest:
name: windows-latest
runs-on: windows-latest

permissions: write-all
environment:
name: release
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -18,7 +22,10 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Add MSBuild to PATH
uses: glennawatson/setup-msbuild@v1.0.3
Expand Down Expand Up @@ -58,6 +65,13 @@ jobs:
name: nuget
path: '**/*.nupkg'

- name: NuGet Push
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
SOURCE_URL: https://api.nuget.org/v3/index.json
run: |
dotnet nuget push -s ${{ env.SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg --skip-duplicate
- name: Changelog
uses: glennawatson/ChangeLog@v1
id: changelog
Expand All @@ -71,10 +85,3 @@ jobs:
release_name: ${{ steps.nbgv.outputs.SemVer2 }}
body: |
${{ steps.changelog.outputs.commitLog }}
- name: NuGet Push
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
SOURCE_URL: https://api.nuget.org/v3/index.json
run: |
dotnet nuget push -s ${{ env.SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg --skip-duplicate
8 changes: 5 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
<NoWarn>CS1591</NoWarn>
<Nullable>enable</Nullable>
<PackageIcon>ModbusRx.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Configurations>Debug;Release;PreRelease</Configurations>
<PackageReleaseNotes>Compatability with Net 6 and netstandard2.0</PackageReleaseNotes>
<PackageReleaseNotes>Compatability with Net 6/7/8 and netstandard2.0</PackageReleaseNotes>
<PackageTags>modbus;nmodbus4;modbusrx;Master;Slave;TCP;UDP;Serial;rx;reactive;extensions;observable;LINQ;net;netstandard</PackageTags>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
Expand All @@ -38,12 +39,13 @@
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)images\ModbusRx.png" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
Expand All @@ -67,7 +69,7 @@
<ItemGroup>
<!--<Compile Update="**\*.cs" DependentUpon="I%(Filename).cs" />-->
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.7.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.10",
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFrameworks>net48</TargetFrameworks>
<IsPackable>false</IsPackable>
<!--<DefineConstants>SERIAL;JAMOD;</DefineConstants>-->
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions src/ModbusRx.IntegrationTests/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ModbusRx.IntegrationTests;

internal static class TestCases
{
public static void Serial()
public static async void Serial()
{
using var masterPort = new SerialPortRx("COM2");
using var slavePort = new SerialPortRx("COM1");
Expand All @@ -25,18 +25,18 @@ public static void Serial()
masterPort.DataBits = slavePort.DataBits = 8;
masterPort.Parity = slavePort.Parity = Parity.None;
masterPort.StopBits = slavePort.StopBits = StopBits.One;
masterPort.Open();
slavePort.Open();
await masterPort.Open();
await slavePort.Open();

using var slave = ModbusSerialSlave.CreateRtu(1, slavePort);
StartSlave(slave);

// create modbus master
using var master = ModbusSerialMaster.CreateRtu(masterPort);
ReadRegistersAsync(master);
await ReadRegistersAsync(master);
}

public static void Tcp()
public static async void Tcp()
{
var slaveClient = new TcpListener(new IPAddress(new byte[] { 127, 0, 0, 1 }), 502);
using var slave = ModbusTcpSlave.CreateTcp((byte)1, slaveClient);
Expand All @@ -46,10 +46,10 @@ public static void Tcp()
var masterClient = new TcpClientRx(address.ToString(), 502);

using var master = ModbusIpMaster.CreateIp(masterClient);
ReadRegistersAsync(master);
await ReadRegistersAsync(master);
}

public static void Udp()
public static async void Udp()
{
var slaveClient = new UdpClientRx(502);
using var slave = ModbusUdpSlave.CreateUdp(slaveClient);
Expand All @@ -60,7 +60,7 @@ public static void Udp()
masterClient.Connect(endPoint);

using var master = ModbusIpMaster.CreateIp(masterClient);
ReadRegistersAsync(master);
await ReadRegistersAsync(master);
}

public static void StartSlave(ModbusSlave slave)
Expand Down
1 change: 0 additions & 1 deletion src/ModbusRx.UnitTests/ModbusRx.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net48;net6.0;</TargetFrameworks>
<!--<DefineConstants>SERIAL</DefineConstants>-->
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ModbusRx/Extensions/Enron/EnronModbus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static async Task<uint[]> ReadInputRegisters32Async(
/// <param name="slaveAddress">Address of the device to write to.</param>
/// <param name="registerAddress">Address to write.</param>
/// <param name="value">Value to write.</param>
public static void WriteSingleRegister32(
public static async void WriteSingleRegister32(
this ModbusMaster master,
byte slaveAddress,
ushort registerAddress,
Expand All @@ -88,7 +88,7 @@ public static void WriteSingleRegister32(
throw new ArgumentNullException(nameof(master));
}

master.WriteMultipleRegisters32Async(slaveAddress, registerAddress, new[] { value });
await master.WriteMultipleRegisters32Async(slaveAddress, registerAddress, [value]);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/ModbusRx/ModbusRx.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
43 changes: 17 additions & 26 deletions src/ModbusRx/Reactive/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ public static IObservable<ModbusUdpSlave> UdpIpSlave(string ipAddress, int port
await slave.ListenAsync();
dis.Add(slave);
observer.OnNext(slave);
return Disposable.Create(() =>
{
dis.Dispose();
});
return Disposable.Create(() => dis.Dispose());
}).Retry().Publish().RefCount();
}

Expand Down Expand Up @@ -659,7 +656,7 @@ public static IObservable<ModbusUdpSlave> UdpIpSlave(string ipAddress, int port
connected = false;
master = null;
observer.OnNext((connected, null, master));
comdis = new CompositeDisposable();
comdis = [];
comdis.AddTo(dis);
}
}
Expand All @@ -670,7 +667,7 @@ public static IObservable<ModbusUdpSlave> UdpIpSlave(string ipAddress, int port
connected = false;
master = null;
observer.OnNext((connected, new ModbusCommunicationException("ModbusRx Master Fault", ex), master));
comdis = new CompositeDisposable();
comdis = [];
comdis.AddTo(dis);
}
}).Retry().Subscribe().AddTo(dis);
Expand Down Expand Up @@ -711,18 +708,15 @@ public static IObservable<ModbusSerialSlave> SerialRtuSlave(string port, byte un
{
var dis = new CompositeDisposable();
var comdis = new CompositeDisposable();
Thread? slaveThread = null;
Task? slaveThread = null;
SerialPortRx.PortNames().Do(x =>
{
try
{
if (comdis?.Count == 0 && x.Contains(port))
{
using var slave = ModbusSerialSlave.CreateRtu(unitId, new SerialPortRx(port, baudRate, dataBits, parity, stopBits, handshake));
slaveThread = new Thread(async () => await slave.ListenAsync())
{
IsBackground = true
};
slaveThread = new Task(async () => await slave.ListenAsync(), TaskCreationOptions.LongRunning);
slaveThread.Start();
dis.Add(slave);
observer.OnNext(slave);
Expand All @@ -731,8 +725,8 @@ public static IObservable<ModbusSerialSlave> SerialRtuSlave(string port, byte un
{
dis.Remove(comdis!);
comdis?.Dispose();
slaveThread?.Abort();
comdis = new CompositeDisposable();
slaveThread?.Dispose();
comdis = [];
comdis.AddTo(dis);
}
}
Expand All @@ -741,15 +735,15 @@ public static IObservable<ModbusSerialSlave> SerialRtuSlave(string port, byte un
observer.OnError(new ModbusCommunicationException("ModbusRx Slave Fault", ex));
dis.Remove(comdis!);
comdis?.Dispose();
slaveThread?.Abort();
comdis = new CompositeDisposable();
slaveThread?.Dispose();
comdis = [];
comdis.AddTo(dis);
}
}).Retry().Subscribe();

return Disposable.Create(() =>
{
slaveThread?.Abort();
slaveThread?.Dispose();
dis.Dispose();
});
}).Retry().Publish().RefCount();
Expand Down Expand Up @@ -788,18 +782,15 @@ public static IObservable<ModbusSerialSlave> SerialAsciiSlave(string port, byte
{
var dis = new CompositeDisposable();
var comdis = new CompositeDisposable();
Thread? slaveThread = null;
Task? slaveThread = null;
SerialPortRx.PortNames().Do(x =>
{
try
{
if (comdis?.Count == 0 && x.Contains(port))
{
using var slave = ModbusSerialSlave.CreateAscii(unitId, new SerialPortRx(port, baudRate, dataBits, parity, stopBits, handshake));
slaveThread = new Thread(async () => await slave.ListenAsync())
{
IsBackground = true
};
slaveThread = new Task(async () => await slave.ListenAsync(), TaskCreationOptions.LongRunning);
slaveThread.Start();
dis.Add(slave);
observer.OnNext(slave);
Expand All @@ -808,8 +799,8 @@ public static IObservable<ModbusSerialSlave> SerialAsciiSlave(string port, byte
{
dis.Remove(comdis!);
comdis?.Dispose();
slaveThread?.Abort();
comdis = new CompositeDisposable();
slaveThread?.Dispose();
comdis = [];
comdis.AddTo(dis);
}
}
Expand All @@ -818,15 +809,15 @@ public static IObservable<ModbusSerialSlave> SerialAsciiSlave(string port, byte
observer.OnError(new ModbusCommunicationException("ModbusRx Slave Fault", ex));
dis.Remove(comdis!);
comdis?.Dispose();
slaveThread?.Abort();
comdis = new CompositeDisposable();
slaveThread?.Dispose();
comdis = [];
comdis.AddTo(dis);
}
}).Retry().Subscribe();

return Disposable.Create(() =>
{
slaveThread?.Abort();
slaveThread?.Dispose();
dis.Dispose();
});
}).Retry().Publish().RefCount();
Expand Down
16 changes: 0 additions & 16 deletions src/ModbusRx/Reactive/ModbusCommunicationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,5 @@ public ModbusCommunicationException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ModbusCommunicationException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the
/// serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains
/// contextual information about the source or destination.
/// </param>
protected ModbusCommunicationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
}
}

0 comments on commit f5dee85

Please sign in to comment.