Fix V0.1.6 bit write to DB don't work #91

This commit is contained in:
Michele Cattafesta
2017-09-14 18:16:35 +01:00
parent 61ebfca0c2
commit cddb826053
3 changed files with 12 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ namespace S7.Net.UnitTest.Helpers
class S7TestServer
{
static S7Server Server;
static private byte[] DB1 = new byte[512]; // Our DB1
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

View File

@@ -455,6 +455,14 @@ namespace S7.Net.UnitTest
plc.Write("DB1.DBX0.7", 0);
boolVariable = (bool)plc.Read("DB1.DBX0.7");
Assert.IsFalse(boolVariable);
plc.Write("DB1.DBX658.0", 1);
boolVariable = (bool)plc.Read("DB1.DBX658.0");
Assert.IsTrue(boolVariable);
plc.Write("DB2.DBX9658.0", 1);
boolVariable = (bool)plc.Read("DB2.DBX9658.0");
Assert.IsTrue(boolVariable);
}
[TestMethod]
@@ -664,8 +672,8 @@ namespace S7.Net.UnitTest
Assert.AreEqual(expectedReadBytes, actualReadBytes);
}
[TestMethod]
[TestMethod]
public void T22_ReadClassWithArray()
{
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");

View File

@@ -1136,7 +1136,7 @@ namespace S7.Net
package.Add(Types.Word.ToByteArray((ushort)varCount));
package.Add(Types.Word.ToByteArray((ushort)(db)));
package.Add((byte)dataType);
var overflow = (int)(startByteAdr * 8 + bitAdr / 0xffffU); // handles words with address bigger than 8191
var overflow = (int)(startByteAdr * 8 / 0xffffU); // handles words with address bigger than 8191
package.Add((byte)overflow);
package.Add(Types.Word.ToByteArray((ushort)(startByteAdr * 8 + bitAdr)));
package.Add(new byte[] { 0, 0x03 }); //ending 0x03 is used for writing a sinlge bit