Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update - add Net8.0 Target #44

Merged
merged 2 commits into from
Nov 11, 2023
Merged
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
39 changes: 10 additions & 29 deletions .github/workflows/BuildOnly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,26 @@ jobs:
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
- name: Get Current Visual Studio Information
shell: bash
run: |
dotnet tool update -g dotnet-vs
echo "-- About RELEASE --"
vs where release

- name: Update Visual Studio Latest Release
shell: bash
run: |
echo "-- Update RELEASE --"
vs update release Enterprise
vs modify release Enterprise +mobile +desktop +uwp +web
echo "-- About RELEASE Updated --"
vs where release

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: Setup .NET
- name: Setup .NET 6/7
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x

- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-quality: 'preview'
dotnet-version: |
8.0.x

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.1.3
with:
Expand All @@ -49,28 +41,17 @@ jobs:
uses: dotnet/nbgv@master
with:
setAllVars: true

- run: echo 'SemVer2=${{ steps.nbgv.outputs.SemVer2 }}'

- name: NuGet Restore
run: dotnet restore SerialPortRx.sln
working-directory: src

- name: Build
run: msbuild /t:build,pack /nowarn:MSB4011 /maxcpucount /p:NoPackageAnalysis=true /verbosity:minimal /p:Configuration=Release SerialPortRx.sln
run: dotnet build --no-restore --configuration Release SerialPortRx.sln
working-directory: src

- name: Run Unit Tests and Generate Coverage
uses: glennawatson/coverlet-msbuild@v2.1
with:
project-files: 'src/**/*Tests*.csproj'
no-build: true
include-filter: 'SerialPortRx*'
output-format: cobertura
configuration: Release

- name: Upload Code Coverage
uses: codecov/codecov-action@v3

- name: Create NuGet Artifacts
uses: actions/upload-artifact@master
with:
Expand Down
27 changes: 10 additions & 17 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,26 @@ jobs:
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
- name: Get Current Visual Studio Information
shell: bash
run: |
dotnet tool update -g dotnet-vs
echo "-- About RELEASE --"
vs where release

- name: Update Visual Studio Latest Release
shell: bash
run: |
echo "-- Update RELEASE --"
vs update release Enterprise
vs modify release Enterprise +mobile +desktop +uwp +web
echo "-- About RELEASE Updated --"
vs where release

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: Setup .NET
- name: Setup .NET 6/7
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x

- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-quality: 'preview'
dotnet-version: |
8.0.x

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.1.3
with:
Expand All @@ -49,14 +41,15 @@ jobs:
uses: dotnet/nbgv@master
with:
setAllVars: true

- run: echo 'SemVer2=${{ steps.nbgv.outputs.SemVer2 }}'

- name: NuGet Restore
run: dotnet restore SerialPortRx.sln
working-directory: src

- name: Build
run: msbuild /t:build,pack /nowarn:MSB4011 /maxcpucount /p:NoPackageAnalysis=true /verbosity:minimal /p:Configuration=Release SerialPortRx.sln
run: dotnet build --no-restore --configuration Release SerialPortRx.sln
working-directory: src

- name: Create NuGet Artifacts
Expand Down
19 changes: 2 additions & 17 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
<LangVersion>preview</LangVersion>
<Configuration>$(TargetFramework)</Configuration>
<Company>ChrisPulman</Company>
<NoWarn>CS1591;IDE0190;IDE1006</NoWarn>
<NoWarn>$(NoWarn);CS1591;IDE0190;IDE1006;SA1010</NoWarn>
<Nullable>enable</Nullable>
<PackageIcon>logo.png</PackageIcon>
<Configurations>Debug;Release;PreRelease</Configurations>
<PackageReleaseNotes>Compatability with Net 6, Net 7 and netstandard2.0</PackageReleaseNotes>
<PackageTags>SerialPort;rx;reactive;extensions;observable;LINQ;net;netstandard</PackageTags>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
Expand Down Expand Up @@ -47,20 +46,6 @@
<None Include="$(MSBuildThisFileDirectory)LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -70,7 +55,7 @@
<!--<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="Roslynator.Analyzers" Version="4.6.1" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.2" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
101 changes: 55 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,65 @@ using System;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using ReactiveMarbles.Extensions;

namespace CP.IO.Ports.Test
namespace CP.IO.Ports.Test;

internal static class Program
{
internal class Program
private static void Main(string[] args)
{
private static void Main(string[] args)
const string comPortName = "COM1";

// configure the data to write, this can be a string, a byte array, or a char array
const string dataToWrite = "DataToWrite";
var dis = new CompositeDisposable();

// Setup the start of message and end of message
var startChar = 0x21.AsObservable();
var endChar = 0x0a.AsObservable();

// Create a disposable for each COM port to allow automatic disposal upon loss of COM port
var comdis = new CompositeDisposable();

// Subscribe to com ports available
SerialPortRx.PortNames().Do(x =>
{
if (comdis?.Count == 0 && x.Contains(comPortName))
{
// Create a port
var port = new SerialPortRx(comPortName, 9600);
port.DisposeWith(comdis);

// Subscribe to Exceptions from port
port.ErrorReceived.Subscribe(Console.WriteLine).DisposeWith(comdis);
port.IsOpenObservable.Subscribe(x => Console.WriteLine($"Port {comPortName} is {(x ? "Open" : "Closed")}")).DisposeWith(comdis);

// Subscribe to the Data Received
port.DataReceived.BufferUntil(startChar, endChar, 100).Subscribe(data => Console.WriteLine(data)).DisposeWith(comdis);

// Subscribe to the Is Open @500ms intervals and write to com port
port.WhileIsOpen(TimeSpan.FromMilliseconds(500)).Subscribe(_ => port.Write(dataToWrite)).DisposeWith(comdis);

// Open the Com Port after subscriptions created
port.Open();
}
else
{
comdis?.Dispose();
Console.WriteLine($"Port {comPortName} Disposed");
comdis = [];
}
}).ForEach().Subscribe(name =>
{
var comPortName = "COM1";
// configure the data to write, this can be a string, a byte array, or a char array
var dataToWrite = "DataToWrite";
var dis = new CompositeDisposable();
// Setup the start of message and end of message
var startChar = (0x21).AsObservable();
var endChar = (0x0a).AsObservable();
// Create a disposable for each COM port to allow automatic disposal upon loss of COM port
var comdis = new CompositeDisposable();
// Subscribe to com ports available
SerialPortRx.PortNames().Do(x => {
if (comdis?.Count == 0 && x.Contains(comPortName)) {
// Create a port
var port = new SerialPortRx(comPortName, 9600);
port.AddTo(comdis);
// Subscribe to Exceptions from port
port.ErrorReceived.Subscribe(Console.WriteLine).AddTo(comdis);
port.IsOpenObservable.Subscribe(x => Console.WriteLine($"Port {comPortName} is {(x ? "Open" : "Closed")}")).AddTo(comdis);
// Subscribe to the Data Received
port.DataReceived.BufferUntil(startChar, endChar, 100).Subscribe(data => {
Console.WriteLine(data);
}).AddTo(comdis);
// Subscribe to the Is Open @500ms intervals and write to com port
port.WhileIsOpen(TimeSpan.FromMilliseconds(500)).Subscribe(x => {
port.Write(dataToWrite);
}).AddTo(comdis);
// Open the Com Port after subscriptions created
port.Open();
} else {
comdis.Dispose();
Console.WriteLine($"Port {comPortName} Disposed");
comdis = new CompositeDisposable();
}
}).ForEach().Subscribe(name => {
// Show available ports
Console.WriteLine(name);
}).AddTo(dis);
Console.ReadLine();
// Cleanup ports
comdis.Dispose();
dis.Dispose();
}
// Show available ports
Console.WriteLine(name);
}).DisposeWith(dis);
Console.ReadLine();

// Cleanup ports
comdis.Dispose();
dis.Dispose();
}
}

```
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.3.4",
"version": "3.0.1",
"nuGetPackageVersion": {
"semVer": 2.0
},
Expand Down
15 changes: 8 additions & 7 deletions src/SerialPortRx.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using ReactiveMarbles.Extensions;

namespace CP.IO.Ports.Test;

Expand Down Expand Up @@ -32,17 +33,17 @@ private static void Main(string[] args)
{
// Create a port
var port = new SerialPortRx(comPortName, 9600);
port.AddTo(comdis);
port.DisposeWith(comdis);

// Subscribe to Exceptions from port
port.ErrorReceived.Subscribe(Console.WriteLine).AddTo(comdis);
port.IsOpenObservable.Subscribe(x => Console.WriteLine($"Port {comPortName} is {(x ? "Open" : "Closed")}")).AddTo(comdis);
port.ErrorReceived.Subscribe(Console.WriteLine).DisposeWith(comdis);
port.IsOpenObservable.Subscribe(x => Console.WriteLine($"Port {comPortName} is {(x ? "Open" : "Closed")}")).DisposeWith(comdis);

// Subscribe to the Data Received
port.DataReceived.BufferUntil(startChar, endChar, 100).Subscribe(data => Console.WriteLine(data)).AddTo(comdis);
port.DataReceived.BufferUntil(startChar, endChar, 100).Subscribe(data => Console.WriteLine(data)).DisposeWith(comdis);

// Subscribe to the Is Open @500ms intervals and write to com port
port.WhileIsOpen(TimeSpan.FromMilliseconds(500)).Subscribe(_ => port.Write(dataToWrite)).AddTo(comdis);
port.WhileIsOpen(TimeSpan.FromMilliseconds(500)).Subscribe(_ => port.Write(dataToWrite)).DisposeWith(comdis);

// Open the Com Port after subscriptions created
port.Open();
Expand All @@ -51,13 +52,13 @@ private static void Main(string[] args)
{
comdis?.Dispose();
Console.WriteLine($"Port {comPortName} Disposed");
comdis = new CompositeDisposable();
comdis = [];
}
}).ForEach().Subscribe(name =>
{
// Show available ports
Console.WriteLine(name);
}).AddTo(dis);
}).DisposeWith(dis);
Console.ReadLine();

// Cleanup ports
Expand Down
32 changes: 0 additions & 32 deletions src/SerialPortRx/IDisposableExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/SerialPortRx/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Chris Pulman. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Reflection;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
Expand Down
Loading
Loading