mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
@@ -359,20 +359,51 @@ namespace S7.Net.UnitTest
|
||||
public async Task Test_Async_ReadMultipleBytes()
|
||||
{
|
||||
Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor.");
|
||||
bool val = true;
|
||||
await plc.WriteAsync("DB2.DBX0.5", val);
|
||||
bool result = (bool)await plc.ReadAsync("DB2.DBX0.5");
|
||||
Assert.AreEqual(val, result);
|
||||
|
||||
ushort val = 16384;
|
||||
await plc.WriteAsync("DB2.DBW16384", val);
|
||||
ushort result = (ushort)await plc.ReadAsync("DB2.DBW16384");
|
||||
Assert.AreEqual(val, result, "A ushort goes from 0 to 64512");
|
||||
ushort val1 = 16384;
|
||||
await plc.WriteAsync("DB2.DBW16384", val1);
|
||||
ushort result1 = (ushort)await plc.ReadAsync("DB2.DBW16384");
|
||||
Assert.AreEqual(val1, result1, "A ushort goes from 0 to 64512");
|
||||
|
||||
ushort val2 = 129;
|
||||
await plc.WriteAsync("DB2.DBW16", val2);
|
||||
ushort result2 = (ushort)await plc.ReadAsync("DB2.DBW16");
|
||||
Assert.AreEqual(val2, result2, "A ushort goes from 0 to 64512");
|
||||
bool val2 = true;
|
||||
await plc.WriteAsync("DB2.DBX8192.7", val2);
|
||||
bool result2 = (bool)await plc.ReadAsync("DB2.DBX8192.7");
|
||||
Assert.AreEqual(val2, result2);
|
||||
|
||||
ushort val3 = 129;
|
||||
await plc.WriteAsync("DB2.DBW16", val3);
|
||||
ushort result3 = (ushort)await plc.ReadAsync("DB2.DBW16");
|
||||
Assert.AreEqual(val3, result3, "A ushort goes from 0 to 64512");
|
||||
|
||||
byte[] val4 = new byte[] { 0x12, 0x34 };
|
||||
await plc.WriteAsync("DB2.DBB2048", val4[0]);
|
||||
await plc.WriteAsync("DB2.DBB2049", val4[1]);
|
||||
byte result4b0 = (byte)await plc.ReadAsync("DB2.DBB2048");
|
||||
byte result4b1 = (byte)await plc.ReadAsync("DB2.DBB2049");
|
||||
Assert.AreEqual(val4[0], result4b0);
|
||||
Assert.AreEqual(val4[1], result4b1);
|
||||
|
||||
bool val6 = true;
|
||||
await plc.WriteAsync("DB2.DBX16384.6", val6);
|
||||
bool result6 = (bool)await plc.ReadAsync("DB2.DBX16384.6");
|
||||
Assert.AreEqual(val6, result6);
|
||||
|
||||
var dataItems = new List<DataItem>()
|
||||
{
|
||||
new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 0,
|
||||
BitAdr = 5,
|
||||
VarType = VarType.Bit
|
||||
}
|
||||
,new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
@@ -381,19 +412,61 @@ namespace S7.Net.UnitTest
|
||||
VarType = VarType.Word
|
||||
},
|
||||
new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 8192,
|
||||
BitAdr = 7,
|
||||
VarType = VarType.Bit
|
||||
},
|
||||
new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 16,
|
||||
VarType = VarType.Word
|
||||
}
|
||||
},
|
||||
// single byte
|
||||
new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 2048,
|
||||
VarType = VarType.Byte
|
||||
},
|
||||
// multiple bytes
|
||||
new DataItem
|
||||
{
|
||||
Count = 2,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 2048,
|
||||
VarType = VarType.Byte
|
||||
},
|
||||
new DataItem
|
||||
{
|
||||
Count = 1,
|
||||
DataType = DataType.DataBlock,
|
||||
DB = 2,
|
||||
StartByteAdr = 16384,
|
||||
BitAdr = 6,
|
||||
VarType = VarType.Bit
|
||||
},
|
||||
};
|
||||
|
||||
dataItems = await plc.ReadMultipleVarsAsync(dataItems);
|
||||
var dataItemsRes = await plc.ReadMultipleVarsAsync(dataItems);
|
||||
|
||||
Assert.AreEqual(dataItems[0].Value, val);
|
||||
Assert.AreEqual(dataItems[1].Value, val2);
|
||||
Assert.AreEqual(val, dataItemsRes[0].Value);
|
||||
Assert.AreEqual(val1, dataItemsRes[1].Value);
|
||||
Assert.AreEqual(val2, dataItemsRes[2].Value);
|
||||
Assert.AreEqual(val3, dataItemsRes[3].Value);
|
||||
Assert.AreEqual(val4[0], dataItemsRes[4].Value);
|
||||
Assert.AreEqual(val4[0], ((byte[])dataItemsRes[5].Value)[0]); //dataItem[5].Value should be byte[2]
|
||||
Assert.AreEqual(val4[1], ((byte[])dataItemsRes[5].Value)[1]);
|
||||
Assert.AreEqual(val6, dataItemsRes[6].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user