Browse Source

fix some bugs

pull/17/head
Gavin 9 years ago
parent
commit
08fead719b
  1. 14
      SCADA/Program/DataService/ExtensionMethods.cs
  2. 2
      SCADA/Program/DataService/PLCGroup.cs
  3. 2
      SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs
  4. BIN
      SCADA/dll/SiemensPLCDriver.dll

14
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]);

2
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;

2
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;

BIN
SCADA/dll/SiemensPLCDriver.dll

Binary file not shown.
Loading…
Cancel
Save