mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Merge pull request #169 from mycroes/dataitem-from-string-write-fix
Dataitem from string write fix
This commit is contained in:
@@ -30,13 +30,17 @@ namespace S7.Net.Protocol
|
||||
Serialization.SetWordAt(message, paramOffset + Parameter.Offsets.Amount, (ushort) value.Length);
|
||||
Serialization.SetWordAt(message, paramOffset + Parameter.Offsets.DbNumber, (ushort) item.DB);
|
||||
message[paramOffset + Parameter.Offsets.Area] = (byte) item.DataType;
|
||||
Serialization.SetAddressAt(message, paramOffset + Parameter.Offsets.Address, item.StartByteAdr, item.BitAdr);
|
||||
|
||||
paramOffset += Parameter.Template.Length;
|
||||
|
||||
data.Add(0x00);
|
||||
if (item.Value is bool b)
|
||||
{
|
||||
if (item.BitAdr > 7)
|
||||
throw new ArgumentException(
|
||||
$"Cannot read bit with invalid {nameof(item.BitAdr)} '{item.BitAdr}'.", nameof(dataItems));
|
||||
|
||||
Serialization.SetAddressAt(message, paramOffset + Parameter.Offsets.Address, item.StartByteAdr,
|
||||
item.BitAdr);
|
||||
|
||||
data.Add(0x03);
|
||||
data.AddWord(1);
|
||||
|
||||
@@ -45,6 +49,8 @@ namespace S7.Net.Protocol
|
||||
}
|
||||
else
|
||||
{
|
||||
Serialization.SetAddressAt(message, paramOffset + Parameter.Offsets.Address, item.StartByteAdr, 0);
|
||||
|
||||
var len = value.Length;
|
||||
data.Add(0x04);
|
||||
data.AddWord((ushort) (len << 3));
|
||||
@@ -55,8 +61,9 @@ namespace S7.Net.Protocol
|
||||
data.Add(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
paramOffset += Parameter.Template.Length;
|
||||
}
|
||||
|
||||
message.Add(data.Array);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace S7.Net.Types
|
||||
DB = dbNumber,
|
||||
VarType = varType,
|
||||
StartByteAdr = startByte,
|
||||
BitAdr = (byte) bitNumber
|
||||
BitAdr = (byte) (bitNumber == -1 ? 0 : bitNumber)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user