private void SendPackageSiemens(IDriverAdapter ISiemens, Device dv, DataBlock db) { try { switch (db.DataType) { case "Bit": lock (ISiemens) { bool[] bitRs = ISiemens.Read <bool>($"{db.MemoryType}{db.StartAddress}", db.Length); int length = bitRs.Length; if (bitRs.Length > db.Tags.Count) { length = db.Tags.Count; } for (int j = 0; j < length; j++) { db.Tags[j].Value = bitRs[j]; db.Tags[j].Checked = bitRs[j]; db.Tags[j].Enabled = bitRs[j]; db.Tags[j].Visible = bitRs[j]; db.Tags[j].ValueSelect1 = bitRs[j]; db.Tags[j].ValueSelect2 = bitRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Int": lock (ISiemens) { short[] IntRs = ISiemens.Read <Int16>($"{db.MemoryType}{db.StartAddress}", db.Length); if (IntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < IntRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(IntRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = IntRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DInt": lock (ISiemens) { int[] DIntRs = ISiemens.Read <Int32>($"{db.MemoryType}{db.StartAddress}", db.Length); if (DIntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < DIntRs.Length; j++) { db.Tags[j].Value = DIntRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Word": lock (ISiemens) { var wdRs = ISiemens.Read <UInt16>($"{db.MemoryType}{db.StartAddress}", db.Length); if (wdRs == null) { return; } if (wdRs.Length > db.Tags.Count) { return; } for (int j = 0; j < wdRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(wdRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = wdRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DWord": lock (ISiemens) { uint[] dwRs = ISiemens.Read <UInt32>($"{db.MemoryType}{db.StartAddress}", (ushort)db.Length); for (int j = 0; j < dwRs.Length; j++) { db.Tags[j].Value = dwRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real1": lock (ISiemens) { float[] rl1Rs = ISiemens.Read <float>($"{db.MemoryType}{db.StartAddress}", (ushort)db.Length); for (int j = 0; j < rl1Rs.Length; j++) { db.Tags[j].Value = rl1Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real2": lock (ISiemens) { double[] rl2Rs = ISiemens.Read <double>($"{db.MemoryType}{db.StartAddress}", (ushort)db.Length); for (int j = 0; j < rl2Rs.Length; j++) { db.Tags[j].Value = rl2Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; } } catch (SocketException ex) { Disconnect(); Console.WriteLine(ex.Message); } catch (Exception ex) { Disconnect(); Console.WriteLine(ex.Message); } }
private void SendPackageModbus(IDriverAdapter DriverAdapter, Device dv, DataBlock db) { try { switch (db.DataType) { case "Bit": lock (DriverAdapter) { bool[] bitRs = DriverAdapter.Read <bool>($"{db.StartAddress}", db.Length); int length = bitRs.Length; if (bitRs.Length > db.Tags.Count) { length = db.Tags.Count; } for (int j = 0; j < length; j++) { db.Tags[j].Value = bitRs[j]; db.Tags[j].Checked = bitRs[j]; db.Tags[j].Enabled = bitRs[j]; db.Tags[j].Visible = bitRs[j]; db.Tags[j].ValueSelect1 = bitRs[j]; db.Tags[j].ValueSelect2 = bitRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Int": lock (DriverAdapter) { short[] IntRs = DriverAdapter.Read <Int16>($"{db.StartAddress}", db.Length); if (IntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < IntRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(IntRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = IntRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DInt": lock (DriverAdapter) { int[] DIntRs = DriverAdapter.Read <Int32>(string.Format("{0}", db.StartAddress), db.Length); if (DIntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < DIntRs.Length; j++) { db.Tags[j].Value = DIntRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Word": lock (DriverAdapter) { var wdRs = DriverAdapter.Read <UInt16>($"{db.StartAddress}", db.Length); if (wdRs == null) { return; } if (wdRs.Length > db.Tags.Count) { return; } for (int j = 0; j < wdRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(wdRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = wdRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DWord": lock (DriverAdapter) { uint[] dwRs = DriverAdapter.Read <UInt32>(string.Format("{0}", db.StartAddress), (ushort)db.Length); for (int j = 0; j < dwRs.Length; j++) { db.Tags[j].Value = dwRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real1": lock (DriverAdapter) { float[] rl1Rs = DriverAdapter.Read <float>(string.Format("{0}", db.StartAddress), (ushort)db.Length); for (int j = 0; j < rl1Rs.Length; j++) { db.Tags[j].Value = rl1Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real2": lock (DriverAdapter) { double[] rl2Rs = DriverAdapter.Read <double>(string.Format("{0}", db.StartAddress), (ushort)db.Length); for (int j = 0; j < rl2Rs.Length; j++) { db.Tags[j].Value = rl2Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; } } catch (SocketException ex) { Disconnect(); EventscadaException?.Invoke(this.GetType().Name, ex.Message); } catch (Exception ex) { Disconnect(); EventscadaException?.Invoke(this.GetType().Name, ex.Message); } }
private void SendPackageLSIS(IDriverAdapter ILSIS, Channel ch, Device dv, DataBlock db) { try { switch (db.DataType) { case "Bit": byte[] bitArys = null; lock (ILSIS) bitArys = ILSIS.BuildReadByte((byte)dv.SlaveId, $"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", (ushort)(2 * db.Length)); if (bitArys == null || bitArys.Length == 0) { return; } var bitRs = HslCommunication.BasicFramework.SoftBasic.ByteToBoolArray(bitArys); if (bitRs.Length > db.Tags.Count) { return; } for (var j = 0; j <= db.Tags.Count - 1; j++) { db.Tags[j].Value = bitRs[j]; db.Tags[j].Visible = bitRs[j]; db.Tags[j].Enabled = bitRs[j]; db.Tags[j].Timestamp = DateTime.Now; } break; case "Int": lock (ILSIS) { short[] IntRs = ILSIS.Read <Int16>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", db.Length); if (IntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < IntRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(IntRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = IntRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DInt": lock (ILSIS) { int[] DIntRs = ILSIS.Read <Int32>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", db.Length); if (DIntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < DIntRs.Length; j++) { db.Tags[j].Value = DIntRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Word": lock (ILSIS) { var wdRs = ILSIS.Read <Int16>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", db.Length); if (wdRs == null) { return; } if (wdRs.Length > db.Tags.Count) { return; } for (int j = 0; j < wdRs.Length; j++) { if (db.Tags[j].IsScaled) { db.Tags[j].Value = Util.Interpolation(wdRs[j], db.Tags[j].AImin, db.Tags[j].AImax, db.Tags[j].RLmin, db.Tags[j].RLmax); } else { db.Tags[j].Value = wdRs[j]; } db.Tags[j].Timestamp = DateTime.Now; } } break; case "DWord": lock (ILSIS) { uint[] dwRs = ILSIS.Read <UInt32>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", (ushort)db.Length); for (int j = 0; j < dwRs.Length; j++) { db.Tags[j].Value = dwRs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real1": lock (ILSIS) { float[] rl1Rs = ILSIS.Read <float>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", (ushort)db.Length); for (int j = 0; j < rl1Rs.Length; j++) { db.Tags[j].Value = rl1Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; case "Real2": lock (ILSIS) { double[] rl2Rs = ILSIS.Read <double>($"{db.MemoryType.Substring(0, 1)}{2 * db.StartAddress}", (ushort)db.Length); for (int j = 0; j < rl2Rs.Length; j++) { db.Tags[j].Value = rl2Rs[j]; db.Tags[j].Timestamp = DateTime.Now; } } break; } } catch (SocketException ex) { Disconnect(); if (ex.Message == "Hex Character Count Not Even") { return; } IsConnected = false; EventscadaException?.Invoke(this.GetType().Name, ex.Message); } catch (Exception ex) { Disconnect(); Console.WriteLine(ex.Message); } }
private void SendPackageLSIS(IDriverAdapter DriverAdapter, DataBlock db) { try { SendDone.WaitOne(-1); int baseAddress = db.StartAddress; switch (db.DataType) { case DataTypes.BitOnByte: baseAddress = ((db.StartAddress >= 2) ? (db.StartAddress / 2) : 0) * 2; break; case DataTypes.BitOnWord: baseAddress = db.StartAddress * 2; break; case DataTypes.Bit when db.IsArray: // baseAddress = ((db.StartAddress >= 16) ? (db.StartAddress / 16) : 0) * 2; baseAddress = db.StartAddress * 2; break; case DataTypes.Byte: baseAddress = db.StartAddress; break; case DataTypes.Short: case DataTypes.UShort: baseAddress = db.StartAddress * 2; break; case DataTypes.Int: case DataTypes.UInt: baseAddress = db.StartAddress * 4; break; case DataTypes.Long: case DataTypes.ULong: baseAddress = db.StartAddress * 8; break; case DataTypes.Float: baseAddress = db.StartAddress * 4; break; case DataTypes.Double: baseAddress = db.StartAddress * 8; break; } switch (db.DataType) { case DataTypes.BitOnByte: case DataTypes.BitOnWord: lock (DriverAdapter) { bool[] bitArys2 = DriverAdapter.Read <bool>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", (ushort)(2 * db.Length)); if (bitArys2 == null || bitArys2.Length == 0) { return; } if (bitArys2.Length > db.Tags.Count) { return; } for (int j = 0; j <= db.Tags.Count - 1; j++) { db.Tags[j].Value = bitArys2[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.Bit: bool[] bitArys = null; if (db.IsArray) { lock (DriverAdapter) { bitArys = DriverAdapter.Read <bool>($"{db.MemoryType.Substring(0, 1)}{ baseAddress}", (ushort)(2 * db.Length)); if (bitArys == null || bitArys.Length == 0) { return; } if (bitArys.Length > db.Tags.Count) { return; } for (int j = 0; j <= db.Tags.Count - 1; j++) { db.Tags[j].Value = bitArys[j]; db.Tags[j].TimeSpan = DateTime.Now; } } } else { lock (DriverAdapter) { bitArys = new bool[db.Tags.Count]; for (int i = 0; i < db.Tags.Count; i++) { bitArys[i] = DriverAdapter.Read <bool>(db.Tags[i].Address); if (bitArys == null || bitArys.Length == 0) { return; } db.Tags[i].Value = bitArys[i]; db.Tags[i].TimeSpan = DateTime.Now; } } } break; case DataTypes.Byte: lock (DriverAdapter) { byte[] byteArys = null; if (db.IsArray) { byteArys = DriverAdapter.Read <byte>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", (ushort)(2 * db.Length)); if (byteArys == null || byteArys.Length == 0) { return; } if (byteArys.Length > db.Tags.Count) { return; } for (int j = 0; j <= db.Tags.Count - 1; j++) { db.Tags[j].Value = byteArys[j]; db.Tags[j].TimeSpan = DateTime.Now; } } else { lock (DriverAdapter) { byteArys = new byte[db.Tags.Count]; for (int i = 0; i < db.Tags.Count; i++) { byteArys[i] = DriverAdapter.Read <byte>(db.Tags[i].Address); if (byteArys == null || byteArys.Length == 0) { return; } db.Tags[i].Value = byteArys[i]; db.Tags[i].TimeSpan = DateTime.Now; } } } } break; case DataTypes.Short: lock (DriverAdapter) { short[] IntRs = null; if (db.IsArray) { IntRs = DriverAdapter.Read <short>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (IntRs == null || IntRs.Length == 0) { return; } if (IntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < IntRs.Length; j++) { db.Tags[j].Value = IntRs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } else { lock (DriverAdapter) { IntRs = new short[db.Tags.Count]; for (int i = 0; i < db.Tags.Count; i++) { IntRs[i] = DriverAdapter.Read <short>(db.Tags[i].Address); if (IntRs == null || IntRs.Length == 0) { return; } db.Tags[i].Value = IntRs[i]; db.Tags[i].TimeSpan = DateTime.Now; } } } } break; case DataTypes.UShort: lock (DriverAdapter) { ushort[] ushortArys = DriverAdapter.Read <ushort>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (ushortArys == null || ushortArys.Length == 0) { return; } if (ushortArys.Length > db.Tags.Count) { return; } for (int j = 0; j <= db.Tags.Count - 1; j++) { db.Tags[j].Value = ushortArys[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.Int: lock (DriverAdapter) { int[] DIntRs = DriverAdapter.Read <int>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (DIntRs == null || DIntRs.Length == 0) { return; } if (DIntRs.Length > db.Tags.Count) { return; } for (int j = 0; j < DIntRs.Length; j++) { db.Tags[j].Value = DIntRs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.UInt: lock (DriverAdapter) { uint[] wdRs = DriverAdapter.Read <uint>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (wdRs == null || wdRs.Length == 0) { return; } if (wdRs.Length > db.Tags.Count) { return; } for (int j = 0; j < db.Tags.Count; j++) { db.Tags[j].Value = wdRs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.Long: lock (DriverAdapter) { long[] dwRs = DriverAdapter.Read <long>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (dwRs == null || dwRs.Length == 0) { return; } if (dwRs.Length > db.Tags.Count) { return; } for (int j = 0; j < dwRs.Length; j++) { db.Tags[j].Value = dwRs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.ULong: lock (DriverAdapter) { ulong[] dwRs = DriverAdapter.Read <ulong>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (dwRs == null || dwRs.Length == 0) { return; } if (dwRs.Length > db.Tags.Count) { return; } for (int j = 0; j < dwRs.Length; j++) { db.Tags[j].Value = dwRs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.Float: lock (DriverAdapter) { float[] rl1Rs = DriverAdapter.Read <float>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (rl1Rs == null || rl1Rs.Length == 0) { return; } if (rl1Rs.Length > db.Tags.Count) { return; } for (int j = 0; j < rl1Rs.Length; j++) { db.Tags[j].Value = rl1Rs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.Double: lock (DriverAdapter) { double[] rl2Rs = DriverAdapter.Read <double>($"{db.MemoryType.Substring(0, 1)}{baseAddress}", db.Length); if (rl2Rs == null || rl2Rs.Length == 0) { return; } if (rl2Rs.Length > db.Tags.Count) { return; } for (int j = 0; j < rl2Rs.Length; j++) { db.Tags[j].Value = rl2Rs[j]; db.Tags[j].TimeSpan = DateTime.Now; } } break; case DataTypes.String: break; default: break; } } catch (Exception ex) { Disconnect(); EventscadaException?.Invoke(GetType().Name, ex.Message); } }