mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Fix reading nested classes
This commit is contained in:
@@ -663,6 +663,28 @@ namespace S7.Net.UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
[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()
|
||||
@@ -737,7 +759,7 @@ namespace S7.Net.UnitTest
|
||||
};
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user