Esempio n. 1
0
        private void DoCheckInitCompleted()
        {
            try
            {
                _workcell.DisplayTitleMessage("Initializing system...");
                Log.Info(this, "{0}, system initialization started", LoggerCategory.SystemInitializationStarted);

                while (true)
                {
                    if (_disposed)
                    {
                        return;
                    }
                    try
                    {
                        bool exit = true;
                        // If all processes are initialized, then exit and stop machine. (Except Non-idle process such MonitorProcess).
                        foreach (ActiveProcess p in this.ActiveProcess.Values)
                        {
                            ActiveProcessHST clp = (ActiveProcessHST)p;
                            if (clp.IsStateInitialized == false && !clp.IsNonIdleProcess)
                            {
                                exit = false;
                            }
                        }
                        if (_isInit & exit)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        // Do nothing
                    }
                }
                Stop();
                Log.Info(this, "{0}, System initialization ended", LoggerCategory.SystemInitializationEnded);

                _lastActiveRunMode       = OperationMode.Auto; // Reset last active mode to Auto
                _isInit                  = false;
                _workcell.IsMachineHomed = true;
                _workcell.DisplayTitleMessage("System Initialized");
                if (OnInit != null)
                {
                    OnInit(this, null);
                }

                // Auto run
                if (_autoRunAfterInit)
                {
                    Start();
                }
            }
            catch (Exception ex)
            {
                Notify.PopUpError("Exception in DoCheckInitCompleted", ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Trigger initialization process for the machine.
        /// </summary>
        public void InitializeMachine(bool isAutoRun)
        {
            if (_monitorProcess.HasError && !HSTMachine.Workcell.Process.MonitorProcess.Controller.IsCriticalTriggeringActivated &&
                !HSTMachine.Workcell.HSTSettings.ResistanceCheckingConfig.ResistanceCriticalActivated)
            {
                throw new Exception("Please clear monitor error first");
            }
            ThreadPool.QueueUserWorkItem(delegate
            {
                Thread.Sleep(1000);
                //lock (ServiceManager.ErrorHandler)
                {
                    try
                    {
                        ServiceManager.ErrorHandler.AutoClearMessages();
                    }
                    catch (Exception ex)
                    {
                        Console.Beep();
                    }
                }
                if (OnInitStart != null)
                {
                    OnInitStart(this, new EventArgs());
                }
                _autoRunAfterInit        = isAutoRun;
                _isInit                  = true;
                _workcell.IsMachineHomed = false;
                if (_checkHomeDoneThread != null && _checkHomeDoneThread.IsAlive)
                {
                    _checkHomeDoneThread.Abort();
                }

                // Make all not init done.
                foreach (ActiveProcess p in this.ActiveProcess.Values)
                {
                    ActiveProcessHST clp   = (ActiveProcessHST)p;
                    clp.IsStateInitialized = false;
                }
                Stop();
                while (true)
                {
                    Thread.Sleep(10);
                    bool isBreak = true;
                    foreach (ActiveProcessHST activeHST in this.activeObjects.Values)
                    {
                        if (activeHST.IsNonIdleProcess == false && activeHST.CurrentStateName != "StateIdle" &&
                            activeHST.IsNonIdleProcess == false && activeHST.CurrentStateName != "StateError")
                        {
                            isBreak = false;
                        }
                    }
                    if (isBreak)
                    {
                        break;
                    }
                }
                Thread.Sleep(200);

                Start();
                Thread.Sleep(200);

                _checkHomeDoneThread              = new Thread(DoCheckInitCompleted);
                _checkHomeDoneThread.Name         = "ProcessInit";
                _checkHomeDoneThread.IsBackground = true;
                _checkHomeDoneThread.Start();

                Thread.Sleep(200);
            });
        }