using FLY.FeedbackRenZiJia.Common; using FLY.FeedbackRenZiJia.IService; using FLY.FeedbackRenZiJia.OBJ_INTERFACE; using FObjBase; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace FLY.FeedbackRenZiJia.Client { public class HeatBufServiceClient : FObj, IHeatBuf { IFConn mConn; UInt32 mServerID; #region 属性,对外接口 #region 参数 private List heatEffectCurve = new List(); /// /// 加热生效曲线,允许为空,则不生效 /// public List HeatEffectCurve { get { return heatEffectCurve; } set { heatEffectCurve = value; NotifyPropertyChanged("HeatEffectCurve"); } } private int stablerange = 2; /// /// 厚度稳定范围 %, 偏差在范围内,都是稳定的 /// public int StableRange { get { return stablerange; } set { if (stablerange != value) { stablerange = value; NotifyPropertyChanged("StableRange"); } } } private int stablerange0 = 2; /// /// 厚度稳定范围 %, 加热量变化为0时,偏差在范围内,都是稳定的 /// public int StableRange0 { get { return stablerange0; } set { if (stablerange0 != value) { stablerange0 = value; NotifyPropertyChanged("StableRange0"); } } } private double thresholdR = 0.7; /// /// 对位模式, 加热与厚度相关性阀值, 相关性 >=0.7 /// public double ThresholdR { get { return thresholdR; } set { if (thresholdR != value) { thresholdR = value; NotifyPropertyChanged("ThresholdR"); } } } private int thresholdMaxMin = 8; /// /// 对位模式 厚度%差 的极差 >= +4%-4%=8%, 单位% /// public int ThresholdMaxMin { get { return thresholdMaxMin; } set { if (thresholdMaxMin != value) { thresholdMaxMin = value; NotifyPropertyChanged("ThresholdMaxMin"); } } } private int thresholdSigmaMax = 20; /// /// % /// 最大sigma, 只有当前的sigma 在 最大sigma 与 最小 sigma 内,才能控制 /// public int ThresholdSigmaMax { get { return thresholdSigmaMax; } set { if (thresholdSigmaMax != value) { thresholdSigmaMax = value; NotifyPropertyChanged("ThresholdSigmaMax"); } } } private double thresholdSigmaMin = 2; /// /// % /// 最小sigma, 只有当前的sigma 在 最大sigma 与 最小 sigma 内,才能控制 /// public double ThresholdSigmaMin { get { return thresholdSigmaMin; } set { if (thresholdSigmaMin != value) { thresholdSigmaMin = value; NotifyPropertyChanged("ThresholdSigmaMin"); } } } private bool isUsedKp = false; /// /// 使用这里独立的Kp, 与 HeatCell 不一样 /// public bool IsUsedLocalKp { get { return isUsedKp; } set { if (isUsedKp != value) { isUsedKp = value; NotifyPropertyChanged("IsUsedLocalKp"); } } } private double localkp = 3; /// /// 本地Kp, 用于判断稳定性 /// public double LocalKp { get { return localkp; } set { if (localkp != value) { localkp = value; NotifyPropertyChanged("LocalKp"); } } } #endregion #region 状态 private TimeSpan delay = TimeSpan.FromSeconds(100); /// /// 总延时 =Delay+mRenZiJiaService.FilmLength/mRenZiJiaService.Velocity /// public TimeSpan Delay { get { return delay; } set { if (delay != value) { delay = value; NotifyPropertyChanged("Delay"); } } } #region 对位 private bool isIntoAutoONo = false; /// /// 进入了对位模式 /// public bool IsIntoAutoONo { get { return isIntoAutoONo; } set { if (isIntoAutoONo != value) { isIntoAutoONo = value; NotifyPropertyChanged("IsIntoAutoONo"); } } } private EAutoONoResult autoONoResult = EAutoONoResult.Idle; /// /// 对位模式结果 /// public EAutoONoResult AutoONoResult { get { return autoONoResult; } set { if (autoONoResult != value) { autoONoResult = value; NotifyPropertyChanged("AutoONoResult"); } } } private int bestOrgBoltNo = -1; /// /// 计算的最佳复位区号 /// public int BestOrgBoltNo { get { return bestOrgBoltNo; } set { if (bestOrgBoltNo != value) { bestOrgBoltNo = value; NotifyPropertyChanged("BestOrgBoltNo"); } } } private double bestkp = -1; /// /// 计算的最佳复位区号 对应的 加热/厚度 /// public double BestKp { get { return bestkp; } set { if (bestkp != value) { bestkp = value; NotifyPropertyChanged("BestKp"); } } } private double maxR = -1; /// /// 计算的最佳复位区号 对应的 加热与厚度相关性 /// public double MaxR { get { return maxR; } set { if (maxR != value) { maxR = value; NotifyPropertyChanged("MaxR"); } } } private double maxmin = -1; /// /// 计算的最佳复位区号 对应的 厚度%变化极差 单位% /// public double MaxMin { get { return maxmin; } set { if (maxmin != value) { maxmin = value; NotifyPropertyChanged("MaxMin"); } } } #endregion #region 稳定性 private STABILITY stability = STABILITY.IDLE; /// /// 当前检测出来的厚度数据 稳定状态 /// public STABILITY Stability { get { return stability; } protected set { if (stability != value) { stability = value; NotifyPropertyChanged("Stability"); } } } private double currR = -1; /// /// 当前检测出来的厚度数据 的稳定性 /// public double CurrR { get { return currR; } protected set { if (currR != value) { currR = value; NotifyPropertyChanged("CurrR"); } } } private double curr2Sigma = -1; /// /// 当前检测出来的厚度数据 2Sigma /// public double Curr2Sigma { get { return curr2Sigma; } protected set { if (curr2Sigma != value) { curr2Sigma = value; NotifyPropertyChanged("Curr2Sigma"); } } } private double currBreakUp = 50; /// /// 当前打散程度。 /// 连续N点都在平均值同一侧为一个块; /// 这些块的长度平均值/总长度, 为打散度; /// 打散度越小越好, 最小为 1/NBolts /// public double CurrBreakUp { get { return currBreakUp; } protected set { if (currBreakUp != value) { currBreakUp = value; NotifyPropertyChanged("CurrBreakUp"); } } } DateTime currtime = DateTime.MinValue; /// /// 当前检测出来的厚度数据,时间 /// public DateTime CurrTime { get { return currtime; } protected set { if (currtime != value) { currtime = value; NotifyPropertyChanged("CurrTime"); } } } private Misc.DIRECTION currDirection = Misc.DIRECTION.FORWARD; /// /// 当前检测出来的厚度数据,方向 /// public Misc.DIRECTION CurrDirection { get { return currDirection; } protected set { if (currDirection != value) { currDirection = value; NotifyPropertyChanged("CurrDirection "); } } } #endregion #region 列表 private int lastbm = 0; /// /// 列表最后1个BM /// public int LastBM { get { return lastbm; } protected set { if (lastbm != value) { lastbm = value; NotifyPropertyChanged("LastBM"); } } } private int firstbm = 0; /// /// 列表第1个BM /// public int FirstBM { get { return firstbm; } protected set { if (firstbm != value) { firstbm = value; NotifyPropertyChanged("FirstBM"); } } } #endregion #region 每个分区状态 private bool[] boltIsStable; public bool[] BoltIsStable { get { return boltIsStable; } protected set { boltIsStable = value; NotifyPropertyChanged("BoltIsStable"); } } #endregion #endregion #endregion public HeatBufServiceClient() { mServerID = OBJ_INTERFACE_ID.HEATBUF_ID; } #region IFObj public override void ConnectNotify(IFConn from) { mConn = from; if (from.IsConnected) { FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_PARAMS); FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_STATE); FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_BM); FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_ISSTABLES); FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD); } } public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata) { switch (memid) { case HEATBUF_OBJ_INTERFACE.GET_PARAMS: { HEATBUF_OBJ_INTERFACE.Pack_Params p = new HEATBUF_OBJ_INTERFACE.Pack_Params(); if (!p.TryParse(infodata)) return; HeatEffectCurve = p.HeatEffectCurve; StableRange = p.StableRange; StableRange0 = p.StableRange0; ThresholdR = p.ThresholdR; ThresholdMaxMin = p.ThresholdMaxMin; ThresholdSigmaMax = p.ThresholdSigmaMax; IsUsedLocalKp = p.IsUsedLocalKp; LocalKp = p.LocalKp; } break; case HEATBUF_OBJ_INTERFACE.GET_STATE: { HEATBUF_OBJ_INTERFACE.Pack_Status p = new HEATBUF_OBJ_INTERFACE.Pack_Status(); if (!p.TryParse(infodata)) return; Delay = p.Delay; IsIntoAutoONo = p.IsIntoAutoONo; AutoONoResult = p.AutoONoResult; BestOrgBoltNo = p.BestOrgBoltNo; BestKp = p.BestKp; MaxR = p.MaxR; MaxMin = p.MaxMin; Stability = p.Stability; CurrR = p.CurrR; Curr2Sigma = p.Curr2Sigma; CurrBreakUp = p.CurrBreakUp; CurrTime = p.CurrTime; CurrDirection = p.CurrDirection; } break; case HEATBUF_OBJ_INTERFACE.GET_BM: { HEATBUF_OBJ_INTERFACE.Pack_BM p = new HEATBUF_OBJ_INTERFACE.Pack_BM(); if (!p.TryParse(infodata)) return; FirstBM = p.firstbm; LastBM = p.lastbm; } break; case HEATBUF_OBJ_INTERFACE.GET_ISSTABLES: { HEATBUF_OBJ_INTERFACE.Pack_IsStables p = new HEATBUF_OBJ_INTERFACE.Pack_IsStables(); if (!p.TryParse(infodata)) return; BoltIsStable = p.isStables; } break; } } public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState) { switch (funcid) { case HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA: { //TODO if (retdata == null) { ((AsyncCBHandler)AsyncDelegate)(AsyncState, null); } else { FlyData_FeedbackHeat p = new FlyData_FeedbackHeat(); if (!p.TryParse(retdata)) return; ((AsyncCBHandler)AsyncDelegate)(AsyncState, p); } } break; case HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD: { if (retdata == null) { ((AsyncCBHandler)AsyncDelegate)(AsyncState, null); } else { FlyData_BoltHeatRecord p = new FlyData_BoltHeatRecord(); if (!p.TryParse(retdata)) return; ((AsyncCBHandler)AsyncDelegate)(AsyncState, p); } } break; } } public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata) { PushGetValue(from, srcid, infoid, infodata); } public override void Dispose() { FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.REMOVE); base.Dispose(); } #endregion public void Apply() { FObjSys.Current.SetValueEx( mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.SET_PARAMS, new HEATBUF_OBJ_INTERFACE.Pack_Params() { HeatEffectCurve = HeatEffectCurve, StableRange = StableRange, StableRange0 = StableRange0, ThresholdR = ThresholdR, ThresholdMaxMin = ThresholdMaxMin, ThresholdSigmaMax = ThresholdSigmaMax, IsUsedLocalKp = IsUsedLocalKp, LocalKp = LocalKp }.ToBytes()); } public void GetHeatsData(int bookmark, AsyncCBHandler AsyncDelegate, object AsyncState) { CurrObjSys.CallFunctionEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA, new HEATBUF_OBJ_INTERFACE.Pack_GetHeatsDataRequest() { bookmark = bookmark }.ToBytes(), AsyncDelegate, AsyncState); } public void ClearBoltHeat() { CurrObjSys.CallFunctionEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.CALL_CLEARBOLTHEAT, null); } /// /// 获取每个分区的加热历史 返回 FlyData_BoltHeatRecord /// /// 分区号 /// /// public void GetBoltHeatRecord(int no, AsyncCBHandler AsyncDelegate, object AsyncState) { CurrObjSys.CallFunctionEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD, new HEATBUF_OBJ_INTERFACE.Pack_GetBoltHeatRecordRequest() { no = no }.ToBytes(), AsyncDelegate, AsyncState); } #region INotifyPropertyChanged 成员 public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyname) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname)); } } #endregion } }