Skip to content

Commit

Permalink
Release S7NetPlus 0.16.0
Browse files Browse the repository at this point in the history
Release highlights:
- Fix UInt32 reads in classes
- Add string support for classes
  • Loading branch information
mycroes committed Dec 10, 2022
2 parents d99d0d0 + 6aa0133 commit 43b2982
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
DOTNET_NOLOGO : 1
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
os: [windows-latest, ubuntu-20.04, macos-latest]
test-framework: [netcoreapp3.1, net5.0]
include:
- os: ubuntu-latest
- os: ubuntu-20.04
test-framework: netcoreapp3.1
installSnap7: true
dotnet-sdk: '3.1.x'
- os: ubuntu-latest
- os: ubuntu-20.04
test-framework: net5.0
installSnap7: true
dotnet-sdk: '5.0.x'
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Snap7 Linux
if: ${{ matrix.installSnap7 && matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.installSnap7 && matrix.os == 'ubuntu-20.04' }}
run: |
sudo add-apt-repository ppa:gijzelaar/snap7
sudo apt-get update
Expand Down
13 changes: 13 additions & 0 deletions S7.Net.UnitTest/Helpers/TestClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

using S7.Net.Types;

namespace S7.Net.UnitTest.Helpers
{
class TestClass
Expand Down Expand Up @@ -51,5 +53,16 @@ class TestClass
/// DB1.DBD16
/// </summary>
public ushort DWordVariable { get; set; }

/// <summary>
/// DB1.DBX20.0
/// </summary>
[S7String(S7StringType.S7WString, 10)]
public string WStringVariable { get; set; }
/// <summary>
/// DB1.DBX44.0
/// </summary>
[S7String(S7StringType.S7String, 10)]
public string StringVariable { get; set; }
}
}
29 changes: 24 additions & 5 deletions S7.Net.UnitTest/S7NetTestsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using S7.UnitTest.Helpers;
using System.Threading.Tasks;
using System.Threading;
using System.Security.Cryptography;

#endregion

Expand Down Expand Up @@ -154,7 +155,9 @@ public async Task Test_Async_ReadAndWriteClass()
IntVariable = -15000,
LRealVariable = -154.789,
RealVariable = -154.789f,
DWordVariable = 850
DWordVariable = 850,
WStringVariable = "ÄÜÉÊéà",
StringVariable = "Hallo"
};

await plc.WriteClassAsync(tc, DB2);
Expand All @@ -168,6 +171,8 @@ public async Task Test_Async_ReadAndWriteClass()
Assert.AreEqual(tc.LRealVariable, tc2.LRealVariable);
Assert.AreEqual(tc.RealVariable, tc2.RealVariable);
Assert.AreEqual(tc.DWordVariable, tc2.DWordVariable);
Assert.AreEqual(tc.WStringVariable, tc2.WStringVariable);
Assert.AreEqual(tc.StringVariable, tc2.StringVariable);
}

[TestMethod]
Expand Down Expand Up @@ -580,7 +585,9 @@ public async Task Test_Async_ReadClassIgnoresNonPublicSetters()
IntVariable = -15000,
LRealVariable = -154.789,
RealVariable = -154.789f,
DWordVariable = 850
DWordVariable = 850,
WStringVariable = "ÄÜÉÊéà",
StringVariable = "Hallo"
};

await plc.WriteClassAsync(tc, DB2);
Expand Down Expand Up @@ -628,7 +635,10 @@ public async Task Test_Async_ReadClassWithGenericReturnsSameResultAsReadClassWit
IntVariable = -15000,
LRealVariable = -154.789,
RealVariable = -154.789f,
DWordVariable = 850
DWordVariable = 850,
WStringVariable = "ÄÜÉÊéà",
StringVariable = "Hallo"

};

await plc.WriteClassAsync(tc, DB2);
Expand All @@ -646,6 +656,9 @@ public async Task Test_Async_ReadClassWithGenericReturnsSameResultAsReadClassWit
Assert.AreEqual(Math.Round(tc2.LRealVariable, 3), Math.Round(tc2Generic.LRealVariable, 3));
Assert.AreEqual(tc2.RealVariable, tc2Generic.RealVariable);
Assert.AreEqual(tc2.DWordVariable, tc2Generic.DWordVariable);
Assert.AreEqual(tc2.WStringVariable, tc2Generic.WStringVariable);
Assert.AreEqual(tc2.StringVariable, tc2Generic.StringVariable);

}

[TestMethod]
Expand All @@ -671,7 +684,9 @@ public async Task Test_Async_ReadClassWithGenericAndClassFactoryReturnsSameResul
IntVariable = -15000,
LRealVariable = -154.789,
RealVariable = -154.789f,
DWordVariable = 850
DWordVariable = 850,
WStringVariable = "ÄÜÉÊéà",
StringVariable = "Hallo"
};

await plc.WriteClassAsync(tc, DB2);
Expand All @@ -686,6 +701,8 @@ public async Task Test_Async_ReadClassWithGenericAndClassFactoryReturnsSameResul
Assert.AreEqual(Math.Round(tc2Generic.LRealVariable, 3), Math.Round(tc2GenericWithClassFactory.LRealVariable, 3));
Assert.AreEqual(tc2Generic.RealVariable, tc2GenericWithClassFactory.RealVariable);
Assert.AreEqual(tc2Generic.DWordVariable, tc2GenericWithClassFactory.DWordVariable);
Assert.AreEqual(tc2Generic.WStringVariable, tc2GenericWithClassFactory.WStringVariable);
Assert.AreEqual(tc2Generic.StringVariable, tc2GenericWithClassFactory.StringVariable);
}

[TestMethod]
Expand Down Expand Up @@ -792,7 +809,9 @@ public async Task Test_Async_ReadClassReturnsNumberOfReadBytesFromThePlc()
IntVariable = -15000,
LRealVariable = -154.789,
RealVariable = -154.789f,
DWordVariable = 850
DWordVariable = 850,
WStringVariable = "ÄÜÉÊéà",
StringVariable = "Hallo"
};
plc.WriteClass(tc, DB2);

Expand Down
19 changes: 19 additions & 0 deletions S7.Net.UnitTest/S7NetTestsSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using S7.Net.UnitTest.Helpers;
using S7.Net.Types;
using S7.UnitTest.Helpers;
using System.Security.Cryptography;

#endregion

Expand Down Expand Up @@ -183,6 +184,9 @@ public void T04_ReadAndWriteClass()
tc.LRealVariable = -154.789;
tc.RealVariable = -154.789f;
tc.DWordVariable = 850;
tc.WStringVariable = "ÄÜÉÊéà";
tc.StringVariable = "Hallo";

plc.WriteClass(tc, DB2);
TestClass tc2 = new TestClass();
// Values that are read from a class are stored inside the class itself, that is passed by reference
Expand All @@ -194,6 +198,8 @@ public void T04_ReadAndWriteClass()
Assert.AreEqual(tc.LRealVariable, tc2.LRealVariable);
Assert.AreEqual(tc.RealVariable, tc2.RealVariable);
Assert.AreEqual(tc.DWordVariable, tc2.DWordVariable);
Assert.AreEqual(tc.WStringVariable, tc2.WStringVariable);
Assert.AreEqual(tc.StringVariable, tc2.StringVariable);
}

/// <summary>
Expand Down Expand Up @@ -577,6 +583,8 @@ public void T12_ReadClassIgnoresNonPublicSetters()
tc.LRealVariable = -154.789;
tc.RealVariable = -154.789f;
tc.DWordVariable = 850;
tc.WStringVariable = "ÄÜÉÊéà";
tc.StringVariable = "Hallo";

plc.WriteClass(tc, DB2);

Expand Down Expand Up @@ -622,6 +630,8 @@ public void T14_ReadClassWithGenericReturnsSameResultAsReadClassWithoutGeneric()
tc.LRealVariable = -154.789;
tc.RealVariable = -154.789f;
tc.DWordVariable = 850;
tc.WStringVariable = "ÄÜÉÊéà";
tc.StringVariable = "Hallo";

plc.WriteClass(tc, DB2);

Expand All @@ -637,6 +647,8 @@ public void T14_ReadClassWithGenericReturnsSameResultAsReadClassWithoutGeneric()
Assert.AreEqual(Math.Round(tc2.LRealVariable, 3), Math.Round(tc2Generic.LRealVariable, 3));
Assert.AreEqual(tc2.RealVariable, tc2Generic.RealVariable);
Assert.AreEqual(tc2.DWordVariable, tc2Generic.DWordVariable);
Assert.AreEqual(tc2.WStringVariable, tc2Generic.WStringVariable);
Assert.AreEqual(tc2.StringVariable, tc2Generic.StringVariable);
}

[TestMethod, ExpectedException(typeof(PlcException))]
Expand Down Expand Up @@ -665,6 +677,8 @@ public void T16_ReadClassWithGenericAndClassFactoryReturnsSameResultAsReadClassW
tc.LRealVariable = -154.789;
tc.RealVariable = -154.789f;
tc.DWordVariable = 850;
tc.WStringVariable = "ÄÜÉÊéà";
tc.StringVariable = "Hallo";

plc.WriteClass(tc, DB2);

Expand All @@ -679,6 +693,8 @@ public void T16_ReadClassWithGenericAndClassFactoryReturnsSameResultAsReadClassW
Assert.AreEqual(Math.Round(tc2Generic.LRealVariable, 3), Math.Round(tc2GenericWithClassFactory.LRealVariable, 3));
Assert.AreEqual(tc2Generic.RealVariable, tc2GenericWithClassFactory.RealVariable);
Assert.AreEqual(tc2Generic.DWordVariable, tc2GenericWithClassFactory.DWordVariable);
Assert.AreEqual(tc2Generic.WStringVariable, tc2GenericWithClassFactory.WStringVariable);
Assert.AreEqual(tc2Generic.StringVariable, tc2GenericWithClassFactory.StringVariable);
}

[TestMethod, ExpectedException(typeof(PlcException))]
Expand Down Expand Up @@ -837,6 +853,9 @@ public void T21_ReadClassReturnsNumberOfReadBytesFromThePlc()
tc.LRealVariable = -154.789;
tc.RealVariable = -154.789f;
tc.DWordVariable = 850;
tc.WStringVariable = "ÄÜÉÊéà";
tc.StringVariable = "Hallo";

plc.WriteClass(tc, DB2);

int expectedReadBytes = (int)Types.Class.GetClassSize(tc);
Expand Down
18 changes: 18 additions & 0 deletions S7.Net.UnitTest/TypeTests/ClassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ public void GetClassSizeTest()
Assert.AreEqual(Class.GetClassSize(new TestClassUnevenSize(3, 17)), 10);
}

/// <summary>
/// Ensure Uint32 is correctly parsed through ReadClass functions. Adresses issue https://github.com/S7NetPlus/s7netplus/issues/414
/// </summary>
[TestMethod]
public void TestUint32Read()
{
var result = new TestUint32();
var data = new byte[4] { 0, 0, 0, 5 };
var bytesRead = Class.FromBytes(result, data);
Assert.AreEqual(bytesRead, data.Length);
Assert.AreEqual(5u, result.Value1);
}

private class TestClassUnevenSize
{
public bool Bool { get; set; }
Expand All @@ -29,5 +42,10 @@ public TestClassUnevenSize(int byteCount, int bitCount)
Bools = new bool[bitCount];
}
}

private class TestUint32
{
public uint Value1 { get; set; }
}
}
}
Loading

0 comments on commit 43b2982

Please sign in to comment.