Fixes a bug that couldn't write correctly negative values when writing short or int.

Signed-off-by: Michele Cattafesta <michele.cattafesta@mesta-automation.com>
This commit is contained in:
Michele Cattafesta
2014-12-22 14:42:29 +01:00
parent 424a01bf07
commit 5c8f6de667

View File

@@ -593,10 +593,24 @@ namespace S7.Net
objValue = Convert.ChangeType(value, typeof(byte));
return Write(DataType.DataBlock, mDB, dbIndex, (byte)objValue);
case "DBW":
objValue = Convert.ChangeType(value, typeof(UInt16));
if (value is short)
{
objValue = ((short)value).ConvertToUshort();
}
else
{
objValue = Convert.ChangeType(value, typeof(UInt16));
}
return Write(DataType.DataBlock, mDB, dbIndex, (UInt16)objValue);
case "DBD":
objValue = Convert.ChangeType(value, typeof(UInt32));
if (value is int)
{
return Write(DataType.DataBlock, mDB, dbIndex, (Int32)value);
}
else
{
objValue = Convert.ChangeType(value, typeof(UInt32));
}
return Write(DataType.DataBlock, mDB, dbIndex, (UInt32)objValue);
case "DBX":
mByte = dbIndex;