diff --git a/SCADA/Example/BatchCoreTest.exe b/SCADA/Example/BatchCoreTest.exe index fdf3269..ed0bd75 100644 Binary files a/SCADA/Example/BatchCoreTest.exe and b/SCADA/Example/BatchCoreTest.exe differ diff --git a/SCADA/Example/ClientDriver.dll b/SCADA/Example/ClientDriver.dll index 884dd00..0170bb3 100644 Binary files a/SCADA/Example/ClientDriver.dll and b/SCADA/Example/ClientDriver.dll differ diff --git a/SCADA/Example/CoreTest.exe b/SCADA/Example/CoreTest.exe index af2f8af..016e451 100644 Binary files a/SCADA/Example/CoreTest.exe and b/SCADA/Example/CoreTest.exe differ diff --git a/SCADA/Example/DataHelper.dll b/SCADA/Example/DataHelper.dll index 6e01c14..7b08c9d 100644 Binary files a/SCADA/Example/DataHelper.dll and b/SCADA/Example/DataHelper.dll differ diff --git a/SCADA/Example/DataService.dll b/SCADA/Example/DataService.dll index 89c63d2..9e04b1c 100644 Binary files a/SCADA/Example/DataService.dll and b/SCADA/Example/DataService.dll differ diff --git a/SCADA/Example/HMIControl.dll b/SCADA/Example/HMIControl.dll index eb263b5..9f47c60 100644 Binary files a/SCADA/Example/HMIControl.dll and b/SCADA/Example/HMIControl.dll differ diff --git a/SCADA/Example/TagConfig.exe b/SCADA/Example/TagConfig.exe index 8d818eb..29529e5 100644 Binary files a/SCADA/Example/TagConfig.exe and b/SCADA/Example/TagConfig.exe differ diff --git a/SCADA/Program/BatchCoreService/DAService.cs b/SCADA/Program/BatchCoreService/DAService.cs index 5559a68..ddc76b3 100644 --- a/SCADA/Program/BatchCoreService/DAService.cs +++ b/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; diff --git a/SCADA/Program/BatchCoreService/SqlMapping.cs b/SCADA/Program/BatchCoreService/SqlMapping.cs index c7a9ec8..ebffebe 100644 --- a/SCADA/Program/BatchCoreService/SqlMapping.cs +++ b/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: diff --git a/SCADA/Program/ClientDriver/ClientDriver.cs b/SCADA/Program/ClientDriver/ClientDriver.cs index f80f146..d4cd9a2 100644 --- a/SCADA/Program/ClientDriver/ClientDriver.cs +++ b/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(BitConverter.ToInt32(data, 0), 0, QUALITIES.QUALITY_GOOD); } + public ItemData ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache) + { + var data = ReadSingleData(address, source); + return data == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : + new ItemData(BitConverter.ToUInt32(data, 0), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache) + { + var data = ReadSingleData(address, source); + return data == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : + new ItemData(BitConverter.ToUInt16(data, 0), 0, QUALITIES.QUALITY_GOOD); + } + public ItemData 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)); diff --git a/SCADA/Program/CoreTest/ClientService.cs b/SCADA/Program/CoreTest/ClientService.cs index 3ee99b1..eae693b 100644 --- a/SCADA/Program/CoreTest/ClientService.cs +++ b/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: diff --git a/SCADA/Program/CoreTest/WindowHelper.cs b/SCADA/Program/CoreTest/WindowHelper.cs index 5e99814..9af7f82 100644 --- a/SCADA/Program/CoreTest/WindowHelper.cs +++ b/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; diff --git a/SCADA/Program/DataHelper/HDAIOHelper.cs b/SCADA/Program/DataHelper/HDAIOHelper.cs index b0bd0fe..9538e31 100644 --- a/SCADA/Program/DataHelper/HDAIOHelper.cs +++ b/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; diff --git a/SCADA/Program/DataService/CacheReader.cs b/SCADA/Program/DataService/CacheReader.cs index e8eb183..6ce7370 100644 --- a/SCADA/Program/DataService/CacheReader.cs +++ b/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 ReadBit(DeviceAddress address) + { + return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) { return new ItemData(BitConverter.ToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); } - public ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData(BitConverter.ToUInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData(BitConverter.ToUInt16(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); } public ItemData 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 ReadBit(DeviceAddress address) + { + return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) { return new ItemData(Utility.NetToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); } - public ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData((uint)Utility.NetToInt32(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData((ushort)Utility.NetToInt16(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD); } public ItemData 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 ReadBit(DeviceAddress address) + { + return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) { int startIndex = address.CacheIndex; @@ -333,9 +394,9 @@ namespace DataService return new ItemData(result, 0, QUALITIES.QUALITY_GOOD); } - public unsafe ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData((uint)ReadInt32(address).Value, 0, QUALITIES.QUALITY_GOOD); } public ItemData ReadInt16(DeviceAddress address) @@ -343,6 +404,11 @@ namespace DataService return new ItemData(_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); } + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadByte(DeviceAddress address) { return new ItemData((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 ReadBit(DeviceAddress address) + { + return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) { int startIndex = address.CacheIndex; @@ -501,9 +587,14 @@ namespace DataService return new ItemData(result, 0, QUALITIES.QUALITY_GOOD); } - public unsafe ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData((uint)ReadInt32(address).Value, 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData((ushort)IPAddress.HostToNetworkOrder(_cache[address.CacheIndex]), 0, QUALITIES.QUALITY_GOOD); } public ItemData 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 ReadInt32(DeviceAddress address) + public unsafe ItemData ReadBit(DeviceAddress address) { + return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) + { return new ItemData(_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); } - public unsafe ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData((uint)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); } public ItemData 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 ReadBit(DeviceAddress address) + { + return new ItemData(((int)_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData ReadInt32(DeviceAddress address) { return new ItemData((int)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); } - public unsafe ItemData ReadBit(DeviceAddress address) + public ItemData ReadUInt32(DeviceAddress address) { - return new ItemData(((int)_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD); + return new ItemData((uint)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + return new ItemData((ushort)_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD); } public ItemData 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; diff --git a/SCADA/Program/DataService/Enums.cs b/SCADA/Program/DataService/Enums.cs index ce7b7c1..b1accd5 100644 --- a/SCADA/Program/DataService/Enums.cs +++ b/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, + } } diff --git a/SCADA/Program/DataService/Eval.cs b/SCADA/Program/DataService/Eval.cs index 14cb0eb..c731b08 100644 --- a/SCADA/Program/DataService/Eval.cs +++ b/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: diff --git a/SCADA/Program/DataService/ExtensionMethods.cs b/SCADA/Program/DataService/ExtensionMethods.cs index 24b0cd4..7c18827 100644 --- a/SCADA/Program/DataService/ExtensionMethods.cs +++ b/SCADA/Program/DataService/ExtensionMethods.cs @@ -115,10 +115,14 @@ namespace DataService var bt = reader.ReadByte(address); return new ItemData(bt.Value, bt.TimeStamp, bt.Quality); case DataType.WORD: + var ush = reader.ReadUInt16(address); + return new ItemData(ush.Value, ush.TimeStamp, ush.Quality); case DataType.SHORT: var sh = reader.ReadInt16(address); return new ItemData(sh.Value, sh.TimeStamp, sh.Quality); - case DataType.TIME: + case DataType.DWORD: + var dw = reader.ReadUInt32(address); + return new ItemData(dw.Value, dw.TimeStamp, dw.Quality); case DataType.INT: var it = reader.ReadInt32(address); return new ItemData(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; diff --git a/SCADA/Program/DataService/IGroup.cs b/SCADA/Program/DataService/IGroup.cs index a3928d4..61959c8 100644 --- a/SCADA/Program/DataService/IGroup.cs +++ b/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 items, bool isSync = true); + ItemData ReadInt32(DeviceAddress address, DataSource source = DataSource.Cache); + ItemData ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache); ItemData ReadInt16(DeviceAddress address, DataSource source = DataSource.Cache); + ItemData ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache); ItemData ReadByte(DeviceAddress address, DataSource source = DataSource.Cache); ItemData ReadFloat(DeviceAddress address, DataSource source = DataSource.Cache); ItemData ReadBool(DeviceAddress address, DataSource source = DataSource.Cache); ItemData 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; } diff --git a/SCADA/Program/DataService/IReader.cs b/SCADA/Program/DataService/IReader.cs index 2e28be0..bf37777 100644 --- a/SCADA/Program/DataService/IReader.cs +++ b/SCADA/Program/DataService/IReader.cs @@ -6,7 +6,9 @@ namespace DataService public interface IReaderWriter { byte[] ReadBytes(DeviceAddress address, ushort size); + ItemData ReadUInt32(DeviceAddress address); ItemData ReadInt32(DeviceAddress address); + ItemData ReadUInt16(DeviceAddress address); ItemData ReadInt16(DeviceAddress address); ItemData ReadByte(DeviceAddress address); ItemData 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); diff --git a/SCADA/Program/DataService/ITag.cs b/SCADA/Program/DataService/ITag.cs index f9f314d..98174d3 100644 --- a/SCADA/Program/DataService/ITag.cs +++ b/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(_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(_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 { diff --git a/SCADA/Program/DataService/PLCGroup.cs b/SCADA/Program/DataService/PLCGroup.cs index a125ae2..f0a0e61 100644 --- a/SCADA/Program/DataService/PLCGroup.cs +++ b/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 ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache) + { + return source == DataSource.Cache ? _cacheReader.ReadUInt32(address) : _plcReader.ReadUInt32(address); + } + + public ItemData ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache) + { + return source == DataSource.Cache ? _cacheReader.ReadUInt16(address) : _plcReader.ReadUInt16(address); + } + public ItemData 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); diff --git a/SCADA/Program/DataService/Storage.cs b/SCADA/Program/DataService/Storage.cs index 1c2df0b..7c57c8b 100644 --- a/SCADA/Program/DataService/Storage.cs +++ b/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, - } } \ No newline at end of file diff --git a/SCADA/Program/FileDriver/DatabaseDriver.cs b/SCADA/Program/FileDriver/DatabaseDriver.cs index 30eab47..80f566b 100644 --- a/SCADA/Program/FileDriver/DatabaseDriver.cs +++ b/SCADA/Program/FileDriver/DatabaseDriver.cs @@ -245,6 +245,18 @@ namespace FileDriver return data; } + public ItemData ReadUInt32(DeviceAddress address) + { + var res = ReadInt32(address); + return new ItemData((uint)res.Value, res.TimeStamp, res.Quality); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + var res = ReadInt16(address); + return new ItemData((ushort)res.Value, res.TimeStamp, res.Quality); + } + public ItemData ReadInt16(DeviceAddress address) { ItemData data = new ItemData(); @@ -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; diff --git a/SCADA/Program/FileDriver/FileDeviceGroup.cs b/SCADA/Program/FileDriver/FileDeviceGroup.cs index f24b741..01b1e43 100644 --- a/SCADA/Program/FileDriver/FileDeviceGroup.cs +++ b/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 ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache) + { + if (source == DataSource.Device) return _fileReader.ReadUInt32(address); + else + { + ITag tag = _items[address.Start]; + return new ItemData(tag.Value.DWord, 0, tag.Quality); + } + } + + public ItemData ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache) + { + if (source == DataSource.Device) return _fileReader.ReadUInt16(address); + else + { + ITag tag = _items[address.Start]; + return new ItemData(tag.Value.Word, 0, tag.Quality); + } + } + public ItemData 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; } - } diff --git a/SCADA/Program/FileDriver/MemoryDriver.cs b/SCADA/Program/FileDriver/MemoryDriver.cs index 61ddecd..f0cc6af 100644 --- a/SCADA/Program/FileDriver/MemoryDriver.cs +++ b/SCADA/Program/FileDriver/MemoryDriver.cs @@ -263,6 +263,24 @@ namespace FileDriver catch { return new ItemData(0, 0, QUALITIES.QUALITY_BAD); } } + public ItemData ReadUInt32(DeviceAddress address) + { + try + { + return new ItemData(accessor.ReadUInt32(FindPosition(address)), 0, QUALITIES.QUALITY_GOOD); + } + catch { return new ItemData(0, 0, QUALITIES.QUALITY_BAD); } + } + + public ItemData ReadUInt16(DeviceAddress address) + { + try + { + return new ItemData(accessor.ReadUInt16(FindPosition(address)), 0, QUALITIES.QUALITY_GOOD); + } + catch { return new ItemData(0, 0, QUALITIES.QUALITY_BAD); } + } + public ItemData 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; diff --git a/SCADA/Program/FileDriver/TagDriver.cs b/SCADA/Program/FileDriver/TagDriver.cs index 5457df0..4f731de 100644 --- a/SCADA/Program/FileDriver/TagDriver.cs +++ b/SCADA/Program/FileDriver/TagDriver.cs @@ -130,6 +130,18 @@ namespace FileDriver return tag == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : new ItemData(tag.Value.Int32, 0, QUALITIES.QUALITY_GOOD); } + public ItemData ReadUInt32(DeviceAddress address) + { + var tag = _parent[(short)address.CacheIndex]; + return tag == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : new ItemData(tag.Value.DWord, 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + var tag = _parent[(short)address.CacheIndex]; + return tag == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : new ItemData(tag.Value.Word, 0, QUALITIES.QUALITY_GOOD); + } + public ItemData 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; diff --git a/SCADA/Program/ModbusDriver/ModbusRTUDriver.cs b/SCADA/Program/ModbusDriver/ModbusRTUDriver.cs index 4c856ba..637ac97 100644 --- a/SCADA/Program/ModbusDriver/ModbusRTUDriver.cs +++ b/SCADA/Program/ModbusDriver/ModbusRTUDriver.cs @@ -348,11 +348,25 @@ namespace ModbusDriver public ItemData ReadInt32(DeviceAddress address) { - byte[] bit = ReadBytes(address, 2); + byte[] bit = ReadBytes(address, 4); return bit == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : new ItemData(BitConverter.ToInt32(bit, 0), 0, QUALITIES.QUALITY_GOOD); } + public ItemData ReadUInt32(DeviceAddress address) + { + byte[] bit = ReadBytes(address, 4); + return bit == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : + new ItemData(BitConverter.ToUInt32(bit, 0), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + byte[] bit = ReadBytes(address, 1); + return bit == null ? new ItemData(0, 0, QUALITIES.QUALITY_BAD) : + new ItemData(BitConverter.ToUInt16(bit, 0), 0, QUALITIES.QUALITY_GOOD); + } + public ItemData 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)); diff --git a/SCADA/Program/ModbusDriver/ModbusTCPDriver.cs b/SCADA/Program/ModbusDriver/ModbusTCPDriver.cs index a40c1d7..71d5d37 100644 --- a/SCADA/Program/ModbusDriver/ModbusTCPDriver.cs +++ b/SCADA/Program/ModbusDriver/ModbusTCPDriver.cs @@ -419,6 +419,24 @@ namespace ModbusDriver return new ItemData(IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD); } + public ItemData ReadUInt32(DeviceAddress address) + { + byte[] data = WriteSyncData(CreateReadHeader(address.Area, address.Start, 2, (byte)address.DBNumber)); + if (data == null) + return new ItemData(0, 0, QUALITIES.QUALITY_BAD); + else + return new ItemData((uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + byte[] data = WriteSyncData(CreateReadHeader(address.Area, address.Start, 1, (byte)address.DBNumber)); + if (data == null) + return new ItemData(0, 0, QUALITIES.QUALITY_BAD); + else + return new ItemData((ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(data, 0)), 0, QUALITIES.QUALITY_GOOD); + } + public ItemData 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))); diff --git a/SCADA/Program/OPCDriver/OPCDriver.cs b/SCADA/Program/OPCDriver/OPCDriver.cs index d3e7ed7..c2cccd5 100644 --- a/SCADA/Program/OPCDriver/OPCDriver.cs +++ b/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 ReadUInt32(DeviceAddress address, DataSource source = DataSource.Cache) + { + var rt = ReadInt32(address, source); + return new ItemData((uint)rt.Value, rt.TimeStamp, rt.Quality); + } + + public ItemData ReadUInt16(DeviceAddress address, DataSource source = DataSource.Cache) + { + var rt = ReadInt16(address, source); + return new ItemData((ushort)rt.Value, rt.TimeStamp, rt.Quality); + } + public ItemData 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; diff --git a/SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj b/SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj index ae3c4d3..00a9621 100644 --- a/SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj +++ b/SCADA/Program/OmronPlcDriver/OmronPlcDriver.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + true diff --git a/SCADA/Program/OmronPlcDriver/OmronUdpReader.cs b/SCADA/Program/OmronPlcDriver/OmronUdpReader.cs index e77745b..39b81d0 100644 --- a/SCADA/Program/OmronPlcDriver/OmronUdpReader.cs +++ b/SCADA/Program/OmronPlcDriver/OmronUdpReader.cs @@ -534,6 +534,24 @@ namespace OmronPlcDriver else return new ItemData(IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD); } + + public ItemData ReadUInt32(DeviceAddress address) + { + byte[] data = WriteSyncData(CreateReadHeader(PcNodeId, address.Start, 2, (byte)address.DBNumber, (byte)address.Area)); + if (data == null) + return new ItemData(0, 0, QUALITIES.QUALITY_BAD); + else + return new ItemData((uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(data, 0)), 0, QUALITIES.QUALITY_GOOD); + } + + public ItemData ReadUInt16(DeviceAddress address) + { + byte[] data = WriteSyncData(CreateReadHeader(PcNodeId, address.Start, 1, (byte)address.DBNumber, (byte)address.Area)); + if (data == null) + return new ItemData(0, 0, QUALITIES.QUALITY_BAD); + else + return new ItemData((ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(data, 0)), 0, QUALITIES.QUALITY_GOOD); + } /// /// 读取16位整数 /// @@ -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); diff --git a/SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs b/SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs index 082eb3f..343b486 100644 --- a/SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs +++ b/SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs @@ -436,6 +436,10 @@ namespace PanasonicPLCriver { throw new NotImplementedException(); } + public ItemData ReadUInt16(DeviceAddress address) + { + throw new NotImplementedException(); + } /// /// 读取一个32位数 返回如果是6300 则认为是0063H 高低位要反 而且是16进账 /// @@ -444,6 +448,10 @@ namespace PanasonicPLCriver { throw new NotImplementedException(); } + public ItemData ReadUInt32(DeviceAddress address) + { + throw new NotImplementedException(); + } public ItemData[] 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(); diff --git a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs b/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs index f09e4fe..5751351 100644 --- a/SCADA/Program/SiemensPLCDriver/SiemensPLCDriver.cs +++ b/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(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ; } + public ItemData 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)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(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ; + } + + public ItemData 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)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(0, 0, QUALITIES.QUALITY_NOT_CONNECTED); ; + } + public ItemData 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: diff --git a/SCADA/Program/TagConfig/TagConfig/DataHelper.cs b/SCADA/Program/TagConfig/TagConfig/DataConvert.cs similarity index 100% rename from SCADA/Program/TagConfig/TagConfig/DataHelper.cs rename to SCADA/Program/TagConfig/TagConfig/DataConvert.cs diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.cs b/SCADA/Program/TagConfig/TagConfig/Form1.cs index 1a73d17..e42d61c 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.cs +++ b/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 DataDict = new List { 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"); diff --git a/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj b/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj index ce509ab..5e27d3a 100644 --- a/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj +++ b/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj @@ -64,7 +64,7 @@ AlarmParam.cs - + Form diff --git a/SCADA/dll/ClientDriver.dll b/SCADA/dll/ClientDriver.dll index 3f3ff77..d7304ae 100644 Binary files a/SCADA/dll/ClientDriver.dll and b/SCADA/dll/ClientDriver.dll differ diff --git a/SCADA/dll/DataHelper.dll b/SCADA/dll/DataHelper.dll index 6d9e6ac..45761cf 100644 Binary files a/SCADA/dll/DataHelper.dll and b/SCADA/dll/DataHelper.dll differ diff --git a/SCADA/dll/DataService.dll b/SCADA/dll/DataService.dll index 63c7cfb..a45dc37 100644 Binary files a/SCADA/dll/DataService.dll and b/SCADA/dll/DataService.dll differ diff --git a/SCADA/dll/FileDriver.dll b/SCADA/dll/FileDriver.dll index f2b4cca..7b44f9c 100644 Binary files a/SCADA/dll/FileDriver.dll and b/SCADA/dll/FileDriver.dll differ diff --git a/SCADA/dll/ModbusDriver.dll b/SCADA/dll/ModbusDriver.dll index 55f70f8..f316ef7 100644 Binary files a/SCADA/dll/ModbusDriver.dll and b/SCADA/dll/ModbusDriver.dll differ diff --git a/SCADA/dll/OPCDriver.dll b/SCADA/dll/OPCDriver.dll index 4084950..8e1a213 100644 Binary files a/SCADA/dll/OPCDriver.dll and b/SCADA/dll/OPCDriver.dll differ diff --git a/SCADA/dll/OmronPlcDriver.dll b/SCADA/dll/OmronPlcDriver.dll index 2f60ff3..f17e2f7 100644 Binary files a/SCADA/dll/OmronPlcDriver.dll and b/SCADA/dll/OmronPlcDriver.dll differ diff --git a/SCADA/dll/PanasonicDriver.dll b/SCADA/dll/PanasonicDriver.dll index 9b7797c..b66894e 100644 Binary files a/SCADA/dll/PanasonicDriver.dll and b/SCADA/dll/PanasonicDriver.dll differ diff --git a/SCADA/dll/SiemensPLCDriver.dll b/SCADA/dll/SiemensPLCDriver.dll index f4b0759..0794a6c 100644 Binary files a/SCADA/dll/SiemensPLCDriver.dll and b/SCADA/dll/SiemensPLCDriver.dll differ