TDGage.cs 35.1 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.ComponentModel;
using Misc;
using FObjBase;
using FlyADBase;
using FLY.Thick.BulkDataModule;
using FLY.Thick.RemoteHistory;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.Server;
using FLY.Thick.Base.IService;
using FLY.Thick.BlowingScan.IService;
using System.Windows.Threading;
潘栩锋's avatar
潘栩锋 committed
20 21 22 23 24 25 26 27
using FLY.Thick.BlowingScan.Server.Model;
using FLY.Thick.Blowing.Server.Model;



using OrgDbModel = FLY.Thick.BlowingScan.Server.Model.OrgDbModel;
using HistoryDb = FLY.Thick.BlowingScan.Server.Model.HistoryDb;
using ScanWarning = FLY.Thick.Blowing.Server.ScanWarning;
潘栩锋's avatar
潘栩锋 committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

namespace FLY.Thick.BlowingScan.Server
{

    public class TDGage : ITDGageService
    {
        #region 延时推送 MARKNO
        const int MARKNO_UPDATEV = 1;
        const int MARKNO_INITHISTORY = 2;
        const int MARKNO_PUSH_ACCESS = 3;
        #endregion
        #region 参数--------------------------------------------------------------------
        #region 初始化------------------------------------------------------------------
        /// <summary>
        /// 参数目录 m_path;数据文件的 根目录默认是 "Gage1", 不能有 @"\"
        /// 目前也是对外的服务器目录
        /// </summary>
        public string mParamDirectory;
        /// <summary>
        /// 名字 如:gage0
        /// </summary>
        public string mName;
        #endregion

        #region 数据--------------------------------------------------------------------

        /// <summary>
        /// 当前基本简单参数
        /// </summary>
        public DynArea mDynArea;

        /// <summary>
        /// 设备参数
        /// </summary>
        public InitParam mInitParam;

        /// <summary>
        /// 运行参数
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
67
        public BlowingProfile mProfile;
潘栩锋's avatar
潘栩锋 committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81

        /// <summary>
        /// 边界查找,由 boltmap 独立出来的功能
        /// </summary>
        public BorderSearch mBorderSearch;

        /// <summary>
        /// AD曲线
        /// </summary>
        public CurveCollection mCurve;

        /// <summary>
        /// 报警系统
        /// </summary>
82
        public FLY.OBJComponents.Server.WarningSystem mWarning;
潘栩锋's avatar
潘栩锋 committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

        /// <summary>
        /// 密码系统,只提供给客户端,在服务器没用。。。
        /// </summary>
        public Password mPassword;

        #region 运行模式

        /// <summary>
        /// AD卡
        /// </summary>
        public FlyADBase.FlyAD7 mFlyAD;
        /// <summary>
        /// 样品修正
        /// </summary>
        public GSample mGetSample;
        /// <summary>
        /// GM管理器
        /// </summary>
        GageModeManager mGMManager;
        /// <summary>
        /// 断开连接
        /// </summary>
        GM_Disconnected mGMDisconnected;

        /// <summary>
        /// 暂停扫描
        /// </summary>
        GM_Pause mGMPause;
        /// <summary>
        /// 自动启动扫描
        /// </summary>
        GM_AutoScan mGMAutoScan;

        /// <summary>
        /// 前进
        /// </summary>
        GM_Forward mGMForw;
        /// <summary>
        /// 后退
        /// </summary>
        GM_Backward mGMBackw;
        /// <summary>
        /// 归零
        /// </summary>
        GM_Origin mGMOrg;
        /// <summary>
        /// 停止
        /// </summary>
        GM_Stop mGMStop;
        /// <summary>
        /// 运行到目标位置
        /// </summary>
        GM_Goto mGMRunto;
        /// <summary>
        /// 机架校正模式,参数
        /// </summary>
        public GM_ScanCorr mGMScanCorr;
        /// <summary>
        /// 扫描模式
        /// </summary>
        public GM_Scan mGMScan;
        /// <summary>
        /// 定点模式
        /// </summary>
        public GM_Fix mGMFix;

        /// <summary>
        /// 吹膜测厚模式.扫描
        /// </summary>
        public GM_BlowingScan mGMRenZiJiaScan;

潘栩锋's avatar
潘栩锋 committed
155 156 157 158 159
        /// <summary>
        /// 扫描报警系统
        /// </summary>
        public ScanWarning mScanWarning;

潘栩锋's avatar
潘栩锋 committed
160 161 162 163 164
        /// <summary>
        /// 机架信息,不同于机架校正
        /// </summary>
        public GM_GageInfo mGMGageInfo;
        #endregion
165

潘栩锋's avatar
潘栩锋 committed
166 167 168 169 170 171 172 173 174 175 176
        /// <summary>
        /// 系统参数
        /// </summary>
        public SysParam mSysParam;


        #region BULKDATA
        /// <summary>
        /// N幅历史数据缓存
        /// </summary>
        public BulkDataService mBulk;
潘栩锋's avatar
潘栩锋 committed
177 178 179
        /// <summary>
        /// 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
180 181
        public BulkDataServiceClientAdv mBulkClient;

潘栩锋's avatar
潘栩锋 committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        /// <summary>
        /// 数据库对象
        /// </summary>
        DbModel mDbModel;
        /// <summary>
        /// 原始数据 数据库对象
        /// </summary>
        OrgDbModel mOrgDbModel;
        /// <summary>
        /// 数据库写操作
        /// </summary>
        public HistoryDb mHistoryDb;
        /// <summary>
        /// 本地数据库
        /// </summary>
        LocalDb mLocalDb;
        /// <summary>
        /// 数据库读操作
        /// </summary>
        public BulkDb mBulkDb;

潘栩锋's avatar
潘栩锋 committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        #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 提取保存的数据

            mSysParam = new SysParam(null);//系统参数

            mInitParam = new InitParam(null);
            mInitParam.HasHold = false;

潘栩锋's avatar
潘栩锋 committed
227
            mProfile = new BlowingProfile(null);//运行配置参数
潘栩锋's avatar
潘栩锋 committed
228 229 230 231 232 233 234

            mBorderSearch = new BorderSearchPlastic(null);//边界查找

            mCurve = new CurveCollection(null);//AD转thick
            
            mPassword = new Password(null);

235
            mDbModel = new DbModel();
潘栩锋's avatar
潘栩锋 committed
236 237 238 239 240 241 242 243 244
            mDbModel.Init();

            mOrgDbModel = new OrgDbModel();
            mOrgDbModel.Init();

            mLocalDb = new LocalDb();

            mHistoryDb = new HistoryDb();
            mHistoryDb.Init(mDbModel, mOrgDbModel, mLocalDb);
245
            mHistoryDb.KeepDBSize(mInitParam.DBKeepMonth);
潘栩锋's avatar
潘栩锋 committed
246 247
            mHistoryDb.KeepOrgDbSize(3);

248 249 250
            PollModule.Current.Poll_Config(PollModule.POLL_CONFIG.ADD, () =>
            {
                //避免1个月都不关程序,每天检查一次
潘栩锋's avatar
潘栩锋 committed
251
                mHistoryDb.KeepOrgDbSize(3);
252
            }, TimeSpan.FromDays(1));
潘栩锋's avatar
潘栩锋 committed
253 254 255 256

            mBulkDb = new BulkDb();
            mBulkDb.Init(mHistoryDb, mLocalDb, mDbModel);

潘栩锋's avatar
潘栩锋 committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
            #endregion
            //---------------------------------------------------------------------------------------------------------------
            //小托辊
            Misc.BindingOperations.SetBinding(mInitParam, new string[] { "HasHold", "PosLength" },
                delegate ()
                {
                    if (!mInitParam.HasHold)
                    {
                        mBorderSearch.Valid.Begin = 0;
                        mBorderSearch.Valid.End = mInitParam.PosLength - 1;
                    }
                });


            #region 动态数据

            mDynArea = new DynArea();
            mDynArea.Version = Version;
潘栩锋's avatar
潘栩锋 committed
275 276 277 278 279 280 281 282 283 284
            Misc.BindingOperations.SetBinding(mProfile.Param, "PName", mDynArea, "ProductName");
            Misc.BindingOperations.SetBinding(mProfile.Param, "Target", () =>
            {
                mDynArea.Target = (int)(mProfile.Param.Target * 100);
            });
            Misc.BindingOperations.SetBinding(mProfile.Param, new string[] { "Target", "TolerancePercent" }, () =>
            {
                mDynArea.Alarm = (int)(mProfile.Param.Target * mProfile.Param.TolerancePercent * 100);
            });
            Misc.BindingOperations.SetBinding(mProfile.Param, "K", mDynArea, "Comp");
潘栩锋's avatar
潘栩锋 committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411



            Misc.BindingOperations.SetBinding(mBorderSearch, new string[] { "Width" },
                delegate()
                {
                    mDynArea.Width = mBorderSearch.Width * mInitParam.Encoder1_mmpp;
                });

            mInitParam.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Encoder1_mmpp")
                {
                    mDynArea.Width = mBorderSearch.Width * mInitParam.Encoder1_mmpp;
                }
            };
            mDynArea.PropertyChanged += new PropertyChangedEventHandler(mDynArea_PropertyChanged);


            //---------------------------------------------------------------------------------------------------------------
            //GageModeManager_Create
            mGMManager = new GageModeManager();
            Misc.BindingOperations.SetBinding(mGMManager, "State", mDynArea, "ControllerState");

            //---------------------------------------------------------------------------------------------------------------
            //FlyAD7_Create
            mFlyAD = new FlyAD7();
            //TODO
            mFlyAD.Connect(mSysParam.FLYAD7EP);
            Misc.BindingOperations.SetBinding(mFlyAD, "LocalEP", mSysParam, "FLYAD7EP");

            Misc.BindingOperations.SetBinding(mInitParam, "PosLength", mFlyAD, "PosLen");

            Misc.BindingOperations.SetBinding(mFlyAD, "IStatus", mDynArea, "IStatus");
            Misc.BindingOperations.SetBinding(mFlyAD, "OStatus", mDynArea, "OStatus");
            Misc.BindingOperations.SetBinding(mFlyAD, "Position", mDynArea, "Position");
            Misc.BindingOperations.SetBinding(mFlyAD, "Position2", mDynArea, "Position2");
            Misc.BindingOperations.SetBinding(mFlyAD, "Surplus", mDynArea, "Hrs");
            Misc.BindingOperations.SetBinding(mFlyAD, "IsConnected", mDynArea, "FLYADIsConnect");

            Misc.BindingOperations.SetBinding(mFlyAD, "PosOfGrid", mInitParam, "PosOfGrid");

            //------------------------------------------------------------------------------------------------------------------------------------
            //速度------------------------------------------------------------------------------------------------------------------------------
            mFlyAD.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Speed")
                {
                    double speed = mFlyAD.Speed * mInitParam.Encoder1_mmpp;//mm/s
                    speed = speed * 60 / 1000;//m/min
                    mDynArea.Velocity = speed;
                }
            };

            //------------------------------------------------------------------------------------------------------------------------------------
            //线速度------------------------------------------------------------------------------------------------------------------------------
            mFlyAD.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Speed2")
                {
                    if (mInitParam.FilmVSrc != FilmVSRC.EN2)
                        return;

                    double speed = mFlyAD.Speed2 * mInitParam.Encoder2_mmpp;//mm/s
                    speed = speed * 60 / 1000;//m/min
                    mDynArea.FilmVelocity = speed;
                }
            };

            //------------------------------------------------------------------------------------------------------------------------------------
            //辊信号生成线速度-----------------------------------------------------------------------------------------------------------------------------
            InitRoundFilmVelocity();


            //------------------------------------------------------------------------------------------------------------------------------------
            //数据有效-----------------------------------------------------------------------------------------------------------------------------
            mFlyAD.IStatusChangedEvent += (s, e) =>
            {
                if (mInitParam.DataValidSrc != DATAVALIDSRC.BYINPUT)
                    return;

                if (Misc.MyBase.CHECKBIT(e.IChanged, 6 - 1))
                {
                    if (!Misc.MyBase.CHECKBIT(e.IStatus, 6 - 1))
                        mDynArea.DataValid = false;
                    else
                        mDynArea.DataValid = true;
                }
            };

            Misc.BindingOperations.SetBinding(mInitParam, new string[] { "DataValidSrc" }, update_datavalid);


            Misc.BindingOperations.SetBinding(mFlyAD, new string[] { "Ratio02", "Ratio01" },
                delegate()
                {
                    mInitParam.Speed1Scale = (double)mFlyAD.Ratio02 / mFlyAD.Ratio01;
                });

            Misc.BindingOperations.SetBinding(mInitParam, new string[] { "SVelocity", "ATime", "DTime", "HVelocity1", "HVelocity2" },
                delegate()
                {
                    PollModule.Current.Poll_JustOnce(delegate()
                    {
                        mFlyAD.SetPosParam(0xffffffff, mInitParam.SVelocity, mInitParam.ATime, mInitParam.DTime, mInitParam.HVelocity1, mInitParam.HVelocity2);

                    }, this, MARKNO_UPDATEV);
                });

            Misc.BindingOperations.SetBinding(mFlyAD, new string[] { "IsConnected" },
                delegate()
                {
                    if (mFlyAD.IsConnected == true)
                    {
                        //还需要在flyad 重新连接上时,设置!!!!!
                        PollModule.Current.Poll_JustOnce(delegate()
                        {
                            mFlyAD.SetPosParam(0xffffffff, mInitParam.SVelocity, mInitParam.ATime, mInitParam.DTime, mInitParam.HVelocity1, mInitParam.HVelocity2);

                        }, this, MARKNO_UPDATEV);
                    }
                });



            //---------------------------------------------------------------------------------------------------------------
            //Warning_Create
潘栩锋's avatar
潘栩锋 committed
412
            mWarning = new OBJComponents.Server.WarningSystem(mHistoryDb.ErrorBuffer);
潘栩锋's avatar
潘栩锋 committed
413

414
            Misc.BindingOperations.SetBinding(mWarning, "IsRinging", () =>
415
            {
416 417 418 419 420 421 422 423 424 425 426 427 428
                if (mWarning.IsRinging)
                {
                    mFlyAD.SetOutput(
                        (UInt16)Misc.MyBase.BIT(4 - 1),
                        (UInt16)~Misc.MyBase.BIT(4 - 1));
                }
                else
                {
                    mFlyAD.SetOutput(
                        (UInt16)Misc.MyBase.BIT(4 - 1),
                        (UInt16)Misc.MyBase.BIT(4 - 1));
                }
            });
潘栩锋's avatar
潘栩锋 committed
429 430 431 432 433 434 435

            //---------------------------------------------------------------------------------------------------------------
            //ScanWarning_Create
            mScanWarning = new ScanWarning();
            mScanWarning.Init(mWarning, mHistoryDb);


潘栩锋's avatar
潘栩锋 committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
            //---------------------------------------------------------------------------------------------------------------
            //GM_Fix_Create
            mGMFix = new GM_Fix(mFlyAD);
            mGMFix.Init(mDynArea, AD2Thick);
            mGMManager.AddGM(mGMFix);


            //---------------------------------------------------------------------------------------------------------------
            //GM_AutoScan_Create
            mGMAutoScan = new GM_AutoScan(mFlyAD);
            mGMAutoScan.Init(StartP1);
            Misc.BindingOperations.SetBinding(mGMAutoScan, "Counter", mDynArea, "AutoScanCounter");
            mGMManager.AddGM(mGMAutoScan);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Disconnected_Create
            mGMDisconnected = new GM_Disconnected(mFlyAD);
            mGMDisconnected.Init(mDynArea, mGMAutoScan);
            mGMManager.AddGM(mGMDisconnected);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Pause_Create
            mGMPause = new GM_Pause(mFlyAD);
            mGMPause.Init(mDynArea, mGMAutoScan);
            Misc.BindingOperations.SetBinding(mInitParam, "ReStartDelay", mGMPause, "Delay");
            Misc.BindingOperations.SetBinding(mInitParam, "AutoF1F3", mGMPause, "Enable");
            mGMManager.AddGM(mGMPause);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Forward_Create
            mGMForw = new GM_Forward(mFlyAD);
            Misc.BindingOperations.SetBinding(mInitParam, "VJOG", mGMForw, "Velocity");
            mGMManager.AddGM(mGMForw);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Backward_Create
            mGMBackw = new GM_Backward(mFlyAD);
            Misc.BindingOperations.SetBinding(mInitParam, "VJOG", mGMBackw, "Velocity");
            mGMManager.AddGM(mGMBackw);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Goto_Create
            mGMRunto = new GM_Goto(mFlyAD);
            Misc.BindingOperations.SetBinding(mInitParam, "VJOG", mGMRunto, "Velocity");
            mGMManager.AddGM(mGMRunto);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Origin_Create
            mGMOrg = new GM_Origin(mFlyAD);
            mGMManager.AddGM(mGMOrg);

            //---------------------------------------------------------------------------------------------------------------
            //GM_Stop_Create
            mGMStop = new GM_Stop(mFlyAD);
            mGMManager.AddGM(mGMStop);

            //---------------------------------------------------------------------------------------------------------------
            //GM_GageInfo_Create
            mGMGageInfo = new GM_GageInfo(mFlyAD);
            Misc.BindingOperations.SetBinding(mInitParam, "VAccuracy", mGMGageInfo, "Velocity");
            mGMManager.AddGM(mGMGageInfo);

            //---------------------------------------------------------------------------------------------------------------
            //GM_ScanCorr_Create
            mGMScanCorr = new GM_ScanCorr(mFlyAD);
            mGMManager.AddGM(mGMScanCorr);
            mFlyAD.CorrectADs = new FlyADBase.CorrectADsHandler(mGMScanCorr.CorrectADs);
            Misc.BindingOperations.SetBinding(mInitParam, "VAccuracy", mGMScanCorr, "Velocity");

            Misc.BindingOperations.SetBinding(mBorderSearch.Valid, "Begin", mGMScanCorr, "ValidBegin", BindingOperations.BindingMode.TwoWay);
            Misc.BindingOperations.SetBinding(mBorderSearch.Valid, "End", mGMScanCorr, "ValidEnd", BindingOperations.BindingMode.TwoWay);
            


            //---------------------------------------------------------------------------------------------------------------
            //GSample_Create
            mGetSample = new GSample(mFlyAD, mGMGageInfo);
            Misc.BindingOperations.SetBinding(mGetSample.Samples[0], "AD", mBorderSearch, "CurrTempAD");
            Misc.BindingOperations.SetBinding(mInitParam, "VAccuracy", mGetSample, "Velocity");
            mGetSample.SampleChangedEvent += new SampleChangedEventHandler(getSample_SampleChangedEvent);

            //---------------------------------------------------------------------------------------------------------------
            //GM_RenZiJiaScan_Create
            mGMRenZiJiaScan = new GM_BlowingScan(mFlyAD, mGetSample);
            mGMManager.AddGM(mGMRenZiJiaScan);

            //---------------------------------------------------------------------------------------------------------------
            //Bulkdata_Create
            mBulk = new BulkDataService(mGMRenZiJiaScan.NBolts, 1, 400);
            mBulkClient = new BulkDataServiceClientAdv(mBulk);



            Misc.BindingOperations.SetBinding(mInitParam, "AutoOrgInterval", mGMRenZiJiaScan, "OrgInterval");
            Misc.BindingOperations.SetBinding(mInitParam, "VScan", mGMRenZiJiaScan, "Velocity");

            Misc.BindingOperations.SetBinding(mGMRenZiJiaScan, "FilmVelocity", mDynArea, "FilmVelocity");

            mDynArea.NBolts = mGMRenZiJiaScan.NBolts;
            mDynArea.FirstBoltNo = 1;
            mDynArea.DataBoltNoBegin = 1;
            mDynArea.DataBoltNoEnd = mGMRenZiJiaScan.NBolts;
            mDynArea.ScanBoltNoBegin = 1;
            mDynArea.ScanBoltNoEnd = mGMRenZiJiaScan.NBolts;

            mGMRenZiJiaScan.Init(
                mBulk,
                mBorderSearch,
潘栩锋's avatar
潘栩锋 committed
544 545
                mDynArea, new AD2ThickHandler(AD2Thick),
                mProfile.Param, mHistoryDb, mBulkDb);
潘栩锋's avatar
潘栩锋 committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564

            mGMRenZiJiaScan.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "NBolts")
                {
                    mBulk.NBolts = mGMRenZiJiaScan.NBolts;

                    mDynArea.NBolts = mGMRenZiJiaScan.NBolts;
                    mDynArea.FirstBoltNo = 1;

                    mDynArea.DataBoltNoBegin = 1;
                    mDynArea.DataBoltNoEnd = mGMRenZiJiaScan.NBolts;
                    mDynArea.ScanBoltNoBegin = 1;
                    mDynArea.ScanBoltNoEnd = mGMRenZiJiaScan.NBolts;
                }
            };



565
        
潘栩锋's avatar
潘栩锋 committed
566 567 568 569
            ErrNoForCheckInit();


            #endregion
570
            mGMFix.Start();
潘栩锋's avatar
潘栩锋 committed
571 572 573 574 575
        }


        class ErrNoForCheckItem
        {
576
            public FLY.OBJComponents.Common.ERRNO errno;
潘栩锋's avatar
潘栩锋 committed
577 578 579 580 581 582 583
            public Func<bool> conditional;
            /// <summary>
            /// 持续时间,单位s
            /// </summary>
            public int cnt;

            int timer = -1;
584
            public FLY.OBJComponents.Server.WarningSystem mWarning;
潘栩锋's avatar
潘栩锋 committed
585 586 587 588 589 590 591
            public void Clear()
            {
                if (timer == 0)
                {
                    mWarning.Add(
                        errno.Code,
                        errno.Descrption,
592
                        FLY.OBJComponents.Common.ERR_STATE.OFF);
潘栩锋's avatar
潘栩锋 committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
                }
                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,
612
                                FLY.OBJComponents.Common.ERR_STATE.ON);
潘栩锋's avatar
潘栩锋 committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
                        }
                    }
                }
                else
                {
                    Clear();
                }
            }
        }

        List<ErrNoForCheckItem> ErrNoForCheckItems = new List<ErrNoForCheckItem>();
        void ErrNoForCheckInit()
        {

            ErrNoForCheckItems.Add(//AD值太小
                new ErrNoForCheckItem()
                {
630
                    errno = FLY.Thick.BlowingScan.Common.ERRNOs.BASE_ERRNO_AD_MIN,
潘栩锋's avatar
潘栩锋 committed
631
                    cnt = 20,
632
                    conditional = delegate ()
潘栩锋's avatar
潘栩锋 committed
633 634 635 636 637 638 639 640
                    {
                        return mDynArea.AD < (mDynArea.ADMax * 0.01);
                    }
                });

            ErrNoForCheckItems.Add(//AD值太大
                new ErrNoForCheckItem()
                {
641
                    errno = FLY.Thick.BlowingScan.Common.ERRNOs.BASE_ERRNO_AD_MAX,
潘栩锋's avatar
潘栩锋 committed
642
                    cnt = 20,
643
                    conditional = delegate ()
潘栩锋's avatar
潘栩锋 committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
                    {
                        return (mDynArea.AD > (mDynArea.ADMax * 0.98));
                    }
                });

            foreach (ErrNoForCheckItem item in ErrNoForCheckItems)
            {
                item.mWarning = mWarning;
            }

            FObjBase.PollModule.Current.Poll_Config(
                FObjBase.PollModule.POLL_CONFIG.ADD,
                onpoll_checkErrNo, TimeSpan.FromSeconds(1));
        }

潘栩锋's avatar
潘栩锋 committed
659
        bool isInit_onpoll_checkErrNo;
潘栩锋's avatar
潘栩锋 committed
660 661
        void onpoll_checkErrNo() //1秒执行一次
        {
潘栩锋's avatar
潘栩锋 committed
662 663 664 665 666 667
            if (!isInit_onpoll_checkErrNo)
            {
                isInit_onpoll_checkErrNo = true;
                checkDynAreaError();
            }

潘栩锋's avatar
潘栩锋 committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
            if (!mDynArea.FLYADIsConnect)
            {
                foreach (ErrNoForCheckItem item in ErrNoForCheckItems)
                    item.Clear();
            }
            else
            {
                foreach (ErrNoForCheckItem item in ErrNoForCheckItems)
                    item.OnPoll();
            }
        }


        #region 辊信号生成 线速度
        DispatcherTimer round_t;
        DateTime dtRound = DateTime.MinValue;
        void InitRoundFilmVelocity()
        {
            round_t = new DispatcherTimer();
            round_t.Interval = TimeSpan.FromSeconds(1);
            round_t.Tick += new EventHandler(round_t_Tick);
            mFlyAD.IStatusChangedEvent += new IStatusChangedEventHandler(mFlyAD_IStatusChangedEvent_round);
        }
        void mFlyAD_IStatusChangedEvent_round(object sender, IStatusChangedEventArgs e)
        {
            if (mInitParam.FilmVSrc != FilmVSRC.ROUND)
                return;

            if (!Misc.MyBase.CHECKBIT(e.IChanged, 11 - 1))
                return;


            if (Misc.MyBase.CHECKBIT(e.IStatus, 11 - 1))
                return;

            //1->0
            DateTime dt = e.Time;
            if (dt <= dtRound)
                return;
            if (dtRound != DateTime.MinValue)
            {

                double v = mInitParam.MmOfR / 1000.0 / (dt - dtRound).TotalMinutes;

                if (v < 1)
                {
                    dt = DateTime.MinValue;
                    v = 0;
                }
                mDynArea.FilmVelocity = v;
            }

            dtRound = dt;

            if (dtRound != DateTime.MinValue)
            {
                if (!round_t.IsEnabled)
                    round_t.Start();
            }
        }
        void round_t_Tick(object sender, EventArgs e)
        {
            if (mInitParam.FilmVSrc != FilmVSRC.ROUND)
            {
                round_t.Stop();
                return;
            }
            if (dtRound == DateTime.MinValue)
            {
                round_t.Stop();
                return;
            }

            //1->0
            DateTime dt = DateTime.Now;
            if (dt <= dtRound)
                return;

            double v = mInitParam.MmOfR / 1000.0 / (dt - dtRound).TotalMinutes;

            if (v < (mDynArea.FilmVelocity - 1))
            {
                if (v < 2)
                {
                    dtRound = DateTime.MinValue;
                    v = 0;
                }
                mDynArea.FilmVelocity = v;
            }

            if (dtRound == DateTime.MinValue)
            {
                round_t.Stop();
                return;
            }
        }

        #endregion
        void mDynArea_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
768
            if (e.PropertyName == "FilmVelocity")
潘栩锋's avatar
潘栩锋 committed
769 770 771 772 773 774 775 776 777
            {
                update_datavalid();
            }
            else if (e.PropertyName == "Hrs")
            {
                if (mDynArea.Hrs < 48 && mDynArea.Hrs > 0)//授权限制提醒
                {

                    mWarning.Add(
778 779 780
                        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);
潘栩锋's avatar
潘栩锋 committed
781 782 783 784 785 786 787
                }
            }
            else if (e.PropertyName == "SecuteLock") //授权限制
            {
                if (mDynArea.SecuteLock)
                {
                    mWarning.Add(
788 789 790
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Code,
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption,
                        OBJComponents.Common.ERR_STATE.ON);
潘栩锋's avatar
潘栩锋 committed
791 792 793 794
                }
                else
                {
                    mWarning.Add(
795 796 797
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Code,
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption,
                        OBJComponents.Common.ERR_STATE.ON);
潘栩锋's avatar
潘栩锋 committed
798 799 800 801 802 803 804
                }
            }
            else if (e.PropertyName == "FLYADIsConnect")//连接断开
            {
                if (!mDynArea.FLYADIsConnect)
                {
                    mWarning.Add(
805 806 807
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code,
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption,
                        OBJComponents.Common.ERR_STATE.ON);
潘栩锋's avatar
潘栩锋 committed
808 809 810 811 812

                }
                else
                {
                    mWarning.Add(
813 814 815
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code,
                        FLY.Thick.Blowing.Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption,
                        OBJComponents.Common.ERR_STATE.OFF);
潘栩锋's avatar
潘栩锋 committed
816 817 818 819 820
                }
            }

        }

潘栩锋's avatar
潘栩锋 committed
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
        void checkDynAreaError()
        {
            if (mDynArea.Hrs < 48 && mDynArea.Hrs > 0)//授权限制提醒
            {
                mWarning.Add(
                    Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Code,
                    Common.ERRNOs.BASE_ERRNO_LICENSE_TIP.Descrption,
                    OBJComponents.Common.ERR_STATE.ON);
            }
            if (mDynArea.SecuteLock)
            {
                mWarning.Add(
                    Common.ERRNOs.BASE_ERRNO_LICENSE.Code,
                    Common.ERRNOs.BASE_ERRNO_LICENSE.Descrption,
                    OBJComponents.Common.ERR_STATE.ON);
            }
            if (!mDynArea.FLYADIsConnect)
            {
                mWarning.Add(
                    Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Code,
                    Common.ERRNOs.BASE_ERRNO_FLYAD7DISCONNECTED.Descrption,
                    OBJComponents.Common.ERR_STATE.ON);
            }

        }
潘栩锋's avatar
潘栩锋 committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874

        void update_datavalid()
        {
            switch (mInitParam.DataValidSrc)
            {
                case DATAVALIDSRC.VALID:
                    mDynArea.DataValid = true;
                    break;
                case DATAVALIDSRC.INVALID:
                    mDynArea.DataValid = false;
                    break;
                case DATAVALIDSRC.BYEN2:
                    {
                        if (mDynArea.FilmVelocity < 2)
                            mDynArea.DataValid = false;
                        else
                            mDynArea.DataValid = true;
                    } break;
                case DATAVALIDSRC.BYINPUT:
                    {
                        if (!Misc.MyBase.CHECKBIT(mFlyAD.IStatus, 6 - 1))
                            mDynArea.DataValid = false;
                        else
                            mDynArea.DataValid = true;
                    } break;
            }
        }


875
        
潘栩锋's avatar
潘栩锋 committed
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896

        #region 数据改变----------------------------------------------------------------




        #endregion

        #region AD卡密码操作,主机版本号操作--------------------------------------------------------
        public string Version//获取版本号
        {
            get
            {
                System.Reflection.Assembly ma = System.Reflection.Assembly.GetEntryAssembly();
                FileInfo fi = new FileInfo(ma.Location);
                FileVersionInfo mfv = FileVersionInfo.GetVersionInfo(ma.Location);
                return mfv.FileVersion;
            }

        }
        #endregion
897 898

        public int AD2Thick(int ad)
潘栩锋's avatar
潘栩锋 committed
899 900 901 902 903 904 905 906 907 908 909
        {
            int thick = Misc.MyBase.NULL_VALUE;

            if (Misc.MyBase.ISVALIDATA(ad))
            {

                if (mGetSample.Enable)//动态温修
                    thick = mCurve.AD2Value(ad, AD2ValueFlag.Revised);
                else
                    thick = mCurve.AD2Value(ad, AD2ValueFlag.NoRevised);
                
潘栩锋's avatar
潘栩锋 committed
910
                thick = (int)(thick * mProfile.Param.K);
潘栩锋's avatar
潘栩锋 committed
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
            }
            return thick;
        }




        void getSample_SampleChangedEvent(object sender)
        {

            CurveCollection pCurve = mCurve;
            GSample gsample = mGetSample;


            for (int i = 0; i < gsample.Samples.Count(); i++)
            {
                mDynArea.SampleAD[i] = gsample.Samples[i].AD;
            }

            if (gsample.OK())
            {
                List<CurveCollection.ExChange> list = new List<CurveCollection.ExChange>();
                for (int i = 0; i < gsample.Samples.Count(); i++)
                {
                    ISampleCell sample = gsample.Samples[i];
                    if ((sample.Enable) && (!sample.JustForCheck) && (sample.AD > 0))
                    {
                        list.Add(new CurveCollection.ExChange() { OrgAD = sample.OrgAD, CurrAD = sample.AD });
                    }
                }
                pCurve.ModifyExChange(list);
                pCurve.ReviseCurve();
潘栩锋's avatar
潘栩锋 committed
943
                
潘栩锋's avatar
潘栩锋 committed
944 945 946 947 948 949 950 951
                for (int i = 0; i < gsample.Samples.Count(); i++)
                {
                    ISampleCell sample = gsample.Samples[i];
                    if ((sample.Enable) && (sample.AD > 0))
                    {
                        sample.SampleValue = mCurve.AD2Value(sample.AD, AD2ValueFlag.Revised);
                    }
                }
潘栩锋's avatar
潘栩锋 committed
952 953 954 955 956 957 958 959 960 961 962 963
                
                //历史数据保存
                var sampleads = from sample in gsample.Samples where sample.Enable select sample.AD;
                if (sampleads.Count() > 0)
                {
                    mHistoryDb.AddSampleData(
                        new Lc_Sample()
                        {
                            Time = DateTime.Now,
                            SampleADs = sampleads.ToArray()
                        });
                }
潘栩锋's avatar
潘栩锋 committed
964 965 966 967 968 969 970

            }
        }


        #region ITDGageService

潘栩锋's avatar
潘栩锋 committed
971 972 973
        /// <summary>
        /// 
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
974 975 976 977 978
        public void StartP1()
        {
            mGMRenZiJiaScan.Start();
        }

潘栩锋's avatar
潘栩锋 committed
979 980 981 982
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mode"></param>
潘栩锋's avatar
潘栩锋 committed
983 984 985 986
        public void StartP2(STARTP2_MODE mode)
        {
            StartP2(mode, 0);
        }
潘栩锋's avatar
潘栩锋 committed
987 988 989 990 991
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="targetpos"></param>
潘栩锋's avatar
潘栩锋 committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
        public void StartP2(STARTP2_MODE mode, int targetpos)
        {
            switch (mode)
            {
                case STARTP2_MODE.ORG:
                    mGMOrg.Start();
                    break;
                case STARTP2_MODE.STOP:
                    mGMStop.Start();
                    break;
                case STARTP2_MODE.FORW:
                case STARTP2_MODE.FORW_UNTIL_STOP:
                    mGMForw.Start();
                    break;
                case STARTP2_MODE.BACKW:
                case STARTP2_MODE.BACKW_UNTIL_STOP:
                    mGMBackw.Start();
                    break;
                case STARTP2_MODE.RUNTO:
                    mGMRunto.Start(targetpos);
                    break;
            }
        }

        #endregion
    }
}