diff --git a/SCADA/Program/DataService/ExtensionMethods.cs b/SCADA/Program/DataService/ExtensionMethods.cs index f27440d..d92cb40 100644 --- a/SCADA/Program/DataService/ExtensionMethods.cs +++ b/SCADA/Program/DataService/ExtensionMethods.cs @@ -1,9 +1,7 @@ using System; -using System.Text; -using System.Net; using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Data.SqlClient; +using System.Net; +using System.Text; namespace DataService { @@ -771,10 +769,12 @@ namespace DataService public static unsafe short NetToInt16(byte[] value, int startIndex) { - if (value == null || startIndex > value.Length - 2) + if (value == null || startIndex > value.Length) { throw new NotImplementedException(); } + if (startIndex > value.Length - 2) + return value[value.Length - startIndex]; fixed (byte* numRef = &(value[startIndex])) { return (short)((numRef[0] << 8) | numRef[1]); @@ -783,10 +783,12 @@ namespace DataService public static unsafe int NetToInt32(byte[] value, int startIndex) { - if (value == null || startIndex > value.Length - 4) + if (value == null || startIndex > value.Length) { throw new NotImplementedException(); } + if (startIndex > value.Length - 4) + return value[value.Length - startIndex]; fixed (byte* numRef = &(value[startIndex])) { return (int)((numRef[0] << 24) | (numRef[1] << 16) | (numRef[2] << 8) | numRef[3]); diff --git a/SCADA/Program/DataService/PLCGroup.cs b/SCADA/Program/DataService/PLCGroup.cs index cea6922..c9b4e79 100644 --- a/SCADA/Program/DataService/PLCGroup.cs +++ b/SCADA/Program/DataService/PLCGroup.cs @@ -363,7 +363,7 @@ namespace DataService ushort size = addr.DataSize; for (int i = 0; i < size; i++) { - if (rcvBytes[iByte1 + i] != cache[iByte + i]) + if (iByte1 + i < rcvBytes.Length && rcvBytes[iByte1 + i] != cache[iByte + i]) { _changedList.Add(index); break; diff --git a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs b/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs index 36e2509..482b59f 100644 --- a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs +++ b/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs @@ -784,7 +784,7 @@ namespace SiemensPLCDriver ushort size = addr.DataSize; for (int i = 0; i < size; i++) { - if (rcvBytes[iByte1 + i] != cache[iByte + i]) + if (iByte1 + i < rcvBytes.Length && rcvBytes[iByte1 + i] != cache[iByte + i]) { _changedList.Add(index); break; diff --git a/SCADA/dll/SiemensPLCDriver.dll b/SCADA/dll/SiemensPLCDriver.dll index 709ceca..6ff1259 100644 Binary files a/SCADA/dll/SiemensPLCDriver.dll and b/SCADA/dll/SiemensPLCDriver.dll differ