public void Trigger(MacTransition transition)
        {
            TriggerMember triggerMember = (TriggerMember)transition.TriggerMembers;
            var           thisState     = transition.StateFrom;

            thisState.ClearException();
            var nextState = transition.StateTo;
            var hasDoExit = false;

            try
            {
                if (triggerMember.Guard())
                {
                    if (triggerMember.Action != null)
                    {
                        triggerMember.Action(triggerMember.ActionParameter);
                    }

                    thisState.DoExit(triggerMember.ThisStateExitEventArgs);
                    hasDoExit = true;
                }
                else
                {
                    if (triggerMember.NotGuardException != null)
                    {
                        throw triggerMember.NotGuardException;
                    }
                }
            }
            catch (Exception ex)
            {
                if (triggerMember.ExceptionHandler != null)
                {
                    thisState.SetException(ex);
                    triggerMember.ExceptionHandler.Invoke(thisState, ex);
                }
            }
            if (hasDoExit)
            {
                if (nextState != null)
                {
                    nextState.DoEntry(triggerMember.NextStateEntryEventArgs);
                }
            }
        }
Example #2
0
        /// <summary> 檢測Pellicle </summary>
        public void InspectPellicle()
        {
            MacTransition transition    = null;
            TriggerMember triggerMember = null;

            transition    = Transitions[EnumMacMsCleanChTransition.ReceiveTriggerToInspectPellicle.ToString()];
            triggerMember = new TriggerMember
            {
                Guard = () =>
                {
                    return(true);
                },
                Action           = null,
                ActionParameter  = null,
                ExceptionHandler = (thisState, ex) =>
                {   // TODO: do something
                },
                NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                ThisStateExitEventArgs  = new MacStateExitEventArgs(),
            };
            transition.SetTriggerMembers(triggerMember);
            Trigger(transition);
        }
Example #3
0
        public override void LoadStateMachine()
        {
            #region State
            MacState sStart = NewState(EnumMacMsCleanChState.Start);
            //MacState sInitial = NewState(EnumMacMsCleanChState.Initial);

            MacState sIdle               = NewState(EnumMacMsCleanChState.Idle);
            MacState sCleaningPellicle   = NewState(EnumMacMsCleanChState.CleaningMask);
            MacState sInspectingPellicle = NewState(EnumMacMsCleanChState.InspectingMask);
            MacState sCleaningGlass      = NewState(EnumMacMsCleanChState.CleaningGlass);
            MacState sInspectingGlass    = NewState(EnumMacMsCleanChState.InspectingGlass);
            #endregion State

            #region Transition
            MacTransition tStart_Idle = NewTransition(sStart, sIdle, EnumMacMsCleanChTransition.PowerON);
            MacTransition tIdle_NULL  = NewTransition(sIdle, null, EnumMacMsCleanChTransition.StandbyAtIdle);

            MacTransition tIdle_CleaningPellicle   = NewTransition(sIdle, sCleaningPellicle, EnumMacMsCleanChTransition.ReceiveTriggerToCleanPellicle);
            MacTransition tCleaningPellicle_NULL   = NewTransition(sCleaningPellicle, null, EnumMacMsCleanChTransition.CleaningPellicle);
            MacTransition tCleaningPellicle_Idle   = NewTransition(sCleaningPellicle, sIdle, EnumMacMsCleanChTransition.ReceiveTriggerToReturnToIdleAfterCleanPellicle);
            MacTransition tIdle_InspectingPellicle = NewTransition(sIdle, sInspectingPellicle, EnumMacMsCleanChTransition.ReceiveTriggerToInspectPellicle);
            MacTransition tInspectingPellicle_NULL = NewTransition(sInspectingPellicle, null, EnumMacMsCleanChTransition.InspectingPellicle);
            MacTransition tInspectingPellicle_Idle = NewTransition(sInspectingPellicle, sIdle, EnumMacMsCleanChTransition.ReceiveTriggerToReturnToIdleAfterInspectPellicle);
            MacTransition tIdle_CleaningGlass      = NewTransition(sIdle, sCleaningGlass, EnumMacMsCleanChTransition.ReceiveTriggerToCleanGlass);
            MacTransition tCleaningGlass_NULL      = NewTransition(sCleaningGlass, null, EnumMacMsCleanChTransition.CleaningGlass);
            MacTransition tCleaningGlass_Idle      = NewTransition(sCleaningGlass, sIdle, EnumMacMsCleanChTransition.ReceiveTriggerToReturnToIdleAfterCleanGlass);
            MacTransition tIdle_InspectingGlass    = NewTransition(sIdle, sInspectingGlass, EnumMacMsCleanChTransition.ReceiveTriggerToInspectGlass);
            MacTransition tInspectingGlass_NULL    = NewTransition(sInspectingGlass, null, EnumMacMsCleanChTransition.InspectingGlass);
            MacTransition tInspectingGlass_Idle    = NewTransition(sInspectingGlass, sIdle, EnumMacMsCleanChTransition.ReceiveTriggerToReturnToIdleAfterInspectGlass);
            #endregion Transition

            #region State Register OnEntry OnExit
            sStart.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new CleanChException(ex.Message);
                }

                var           transition    = tStart_Idle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sStart.OnExit += (sender, e) =>
            { };
            sIdle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new CleanChException(ex.Message);
                }

                var           transition    = tIdle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sIdle.OnExit += (sender, e) =>
            { };

            sCleaningPellicle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    // TODO:清理的詳細動作
                }
                catch (Exception ex)
                {
                    throw new CleanChCleanFailException(ex.Message);
                }

                var           transition    = tCleaningPellicle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sCleaningPellicle.OnExit += (sender, e) =>
            { };
            sInspectingPellicle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    // TODO:檢查的詳細動作
                }
                catch (Exception ex)
                {
                    throw new CleanChInspectFailException(ex.Message);
                }

                var           transition    = tInspectingPellicle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sInspectingPellicle.OnExit += (sender, e) =>
            { };
            sCleaningGlass.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    // TODO:清理的詳細動作
                }
                catch (Exception ex)
                {
                    throw new CleanChCleanFailException(ex.Message);
                }

                var           transition    = tCleaningGlass_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sCleaningGlass.OnExit += (sender, e) =>
            { };
            sInspectingGlass.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    // TODO:檢查的詳細動作
                }
                catch (Exception ex)
                {
                    throw new CleanChInspectFailException(ex.Message);
                }

                var           transition    = tInspectingGlass_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sInspectingGlass.OnExit += (sender, e) =>
            { };
            #endregion State Register OnEntry OnExit
        }
Example #4
0
        public override void LoadStateMachine()
        {
            #region State
            MacState sStart   = NewState(EnumMacMsInspectionChState.Start);
            MacState sInitial = NewState(EnumMacMsInspectionChState.Initial);

            MacState sIdle                      = NewState(EnumMacMsInspectionChState.Idle);
            MacState sPellicleOnStage           = NewState(EnumMacMsInspectionChState.MaskOnStage);
            MacState sDefensingPellicle         = NewState(EnumMacMsInspectionChState.DefensingMask);
            MacState sInspectingPellicle        = NewState(EnumMacMsInspectionChState.InspectingMask);
            MacState sPellicleOnStageInspected  = NewState(EnumMacMsInspectionChState.MaskOnStageInspected);
            MacState sWaitingForReleasePellicle = NewState(EnumMacMsInspectionChState.WaitingForReleaseMask);

            MacState sGlassOnStage           = NewState(EnumMacMsInspectionChState.GlassOnStage);
            MacState sDefensingGlass         = NewState(EnumMacMsInspectionChState.DefensingGlass);
            MacState sInspectingGlass        = NewState(EnumMacMsInspectionChState.InspectingGlass);
            MacState sGlassOnStageInspected  = NewState(EnumMacMsInspectionChState.GlassOnStageInspected);
            MacState sWaitingForReleaseGlass = NewState(EnumMacMsInspectionChState.WaitingForReleaseGlass);
            #endregion State

            #region Transition
            MacTransition tStart_Initial = NewTransition(sStart, sInitial, EnumMacMsInspectionChTransition.PowerON);
            MacTransition tInitial_Idle  = NewTransition(sStart, sIdle, EnumMacMsInspectionChTransition.Initial);
            MacTransition tIdle_NULL     = NewTransition(sIdle, null, EnumMacMsInspectionChTransition.StandbyAtIdle);

            MacTransition tIdle_PellicleOnStage = NewTransition(sIdle, sPellicleOnStage, EnumMacMsInspectionChTransition.ReceiveTriggerToInspectPellicle);
            MacTransition tPellicleOnStage_DefensingPellicle                  = NewTransition(sPellicleOnStage, sDefensingPellicle, EnumMacMsInspectionChTransition.DefensePellicle);
            MacTransition tDefensingPellicle_InspectingPellicle               = NewTransition(sDefensingPellicle, sInspectingPellicle, EnumMacMsInspectionChTransition.InspectPellicle);
            MacTransition tInspectingPellicle_PellicleOnStageInspected        = NewTransition(sInspectingPellicle, sPellicleOnStageInspected, EnumMacMsInspectionChTransition.StandbyAtStageWithPellicleInspected);
            MacTransition tPellicleOnStageInspected_WaitingForReleasePellicle = NewTransition(sPellicleOnStageInspected, sWaitingForReleasePellicle, EnumMacMsInspectionChTransition.WaitForReleasePellicle);
            MacTransition tWaitingForReleasePellicle_NULL = NewTransition(sWaitingForReleasePellicle, null, EnumMacMsInspectionChTransition.StandbyAtWaitForReleasePellicle);
            MacTransition tWaitingForReleasePellicle_Idle = NewTransition(sWaitingForReleasePellicle, sIdle, EnumMacMsInspectionChTransition.ReceiveTriggerToIdleAfterReleasePellicle);

            MacTransition tIdle_GlassOnStage                            = NewTransition(sIdle, sGlassOnStage, EnumMacMsInspectionChTransition.ReceiveTriggerToInspectGlass);
            MacTransition tGlassOnStage_DefensingGlass                  = NewTransition(sGlassOnStage, sDefensingGlass, EnumMacMsInspectionChTransition.DefenseGlass);
            MacTransition tDefensingGlass_InspectingGlass               = NewTransition(sDefensingGlass, sInspectingGlass, EnumMacMsInspectionChTransition.InspectGlass);
            MacTransition tInspectingGlass_GlassOnStageInspected        = NewTransition(sInspectingGlass, sGlassOnStageInspected, EnumMacMsInspectionChTransition.StandbyAtStageWithGlassInspected);
            MacTransition tGlassOnStageInspected_WaitingForReleaseGlass = NewTransition(sGlassOnStageInspected, sWaitingForReleaseGlass, EnumMacMsInspectionChTransition.WaitForReleaseGlass);
            MacTransition tWaitingForReleaseGlass_NULL                  = NewTransition(sWaitingForReleaseGlass, null, EnumMacMsInspectionChTransition.StandbyAtWaitForReleaseGlass);
            MacTransition tWaitingForReleaseGlass_Idle                  = NewTransition(sWaitingForReleaseGlass, sIdle, EnumMacMsInspectionChTransition.ReceiveTriggerToIdleAfterReleaseGlass);
            #endregion Transition

            #region State Register OnEntry OnExit
            sStart.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new InspectionChException(ex.Message);
                }

                var           transition    = tStart_Initial;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sStart.OnExit += (sender, e) =>
            { };
            sInitial.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.Initial();
                }
                catch (Exception ex)
                {
                    throw new InspectionChInitialFailException(ex.Message);
                }

                var           transition    = tInitial_Idle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sInitial.OnExit += (sender, e) =>
            { };
            sIdle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.XYPosition(0, 0);
                    HalInspectionCh.WPosition(0);
                }
                catch (Exception ex)
                {
                    throw new InspectionChPLCExecuteFailException(ex.Message);
                }

                var           transition    = tIdle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sIdle.OnExit += (sender, e) =>
            { };


            sPellicleOnStage.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new InspectionChException(ex.Message);
                }

                var           transition    = tPellicleOnStage_DefensingPellicle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sPellicleOnStage.OnExit += (sender, e) =>
            { };
            sDefensingPellicle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    //上方相機
                    HalInspectionCh.Camera_TopDfs_CapToSave("D:/Image/IC/TopDfs", "bmp");
                    Thread.Sleep(500);

                    //側邊相機
                    for (int i = 0; i < 360; i += 90)
                    {
                        HalInspectionCh.WPosition(i);
                        HalInspectionCh.Camera_SideDfs_CapToSave("D:/Image/IC/SideDfs", "bmp");
                        Thread.Sleep(500);
                    }
                }
                catch (Exception ex)
                {
                    throw new InspectionChDefenseFailException(ex.Message);
                }

                var           transition    = tDefensingPellicle_InspectingPellicle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sDefensingPellicle.OnExit += (sender, e) =>
            { };
            sInspectingPellicle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.ZPosition(-29.6);
                    //上方相機
                    for (int i = 158; i <= 296; i += 23)
                    {
                        for (int j = 123; j <= 261; j += 23)
                        {
                            HalInspectionCh.XYPosition(i, j);
                            HalInspectionCh.Camera_TopInsp_CapToSave("D:/Image/IC/TopInsp", "bmp");
                            Thread.Sleep(500);
                        }
                    }

                    //側邊相機
                    HalInspectionCh.XYPosition(246, 208);
                    for (int i = 0; i < 360; i += 90)
                    {
                        HalInspectionCh.WPosition(i);
                        HalInspectionCh.Camera_SideInsp_CapToSave("D:/Image/IC/SideInsp", "bmp");
                        Thread.Sleep(500);
                    }
                }
                catch (Exception ex)
                {
                    throw new InspectionChInspectFailException(ex.Message);
                }

                var           transition    = tInspectingPellicle_PellicleOnStageInspected;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sInspectingPellicle.OnExit += (sender, e) =>
            { };
            sPellicleOnStageInspected.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.XYPosition(0, 0);
                    HalInspectionCh.ZPosition(0);
                }
                catch (Exception ex)
                {
                    throw new InspectionChPLCExecuteFailException(ex.Message);
                }

                var           transition    = tPellicleOnStageInspected_WaitingForReleasePellicle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sPellicleOnStageInspected.OnExit += (sender, e) =>
            { };
            sWaitingForReleasePellicle.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new InspectionChException(ex.Message);
                }

                var           transition    = tWaitingForReleasePellicle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sWaitingForReleasePellicle.OnExit += (sender, e) =>
            { };


            sGlassOnStage.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new InspectionChException(ex.Message);
                }

                var           transition    = tGlassOnStage_DefensingGlass;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sGlassOnStage.OnExit += (sender, e) =>
            { };
            sDefensingGlass.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    //上方相機
                    HalInspectionCh.Camera_TopDfs_CapToSave("D:/Image/IC/TopDfs", "bmp");
                    Thread.Sleep(500);

                    //側邊相機
                    for (int i = 0; i < 360; i += 90)
                    {
                        HalInspectionCh.WPosition(i);
                        HalInspectionCh.Camera_SideDfs_CapToSave("D:/Image/IC/SideDfs", "bmp");
                        Thread.Sleep(500);
                    }
                }
                catch (Exception ex)
                {
                    throw new InspectionChDefenseFailException(ex.Message);
                }

                var           transition    = tDefensingGlass_InspectingGlass;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sDefensingGlass.OnExit += (sender, e) =>
            { };
            sInspectingGlass.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.ZPosition(-29.6);
                    //上方相機
                    for (int i = 158; i <= 296; i += 23)
                    {
                        for (int j = 123; j <= 261; j += 23)
                        {
                            HalInspectionCh.XYPosition(i, j);
                            HalInspectionCh.Camera_TopInsp_CapToSave("D:/Image/IC/TopInsp", "bmp");
                            Thread.Sleep(500);
                        }
                    }

                    //側邊相機
                    HalInspectionCh.XYPosition(246, 208);
                    for (int i = 0; i < 360; i += 90)
                    {
                        HalInspectionCh.WPosition(i);
                        HalInspectionCh.Camera_SideInsp_CapToSave("D:/Image/IC/SideInsp", "bmp");
                        Thread.Sleep(500);
                    }
                }
                catch (Exception ex)
                {
                    throw new InspectionChInspectFailException(ex.Message);
                }

                var           transition    = tInspectingGlass_GlassOnStageInspected;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sInspectingGlass.OnExit += (sender, e) =>
            { };
            sGlassOnStageInspected.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                    HalInspectionCh.XYPosition(0, 0);
                    HalInspectionCh.ZPosition(0);
                }
                catch (Exception ex)
                {
                    throw new InspectionChPLCExecuteFailException(ex.Message);
                }

                var           transition    = tGlassOnStageInspected_WaitingForReleaseGlass;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sGlassOnStageInspected.OnExit += (sender, e) =>
            { };
            sWaitingForReleaseGlass.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);

                CheckEquipmentStatus();
                CheckAssemblyAlarmSignal();
                CheckAssemblyWarningSignal();

                try
                {
                }
                catch (Exception ex)
                {
                    throw new InspectionChException(ex.Message);
                }

                var           transition    = tWaitingForReleaseGlass_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sWaitingForReleaseGlass.OnExit += (sender, e) =>
            { };
            #endregion State Register OnEntry OnExit
        }
Example #5
0
        public override void LoadStateMachine()
        {
            #region state



            MacState sLoadMoveDrawerTraysToOutStart    = NewState(EnumMacCabinetState.LoadMoveDrawerTraysToOutStart);
            MacState sLoadMoveDrawerTraysToOutIng      = NewState(EnumMacCabinetState.LoadMoveDrawerTraysToOutIng);
            MacState sLoadMoveDrawerTraysToOutComplete = NewState(EnumMacCabinetState.LoadMoveDrawerTraysToOutComplete);

            MacState sBootupInitialDrawersStart    = NewState(EnumMacCabinetState.BootupInitialDrawersStart);
            MacState sBootupInitialDrawersIng      = NewState(EnumMacCabinetState.BootupInitialDrawersIng);
            MacState sBootupInitialDrawersComplete = NewState(EnumMacCabinetState.BootupInitialDrawersComplete);

            MacState sSynchronousDrawerStatesStart    = NewState(EnumMacCabinetState.SynchronousDrawerStatesStart);
            MacState sSynchronousDrawerStatesIng      = NewState(EnumMacCabinetState.SynchronousDrawerStatesIng);
            MacState sSynchronousDrawerStatesComplete = NewState(EnumMacCabinetState.SynchronousDrawerStatesComplete);
            #endregion state

            #region transition

            MacTransition tLoadMoveDrawerTraysToOutStart_LoadMoveDrawerTraysToOutIng = NewTransition(sLoadMoveDrawerTraysToOutStart, sLoadMoveDrawerTraysToOutIng,
                                                                                                     EnumMacCabinetTransition.LoadMoveDrawerTraysToOutStart_LoadMoveDrawerTraysToOutIng);
            MacTransition tLoadMoveDrawerTraysToOutIng_LoadMoveDrawerTraysToOutComplete = NewTransition(sLoadMoveDrawerTraysToOutIng, sLoadMoveDrawerTraysToOutComplete,
                                                                                                        EnumMacCabinetTransition.LoadMoveDrawerTraysToOutIng_LoadMoveDrawerTraysToOutComplete);
            MacTransition tLoadMoveDrawerTraysToOutComplete_NULL = NewTransition(sLoadMoveDrawerTraysToOutComplete, null,
                                                                                 EnumMacCabinetTransition.LoadMoveDrawerTraysToOutComplete_NULL);

            MacTransition tBootupInitialDrawersStart_BootupInitialDrawersIng = NewTransition(sBootupInitialDrawersStart, sBootupInitialDrawersIng,
                                                                                             EnumMacCabinetTransition.BootupInitialDrawersStart_BootupInitialDrawersIng);
            MacTransition tBootupInitialDrawersIng_BootupInitialDrawersComplete = NewTransition(sBootupInitialDrawersIng, sBootupInitialDrawersComplete,
                                                                                                EnumMacCabinetTransition.BootupInitialDrawersIng_BootupInitialDrawersComplete);
            MacTransition tBootupInitialDrawersComplete_NULL = NewTransition(sBootupInitialDrawersComplete, null,
                                                                             EnumMacCabinetTransition.BootupInitialDrawersComplete_NULL);


            MacTransition tSynchronousDrawerStatesStart_SynchronousDrawerStatesIng = NewTransition(sSynchronousDrawerStatesStart, sSynchronousDrawerStatesIng,
                                                                                                   EnumMacCabinetTransition.SynchronousDrawerStatesStart_SynchronousDrawerStatesIng);
            MacTransition tSynchronousDrawerStatesIng_SynchronousDrawerStatesComplete = NewTransition(sSynchronousDrawerStatesIng, sSynchronousDrawerStatesComplete,
                                                                                                      EnumMacCabinetTransition.SynchronousDrawerStatesIng_SynchronousDrawerStatesComplete);
            MacTransition tSynchronousDrawerStatesComplete_NULL = NewTransition(sSynchronousDrawerStatesComplete, null, EnumMacCabinetTransition.SynchronousDrawerStatesComplete_NULL);
            #endregion transition

            #region event

            sLoadMoveDrawerTraysToOutStart.OnEntry += (sender, e) =>
            { // Synch
                SetCurrentState((MacState)sender);
                var transition = tLoadMoveDrawerTraysToOutStart_LoadMoveDrawerTraysToOutIng;
                var args       = (CabinetLoadStartMacStateEntryEventArgs)e;

                var triggerMember = new TriggerMember
                {
                    Action = (parameter) =>
                    {
                        var loadDrawerStates = (List <MacMsCabinetDrawer>)parameter;
                        foreach (var state in loadDrawerStates)
                        {
                            state.Load_MoveTrayToOut();
                        }
                    },
                    ActionParameter  = args.LoadDrawerStates,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do something,
                    },
                    Guard = () => { return(true); },
                    NextStateEntryEventArgs = e,
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sLoadMoveDrawerTraysToOutStart.OnExit += (sender, e) =>
            { };

            sLoadMoveDrawerTraysToOutIng.OnEntry += (sender, e) =>
            {  // Async
                SetCurrentState((MacState)sender);
                var transition         = tLoadMoveDrawerTraysToOutIng_LoadMoveDrawerTraysToOutComplete;
                var args               = (CabinetLoadStartMacStateEntryEventArgs)e;
                var triggerMemberAsync = new TriggerMemberAsync
                {
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do something
                    },
                    Guard = (startTime) =>
                    {
                        var rtnV             = false;
                        var completeDrawers  = args.LoadDrawerStates.Where(m => m.CutrrentState == m.StateLoadWaitingPutBoxOnTray).ToList().Count();
                        var exceptionDrawers = args.LoadDrawerStates.Where(m => m.CutrrentState.IsStateMachineException.HasValue).ToList().Count();
                        if (completeDrawers + exceptionDrawers == args.LoadDrawerStates.Count())
                        {
                            rtnV = true;
                        }
                        return(rtnV);
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMemberAsync);
                TriggerAsync(transition);
            };
            sLoadMoveDrawerTraysToOutIng.OnExit += (sender, e) =>
            { };

            sLoadMoveDrawerTraysToOutComplete.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition    = tLoadMoveDrawerTraysToOutComplete_NULL;
                var triggerMember = new TriggerMember
                {
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do domething
                    },
                    Guard = () => { return(true); },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sLoadMoveDrawerTraysToOutComplete.OnExit += (sender, e) =>
            {
            };

            sBootupInitialDrawersStart.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition    = tBootupInitialDrawersStart_BootupInitialDrawersIng;
                var args          = (CabinetSystemUpInitialMacStateEntryEventArgs)e;
                var triggerMember = new TriggerMember
                {
                    Action = (parameter) =>
                    {
                        var initialDrawerStates = (List <MacMsCabinetDrawer>)parameter;
                        foreach (var state in initialDrawerStates)
                        {
                            state.SystemBootupInitial();
                        }
                    },
                    ActionParameter  = args.InitialDrawerStates,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do domething
                    },
                    Guard = () => { return(true); },
                    NextStateEntryEventArgs = e,
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sBootupInitialDrawersStart.OnExit += (sender, e) =>
            {
            };

            sBootupInitialDrawersIng.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition         = tBootupInitialDrawersIng_BootupInitialDrawersComplete;
                var args               = (CabinetSystemUpInitialMacStateEntryEventArgs)e;
                var triggerMemberAsync = new TriggerMemberAsync
                {
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do something
                    },
                    Guard = (startTime) =>
                    {
                        var rtnV = false;

                        var completeDrawers  = args.InitialDrawerStates.Where(m => m.CutrrentState == m.StateWaitingLoadInstruction).ToList().Count();
                        var exceptionDrawers = args.InitialDrawerStates.Where(m => m.CutrrentState.IsStateMachineException.HasValue).ToList().Count();
                        if (completeDrawers + exceptionDrawers == args.InitialDrawerStates.Count())
                        {
                            rtnV = true;
                        }
                        return(rtnV);
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMemberAsync);
                TriggerAsync(transition);
            };
            sBootupInitialDrawersIng.OnExit += (sender, e) =>
            {
            };

            sBootupInitialDrawersComplete.OnEntry += (sender, e) =>
            {
                var transition = tBootupInitialDrawersComplete_NULL;
                SetCurrentState((MacState)sender);
                var triggerMember = new TriggerMember
                {
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do something
                    },
                    Guard = () => { return(true); },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sBootupInitialDrawersComplete.OnExit += (sender, e) =>
            {
            };

            sSynchronousDrawerStatesStart.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition    = tSynchronousDrawerStatesStart_SynchronousDrawerStatesIng;
                var args          = (CabinetSynchronousDrawerStatesMacStateEntryEventArgs)e;
                var triggerMember = new TriggerMember
                {
                    Action = (parameter) =>
                    {
                        foreach (var state in args.SynchronousDrawerStates)
                        {
                            state.SystemBootup();
                        }
                    },
                    ActionParameter  = args.SynchronousDrawerStates,
                    ExceptionHandler = (state, ex) =>
                    {
                        // do something
                    },
                    Guard = () => { return(true); },
                    NextStateEntryEventArgs = e,
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sSynchronousDrawerStatesStart.OnEntry += (sender, e) =>
            {
            };

            sSynchronousDrawerStatesIng.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition = tSynchronousDrawerStatesIng_SynchronousDrawerStatesComplete;
                //  var args = (CabinetSystemUpInitialMacStateEntryEventArgs)e;
                var args = (CabinetSynchronousDrawerStatesMacStateEntryEventArgs)e;

                var triggerMemberAsync = new TriggerMemberAsync
                {
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (state, ex) =>
                    {
                    },
                    Guard = (startTime) =>
                    {
                        var rtnV             = false;
                        var completeDrawers  = args.SynchronousDrawerStates.Where(m => m.CutrrentState == m.StateWaitingLoadInstruction).ToList().Count();
                        var exceptionDrawers = args.SynchronousDrawerStates.Where(m => m.CutrrentState.IsStateMachineException.HasValue).ToList().Count();
                        if (completeDrawers + exceptionDrawers == args.SynchronousDrawerStates.Count())
                        {
                            rtnV = true;
                        }
                        return(rtnV);
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMemberAsync);
                TriggerAsync(transition);
            };
            sSynchronousDrawerStatesIng.OnExit += (sender, e) =>
            {
            };

            sSynchronousDrawerStatesComplete.OnEntry += (sender, e) =>
            {
                SetCurrentState((MacState)sender);
                var transition    = tSynchronousDrawerStatesComplete_NULL;
                var triggerMember = new TriggerMember
                {
                    Action                  = null,
                    ActionParameter         = null,
                    ExceptionHandler        = (state, ex) => {
                        //do something
                    },
                    Guard                   = () => { return(true); },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(),
                    NotGuardException       = null,
                    ThisStateExitEventArgs  = new MacStateExitEventArgs()
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sSynchronousDrawerStatesComplete.OnEntry += (sender, e) =>
            {
            };

            #endregion event
        }
Example #6
0
        public override void LoadStateMachine()
        {
            #region State
            MacState sStart = NewState(EnumMacMsUniversalState.Start);
            MacState sIdle  = NewState(EnumMacMsUniversalState.Idle);
            #endregion State

            #region Transition
            MacTransition tStart_Idle = NewTransition(sStart, sIdle, EnumMacMsUniversalTransition.PowerON);
            MacTransition tIdle_NULL  = NewTransition(sIdle, null, EnumMacMsUniversalTransition.ReceiveTriggerAtIdle);
            #endregion Transition

            #region State Register OnEntry OnExit
            sStart.OnEntry += (sender, e) =>
            {
                try
                {
                }
                catch (Exception ex)
                {
                    throw new UniversalException(ex.Message);
                }

                var           transition    = tStart_Idle;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sStart.OnExit += (sender, e) =>
            { };
            sIdle.OnEntry += (sender, e) =>
            {
                try
                {
                }
                catch (Exception ex)
                {
                    throw new UniversalException(ex.Message);
                }

                var           transition    = tIdle_NULL;
                TriggerMember triggerMember = new TriggerMember
                {
                    Guard = () =>
                    {
                        return(true);
                    },
                    Action           = null,
                    ActionParameter  = null,
                    ExceptionHandler = (thisState, ex) =>
                    { // TODO: do something
                    },
                    NextStateEntryEventArgs = new MacStateEntryEventArgs(null),
                    ThisStateExitEventArgs  = new MacStateExitEventArgs(),
                };
                transition.SetTriggerMembers(triggerMember);
                Trigger(transition);
            };
            sIdle.OnExit += (sender, e) =>
            { };
            #endregion State Register OnEntry OnExit
        }