Skip to content

Commit

Permalink
Release S7NetPlus 0.4.0
Browse files Browse the repository at this point in the history
Release highlights:
- Adress checks for bit writes
- Support for reading/writing complex objects
- Better exceptions on Open(Async)
- Revert negotiated max PDU size to 960
- Add Logo0BA8 support
- Read/Write-Timeout support on TCP connection
- Fix for 0-padding of last dataItem in WriteMultiple
- Allow override of default port
- Improve exception message when parsing string
- Add DateTime type for reading/writing
- Verify items fit in a PDU on Read/Write-Multiple
- Fix size calculation for bit arrays
  • Loading branch information
mycroes committed Jul 17, 2019
2 parents fd17bfa + 2fbf659 commit 798913c
Show file tree
Hide file tree
Showing 24 changed files with 797 additions and 100 deletions.
12 changes: 8 additions & 4 deletions GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ branches:
master:
tag: rc
increment: Minor
features?[/-]:
feature:
regex: features?[/-]
tag: rc-{BranchName}
increment: Minor
(pull|pull\-requests|pr)[/-]:
pull-request:
regex: (pull|pull\-requests|pr)[/-]
tag: rc-pr-{BranchName}
increment: Minor
hotfix(es)?[/-]:
hotfix:
regex: hotfix(es)?[/-]
tag: rc
increment: Patch
dev(elop)?(ment)?$:
develop:
regex: dev(elop)?(ment)?$
tag: b
2 changes: 1 addition & 1 deletion S7.Net.UnitTest/ConnectionRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static byte[] MakeConnectionRequest(byte sourceTsap1, byte sourceTsap2,
destTsap1, destTsap2, //Destination TASP
192, //Parameter Code (tpdu-size)
1, //Parameter Length
11 //TPDU Size (2^11 = 2048)
10 //TPDU Size (2^11 = 2048)
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion S7.Net.UnitTest/Helpers/S7TestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class S7TestServer
static private byte[] DB1 = new byte[1024]; // Our DB1
static private byte[] DB2 = new byte[64000]; // Our DB2
static private byte[] DB3 = new byte[1024]; // Our DB3
static private byte[] DB4 = new byte[6] { 3, 128, 1, 0, 197, 104 }; // Our DB4

private static S7Server.TSrvCallback TheEventCallBack; // <== Static var containig the callback
private static S7Server.TSrvCallback TheReadCallBack; // <== Static var containig the callback
Expand Down Expand Up @@ -36,9 +37,10 @@ public static void Start()
1, // Its number is 1 (DB1)
DB1, // Our buffer for DB1
DB1.Length); // Its size
// Do the same for DB2 and DB3
// Do the same for DB2, DB3, and DB4
Server.RegisterArea(S7Server.srvAreaDB, 2, DB2, DB2.Length);
Server.RegisterArea(S7Server.srvAreaDB, 3, DB3, DB3.Length);
Server.RegisterArea(S7Server.srvAreaDB, 4, DB4, DB4.Length);

// Exclude read event to avoid the double report
// Set the callbacks (using the static var to avoid the garbage collect)
Expand Down
51 changes: 51 additions & 0 deletions S7.Net.UnitTest/Helpers/TestClassWithNestedClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace S7.Net.UnitTest.Helpers
{
class TestClassInnerWithBool
{
public bool BitVariable00 { get; set; }
}

class TestClassInnerWithByte
{
public byte ByteVariable00 { get; set; }
}

class TestClassInnerWithShort
{
public short ShortVarialbe00 { get; set; }
}

class TestClassWithNestedClass
{
/// <summary>
/// DB1.DBX0.0
/// </summary>
public bool BitVariable00 { get; set; }

/// <summary>
/// DB1.DBX0.1
/// </summary>
public TestClassInnerWithBool BitVariable01 { get; set; } = new TestClassInnerWithBool();

/// <summary>
/// DB1.DBB1.0
/// </summary>
public TestClassInnerWithByte ByteVariable02 { get; set; } = new TestClassInnerWithByte();

/// <summary>
/// DB1.DBX2.0
/// </summary>
public bool BitVariable03 { get; set; }

/// <summary>
/// DB1.DBW4
/// </summary>
public TestClassInnerWithShort ShortVariable04 { get; set; } = new TestClassInnerWithShort();
}
}
2 changes: 2 additions & 0 deletions S7.Net.UnitTest/S7.Net.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="ConnectionRequestTest.cs" />
<Compile Include="ConvertersUnitTest.cs" />
<Compile Include="Helpers\TestClassWithNestedClass.cs" />
<Compile Include="ProtocolTests.cs" />
<Compile Include="Helpers\ConsoleManager.cs" />
<Compile Include="Helpers\NativeMethods.cs" />
Expand All @@ -78,6 +79,7 @@
<Compile Include="S7NetTestsSync.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\TestLongStruct.cs" />
<Compile Include="TypeTests\DateTimeTests.cs" />
<Compile Include="TypeTests\StringExTests.cs" />
<Compile Include="TypeTests\StringTests.cs" />
</ItemGroup>
Expand Down
49 changes: 48 additions & 1 deletion S7.Net.UnitTest/S7NetTestsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,31 @@ public async Task Test_Async_ReadAndWriteClass()
Assert.AreEqual(tc.DWordVariable, tc2.DWordVariable);
}

[TestMethod]
public async Task Test_Async_ReadAndWriteNestedClass()
{
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");

TestClassWithNestedClass tc = new TestClassWithNestedClass
{
BitVariable00 = true,
BitVariable01 = new TestClassInnerWithBool { BitVariable00 = true },
ByteVariable02 = new TestClassInnerWithByte { ByteVariable00 = 128 },
BitVariable03 = true,
ShortVariable04 = new TestClassInnerWithShort { ShortVarialbe00 = -15000 }
};

await plc.WriteClassAsync(tc, DB4);
TestClassWithNestedClass tc2 = new TestClassWithNestedClass();
// Values that are read from a class are stored inside the class itself, that is passed by reference
await plc.ReadClassAsync(tc2, DB4);
Assert.AreEqual(tc.BitVariable00, tc2.BitVariable00);
Assert.AreEqual(tc.BitVariable01.BitVariable00, tc2.BitVariable01.BitVariable00);
Assert.AreEqual(tc.ByteVariable02.ByteVariable00, tc2.ByteVariable02.ByteVariable00);
Assert.AreEqual(tc.BitVariable03, tc2.BitVariable03);
Assert.AreEqual(tc.ShortVariable04.ShortVarialbe00, tc2.ShortVariable04.ShortVarialbe00);
}

/// <summary>
/// Read/Write a struct that has the same properties of a DB with the same field in the same order
/// </summary>
Expand Down Expand Up @@ -663,6 +688,28 @@ public async Task Test_Async_ReadClassWithGenericAndClassFactoryThrowsExceptionP
}
}

[TestMethod]
public async Task Test_Async_ReadClassWithNestedClassAfterBit()
{
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");

Assert.AreEqual(6, Types.Class.GetClassSize(new TestClassWithNestedClass()));

TestClassWithNestedClass tc = new TestClassWithNestedClass();
tc.BitVariable00 = true;
tc.BitVariable01.BitVariable00 = true;
tc.ByteVariable02.ByteVariable00 = 128;
tc.BitVariable03 = true;
tc.ShortVariable04.ShortVarialbe00 = -15000;

TestClassWithNestedClass tc2 = await plc.ReadClassAsync<TestClassWithNestedClass>(DB4);
Assert.AreEqual(tc.BitVariable00, tc2.BitVariable00);
Assert.AreEqual(tc.BitVariable01.BitVariable00, tc2.BitVariable01.BitVariable00);
Assert.AreEqual(tc.ByteVariable02.ByteVariable00, tc2.ByteVariable02.ByteVariable00);
Assert.AreEqual(tc.BitVariable03, tc2.BitVariable03);
Assert.AreEqual(tc.ShortVariable04.ShortVarialbe00, tc2.ShortVariable04.ShortVarialbe00);
}

[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public async Task Test_Async_ReadStructThrowsExceptionPlcIsNotConnected()
Expand Down Expand Up @@ -737,7 +784,7 @@ public async Task Test_Async_ReadClassReturnsNumberOfReadBytesFromThePlc()
};
plc.WriteClass(tc, DB2);

int expectedReadBytes = Types.Class.GetClassSize(tc);
int expectedReadBytes = (int)Types.Class.GetClassSize(tc);

TestClass tc2 = new TestClass();
// Values that are read from a class are stored inside the class itself, that is passed by reference
Expand Down
51 changes: 50 additions & 1 deletion S7.Net.UnitTest/S7NetTestsSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public partial class S7NetTests : IDisposable
{
#region Constants
const int DB2 = 2;
const int DB4 = 4;
#endregion

#region Private fields
Expand Down Expand Up @@ -694,6 +695,54 @@ public void T17_ReadClassWithGenericAndClassFactoryThrowsIfPlcIsNotConnected()
}
}

[TestMethod]
public void T31_ReadClassWithNestedClassAfterBit()
{
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");

Assert.AreEqual(6, Types.Class.GetClassSize(new TestClassWithNestedClass()));

TestClassWithNestedClass tc = new TestClassWithNestedClass();
tc.BitVariable00 = true;
tc.BitVariable01.BitVariable00 = true;
tc.ByteVariable02.ByteVariable00 = 128;
tc.BitVariable03 = true;
tc.ShortVariable04.ShortVarialbe00 = -15000;

TestClassWithNestedClass tc2 = new TestClassWithNestedClass();
plc.ReadClass(tc2, DB4);
Assert.AreEqual(tc.BitVariable00, tc2.BitVariable00);
Assert.AreEqual(tc.BitVariable01.BitVariable00, tc2.BitVariable01.BitVariable00);
Assert.AreEqual(tc.ByteVariable02.ByteVariable00, tc2.ByteVariable02.ByteVariable00);
Assert.AreEqual(tc.BitVariable03, tc2.BitVariable03);
Assert.AreEqual(tc.ShortVariable04.ShortVarialbe00, tc2.ShortVariable04.ShortVarialbe00);
}

[TestMethod]
public void T32_ReadAndWriteNestedClass()
{
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");

TestClassWithNestedClass tc = new TestClassWithNestedClass
{
BitVariable00 = true,
BitVariable01 = new TestClassInnerWithBool { BitVariable00 = true },
ByteVariable02 = new TestClassInnerWithByte { ByteVariable00 = 128 },
BitVariable03 = true,
ShortVariable04 = new TestClassInnerWithShort { ShortVarialbe00 = -15000 }
};

plc.WriteClass(tc, DB4);
TestClassWithNestedClass tc2 = new TestClassWithNestedClass();
// Values that are read from a class are stored inside the class itself, that is passed by reference
plc.ReadClass(tc2, DB4);
Assert.AreEqual(tc.BitVariable00, tc2.BitVariable00);
Assert.AreEqual(tc.BitVariable01.BitVariable00, tc2.BitVariable01.BitVariable00);
Assert.AreEqual(tc.ByteVariable02.ByteVariable00, tc2.ByteVariable02.ByteVariable00);
Assert.AreEqual(tc.BitVariable03, tc2.BitVariable03);
Assert.AreEqual(tc.ShortVariable04.ShortVarialbe00, tc2.ShortVariable04.ShortVarialbe00);
}

[TestMethod, ExpectedException(typeof(PlcException))]
public void T18_ReadStructThrowsIfPlcIsNotConnected()
{
Expand Down Expand Up @@ -767,7 +816,7 @@ public void T21_ReadClassReturnsNumberOfReadBytesFromThePlc()
tc.DWordVariable = 850;
plc.WriteClass(tc, DB2);

int expectedReadBytes = Types.Class.GetClassSize(tc);
int expectedReadBytes = (int)Types.Class.GetClassSize(tc);

TestClass tc2 = new TestClass();
// Values that are read from a class are stored inside the class itself, that is passed by reference
Expand Down
Loading

0 comments on commit 798913c

Please sign in to comment.