Skip to content

Commit

Permalink
Merge pull request #42 from ChrisPulman/UseCollectionInit
Browse files Browse the repository at this point in the history
Use collection Initialisers.
  • Loading branch information
ChrisPulman authored Dec 19, 2023
2 parents 04f5046 + ea2bd11 commit 7f5310c
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ dotnet_diagnostic.SA1006.severity = error
dotnet_diagnostic.SA1007.severity = error
dotnet_diagnostic.SA1008.severity = error
dotnet_diagnostic.SA1009.severity = error
dotnet_diagnostic.SA1010.severity = error
dotnet_diagnostic.SA1010.severity = none
dotnet_diagnostic.SA1011.severity = error
dotnet_diagnostic.SA1012.severity = error
dotnet_diagnostic.SA1013.severity = error
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/BuildDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
windows-latest:
name: windows-latest
runs-on: windows-latest
environment:
name: release
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -45,3 +47,17 @@ jobs:
with:
name: output
path: output

- name: Changelog
uses: glennawatson/ChangeLog@v1
id: changelog

- name: Create Release
uses: actions/create-release@v1.1.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.nbgv.outputs.SemVer2 }}
release_name: ${{ steps.nbgv.outputs.SemVer2 }}
body: |
${{ steps.changelog.outputs.commitLog }}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<ItemGroup>
<!--<Compile Update="**\*.cs" DependentUpon="I%(Filename).cs" />-->
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.4" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.7.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
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/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.2.4",
"version": "1.2.5",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
28 changes: 14 additions & 14 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
using Nuke.Common.Tools.PowerShell;
using CP.BuildTools;

[GitHubActions(
"BuildOnly",
GitHubActionsImage.WindowsLatest,
OnPushBranchesIgnore = new[] { "main" },
FetchDepth = 0,
InvokedTargets = new[] { nameof(Compile) })]
[GitHubActions(
"BuildDeploy",
GitHubActionsImage.WindowsLatest,
OnPushBranches = new[] { "main" },
FetchDepth = 0,
ImportSecrets = new[] { nameof(NuGetApiKey) },
InvokedTargets = new[] { nameof(Compile), nameof(Deploy) })]
////[GitHubActions(
//// "BuildOnly",
//// GitHubActionsImage.WindowsLatest,
//// OnPushBranchesIgnore = new[] { "main" },
//// FetchDepth = 0,
//// InvokedTargets = new[] { nameof(Compile) })]
////[GitHubActions(
//// "BuildDeploy",
//// GitHubActionsImage.WindowsLatest,
//// OnPushBranches = new[] { "main" },
//// FetchDepth = 0,
//// ImportSecrets = new[] { nameof(NuGetApiKey) },
//// InvokedTargets = new[] { nameof(Compile), nameof(Deploy) })]
partial class Build : NukeBuild
{
//// Support plugins are available for:
Expand Down Expand Up @@ -57,7 +57,7 @@ partial class Build : NukeBuild

PackagesDirectory.CreateOrCleanDirectory();
////await this.UpdateVisualStudio();
await this.InstallDotNetSdk("3.1.x", "5.x.x", "6.x.x", "7.x.x");
await this.InstallDotNetSdk("6.x.x", "7.x.x", "8.x.x");
});

Target Restore => _ => _
Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<NoWarn>$(NoWarn);CS0649;CS0169;CA1822;IDE1006</NoWarn>
<NoWarn>$(NoWarn);CS0649;CS0169;CA1822;IDE1006;IDE0051</NoWarn>
<IsPackable>false</IsPackable>
<RootNamespace></RootNamespace>
<NukeRootDirectory>..</NukeRootDirectory>
Expand All @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CP.Nuke.BuildTools" Version="1.0.34" />
<PackageReference Include="CP.Nuke.BuildTools" Version="1.0.36" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Nuke.Common" Version="7.0.6" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "7.0.400"
"version": "8.0.10",
"rollForward": "latestMinor"
}
}
1 change: 0 additions & 1 deletion src/S7PlcRx.TestApp/S7PlcRx.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions src/S7PlcRx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProjectConfig", "ProjectCon
..\.gitignore = ..\.gitignore
..\.github\dependabot.yml = ..\.github\dependabot.yml
..\Directory.Build.props = ..\Directory.Build.props
..\global.json = ..\global.json
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
..\Images\S7PlcRx.ico = ..\Images\S7PlcRx.ico
Expand Down
22 changes: 14 additions & 8 deletions src/S7PlcRx/Core/S7SocketRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class S7SocketRx : IDisposable
{
private const string Failed = nameof(Failed);
private const string Success = nameof(Success);
private readonly ISubject<Exception> _socketExceptionSubject = new Subject<Exception>();
private readonly Subject<Exception> _socketExceptionSubject = new();
private IDisposable _disposable;
private bool _disposedValue;
private bool _initComplete;
Expand Down Expand Up @@ -328,8 +328,8 @@ public int Send(Tag tag, byte[] buffer, int size)
internal (byte[] data, ushort size) GetSZLData(ushort szlArea, ushort index = 0)
{
//// 0, 1, 2, 3 , 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19, 20,21, 22, 23,24,25, 26,27,28,29,30,31,32
byte[] s7_SZL1 = { 3, 0, 0, 33, 2, 240, 128, 50, 7, 0, 0, 5, 0, 0, 8, 0, 8, 0, 1, 18, 4, 17, 68, 1, 0, 255, 9, 0, 4, 0, 0, 0, 0 };
byte[] s7_SZL2 = { 3, 0, 0, 33, 2, 240, 128, 50, 7, 0, 0, 6, 0, 0, 12, 0, 4, 0, 1, 18, 8, 18, 68, 1, 1, 0, 0, 0, 0, 10, 0, 0, 0 };
byte[] s7_SZL1 = [3, 0, 0, 33, 2, 240, 128, 50, 7, 0, 0, 5, 0, 0, 8, 0, 8, 0, 1, 18, 4, 17, 68, 1, 0, 255, 9, 0, 4, 0, 0, 0, 0];
byte[] s7_SZL2 = [3, 0, 0, 33, 2, 240, 128, 50, 7, 0, 0, 6, 0, 0, 12, 0, 4, 0, 1, 18, 8, 18, 68, 1, 1, 0, 0, 0, 0, 10, 0, 0, 0];
const int size = 1024;
var data = new byte[size];
var resultData = new byte[size];
Expand Down Expand Up @@ -480,9 +480,15 @@ private static void CloseSocket(Socket? socket)
{
if (socket?.Connected == true)
{
socket.Shutdown(SocketShutdown.Both);
socket.Close();
socket.Dispose();
try
{
socket.Shutdown(SocketShutdown.Both);
socket.Close();
socket.Dispose();
}
catch
{
}
}
}

Expand All @@ -507,7 +513,7 @@ private async Task<bool> InitialiseSiemensConnectionAsync()
}

//// //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21//
byte[] bSend1 = { 3, 0, 0, 22, 17, 224, 0, 0, 0, 46, 0, 193, 2, 1, 0, 194, 2, 3, 0, 192, 1, 9 };
byte[] bSend1 = [3, 0, 0, 22, 17, 224, 0, 0, 0, 46, 0, 193, 2, 1, 0, 194, 2, 3, 0, 192, 1, 9];

switch (PLCType)
{
Expand Down Expand Up @@ -558,7 +564,7 @@ private async Task<bool> InitialiseSiemensConnectionAsync()
}

//// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25//
byte[] bsend2 = { 3, 0, 0, 25, 2, 240, 128, 50, 1, 0, 0, 4, 0, 0, 8, 0, 0, 240, 0, 0, 1, 0, 1, 0, 30 };
byte[] bsend2 = [3, 0, 0, 25, 2, 240, 128, 50, 1, 0, 0, 4, 0, 0, 8, 0, 0, 240, 0, 0, 1, 0, 1, 0, 30];

// (23,24) PDU Length Requested = HI-LO Here Default 480 bytes
Word.ToByteArray(DataReadLength, bsend2, 23);
Expand Down
6 changes: 3 additions & 3 deletions src/S7PlcRx/PlcTypes/ByteArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace S7PlcRx.PlcTypes;

internal class ByteArray
{
private List<byte> _list = new();
private List<byte> _list;

/// <summary>
/// Initializes a new instance of the <see cref="ByteArray"/> class.
/// </summary>
public ByteArray() => _list = new();
public ByteArray() => _list = [];

/// <summary>
/// Initializes a new instance of the <see cref="ByteArray"/> class.
Expand Down Expand Up @@ -45,5 +45,5 @@ internal class ByteArray
/// <summary>
/// Clears this instance.
/// </summary>
public void Clear() => _list = new();
public void Clear() => _list = [];
}
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void FromBytes(object? sourceClass, Type classType, byte[] bytes)
}

// hier auswerten
property.SetValue(sourceClass, LReal.FromByteArray(new byte[] { bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3] }), null);
property.SetValue(sourceClass, LReal.FromByteArray([bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3]]), null);
numBytes += 4;
break;

Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/Counter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static ushort[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 2; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/DInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static int[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 4; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/DWord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static uint[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 4; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/Int.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static short[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 2; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/LReal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static double[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes!.Length / 4; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
6 changes: 3 additions & 3 deletions src/S7PlcRx/PlcTypes/Real.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static float FromByteArray(byte[] bytes)
if (BitConverter.IsLittleEndian)
{
// create deep copy of the array and reverse
bytes = new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] };
bytes = [bytes[3], bytes[2], bytes[1], bytes[0]];
}

return BitConverter.ToSingle(bytes, 0);
Expand All @@ -39,7 +39,7 @@ public static byte[] ToByteArray(float value)
}

// create deep copy of the array and reverse
return new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] };
return [bytes[3], bytes[2], bytes[1], bytes[0]];
}

/// <summary>
Expand Down Expand Up @@ -67,7 +67,7 @@ public static float[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 4; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++], bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
6 changes: 3 additions & 3 deletions src/S7PlcRx/PlcTypes/Struct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ internal static class Struct
}

// Evaluating here
info.SetValue(structValue, LReal.FromByteArray(new byte[]
{
info.SetValue(structValue, LReal.FromByteArray(
[
bytes[(int)numBytes],
bytes[(int)numBytes + 1],
bytes[(int)numBytes + 2],
bytes[(int)numBytes + 3]
}));
]));
numBytes += 4;
break;

Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static double[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 2; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
2 changes: 1 addition & 1 deletion src/S7PlcRx/PlcTypes/Word.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static ushort[] ToArray(byte[] bytes)
var counter = 0;
for (var cnt = 0; cnt < bytes.Length / 2; cnt++)
{
values[cnt] = FromByteArray(new byte[] { bytes[counter++], bytes[counter++] });
values[cnt] = FromByteArray([bytes[counter++], bytes[counter++]]);
}

return values;
Expand Down
Loading

0 comments on commit 7f5310c

Please sign in to comment.