Browse Source

add word,dword datatype

pull/15/head
Gavin 9 years ago
parent
commit
d026111f85
  1. BIN
      SCADA/Example/BatchCoreTest.exe
  2. BIN
      SCADA/Example/ClientDriver.dll
  3. BIN
      SCADA/Example/CoreTest.exe
  4. BIN
      SCADA/Example/DataHelper.dll
  5. BIN
      SCADA/Example/DataService.dll
  6. BIN
      SCADA/Example/HMIControl.dll
  7. BIN
      SCADA/Example/TagConfig.exe
  8. 30
      SCADA/Program/BatchCoreService/DAService.cs
  9. 3
      SCADA/Program/BatchCoreService/SqlMapping.cs
  10. 137
      SCADA/Program/ClientDriver/ClientDriver.cs
  11. 2
      SCADA/Program/CoreTest/ClientService.cs
  12. 12
      SCADA/Program/CoreTest/WindowHelper.cs
  13. 29
      SCADA/Program/DataHelper/HDAIOHelper.cs
  14. 185
      SCADA/Program/DataService/CacheReader.cs
  15. 30
      SCADA/Program/DataService/Enums.cs
  16. 14
      SCADA/Program/DataService/Eval.cs
  17. 49
      SCADA/Program/DataService/ExtensionMethods.cs
  18. 7
      SCADA/Program/DataService/IGroup.cs
  19. 4
      SCADA/Program/DataService/IReader.cs
  20. 137
      SCADA/Program/DataService/ITag.cs
  21. 52
      SCADA/Program/DataService/PLCGroup.cs
  22. 57
      SCADA/Program/DataService/Storage.cs
  23. 38
      SCADA/Program/FileDriver/DatabaseDriver.cs
  24. 69
      SCADA/Program/FileDriver/FileDeviceGroup.cs
  25. 44
      SCADA/Program/FileDriver/MemoryDriver.cs
  26. 22
      SCADA/Program/FileDriver/TagDriver.cs
  27. 33
      SCADA/Program/ModbusDriver/ModbusRTUDriver.cs
  28. 30
      SCADA/Program/ModbusDriver/ModbusTCPDriver.cs
  29. 49
      SCADA/Program/OPCDriver/OPCDriver.cs
  30. 1
      SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj
  31. 30
      SCADA/Program/OmronPlcDriver/OmronUdpReader.cs
  32. 18
      SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs
  33. 68
      SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs
  34. 0
      SCADA/Program/TagConfig/TagConfig/DataConvert.cs
  35. 20
      SCADA/Program/TagConfig/TagConfig/Form1.cs
  36. 2
      SCADA/Program/TagConfig/TagConfig/TagConfig.csproj
  37. BIN
      SCADA/dll/ClientDriver.dll
  38. BIN
      SCADA/dll/DataHelper.dll
  39. BIN
      SCADA/dll/DataService.dll
  40. BIN
      SCADA/dll/FileDriver.dll
  41. BIN
      SCADA/dll/ModbusDriver.dll
  42. BIN
      SCADA/dll/OPCDriver.dll
  43. BIN
      SCADA/dll/OmronPlcDriver.dll
  44. BIN
      SCADA/dll/PanasonicDriver.dll
  45. BIN
      SCADA/dll/SiemensPLCDriver.dll

BIN
SCADA/Example/BatchCoreTest.exe

Binary file not shown.

BIN
SCADA/Example/ClientDriver.dll

Binary file not shown.

BIN
SCADA/Example/CoreTest.exe

Binary file not shown.

BIN
SCADA/Example/DataHelper.dll

Binary file not shown.

BIN
SCADA/Example/DataService.dll

Binary file not shown.

BIN
SCADA/Example/HMIControl.dll

Binary file not shown.

BIN
SCADA/Example/TagConfig.exe

Binary file not shown.

30
SCADA/Program/BatchCoreService/DAService.cs

@ -817,10 +817,14 @@ namespace BatchCoreService
value.Byte = buffer[6];
break;
case DataType.WORD:
value.Word = BitConverter.ToUInt16(buffer, 6);
break;
case DataType.SHORT:
value.Int16 = BitConverter.ToInt16(buffer, 6);
break;
case DataType.TIME:
case DataType.DWORD:
value.DWord = BitConverter.ToUInt32(buffer, 6);
break;
case DataType.INT:
value.Int32 = BitConverter.ToInt32(buffer, 6);
break;
@ -871,10 +875,14 @@ namespace BatchCoreService
values.Add(tag, buffer[j]);
break;
case DataType.WORD:
values.Add(tag, BitConverter.ToUInt16(buffer, j));
break;
case DataType.SHORT:
values.Add(tag, BitConverter.ToInt16(buffer, j));
break;
case DataType.TIME:
case DataType.DWORD:
values.Add(tag, BitConverter.ToUInt32(buffer, j));
break;
case DataType.INT:
values.Add(tag, BitConverter.ToInt32(buffer, j));
break;
@ -1392,6 +1400,13 @@ namespace BatchCoreService
sendBuffer[j++] = data[i].Value.Byte;
break;
case DataType.WORD:
{
sendBuffer[j++] = 2;
byte[] bt = BitConverter.GetBytes(data[i].Value.Word);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
}
break;
case DataType.SHORT:
{
sendBuffer[j++] = 2;
@ -1400,7 +1415,16 @@ namespace BatchCoreService
sendBuffer[j++] = bt[1];
}
break;
case DataType.TIME:
case DataType.DWORD:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.DWord);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.INT:
{
sendBuffer[j++] = 4;

3
SCADA/Program/BatchCoreService/SqlMapping.cs

@ -510,9 +510,12 @@ namespace BatchCoreService
return ff > -2E-38 && ff < 2E-38 ? 0f : ff;
case DataType.BOOL:
return _enumer.Current.Value.Boolean ? 1f : 0f;
case DataType.DWORD:
return _enumer.Current.Value.DWord;
case DataType.INT:
return _enumer.Current.Value.Int32;
case DataType.WORD:
return _enumer.Current.Value.Word;
case DataType.SHORT:
return _enumer.Current.Value.Int16;
case DataType.BYTE:

137
SCADA/Program/ClientDriver/ClientDriver.cs

@ -414,9 +414,14 @@ namespace ClientDriver
value.Byte = temp[j];
break;
case DataType.WORD:
value.Word = BitConverter.ToUInt16(temp, j);//需测试
break;
case DataType.SHORT:
value.Int16 = BitConverter.ToInt16(temp, j);//需测试
break;
case DataType.DWORD:
value.DWord = BitConverter.ToUInt32(temp, j);//需测试
break;
case DataType.INT:
value.Int32 = BitConverter.ToInt32(temp, j);//需测试
break;
@ -483,9 +488,14 @@ namespace ClientDriver
value.Byte = bytes[j];
break;
case DataType.WORD:
value.Word = BitConverter.ToUInt16(bytes, j);//需测试
break;
case DataType.SHORT:
value.Int16 = BitConverter.ToInt16(bytes, j);//需测试
break;
case DataType.DWORD:
value.DWord = BitConverter.ToUInt32(bytes, j);//需测试
break;
case DataType.INT:
value.Int32 = BitConverter.ToInt32(bytes, j);//需测试
break;
@ -565,13 +575,17 @@ namespace ClientDriver
dataItem = new ByteTag(meta.ID, addr, this);
break;
case DataType.WORD:
dataItem = new UShortTag(meta.ID, addr, this);
break;
case DataType.SHORT:
dataItem = new ShortTag(meta.ID, addr, this);
break;
case DataType.TIME:
case DataType.INT:
dataItem = new IntTag(meta.ID, addr, this);
break;
case DataType.DWORD:
dataItem = new UIntTag(meta.ID, addr, this);
break;
case DataType.FLOAT:
dataItem = new FloatTag(meta.ID, addr, this);
break;
@ -678,9 +692,14 @@ namespace ClientDriver
values[i].Value.Byte = tcpBuffer[j];
break;
case DataType.WORD:
values[i].Value.Word = BitConverter.ToUInt16(tcpBuffer, j);
break;
case DataType.SHORT:
values[i].Value.Int16 = BitConverter.ToInt16(tcpBuffer, j);
break;
case DataType.DWORD:
values[i].Value.DWord = BitConverter.ToUInt32(tcpBuffer, j);
break;
case DataType.INT:
values[i].Value.Int32 = BitConverter.ToInt32(tcpBuffer, j);
break;
@ -727,9 +746,14 @@ namespace ClientDriver
list.Add(Convert.ToByte(item.Value));
break;
case DataType.WORD:
list.AddRange(BitConverter.GetBytes(Convert.ToUInt16(item.Value)));
break;
case DataType.SHORT:
list.AddRange(BitConverter.GetBytes(Convert.ToInt16(item.Value)));
break;
case DataType.DWORD:
list.AddRange(BitConverter.GetBytes(Convert.ToUInt32(item.Value)));
break;
case DataType.INT:
list.AddRange(BitConverter.GetBytes(Convert.ToInt32(item.Value)));
break;
@ -806,10 +830,14 @@ namespace ClientDriver
data.Value.Byte = tcpBuffer[index];
break;
case DataType.WORD:
data.Value.Word = BitConverter.ToUInt16(temp, 2);
break;
case DataType.SHORT:
data.Value.Int16 = BitConverter.ToInt16(temp, 2);
break;
case DataType.TIME:
case DataType.DWORD:
data.Value.DWord = BitConverter.ToUInt32(temp, 2);
break;
case DataType.INT:
data.Value.Int32 = BitConverter.ToInt32(temp, 2);
break;
@ -845,10 +873,14 @@ namespace ClientDriver
data.Value.Byte = tcpBuffer[index];
break;
case DataType.WORD:
data.Value.Word = BitConverter.ToUInt16(tcpBuffer, index);
break;
case DataType.SHORT:
data.Value.Int16 = BitConverter.ToInt16(tcpBuffer, index);
break;
case DataType.TIME:
case DataType.DWORD:
data.Value.DWord = BitConverter.ToUInt32(tcpBuffer, index);
break;
case DataType.INT:
data.Value.Int32 = BitConverter.ToInt32(tcpBuffer, index);
break;
@ -924,6 +956,81 @@ namespace ClientDriver
index += 12 - result;//丢弃一个值
} while (result > 0);
break;
case DataType.SHORT:
do
{
result = _tcpSend.Receive(tcpBuffer, 0, tcpBuffer.Length, SocketFlags.None, out error);
if (error == SocketError.ConnectionReset || error == SocketError.Interrupted || error == SocketError.HostDown || error == SocketError.NetworkDown || error == SocketError.Shutdown)
{
_tcpSend.Dispose();
yield break;
}
while (index + 10 <= result)
{
data.Value.Int16 = BitConverter.ToInt16(tcpBuffer, index);//未来可考虑量程转换和其他数据类型
index += 2;
long fileTime = BitConverter.ToInt64(tcpBuffer, index);
if (fileTime == -1) yield break;
data.TimeStamp = DateTime.FromFileTime(fileTime);
index += 8;
yield return data;
}
if (index == result)
index = 0;
else
index += 10 - result;//丢弃一个值
} while (result > 0);
break;
case DataType.WORD:
do
{
result = _tcpSend.Receive(tcpBuffer, 0, tcpBuffer.Length, SocketFlags.None, out error);
if (error == SocketError.ConnectionReset || error == SocketError.Interrupted || error == SocketError.HostDown || error == SocketError.NetworkDown || error == SocketError.Shutdown)
{
_tcpSend.Dispose();
yield break;
}
while (index + 10 <= result)
{
data.Value.Word = BitConverter.ToUInt16(tcpBuffer, index);//未来可考虑量程转换和其他数据类型
index += 2;
long fileTime = BitConverter.ToInt64(tcpBuffer, index);
if (fileTime == -1) yield break;
data.TimeStamp = DateTime.FromFileTime(fileTime);
index += 8;
yield return data;
}
if (index == result)
index = 0;
else
index += 10 - result;//丢弃一个值
} while (result > 0);
break;
case DataType.DWORD:
do
{
result = _tcpSend.Receive(tcpBuffer, 0, tcpBuffer.Length, SocketFlags.None, out error);
if (error == SocketError.ConnectionReset || error == SocketError.Interrupted || error == SocketError.HostDown || error == SocketError.NetworkDown || error == SocketError.Shutdown)
{
_tcpSend.Dispose();
yield break;
}
while (index + 12 <= result)
{
data.Value.DWord = BitConverter.ToUInt32(tcpBuffer, index);//未来可考虑量程转换和其他数据类型
index += 4;
long fileTime = BitConverter.ToInt64(tcpBuffer, index);
if (fileTime == -1) yield break;
data.TimeStamp = DateTime.FromFileTime(fileTime);
index += 8;
yield return data;
}
if (index == result)
index = 0;
else
index += 12 - result;//丢弃一个值
} while (result > 0);
break;
case DataType.INT:
do
{
@ -1045,6 +1152,20 @@ namespace ClientDriver
new ItemData<int>(BitConverter.ToInt32(data, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<uint> ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache)
{
var data = ReadSingleData(address, source);
return data == null ? new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD) :
new ItemData<uint>(BitConverter.ToUInt32(data, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
var data = ReadSingleData(address, source);
return data == null ? new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD) :
new ItemData<ushort>(BitConverter.ToUInt16(data, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
var data = ReadSingleData(address, source);
@ -1090,6 +1211,16 @@ namespace ClientDriver
return WriteSingleData(address, BitConverter.GetBytes(value));
}
public int WriteUInt32(DeviceAddress address, uint value)
{
return WriteSingleData(address, BitConverter.GetBytes(value));
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
return WriteSingleData(address, BitConverter.GetBytes(value));
}
public int WriteInt16(DeviceAddress address, short value)
{
return WriteSingleData(address, BitConverter.GetBytes(value));

2
SCADA/Program/CoreTest/ClientService.cs

@ -823,7 +823,7 @@ namespace CoreTest
case DataType.SHORT:
max = short.MaxValue; min = short.MinValue;
break;
case DataType.TIME:
case DataType.DWORD:
max = uint.MaxValue; min = 0;
break;
case DataType.INT:

12
SCADA/Program/CoreTest/WindowHelper.cs

@ -591,10 +591,14 @@ namespace CoreTest
source.SetYMapping(Y => Y.Value.Byte);
break;
case DataType.WORD:
source.SetYMapping(Y => Y.Value.Word);
break;
case DataType.SHORT:
source.SetYMapping(Y => Y.Value.Int16);
break;
case DataType.TIME:
case DataType.DWORD:
source.SetYMapping(Y => Y.Value.DWord);
break;
case DataType.INT:
source.SetYMapping(Y => Y.Value.Int32);
break;
@ -618,10 +622,14 @@ namespace CoreTest
source.SetYMapping(Y => Y.Value.Byte);
break;
case DataType.WORD:
source.SetYMapping(Y => Y.Value.Word);
break;
case DataType.SHORT:
source.SetYMapping(Y => Y.Value.Int16);
break;
case DataType.TIME:
case DataType.DWORD:
source.SetYMapping(Y => Y.Value.DWord);
break;
case DataType.INT:
source.SetYMapping(Y => Y.Value.Int32);
break;

29
SCADA/Program/DataHelper/HDAIOHelper.cs

@ -169,9 +169,14 @@ namespace DatabaseLib
w.Write((byte)dataReader.GetFloat(1));
break;
case DataType.WORD:
w.Write((ushort)dataReader.GetFloat(1));
break;
case DataType.SHORT:
w.Write((short)dataReader.GetFloat(1));
break;
case DataType.DWORD:
w.Write((uint)dataReader.GetFloat(1));
break;
case DataType.INT:
w.Write((int)dataReader.GetFloat(1));
break;
@ -305,10 +310,17 @@ namespace DatabaseLib
pos++;
break;
case DataType.WORD:
data.Value.Word = acc.ReadUInt16(pos);
pos += 2;
break;
case DataType.SHORT:
data.Value.Int16 = acc.ReadInt16(pos);
pos += 2;
break;
case DataType.DWORD:
data.Value.DWord = acc.ReadUInt32(pos);
pos += 4;
break;
case DataType.INT:
data.Value.Int32 = acc.ReadInt32(pos);
pos += 4;
@ -416,10 +428,17 @@ namespace DatabaseLib
pos++;
break;
case DataType.WORD:
data.Value.Word = acc2.ReadUInt16(pos);
pos += 2;
break;
case DataType.SHORT:
data.Value.Int16 = acc2.ReadInt16(pos);
pos += 2;
break;
case DataType.DWORD:
data.Value.DWord = acc2.ReadUInt32(pos);
pos += 4;
break;
case DataType.INT:
data.Value.Int32 = acc2.ReadInt32(pos);
pos += 4;
@ -464,9 +483,14 @@ namespace DatabaseLib
data.Value.Byte = Convert.ToByte(dataReader.GetFloat(ivalue));
break;
case DataType.WORD:
data.Value.Word = Convert.ToUInt16(dataReader.GetFloat(ivalue));
break;
case DataType.SHORT:
data.Value.Int16 = Convert.ToInt16(dataReader.GetFloat(ivalue));
break;
case DataType.DWORD:
data.Value.DWord = Convert.ToUInt32(dataReader.GetFloat(ivalue));
break;
case DataType.INT:
data.Value.Int32 = Convert.ToInt32(dataReader.GetFloat(ivalue));
break;
@ -511,9 +535,14 @@ namespace DatabaseLib
data.Value.Byte = Convert.ToByte(dataReader.GetFloat(ivalue));
break;
case DataType.WORD:
data.Value.Word = Convert.ToUInt16(dataReader.GetFloat(ivalue));
break;
case DataType.SHORT:
data.Value.Int16 = Convert.ToInt16(dataReader.GetFloat(ivalue));
break;
case DataType.DWORD:
data.Value.DWord = Convert.ToUInt32(dataReader.GetFloat(ivalue));
break;
case DataType.INT:
data.Value.Int32 = Convert.ToInt32(dataReader.GetFloat(ivalue));
break;

185
SCADA/Program/DataService/CacheReader.cs

@ -34,14 +34,24 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
return new ItemData<int>(BitConverter.ToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>(BitConverter.ToUInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>(BitConverter.ToUInt16(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -90,6 +100,24 @@ namespace DataService
return 0;
}
public unsafe int WriteUInt16(DeviceAddress address, ushort value)
{
fixed (byte* p1 = _cache)
{
Marshal.WriteInt16((IntPtr)(p1 + address.CacheIndex), (short)value);
}
return 0;
}
public unsafe int WriteUInt32(DeviceAddress address, uint value)
{
fixed (byte* p1 = _cache)
{
Marshal.WriteInt32((IntPtr)(p1 + address.CacheIndex), (int)value);
}
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
{
fixed (byte* p1 = _cache)
@ -168,14 +196,24 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
return new ItemData<int>(Utility.NetToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>((uint)Utility.NetToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>((ushort)Utility.NetToInt16(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -224,6 +262,24 @@ namespace DataService
return 0;
}
public unsafe int WriteUInt16(DeviceAddress address, ushort value)
{
fixed (byte* p1 = _cache)
{
Marshal.WriteInt16((IntPtr)(p1 + address.CacheIndex), IPAddress.HostToNetworkOrder((short)value));
}
return 0;
}
public unsafe int WriteUInt32(DeviceAddress address, uint value)
{
fixed (byte* p1 = _cache)
{
Marshal.WriteInt32((IntPtr)(p1 + address.CacheIndex), IPAddress.HostToNetworkOrder((int)value));
}
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
{
fixed (byte* p1 = _cache)
@ -318,6 +374,11 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
int startIndex = address.CacheIndex;
@ -333,9 +394,9 @@ namespace DataService
return new ItemData<int>(result, 0, QUALITIES.QUALITY_GOOD);
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>((uint)ReadInt32(address).Value, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -343,6 +404,11 @@ namespace DataService
return new ItemData<short>(_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<byte> ReadByte(DeviceAddress address)
{
return new ItemData<byte>((byte)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
@ -387,12 +453,27 @@ namespace DataService
return 0;
}
public unsafe int WriteInt16(DeviceAddress address, short value)
public int WriteInt16(DeviceAddress address, short value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
_cache[address.CacheIndex] = (short)value;
return 0;
}
public unsafe int WriteUInt32(DeviceAddress address, uint value)
{
fixed (short* p1 = _cache)
{
Marshal.WriteInt32((IntPtr)(p1 + address.CacheIndex), (int)value);
}
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
{
fixed (short* p1 = _cache)
@ -486,6 +567,11 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
int startIndex = address.CacheIndex;
@ -501,9 +587,14 @@ namespace DataService
return new ItemData<int>(result, 0, QUALITIES.QUALITY_GOOD);
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>((uint)ReadInt32(address).Value, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>((ushort)IPAddress.HostToNetworkOrder(_cache[address.CacheIndex]), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -561,12 +652,18 @@ namespace DataService
return 0;
}
public unsafe int WriteInt16(DeviceAddress address, short value)
public int WriteInt16(DeviceAddress address, short value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
_cache[address.CacheIndex] = (short)value;
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
{
fixed (short* p1 = _cache)
@ -576,6 +673,15 @@ namespace DataService
return 0;
}
public unsafe int WriteUInt32(DeviceAddress address, uint value)
{
fixed (short* p1 = _cache)
{
Marshal.WriteInt32((IntPtr)(p1 + address.CacheIndex), IPAddress.HostToNetworkOrder((int)value));
}
return 0;
}
public unsafe int WriteFloat(DeviceAddress address, float value)
{
fixed (short* p1 = _cache)
@ -661,15 +767,24 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public ItemData<int> ReadInt32(DeviceAddress address)
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
return new ItemData<int>(_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>((uint)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -718,6 +833,18 @@ namespace DataService
return 0;
}
public unsafe int WriteUInt16(DeviceAddress address, ushort value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public unsafe int WriteUInt32(DeviceAddress address, uint value)
{
_cache[address.CacheIndex] = (int)value;
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
{
_cache[address.CacheIndex] = value;
@ -809,15 +936,25 @@ namespace DataService
return start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue;
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
{
return new ItemData<bool>(((int)_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<int> ReadInt32(DeviceAddress address)
{
return new ItemData<int>((int)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public unsafe ItemData<bool> ReadBit(DeviceAddress address)
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
return new ItemData<bool>(((int)_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD);
return new ItemData<uint>((uint)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
return new ItemData<ushort>((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
@ -859,19 +996,31 @@ namespace DataService
return 0;
}
public unsafe int WriteInt16(DeviceAddress address, short value)
public int WriteInt16(DeviceAddress address, short value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public unsafe int WriteInt32(DeviceAddress address, int value)
public int WriteUInt16(DeviceAddress address, ushort value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public unsafe int WriteFloat(DeviceAddress address, float value)
public int WriteUInt32(DeviceAddress address, uint value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public int WriteInt32(DeviceAddress address, int value)
{
_cache[address.CacheIndex] = value;
return 0;
}
public int WriteFloat(DeviceAddress address, float value)
{
_cache[address.CacheIndex] = value;
return 0;

30
SCADA/Program/DataService/Enums.cs

@ -16,7 +16,7 @@ namespace DataService
BYTE = 3,
SHORT = 4,
WORD = 5,
TIME = 6,
DWORD = 6,
INT = 7,
FLOAT = 8,
SYS = 9,
@ -96,4 +96,32 @@ namespace DataService
Absolute = 0,
Percent = 1
}
public enum QUALITIES : short
{
// Fields
LIMIT_CONST = 3,
LIMIT_HIGH = 2,
LIMIT_LOW = 1,
//LIMIT_MASK = 3,
//LIMIT_OK = 0,
QUALITY_BAD = 0,
QUALITY_COMM_FAILURE = 0x18,
QUALITY_CONFIG_ERROR = 4,
QUALITY_DEVICE_FAILURE = 12,
QUALITY_EGU_EXCEEDED = 0x54,
QUALITY_GOOD = 0xc0,
QUALITY_LAST_KNOWN = 20,
QUALITY_LAST_USABLE = 0x44,
QUALITY_LOCAL_OVERRIDE = 0xd8,
QUALITY_MASK = 0xc0,
QUALITY_NOT_CONNECTED = 8,
QUALITY_OUT_OF_SERVICE = 0x1c,
QUALITY_SENSOR_CAL = 80,
QUALITY_SENSOR_FAILURE = 0x10,
QUALITY_SUB_NORMAL = 0x58,
QUALITY_UNCERTAIN = 0x40,
QUALITY_WAITING_FOR_INITIAL_DATA = 0x20,
STATUS_MASK = 0xfc,
}
}

14
SCADA/Program/DataService/Eval.cs

@ -531,7 +531,7 @@ namespace DataService
case DataType.BYTE:
case DataType.WORD:
case DataType.SHORT:
case DataType.TIME:
case DataType.DWORD:
case DataType.INT:
return Expression.Call(_param1, _intinfo, Expression.Constant(tagName));
case DataType.FLOAT:
@ -554,9 +554,11 @@ namespace DataService
case DataType.BYTE:
return Convert.ToBoolean(tag.Value.Byte);
case DataType.WORD:
return Convert.ToBoolean(tag.Value.Word);
case DataType.SHORT:
return Convert.ToBoolean(tag.Value.Int16);
case DataType.TIME:
case DataType.DWORD:
return Convert.ToBoolean(tag.Value.DWord);
case DataType.INT:
return Convert.ToBoolean(tag.Value.Int32);
case DataType.FLOAT:
@ -584,11 +586,13 @@ namespace DataService
case DataType.BOOL:
return tag.Value.Boolean ? 1 : 0;
case DataType.BYTE:
return (int)tag.Value.Byte;
return tag.Value.Byte;
case DataType.WORD:
return tag.Value.Word;
case DataType.SHORT:
return (int)tag.Value.Int16;
case DataType.TIME:
return tag.Value.Int16;
case DataType.DWORD:
return (int)tag.Value.DWord;
case DataType.INT:
return tag.Value.Int32;
case DataType.FLOAT:

49
SCADA/Program/DataService/ExtensionMethods.cs

@ -115,10 +115,14 @@ namespace DataService
var bt = reader.ReadByte(address);
return new ItemData<object>(bt.Value, bt.TimeStamp, bt.Quality);
case DataType.WORD:
var ush = reader.ReadUInt16(address);
return new ItemData<object>(ush.Value, ush.TimeStamp, ush.Quality);
case DataType.SHORT:
var sh = reader.ReadInt16(address);
return new ItemData<object>(sh.Value, sh.TimeStamp, sh.Quality);
case DataType.TIME:
case DataType.DWORD:
var dw = reader.ReadUInt32(address);
return new ItemData<object>(dw.Value, dw.TimeStamp, dw.Quality);
case DataType.INT:
var it = reader.ReadInt32(address);
return new ItemData<object>(it.Value, it.TimeStamp, it.Quality);
@ -141,9 +145,11 @@ namespace DataService
case DataType.BYTE:
return writer.WriteBits(address, Convert.ToByte(value));
case DataType.WORD:
return writer.WriteUInt16(address, Convert.ToUInt16(value));
case DataType.SHORT:
return writer.WriteInt16(address, Convert.ToInt16(value));
case DataType.TIME:
case DataType.DWORD:
return writer.WriteUInt32(address, Convert.ToUInt32(value));
case DataType.INT:
return writer.WriteInt32(address, Convert.ToInt32(value));
case DataType.FLOAT:
@ -267,10 +273,14 @@ namespace DataService
items[i].Value.Byte = cache.ReadByte(addrsArr[i]).Value;
break;
case DataType.WORD:
items[i].Value.Word = cache.ReadUInt16(addrsArr[i]).Value;
break;
case DataType.SHORT:
items[i].Value.Int16 = cache.ReadInt16(addrsArr[i]).Value;
break;
case DataType.TIME:
case DataType.DWORD:
items[i].Value.DWord = cache.ReadUInt32(addrsArr[i]).Value;
break;
case DataType.INT:
items[i].Value.Int32 = cache.ReadInt32(addrsArr[i]).Value;
break;
@ -365,8 +375,9 @@ namespace DataService
case DataType.SHORT:
return typeof(short);
case DataType.INT:
case DataType.TIME:
return typeof(int);
case DataType.DWORD:
return typeof(uint);
case DataType.FLOAT:
return typeof(float);
case DataType.STR:
@ -433,10 +444,14 @@ namespace DataService
value.Byte = Convert.ToByte(obj);
break;
case DataType.WORD:
value.Word = Convert.ToUInt16(obj);
break;
case DataType.SHORT:
value.Int16 = Convert.ToInt16(obj);
break;
case DataType.TIME:
case DataType.DWORD:
value.DWord = Convert.ToUInt32(obj);
break;
case DataType.INT:
value.Int32 = Convert.ToInt32(obj);
break;
@ -456,8 +471,11 @@ namespace DataService
case DataType.BYTE:
return new byte[] { tag.Value.Byte };
case DataType.WORD:
return BitConverter.GetBytes(tag.Value.Word);
case DataType.SHORT:
return BitConverter.GetBytes(tag.Value.Int16);
case DataType.DWORD:
return BitConverter.GetBytes(tag.Value.DWord);
case DataType.INT:
return BitConverter.GetBytes(tag.Value.Int32);
case DataType.FLOAT:
@ -478,8 +496,11 @@ namespace DataService
case DataType.BYTE:
return new byte[] { value.Byte };
case DataType.WORD:
return BitConverter.GetBytes(value.Word);
case DataType.SHORT:
return BitConverter.GetBytes(value.Int16);
case DataType.DWORD:
return BitConverter.GetBytes(value.DWord);
case DataType.INT:
return BitConverter.GetBytes(value.Int32);
case DataType.FLOAT:
@ -500,9 +521,11 @@ namespace DataService
case DataType.BYTE:
return value.Byte;
case DataType.WORD:
return value.Word;
case DataType.SHORT:
return value.Int16;
case DataType.TIME:
case DataType.DWORD:
return value.DWord;
case DataType.INT:
return value.Int32;
case DataType.FLOAT:
@ -544,12 +567,15 @@ namespace DataService
switch (type)
{
case DataType.BYTE:
return (float)value.Byte;
return value.Byte;
case DataType.WORD:
return value.Word;
case DataType.SHORT:
return (float)value.Int16;
return value.Int16;
case DataType.DWORD:
return value.DWord;
case DataType.INT:
return (float)value.Int32;
return value.Int32;
case DataType.FLOAT:
return value.Single;
case DataType.STR:
@ -567,9 +593,14 @@ namespace DataService
temp = (value.Byte - meta.RawLo) / (meta.RawHi - meta.RawLo);
break;
case DataType.WORD:
temp = (value.Word - meta.RawLo) / (meta.RawHi - meta.RawLo);
break;
case DataType.SHORT:
temp = (value.Int16 - meta.RawLo) / (meta.RawHi - meta.RawLo);
break;
case DataType.DWORD:
temp = (value.DWord - meta.RawLo) / (meta.RawHi - meta.RawLo);
break;
case DataType.INT:
temp = (value.Int32 - meta.RawLo) / (meta.RawHi - meta.RawLo);
break;

7
SCADA/Program/DataService/IGroup.cs

@ -20,18 +20,25 @@ namespace DataService
ITag FindItemByAddress(DeviceAddress addr);
HistoryData[] BatchRead(DataSource source, bool isSync, params ITag[] itemArray);
int BatchWrite(SortedDictionary<ITag, object> items, bool isSync = true);
ItemData<int> ReadInt32(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<uint> ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<short> ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<ushort> ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<byte> ReadByte(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<float> ReadFloat(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<bool> ReadBool(DeviceAddress address, DataSource source = DataSource.Cache);
ItemData<string> ReadString(DeviceAddress address, DataSource source = DataSource.Cache);
int WriteInt32(DeviceAddress address, int value);
int WriteUInt32(DeviceAddress address, uint value);
int WriteInt16(DeviceAddress address, short value);
int WriteUInt16(DeviceAddress address, ushort value);
int WriteFloat(DeviceAddress address, float value);
int WriteString(DeviceAddress address, string value);
int WriteBit(DeviceAddress address, bool value);
int WriteBits(DeviceAddress address, byte value);
event DataChangeEventHandler DataChange;
}

4
SCADA/Program/DataService/IReader.cs

@ -6,7 +6,9 @@ namespace DataService
public interface IReaderWriter
{
byte[] ReadBytes(DeviceAddress address, ushort size);
ItemData<uint> ReadUInt32(DeviceAddress address);
ItemData<int> ReadInt32(DeviceAddress address);
ItemData<ushort> ReadUInt16(DeviceAddress address);
ItemData<short> ReadInt16(DeviceAddress address);
ItemData<byte> ReadByte(DeviceAddress address);
ItemData<string> ReadString(DeviceAddress address, ushort size);
@ -18,7 +20,9 @@ namespace DataService
int WriteBit(DeviceAddress address, bool bit);
int WriteBits(DeviceAddress address, byte bits);
int WriteInt16(DeviceAddress address, short value);
int WriteUInt16(DeviceAddress address, ushort value);
int WriteInt32(DeviceAddress address, int value);
int WriteUInt32(DeviceAddress address, uint value);
int WriteFloat(DeviceAddress address, float value);
int WriteString(DeviceAddress address, string str);
int WriteValue(DeviceAddress address, object value);

137
SCADA/Program/DataService/ITag.cs

@ -366,6 +366,75 @@ namespace DataService
}
}
public sealed class UShortTag : ITag
{
public UShortTag(short id, DeviceAddress addr, IGroup group)
: base(id, addr, group)
{
}
#region IDevice Members
public override bool Refresh(DataSource source = DataSource.Device)
{
var _newvalue = _group.ReadUInt16(_plcAddress, source);
if (_newvalue.Value != _value.Word)
{
Storage value = Storage.Empty;
value.Word = _newvalue.Value;
DateTime time = _newvalue.TimeStamp.ToDateTime();
if (ValueChanging != null)
{
ValueChanging(this, new ValueChangingEventArgs<Storage>(_newvalue.Quality, _value, value, _timeStamp, time));
}
_timeStamp = time;
_quality = _newvalue.Quality;
if (_quality == QUALITIES.QUALITY_GOOD)
{
_value = value;
if (ValueChanged != null)
{
ValueChanged(this, new ValueChangedEventArgs(value));
}
}
return true;
}
return false;
}
public override Storage Read(DataSource source = DataSource.Cache)
{
Storage value = Storage.Empty;
value.Word = _group.ReadUInt16(_plcAddress, source).Value;
return value;
}
public override int Write(object value)
{
var temp = _value.Word;
var str = value as string;
if (str == null)
temp = Convert.ToUInt16(value);
else if (!ushort.TryParse(str, out temp))
return -1;
_timeStamp = DateTime.Now;
return _group.WriteUInt16(_plcAddress, temp);
}
protected override int InnerWrite(Storage value)
{
return _group.WriteUInt16(_plcAddress, value.Word);
}
#endregion
public override string ToString()
{
return _value.Word.ToString();
}
}
public sealed class IntTag : ITag
{
@ -434,6 +503,74 @@ namespace DataService
}
}
public sealed class UIntTag : ITag
{
public UIntTag(short id, DeviceAddress addr, IGroup group)
: base(id, addr, group)
{
}
#region IDevice Members
public override bool Refresh(DataSource source = DataSource.Device)
{
var _newvalue = _group.ReadUInt32(_plcAddress, source);
if (_newvalue.Value != _value.DWord)
{
Storage value = Storage.Empty;
value.DWord = _newvalue.Value;
DateTime time = _newvalue.TimeStamp.ToDateTime();
if (ValueChanging != null)
{
ValueChanging(this, new ValueChangingEventArgs<Storage>(_newvalue.Quality, _value, value, _timeStamp, time));
}
_timeStamp = time;
_quality = _newvalue.Quality;
if (_quality == QUALITIES.QUALITY_GOOD)
{
_value = value;
if (ValueChanged != null)
{
ValueChanged(this, new ValueChangedEventArgs(value));
}
}
return true;
}
return false;
}
public override Storage Read(DataSource source = DataSource.Cache)
{
Storage value = Storage.Empty;
value.DWord = _group.ReadUInt32(_plcAddress, source).Value;
return value;
}
public override int Write(object value)
{
var temp = _value.DWord;
var str = value as string;
if (str == null)
temp = Convert.ToUInt32(value);
else if (!uint.TryParse(str, out temp))
return -1;
_timeStamp = DateTime.Now;
return _group.WriteUInt32(_plcAddress, temp);
}
protected override int InnerWrite(Storage value)
{
return _group.WriteUInt32(_plcAddress, value.DWord);
}
#endregion
public override string ToString()
{
return _value.DWord.ToString();
}
}
public sealed class FloatTag : ITag
{

52
SCADA/Program/DataService/PLCGroup.cs

@ -163,10 +163,14 @@ namespace DataService
dataItem = new ByteTag(meta.ID, addr, this);
break;
case DataType.WORD:
dataItem = new UShortTag(meta.ID, addr, this);
break;
case DataType.SHORT:
dataItem = new ShortTag(meta.ID, addr, this);
break;
case DataType.TIME:
case DataType.DWORD:
dataItem = new UIntTag(meta.ID, addr, this);
break;
case DataType.INT:
dataItem = new IntTag(meta.ID, addr, this);
break;
@ -524,6 +528,16 @@ namespace DataService
return source == DataSource.Cache ? _cacheReader.ReadInt32(address) : _plcReader.ReadInt32(address);
}
public ItemData<uint> ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache)
{
return source == DataSource.Cache ? _cacheReader.ReadUInt32(address) : _plcReader.ReadUInt32(address);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
return source == DataSource.Cache ? _cacheReader.ReadUInt16(address) : _plcReader.ReadUInt16(address);
}
public ItemData<short> ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
return source == DataSource.Cache ? _cacheReader.ReadInt16(address) : _plcReader.ReadInt16(address);
@ -569,6 +583,42 @@ namespace DataService
return rs;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
int rs = _plcReader.WriteUInt32(address, value);
if (rs >= 0)
{
if (DataChange != null)
{
ITag tag = GetTagByAddress(address);
if (tag != null)
DataChange(this, new DataChangeEventArgs(1, new HistoryData[1]
{
new HistoryData(tag.ID,QUALITIES.QUALITY_GOOD,new Storage{DWord=value}, DateTime.Now)
}));
}
}
return rs;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
int rs = _plcReader.WriteUInt16(address, value);
if (rs >= 0)
{
if (DataChange != null)
{
ITag tag = GetTagByAddress(address);
if (tag != null)
DataChange(this, new DataChangeEventArgs(1, new HistoryData[1]
{
new HistoryData(tag.ID,QUALITIES.QUALITY_GOOD,new Storage{Word=value}, DateTime.Now)
}));
}
}
return rs;
}
public int WriteInt16(DeviceAddress address, short value)
{
int rs = _plcReader.WriteInt16(address, value);

57
SCADA/Program/DataService/Storage.cs

@ -17,6 +17,10 @@ namespace DataService
public int Int32;
[FieldOffset(0)]
public float Single;
[FieldOffset(0)]
public ushort Word;
[FieldOffset(0)]
public uint DWord;
public static readonly Storage Empty ;
@ -33,17 +37,21 @@ namespace DataService
return this.Int32 == ((Storage)obj).Int32;
else
{
if (type == typeof(Int32))
return this.Int32 == (Int32)obj;
if (type == typeof(Int16))
return this.Int16 == (Int16)obj;
if (type == typeof(Byte))
return this.Byte == (Byte)obj;
if (type == typeof(Boolean))
return this.Boolean == (Boolean)obj;
if (type == typeof(Single))
return this.Single == (Single)obj;
if (type == typeof(String))
if (type == typeof(int))
return this.Int32 == (int)obj;
if (type == typeof(short))
return this.Int16 == (short)obj;
if (type == typeof(byte))
return this.Byte == (byte)obj;
if (type == typeof(bool))
return this.Boolean == (bool)obj;
if (type == typeof(float))
return this.Single == (float)obj;
if (type == typeof(ushort))
return this.Word == (ushort)obj;
if (type == typeof(uint))
return this.DWord == (uint)obj;
if (type == typeof(string))
return this.ToString() == obj.ToString();
}
return false;
@ -65,31 +73,4 @@ namespace DataService
}
}
public enum QUALITIES : short
{
// Fields
LIMIT_CONST = 3,
LIMIT_HIGH = 2,
LIMIT_LOW = 1,
//LIMIT_MASK = 3,
//LIMIT_OK = 0,
QUALITY_BAD = 0,
QUALITY_COMM_FAILURE = 0x18,
QUALITY_CONFIG_ERROR = 4,
QUALITY_DEVICE_FAILURE = 12,
QUALITY_EGU_EXCEEDED = 0x54,
QUALITY_GOOD = 0xc0,
QUALITY_LAST_KNOWN = 20,
QUALITY_LAST_USABLE = 0x44,
QUALITY_LOCAL_OVERRIDE = 0xd8,
QUALITY_MASK = 0xc0,
QUALITY_NOT_CONNECTED = 8,
QUALITY_OUT_OF_SERVICE = 0x1c,
QUALITY_SENSOR_CAL = 80,
QUALITY_SENSOR_FAILURE = 0x10,
QUALITY_SUB_NORMAL = 0x58,
QUALITY_UNCERTAIN = 0x40,
QUALITY_WAITING_FOR_INITIAL_DATA = 0x20,
STATUS_MASK = 0xfc,
}
}

38
SCADA/Program/FileDriver/DatabaseDriver.cs

@ -245,6 +245,18 @@ namespace FileDriver
return data;
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
var res = ReadInt32(address);
return new ItemData<uint>((uint)res.Value, res.TimeStamp, res.Quality);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
var res = ReadInt16(address);
return new ItemData<ushort>((ushort)res.Value, res.TimeStamp, res.Quality);
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
ItemData<short> data = new ItemData<short>();
@ -393,6 +405,20 @@ namespace FileDriver
new SqlParameter("@Value", SqlDbType.Variant) { Value = value });
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
return ExecuteStoredProcedure("UpdateValueByID",
new SqlParameter("@ID", SqlDbType.SmallInt) { Value = address.CacheIndex },
new SqlParameter("@Value", SqlDbType.Variant) { Value = value });
}
public int WriteUInt32(DeviceAddress address, uint value)
{
return ExecuteStoredProcedure("UpdateValueByID",
new SqlParameter("@ID", SqlDbType.SmallInt) { Value = address.CacheIndex },
new SqlParameter("@Value", SqlDbType.Variant) { Value = value });
}
public int WriteInt32(DeviceAddress address, int value)
{
return ExecuteStoredProcedure("UpdateValueByID",
@ -450,10 +476,14 @@ namespace FileDriver
itemArr[i].Value.Byte = dataReader.GetByte(0);
break;
case DataType.WORD:
itemArr[i].Value.Word = (ushort)dataReader.GetInt16(0);
break;
case DataType.SHORT:
itemArr[i].Value.Int16 = dataReader.GetInt16(0);
break;
case DataType.TIME:
case DataType.DWORD:
itemArr[i].Value.DWord = (uint)dataReader.GetInt32(0);
break;
case DataType.INT:
itemArr[i].Value.Int32 = dataReader.GetInt32(0);
break;
@ -507,10 +537,14 @@ namespace FileDriver
list[i].Value.Byte = Convert.ToByte(reader.GetValue(2));
break;
case DataType.WORD:
list[i].Value.Word = Convert.ToUInt16(reader.GetValue(2));
break;
case DataType.SHORT:
list[i].Value.Int16 = Convert.ToInt16(reader.GetValue(2));
break;
case DataType.TIME:
case DataType.DWORD:
list[i].Value.DWord = Convert.ToUInt32(reader.GetValue(2));
break;
case DataType.INT:
list[i].Value.Int32 = Convert.ToInt32(reader.GetValue(2));
break;

69
SCADA/Program/FileDriver/FileDeviceGroup.cs

@ -202,10 +202,14 @@ namespace FileDriver
dataItem = new ByteTag(meta.ID, addr, this);
break;
case DataType.WORD:
dataItem = new UShortTag(meta.ID, addr, this);
break;
case DataType.SHORT:
dataItem = new ShortTag(meta.ID, addr, this);
break;
case DataType.TIME:
case DataType.DWORD:
dataItem = new UIntTag(meta.ID, addr, this);
break;
case DataType.INT:
dataItem = new IntTag(meta.ID, addr, this);
break;
@ -418,10 +422,14 @@ namespace FileDriver
value.Byte = Convert.ToByte(d.Right(ind));
break;
case DataType.WORD:
value.Word = Convert.ToUInt16(d.Right(ind));
break;
case DataType.SHORT:
value.Int16 = Convert.ToInt16(d.Right(ind));
break;
case DataType.TIME:
case DataType.DWORD:
value.DWord = Convert.ToUInt32(d.Right(ind));
break;
case DataType.INT:
value.Int32 = Convert.ToInt32(d.Right(ind));
break;
@ -463,6 +471,26 @@ namespace FileDriver
}
}
public ItemData<uint> ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache)
{
if (source == DataSource.Device) return _fileReader.ReadUInt32(address);
else
{
ITag tag = _items[address.Start];
return new ItemData<uint>(tag.Value.DWord, 0, tag.Quality);
}
}
public ItemData<ushort> ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
if (source == DataSource.Device) return _fileReader.ReadUInt16(address);
else
{
ITag tag = _items[address.Start];
return new ItemData<ushort>(tag.Value.Word, 0, tag.Quality);
}
}
public ItemData<short> ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
if (source == DataSource.Device) return _fileReader.ReadInt16(address);
@ -532,6 +560,42 @@ namespace FileDriver
return rs;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
int rs = _fileReader.WriteUInt32(address, value);
if (rs >= 0)
{
Storage stor = new Storage { DWord = value };
_items[address.Start].Update(stor, DateTime.Now, QUALITIES.QUALITY_GOOD);
if (DataChange != null)
{
DataChange(this, new DataChangeEventArgs(1, new HistoryData[1]
{
new HistoryData( (short)address.CacheIndex,QUALITIES.QUALITY_GOOD,stor, DateTime.Now)
}));
}
}
return rs;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
int rs = _fileReader.WriteUInt16(address, value);
if (rs >= 0)
{
Storage stor = new Storage { Word = value };
_items[address.Start].Update(stor, DateTime.Now, QUALITIES.QUALITY_GOOD);
if (DataChange != null)
{
DataChange(this, new DataChangeEventArgs(1, new HistoryData[1]
{
new HistoryData( (short)address.CacheIndex,QUALITIES.QUALITY_GOOD,stor, DateTime.Now)
}));
}
}
return rs;
}
public int WriteInt16(DeviceAddress address, short value)
{
int rs = _fileReader.WriteInt16(address, value);
@ -633,5 +697,4 @@ namespace FileDriver
public event DataChangeEventHandler DataChange;
}
}

44
SCADA/Program/FileDriver/MemoryDriver.cs

@ -263,6 +263,24 @@ namespace FileDriver
catch { return new ItemData<int>(0, 0, QUALITIES.QUALITY_BAD); }
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
try
{
return new ItemData<uint>(accessor.ReadUInt32(FindPosition(address)), 0, QUALITIES.QUALITY_GOOD);
}
catch { return new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD); }
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
try
{
return new ItemData<ushort>(accessor.ReadUInt16(FindPosition(address)), 0, QUALITIES.QUALITY_GOOD);
}
catch { return new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD); }
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
try
@ -355,6 +373,26 @@ namespace FileDriver
catch { return -1; }
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
try
{
accessor.Write(FindPosition(address), value);
return 0;
}
catch { return -1; }
}
public int WriteUInt32(DeviceAddress address, uint value)
{
try
{
accessor.Write(FindPosition(address), value);
return 0;
}
catch { return -1; }
}
public int WriteInt32(DeviceAddress address, int value)
{
try
@ -420,10 +458,14 @@ namespace FileDriver
hdata[i].Value.Byte = accessor.ReadByte(pos);
break;
case DataType.WORD:
hdata[i].Value.Word = accessor.ReadUInt16(pos);
break;
case DataType.SHORT:
hdata[i].Value.Int16 = accessor.ReadInt16(pos);
break;
case DataType.TIME:
case DataType.DWORD:
hdata[i].Value.DWord = accessor.ReadUInt32(pos);
break;
case DataType.INT:
hdata[i].Value.Int32 = accessor.ReadInt32(pos);
break;

22
SCADA/Program/FileDriver/TagDriver.cs

@ -130,6 +130,18 @@ namespace FileDriver
return tag == null ? new ItemData<int>(0, 0, QUALITIES.QUALITY_BAD) : new ItemData<int>(tag.Value.Int32, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
var tag = _parent[(short)address.CacheIndex];
return tag == null ? new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD) : new ItemData<uint>(tag.Value.DWord, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
var tag = _parent[(short)address.CacheIndex];
return tag == null ? new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD) : new ItemData<ushort>(tag.Value.Word, 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
var tag = _parent[(short)address.CacheIndex];
@ -185,6 +197,16 @@ namespace FileDriver
return 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
return 0;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
return 0;
}
public int WriteInt32(DeviceAddress address, int value)
{
return 0;

33
SCADA/Program/ModbusDriver/ModbusRTUDriver.cs

@ -348,11 +348,25 @@ namespace ModbusDriver
public ItemData<int> ReadInt32(DeviceAddress address)
{
byte[] bit = ReadBytes(address, 2);
byte[] bit = ReadBytes(address, 4);
return bit == null ? new ItemData<int>(0, 0, QUALITIES.QUALITY_BAD) :
new ItemData<int>(BitConverter.ToInt32(bit, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
byte[] bit = ReadBytes(address, 4);
return bit == null ? new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD) :
new ItemData<uint>(BitConverter.ToUInt32(bit, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
byte[] bit = ReadBytes(address, 1);
return bit == null ? new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD) :
new ItemData<ushort>(BitConverter.ToUInt16(bit, 0), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
byte[] bit = ReadBytes(address, 1);
@ -428,6 +442,23 @@ namespace ModbusDriver
return (chr & 0x80) > 0 ? -1 : 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
var data = WriteSingleRegister(address.Start, BitConverter.GetBytes(value));
_serialPort.Write(data, 0, data.Length);
var chr = _serialPort.ReadByte();
return (chr & 0x80) > 0 ? -1 : 0;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
var data = WriteMultipleRegister(address.Start, BitConverter.GetBytes(value));
_serialPort.Write(data, 0, data.Length);
_serialPort.ReadByte();
var chr = _serialPort.ReadByte();
return (chr & 0x80) > 0 ? -1 : 0;
}
public int WriteInt32(DeviceAddress address, int value)
{
var data = WriteMultipleRegister(address.Start, BitConverter.GetBytes(value));

30
SCADA/Program/ModbusDriver/ModbusTCPDriver.cs

@ -419,6 +419,24 @@ namespace ModbusDriver
return new ItemData<int>(IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
byte[] data = WriteSyncData(CreateReadHeader(address.Area, address.Start, 2, (byte)address.DBNumber));
if (data == null)
return new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD);
else
return new ItemData<uint>((uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
byte[] data = WriteSyncData(CreateReadHeader(address.Area, address.Start, 1, (byte)address.DBNumber));
if (data == null)
return new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD);
else
return new ItemData<ushort>((ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
byte[] data = WriteSyncData(CreateReadHeader(address.Area, address.Start, 1, (byte)address.DBNumber));
@ -510,6 +528,18 @@ namespace ModbusDriver
return data == null ? -1 : 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
var data = WriteSingleRegister(address.Area, address.Start, BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)value)));
return data == null ? -1 : 0;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
var data = WriteMultipleRegister(address.Area, address.Start, BitConverter.GetBytes((uint)IPAddress.HostToNetworkOrder((int)value)));
return data == null ? -1 : 0;
}
public int WriteInt32(DeviceAddress address, int value)
{
var data = WriteMultipleRegister(address.Area, address.Start, BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value)));

49
SCADA/Program/OPCDriver/OPCDriver.cs

@ -177,13 +177,17 @@ namespace OPCDriver
dataItem = new ByteTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 1, 0, DataType.BYTE), this);
break;
case DataType.WORD:
dataItem = new UShortTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 2, 0, DataType.WORD), this);
break;
case DataType.SHORT:
dataItem = new ShortTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 2, 0, DataType.SHORT), this);
break;
case DataType.INT:
case DataType.TIME:
dataItem = new IntTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 4, 0, DataType.INT), this);
break;
case DataType.DWORD:
dataItem = new UIntTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 4, 0, DataType.DWORD), this);
break;
case DataType.FLOAT:
dataItem = new FloatTag((short)itemDef.hClient, new DeviceAddress(-0x100, 0, 0, Marshal.ReadInt32(pAddResults), 4, 0, DataType.FLOAT), this);
break;
@ -321,9 +325,14 @@ namespace OPCDriver
values[i].Value.Byte = Marshal.ReadByte(pItemValues + 16);
break;
case DataType.WORD:
values[i].Value.Word = (ushort)Marshal.ReadInt16(pItemValues + 16);
break;
case DataType.SHORT:
values[i].Value.Int16 = Marshal.ReadInt16(pItemValues + 16);
break;
case DataType.DWORD:
values[i].Value.DWord = (uint)Marshal.ReadInt32(pItemValues + 16);
break;
case DataType.INT:
values[i].Value.Int32 = Marshal.ReadInt32(pItemValues + 16);
break;
@ -410,6 +419,18 @@ namespace OPCDriver
return rt;
}
public ItemData<uint> ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache)
{
var rt = ReadInt32(address, source);
return new ItemData<uint>((uint)rt.Value, rt.TimeStamp, rt.Quality);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
var rt = ReadInt16(address, source);
return new ItemData<ushort>((ushort)rt.Value, rt.TimeStamp, rt.Quality);
}
public ItemData<short> ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache)
{
IntPtr pItemValues;
@ -540,6 +561,22 @@ namespace OPCDriver
return rt;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
IntPtr pErrors;
int rt = _sync.Write(1, new int[1] { address.Start }, new object[] { value }, out pErrors);
Marshal.FreeCoTaskMem(pErrors);
return rt;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
IntPtr pErrors;
int rt = _sync.Write(1, new int[1] { address.Start }, new object[] { value }, out pErrors);
Marshal.FreeCoTaskMem(pErrors);
return rt;
}
public int WriteInt16(DeviceAddress address, short value)
{
IntPtr pErrors;
@ -656,9 +693,14 @@ namespace OPCDriver
value.Byte = Marshal.ReadByte(pvValues + 8);
break;
case DataType.WORD:
value.Word = (ushort)Marshal.ReadInt16(pvValues + 8);
break;
case DataType.SHORT:
value.Int16 = Marshal.ReadInt16(pvValues + 8);
break;
case DataType.DWORD:
value.DWord = (uint)Marshal.ReadInt32(pvValues + 8);
break;
case DataType.INT:
value.Int32 = Marshal.ReadInt32(pvValues + 8);
break;
@ -726,9 +768,14 @@ namespace OPCDriver
value.Byte = Marshal.ReadByte(pvValues + 8);
break;
case DataType.WORD:
value.Word = (ushort)Marshal.ReadInt16(pvValues + 8);
break;
case DataType.SHORT:
value.Int16 = Marshal.ReadInt16(pvValues + 8);
break;
case DataType.DWORD:
value.DWord = (uint)Marshal.ReadInt32(pvValues + 8);
break;
case DataType.INT:
value.Int32 = Marshal.ReadInt32(pvValues + 8);
break;

1
SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj

@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

30
SCADA/Program/OmronPlcDriver/OmronUdpReader.cs

@ -534,6 +534,24 @@ namespace OmronPlcDriver
else
return new ItemData<int>(IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
byte[] data = WriteSyncData(CreateReadHeader(PcNodeId, address.Start, 2, (byte)address.DBNumber, (byte)address.Area));
if (data == null)
return new ItemData<uint>(0, 0, QUALITIES.QUALITY_BAD);
else
return new ItemData<uint>((uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
byte[] data = WriteSyncData(CreateReadHeader(PcNodeId, address.Start, 1, (byte)address.DBNumber, (byte)address.Area));
if (data == null)
return new ItemData<ushort>(0, 0, QUALITIES.QUALITY_BAD);
else
return new ItemData<ushort>((ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(data, 0)), 0, QUALITIES.QUALITY_GOOD);
}
/// <summary>
/// 读取16位整数
/// </summary>
@ -653,6 +671,18 @@ namespace OmronPlcDriver
return data == null ? -1 : 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
var data = WriteSingleRegister(PcNodeId, address.Start, (byte)address.DBNumber, BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)value)), (byte)address.Area);
return data == null ? -1 : 0;
}
public int WriteUInt32(DeviceAddress address, uint value)
{
var data = WriteMultipleRegister(PcNodeId, address.Start, (byte)address.DBNumber, BitConverter.GetBytes((uint)IPAddress.HostToNetworkOrder((int)value)), (byte)address.Area);
return data == null ? -1 : 0;
}
public int WriteInt32(DeviceAddress address, int value)
{
var data = WriteMultipleRegister(PcNodeId, address.Start, (byte)address.DBNumber, BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value)), (byte)address.Area);

18
SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs

@ -436,6 +436,10 @@ namespace PanasonicPLCriver
{
throw new NotImplementedException();
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
throw new NotImplementedException();
}
/// <summary>
/// 读取一个32位数 返回如果是6300 则认为是0063H 高低位要反 而且是16进账
/// </summary>
@ -444,6 +448,10 @@ namespace PanasonicPLCriver
{
throw new NotImplementedException();
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
throw new NotImplementedException();
}
public ItemData<Storage>[] ReadMultiple(DeviceAddress[] addrsArr)
{
@ -496,6 +504,16 @@ namespace PanasonicPLCriver
return 0;
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
return WriteInt16(address, (short)value);
}
public int WriteUInt32(DeviceAddress address, uint value)
{
throw new NotImplementedException();
}
public int WriteInt32(DeviceAddress address, int value)
{
throw new NotImplementedException();

68
SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs

@ -133,6 +133,7 @@ namespace SiemensPLCDriver
case DataType.SHORT:
return string.Concat(addr, "W", address.Start);
case DataType.FLOAT:
case DataType.DWORD:
case DataType.INT:
return string.Concat(addr, "D", address.Start);
default:
@ -398,6 +399,44 @@ namespace SiemensPLCDriver
return new ItemData<int>(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ;
}
public ItemData<uint> ReadUInt32(DeviceAddress address)
{
if (dc != null)
{
int res = -1;
lock (_async)
{
res = dc.readBytes(address.Area, address.DBNumber, address.Start, 4, null);
if (res == 0) return new ItemData<uint>((uint)dc.getS32(), 0, QUALITIES.QUALITY_GOOD);
}
_closed = true; dc = null; _closeTime = DateTime.Now;
if (OnClose != null)
{
OnClose(this, new ShutdownRequestEventArgs(daveStrerror(res)));
}
}
return new ItemData<uint>(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ;
}
public ItemData<ushort> ReadUInt16(DeviceAddress address)
{
if (dc != null)
{
int res = -1;
lock (_async)
{
res = dc.readBytes(address.Area, address.DBNumber, address.Start, 2, null);
if (res == 0) return new ItemData<ushort>((ushort)dc.getS16(), 0, QUALITIES.QUALITY_GOOD);
}
_closed = true; dc = null; _closeTime = DateTime.Now;
if (OnClose != null)
{
OnClose(this, new ShutdownRequestEventArgs(daveStrerror(res)));
}
}
return new ItemData<ushort>(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ;
}
public ItemData<short> ReadInt16(DeviceAddress address)
{
if (dc != null)
@ -503,6 +542,24 @@ namespace SiemensPLCDriver
}
}
public int WriteUInt16(DeviceAddress address, ushort value)
{
byte[] b = BitConverter.GetBytes(value); Array.Reverse(b);
lock (_async)
{
return dc == null ? -1 : dc.writeBytes(address.Area, address.DBNumber, address.Start, 2, b);
}
}
public int WriteUInt32(DeviceAddress address, uint value)
{
byte[] b = BitConverter.GetBytes(value); Array.Reverse(b);
lock (_async)
{
return dc == null ? -1 : dc.writeBytes(address.Area, address.DBNumber, address.Start, 4, b);
}
}
public int WriteInt32(DeviceAddress address, int value)
{
byte[] b = BitConverter.GetBytes(value); Array.Reverse(b);
@ -605,9 +662,14 @@ namespace SiemensPLCDriver
itemArr[i].Value.Byte = (byte)dc.getU8();
break;
case DataType.WORD:
itemArr[i].Value.Word = (ushort)dc.getS16();
break;
case DataType.SHORT:
itemArr[i].Value.Int16 = (short)dc.getS16();
break;
case DataType.DWORD:
itemArr[i].Value.DWord = (uint)dc.getS32();
break;
case DataType.INT:
itemArr[i].Value.Int32 = dc.getS32();
break;
@ -681,8 +743,12 @@ namespace SiemensPLCDriver
b = BitConverter.GetBytes(Convert.ToInt16(buffer[i])); Array.Reverse(b);
p2.addVarToWriteRequest(addr.Area, addr.DBNumber, addr.Start, 2, b);
break;
case DataType.DWORD:
b = BitConverter.GetBytes(Convert.ToUInt32(buffer[i])); Array.Reverse(b);
p2.addVarToWriteRequest(addr.Area, addr.DBNumber, addr.Start, 4, b);
break;
case DataType.INT:
b = BitConverter.GetBytes((int)Convert.ToDouble(buffer[i])); Array.Reverse(b);
b = BitConverter.GetBytes(Convert.ToInt32(buffer[i])); Array.Reverse(b);
p2.addVarToWriteRequest(addr.Area, addr.DBNumber, addr.Start, 4, b);
break;
case DataType.FLOAT:

0
SCADA/Program/TagConfig/TagConfig/DataHelper.cs → SCADA/Program/TagConfig/TagConfig/DataConvert.cs

20
SCADA/Program/TagConfig/TagConfig/Form1.cs

@ -33,24 +33,10 @@ namespace TagConfig
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
public enum DataType : byte
{
NONE = 0,
BOOL = 1,
BYTE = 3,
SHORT = 4,
WORD = 5,
TIME = 6,
INT = 7,
FLOAT = 8,
SYS = 9,
STR = 11
}
public static readonly List<DataTypeSource> DataDict = new List<DataTypeSource>
{
new DataTypeSource (1,"开关型"),new DataTypeSource (3,"字节"), new DataTypeSource (4,"短整型"),
new DataTypeSource (5,"单字型"),new DataTypeSource (6,"时间型"),new DataTypeSource (7,"双字型"),
new DataTypeSource (5,"单字型"),new DataTypeSource (6,"双字型"),new DataTypeSource (7,"长整型"),
new DataTypeSource (8,"浮点型"),new DataTypeSource (9,"系统型"),new DataTypeSource (10,"ASCII字符串"),
new DataTypeSource (11,"UNICODE字符串"),new DataTypeSource(0,"")
};
@ -213,7 +199,7 @@ namespace TagConfig
list.Clear();
majorTop.Nodes.Clear();
using (XmlReader reader = XmlTextReader.Create(file))
using (XmlReader reader = XmlReader.Create(file))
{
while (reader.Read())
{
@ -342,7 +328,7 @@ namespace TagConfig
private void SaveToXml(string file)
{
using (var writer = XmlTextWriter.Create(file))
using (var writer = XmlWriter.Create(file))
{
writer.WriteStartDocument();
writer.WriteStartElement("Sever");

2
SCADA/Program/TagConfig/TagConfig/TagConfig.csproj

@ -64,7 +64,7 @@
<DependentUpon>AlarmParam.cs</DependentUpon>
</Compile>
<Compile Include="Condition.cs" />
<Compile Include="DataHelper.cs" />
<Compile Include="DataConvert.cs" />
<Compile Include="ExMethos.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>

BIN
SCADA/dll/ClientDriver.dll

Binary file not shown.

BIN
SCADA/dll/DataHelper.dll

Binary file not shown.

BIN
SCADA/dll/DataService.dll

Binary file not shown.

BIN
SCADA/dll/FileDriver.dll

Binary file not shown.

BIN
SCADA/dll/ModbusDriver.dll

Binary file not shown.

BIN
SCADA/dll/OPCDriver.dll

Binary file not shown.

BIN
SCADA/dll/OmronPlcDriver.dll

Binary file not shown.

BIN
SCADA/dll/PanasonicDriver.dll

Binary file not shown.

BIN
SCADA/dll/SiemensPLCDriver.dll

Binary file not shown.
Loading…
Cancel
Save