using System; using System.IO; using System.Collections.Generic; using Mesnac.Equips.Connection; namespace Mesnac.Equips.BaseInfo { public class CaptionAttribute : Attribute { public CaptionAttribute(string ss) { this.Caption = ss; } public string Caption { get; set; } } /// /// 设置主信息 /// public class Main { private int _readHz = 0; /// /// 设备读取频率更改事件 /// public event EventHandler OnReadHzChange; //定义设备读取频率更改事件 public Main() { this.Equip = null; this.Brand = string.Empty; this.Model = string.Empty; this._readHz = 1000; this.ConnType = new ConnType(); this.UnitLen = 8; } /// /// 设备 /// public BaseEquip Equip { get; set; } /// /// 品牌 /// public string Brand { get; set; } /// /// 型号 /// public string Model { get; set; } /// /// 连接方式 /// public ConnType ConnType { get; set; } /// /// 读取频率 /// public int ReadHz { get { return this._readHz; } set { if (this._readHz != value) { this._readHz = value; if (OnReadHzChange != null) { OnReadHzChange(this, System.EventArgs.Empty); //触发设备读取频率更改事件 } } } } /// /// 字节长度 /// public int UnitLen { get; set; } } /// /// 数据读取块 /// public class Group { public Group() { this.Equip = null; this.Name = string.Empty; this.Remark = string.Empty; this.Block = string.Empty; this.Start = 0; this.Len = 0; this.Access = FileAccess.ReadWrite; this.IsAutoRead = true; this.Value = new string[0]; this.Data = new Dictionary(); } /// /// 设备 /// public BaseEquip Equip { get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 块地址 /// public string Block { get; set; } /// /// 起始地址 /// public int Start { get; set; } /// /// 长度 /// public int Len { get; set; } /// /// 权限 /// public FileAccess Access { get; set; } /// /// 说明 /// public string Remark { get; set; } /// /// 数据 /// public object[] Value { get; set; } /// /// 是否自动读取 /// public bool IsAutoRead { get; set; } /// /// 读取数据信息 /// public Dictionary Data { get; set; } } /// /// 数据信息 /// public class Data { public Data() { this.ReadTime = DateTime.MinValue; this.Group = null; this.Name = string.Empty; this.RunName = string.Empty; this.KeyName = string.Empty; this.Remark = string.Empty; this.Start = 0; this.Len = 0; this.Method = string.Empty; this.Max = string.Empty; this.Subtractor = string.Empty; this.Value = null; this.LastBeforeMathValue = null; this.IsSave = true; } public Group Group { get; set; } /// /// 值读取时间 /// public DateTime ReadTime { get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 别名 系统中使用名称 /// public string RunName { get; set; } /// /// 唯一主键 /// public string KeyName { get; set; } /// /// 起始地址 /// public int Start { get; set; } /// /// 长度 /// public int Len { get; set; } /// /// 处理方法 /// public string Method { get; set; } /// /// 最大值 /// public string Max { get; set; } /// /// 是否进行保存 /// public bool IsSave { get; set; } /// /// 被减数 /// public string Subtractor { get; set; } /// /// 说明 /// public string Remark { get; set; } private object value = null; private void SetValue(object v) { this.value = v; double d = 0; double max = 0; if ((this.value != null) && (double.TryParse(v.ToString(), out d)) && (!string.IsNullOrWhiteSpace(this.Max)) && (double.TryParse(this.Max, out max))) { this.ReadTime = DateTime.Now; if (d > max) { max = 0; if (!string.IsNullOrWhiteSpace(this.Subtractor) && (double.TryParse(this.Subtractor, out max))) { this.value = d - max; } else { this.value = 0; } } } try { if ((this.Group != null) && (this.Group.Equip != null)) { this.Group.Equip.RefreshEventArgsValue(this); } } catch { } } /// /// 数据 /// public object Value { get { return value; } set { SetValue(value); } } public object[] LastBeforeMathValue { get; set; } } }