using FLY.Thick.Base.Common; using FLY.Thick.Base.Server; using FLY.Thick.Blowing; using FLY.Thick.Blowing.Common; using FLY.Thick.Blowing.Server; using FLY.Thick.Blowing.Server.Model; using FLY.Thick.Blowing360.IService; using FlyADBase; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FLY.Thick.Blowing360.Server { public class TDGage { #region 延时推送 MARKNO #endregion #region 输入口定义 /// /// 报警灯信号 /// const int alarmLamp_bit = 4; #endregion #region 参数-------------------------------------------------------------------- #region 初始化------------------------------------------------------------------ /// /// 参数目录 m_path;数据文件的 根目录默认是 "Gage1", 不能有 @"\" /// 目前也是对外的服务器目录 /// public string mParamDirectory; /// /// 名字 如:gage0 /// public string mName; #endregion #region 数据-------------------------------------------------------------------- /// /// 当前基本简单参数 /// public DynArea dynArea; /// /// 运行参数 /// public BlowingFixProfile profile; /// /// AD曲线 /// public CurveCollection curve; /// /// 报警系统 /// public FLY.OBJComponents.Server.WarningSystem warning; #region 运行模式 /// /// AD卡 /// public FlyADBase.FlyAD7 flyAd; /// /// GM管理器 /// GageModeManager gmManager; /// /// 定点模式 /// public GM_Fix gmFix; /// /// 吹膜测厚模式.定点 /// public GM_BlowingFix360 gmRenZiJiaFix; public BlowingDetect360 blowingDetect; /// /// 扫描报警系统 /// public ScanWarning scanWarning; /// /// 设备参数 /// public InitParam initParam; #endregion /// /// 系统参数 /// public SysParam sysParam; #region BULKDATA /// /// 数据库对象 /// DbModel dbModel; ///// ///// 原始数据 数据库对象 ///// //OrgDbModel orgDbModel; /// /// 数据库写操作 /// public HistoryDb historyDb; //OrgHistoryDb orgHistoryDb; /// /// 本地数据库 /// LocalDb localDb; /// /// 数据库读操作 /// public BulkDb bulkDb; #endregion #endregion #endregion public TDGage(string nam) { mName = nam; mParamDirectory = mName;// @"D:\" + m_name; if (!System.IO.Directory.Exists(mParamDirectory)) { System.IO.Directory.CreateDirectory(mParamDirectory); } System.Environment.CurrentDirectory = mParamDirectory; #region create sysParam = new SysParam(null);//系统参数 profile = new BlowingFixProfile(null);//运行配置参数 curve = new CurveCollection(null);//AD转thick initParam = new InitParam(null); dbModel = new DbModel(); //orgDbModel = new OrgDbModel(); localDb = new LocalDb(); historyDb = new HistoryDb(); //orgHistoryDb = new OrgHistoryDb(); bulkDb = new BulkDb(); dynArea = new DynArea(); warning = new FLY.OBJComponents.Server.WarningSystem(); scanWarning = new ScanWarning(); flyAd = new FlyAD7(); gmManager = new GageModeManager(); gmFix = new GM_Fix(flyAd); gmRenZiJiaFix = new GM_BlowingFix360(flyAd); blowingDetect = new BlowingDetect360(); #endregion #region 注入初始化 //--------------------------------------------------------------------------------------------------------------- //数据库 dbModel.Init(); dbModel.KeepDBSize(initParam.DBKeepMonth); historyDb.Init(dbModel, localDb); bulkDb.Init(historyDb, localDb, dbModel); //--------------------------------------------------------------------------------------------------------------- //dynarea Misc.BindingOperations.SetBinding(profile.Param, nameof(BlowingFixProfileParam.PName), dynArea, nameof(DynArea.ProductName)); Misc.BindingOperations.SetBinding(profile.Param, nameof(BlowingFixProfileParam.Target), () => { dynArea.Target = (int)(profile.Param.Target * 100); }); Misc.BindingOperations.SetBinding(profile.Param, new string[] { nameof(BlowingFixProfileParam.Target), nameof(BlowingFixProfileParam.TolerancePercent) }, () => { dynArea.Alarm = (int)(profile.Param.Target * profile.Param.TolerancePercent * 100); }); Misc.BindingOperations.SetBinding(profile.Param, nameof(BlowingFixProfileParam.K), dynArea, nameof(DynArea.Comp)); dynArea.PropertyChanged += new PropertyChangedEventHandler(mDynArea_PropertyChanged); //--------------------------------------------------------------------------------------------------------------- //GageModeManager_Create Misc.BindingOperations.SetBinding(gmManager, nameof(gmManager.State), dynArea, nameof(DynArea.ControllerState)); //--------------------------------------------------------------------------------------------------------------- //FlyAD7_Create flyAd.Load(); flyAd.Connect(); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.IStatus), dynArea, nameof(DynArea.IStatus)); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.OStatus), dynArea, nameof(DynArea.OStatus)); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.Position), dynArea, nameof(DynArea.Position)); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.Position2), dynArea, nameof(DynArea.Position2)); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.Surplus), dynArea, nameof(DynArea.Hrs)); Misc.BindingOperations.SetBinding(flyAd, nameof(FlyAD7.IsConnected), dynArea, nameof(DynArea.FLYADIsConnect)); //--------------------------------------------------------------------------------------------------------------- //Warning_Create warning.Init(historyDb.ErrorBuffer); Misc.BindingOperations.SetBinding(warning, nameof(warning.IsRinging), () => { if (warning.IsRinging) { flyAd.SetOutput( (UInt16)Misc.MyBase.BIT(alarmLamp_bit - 1), (UInt16)~Misc.MyBase.BIT(alarmLamp_bit - 1)); } else { flyAd.SetOutput( (UInt16)Misc.MyBase.BIT(alarmLamp_bit - 1), (UInt16)Misc.MyBase.BIT(alarmLamp_bit - 1)); } }); //--------------------------------------------------------------------------------------------------------------- //ScanWarning_Create scanWarning.Init(warning, historyDb); //--------------------------------------------------------------------------------------------------------------- //GM_Fix_Create gmFix.Init(dynArea, AD2Thick); gmFix.IsIgnoreDataWhenIdle = false; gmManager.AddGM(gmFix); //--------------------------------------------------------------------------------------------------------------- gmManager.AddGM(gmRenZiJiaFix); //--------------------------------------------------------------------------------------------------------------- blowingDetect.Init(flyAd); gmRenZiJiaFix.Init(blowingDetect, Ad2Thk, dynArea, profile.Param, historyDb, bulkDb); gmRenZiJiaFix.Start(); ErrNoForCheckInit(); #endregion } void mGMRenZiJiaFix_EPCSampled(int ad) { CurveCollection pCurve = curve; dynArea.SampleAD[0] = ad; List list = new List(); if (pCurve.Curves.Count == 0) return; list.Add(new CurveCollection.ExChange() { OrgAD = pCurve.Curves[0].AD, CurrAD = ad }); pCurve.ModifyExChange(list); pCurve.ReviseCurve(); } #region 异常检测 class ErrNoForCheckItem { public FLY.OBJComponents.Common.ERRNO errno; public Func conditional; /// /// 持续时间,单位s /// public int cnt; int timer = -1; public FLY.OBJComponents.Server.WarningSystem mWarning; public void Clear() { if (timer == 0) { mWarning.Add( errno.Code, errno.Descrption, FLY.OBJComponents.Common.ERR_STATE.OFF); } timer = -1; } public void OnPoll() { if (conditional()) { if (timer < 0) timer = cnt; else { if (timer > 0) timer--; if (timer == 0) { mWarning.Add( errno.Code, errno.Descrption, FLY.OBJComponents.Common.ERR_STATE.ON); } } } else { Clear(); } } } List ErrNoForCheckItems = new List(); void ErrNoForCheckInit() { ErrNoForCheckItems.Add(//AD值太小 new ErrNoForCheckItem() { errno = FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_AD_MIN, cnt = 20, conditional = delegate () { return dynArea.AD < (dynArea.ADMax * 0.01); } }); ErrNoForCheckItems.Add(//AD值太大 new ErrNoForCheckItem() { errno = FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_AD_MAX, cnt = 20, conditional = delegate () { return (dynArea.AD > (dynArea.ADMax * 0.98)); } }); foreach (ErrNoForCheckItem item in ErrNoForCheckItems) { item.mWarning = warning; } FObjBase.PollModule.Current.Poll_Config( FObjBase.PollModule.POLL_CONFIG.ADD, onpoll_checkErrNo, TimeSpan.FromSeconds(1)); } bool isInit_onpoll_checkErrNo; void onpoll_checkErrNo() //1秒执行一次 { if (!isInit_onpoll_checkErrNo) { isInit_onpoll_checkErrNo = true; checkDynAreaError(); } if (!dynArea.FLYADIsConnect) { foreach (ErrNoForCheckItem item in ErrNoForCheckItems) item.Clear(); } else { foreach (ErrNoForCheckItem item in ErrNoForCheckItems) item.OnPoll(); } } #endregion void mDynArea_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(dynArea.Hrs)) { if (dynArea.Hrs < 48 && dynArea.Hrs > 0)//授权限制提醒 { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Descrption, OBJComponents.Common.ERR_STATE.ON); } } else if (e.PropertyName == nameof(dynArea.SecuteLock)) //授权限制 { if (dynArea.SecuteLock) { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption, OBJComponents.Common.ERR_STATE.ON); } else { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption, OBJComponents.Common.ERR_STATE.ON); } } else if (e.PropertyName == nameof(dynArea.FLYADIsConnect))//连接断开 { if (!dynArea.FLYADIsConnect) { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption, OBJComponents.Common.ERR_STATE.ON); } else { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption, OBJComponents.Common.ERR_STATE.OFF); } } } void checkDynAreaError() { if (dynArea.Hrs < 48 && dynArea.Hrs > 0)//授权限制提醒 { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Descrption, OBJComponents.Common.ERR_STATE.ON); } if (dynArea.SecuteLock) { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption, OBJComponents.Common.ERR_STATE.ON); } if (!dynArea.FLYADIsConnect) { warning.Add( FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code, FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption, OBJComponents.Common.ERR_STATE.ON); } } #region 推送处理 public int AD2Thick(int ad) { int thick = Misc.MyBase.NULL_VALUE; if (Misc.MyBase.ISVALIDATA(ad)) { thick = curve.AD2Value(ad, AD2ValueFlag.Revised); thick = (int)(thick * profile.Param.K); } return thick; } public double Ad2Thk(int ad) { double thk = double.NaN; if (Misc.MyBase.ISVALIDATA(ad)) { thk = curve.AD2Value(ad, AD2ValueFlag.Revised) / 100.0; thk = thk * profile.Param.K; } return thk; } #endregion } }