private void MakeProcess()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = Process;

            #region RegisterEventHandler
            seq.OnStart +=
                delegate
                {
                    RetryInfoGateChangeRetry.ClearCount();
                };
            #endregion

            #region AddSteps
            seq.Steps.Add("IncreaseGateNo", new StepInfo());
            seq.Steps.Add("RetryRequestLotClose", new StepInfo());
            seq.Steps.Add("RequestMasterInfo", new StepInfo());
            seq.Steps.Add("RequestLotClose", new StepInfo());
            seq.Steps.Add("SelectUnloadingDirection", new StepInfo());
            #endregion

            seq.AddItem(Aligner.Extend.Sequence);
            #region CheckTrayEdge
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (UseTrayIndexCheck && RFReaderUnit.EdgeSensor.IsOn)
                    {
                        string windowName = string.Empty;
                        var alarm = Utility.AlarmUtility.GetAlarm(AlarmTrayIndexDirectionFailDetected, "[RF READER MODULE] Tray Index Direction Fail.");
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                            "TrayIndexDirectionFail",
                            out windowName,
                            alarm,
                            string.Empty,
                            true);

                        NextModule = FailureWayModule;
                        WriteTraceLog("Unloading to Fail C/V. Edge Sensor Detected.");
                        actor.NextStep("SelectUnloadingDirection");
                    }
                    else
                    {
                        actor.NextStep();
                    }
                });
            #endregion
            #region ConfirmManualLotIDInput
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN)
                    {
                        ProductInfo.VT8792ProductInfo.TrayCount = LotTrayCount;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID = "TEST_LOT";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_MARKING = "TEST";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID = "TEST";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X = 2;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y = 3;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = LotSmallBoxMOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = LotSmallBoxMOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = LotSmallBoxMOQ;
                        WriteTraceLog("Track In " + ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID);
                        actor.NextStep();
                    }
                    else if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        ProductInfo.VT8792ProductInfo.TrayCount = LotTrayCount;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID = "TEST_LOT";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_MARKING = "TEST";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID = "TEST";
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X = 2;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y = 3;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = LotSmallBoxMOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = LotSmallBoxMOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = LotSmallBoxMOQ;
                        actor.NextStep();
                    }
                    else
                    {
                        if (UseManualLotIDInput)
                        {
                            if (LotIDList.Count > 0)
                            {
                                try
                                {
                                    ReadingLotID = LotIDList.First();
                                    string lotID = ReadingLotID;

                                    WriteTraceLog(string.Format("Read Lot ID. {0}", ReadingLotID));

                                    System.Windows.Threading.DispatcherTimer timer =
                                        new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Normal, App.Current.Dispatcher);

                                    timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
                                    timer.Tick +=
                                        delegate
                                        {
                                            try
                                            {
                                                LotIDList.Remove(lotID);
                                                timer.Stop();
                                            }
                                            catch
                                            {
                                            }
                                        };
                                    timer.Start();

                                    actor.NextStep();
                                }
                                catch
                                {
                                    actor.NextStep();
                                }
                            }
                        }
                        else
                            actor.NextStep();
                    }
                });
            #endregion
            #region IncreaseGateNo
            seq.Steps["IncreaseGateNo"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    if (CurrentGate == GATE_NO_ZERO)
                    {
                        CurrentGate = GATE_NO_MIN;
                    }
                    else
                    {
                        CurrentGate++;
                        if (CurrentGate > GATE_NO_MAX)
                            CurrentGate = GATE_NO_MIN;
                    }
                });
            #endregion
            seq.AddItem(new FASequenceAtomicInfo(ScanAndTrayCounting, true));
            #region ConfirmReadSuccessRFID
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        if (RFIDScanSuccess)
                            actor.NextStep();
                        else
                        {
                            string windowName = string.Empty;
                            var alarm = Utility.AlarmUtility.GetAlarm(AlarmRFIDScanFail, "[RF READER MODULE] RFID Scan Fail.");
                            Manager.MessageWindowManager.Instance.Show(Equipment,
                                "RFIDScanFail",
                                out windowName,
                                alarm,
                                string.Empty,
                                true);
                            NextModule = FailureWayModule;
                            actor.NextStep("SelectUnloadingDirection");
                        }
                    }
                    else
                    {
                        actor.NextStep("SelectUnloadingDirection");
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    string msg = string.Empty;
                    if (ConstainLot(ReadingLotID, out msg) == true)
                        actor.NextStep();
                    else
                    {
                        string windowName = string.Empty;
                        var alarm = Utility.AlarmUtility.GetAlarm(AlarmDuplicateLotID, "[RF READER MODULE] Duplicate LotID.");
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                            "RFReaderDuplicateLotID",
                            out windowName,
                            alarm,
                            string.Format("LOT_ID={0}", ReadingLotID),
                            true);
                        NextModule = FailureWayModule;
                        actor.NextStep("SelectUnloadingDirection");
                    }
                });
            #endregion
            #region RequestMasterInfo
            seq.Steps["RequestMasterInfo"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.PACKING_MASTER_INFO_REQ command = new FAECInfo.PACKING_MASTER_INFO_REQ();
                    command.LOT_ID = ReadingLotID;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.PACKING_MASTER_INFO.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ProductInfo.SerialBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.SERIAL);
                                ProductInfo.PPIDBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.PPID);
                                ProductInfo.WWNBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.WWN);
                                ProductInfo.CSerialBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.C_SERIAL);
                                ProductInfo.PSIDBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.PSID);

                                WriteTraceLog("PACKING MASTER INFO RECEIVE OK");
                                ecResult.ECInfo.PACKING_MASTER_INFO.CopyTo(ProductInfo.ECInfo.PACKING_MASTER_INFO);
                                actor.NextStep();
                            }
                            else
                            {
                                string windowName = string.Empty;
                                var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] PACKING MASTER INFO EC RESULT FAIL.");
                                Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                                NextModule = FailureWayModule;
                                actor.NextStep("SelectUnloadingDirection");
                            }
                        }
                        else
                        {
                            string windowName = string.Empty;
                            var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] EC PACKING MASTER INFO RECEIVE DATA PARSING FAIL.");
                            Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                            NextModule = FailureWayModule;
                            actor.NextStep("SelectUnloadingDirection");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        string windowName = string.Empty;
                        var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] EC PACKING MASTER INFO RECEIVE FAIL.");
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                        NextModule = FailureWayModule;
                        actor.NextStep("SelectUnloadingDirection");
                    }
                });
            #endregion
            #region ConfirmStepCorrection
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    var step = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_STEP;
                    bool result = false;
                    string windowName = string.Empty;
                    string msg = string.Empty;

                    if (string.IsNullOrEmpty(step) == true)
                        msg = string.Format("LOT_ID={0}, Step is Empty", ReadingLotID);
                    else if (step == ValidStep1 ||
                        step == ValidStep2 ||
                        step == ValidStep3)
                        result = true;
                    else
                        msg = string.Format("LOT_ID={0}, Invalid Step. {1}", ReadingLotID, step);

                    if (result == true)
                    {
                        actor.NextStep();
                    }
                    else
                    {
                        var alarm = Utility.AlarmUtility.GetAlarm(AlarmInvalidStep, msg);
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "InvalidStep",
                                    out windowName,
                                    alarm,
                                    msg,
                                    true);
                        NextModule = FailureWayModule;
                        actor.NextStep("SelectUnloadingDirection");
                    }
                });
            #endregion
            seq.AddItem(LoadJob);
            #region SendRecipeFileToGEM
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    var VT8792Equipment = Equipment as VT8792.SubEquipment;
                    if (VT8792Equipment.GlobalConfigModule.UseGEMCommunication == false)
                    {
                        actor.NextStep();
                        return;
                    }

                    bool raisedException = false;
                    try
                    {
                        string recipeName = ProductInfo.ECInfo.PACKING_MASTER_INFO.PRODUCT_NAME;
                        string recipeFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), recipeName);
                        string recipe = string.Empty;
                        LotJobInfo.ToINIFormat(out recipe);
                        System.IO.File.WriteAllText(recipeFileName, recipe);
                        GEM.GEMFuncWrapper.SendRecipeFile(recipeName, recipeFileName);
                        raisedException = false;
                    }
                    catch
                    {
                        raisedException = true;
                    }
                    finally
                    {
                        if (raisedException == false)
                            actor.NextStep();
                    }
                });
            #endregion
            #region ConfirmTrayCountCorrection
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        if (UseTrayCodeOfAJob)
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_MARKING = JobInfo.TrayCode;

                        var ecTrayCount = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY /
                            (ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X * ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y);
                        var ssdCountInTray = ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X * ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y;
                        var lotQty = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY;
                        ecTrayCount = lotQty / ssdCountInTray;

                        if (lotQty % ssdCountInTray > 0)
                            ecTrayCount += 1;

                        ProductInfo.VT8792ProductInfo.TrayCount = ecTrayCount;
                        ProductInfo.VT8792ProductInfo.RemainSSDCount = lotQty % ssdCountInTray;

                        if (ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ < ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY)
                        {
                            NextModule = FailureWayModule;

                            string msg = string.Format("EC Data Invalid. LOT_QTY is better than S_BOX_MOQ. LOT_QTY={0}, S_BOX_MOQ={1}",
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ);

                            Manager.MessageWindowManager.Instance.Show(Equipment, "TrayCountNotCorrect", msg);
                            actor.NextStep("SelectUnloadingDirection");
                        }
                        else if (ecTrayCount > TRAY_NO_MAX)
                        {
                            NextModule = FailureWayModule;

                            string msg = string.Format("EC Tray Count is better than {0}. LOT_QTY={1}, ARRAY_X={2}, ARRAY_Y={3}",
                                TRAY_NO_MAX,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y);

                            Manager.MessageWindowManager.Instance.Show(Equipment, "TrayCountNotCorrect", msg);
                            actor.NextStep("SelectUnloadingDirection");
                        }
                        else if (ecTrayCount != TrayCount - 1 && UseTrayCountCheck)
                        {
                            NextModule = FailureWayModule;

                            string msg = string.Format("Tray Count Not Correct.\n[DETECTED TRAY COUNT]={0}\n[EC INFO] TRAY_COUNT={1}, LOT_QTY={2}, ARRAY_X={3}, ARRAY_Y={4}",
                            TrayCount - 1,
                            ecTrayCount,
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY,
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X,
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y);

                            Manager.MessageWindowManager.Instance.Show(Equipment, "TrayCountNotCorrect", msg);
                            actor.NextStep("SelectUnloadingDirection");
                        }
                        else
                            actor.NextStep("RequestLotClose");
                    }
                });
            #endregion
            #region RetryRequestLotClose
            seq.Steps["RetryRequestLotClose"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    if (CurrentGate == GATE_NO_ZERO)
                    {
                        CurrentGate = GATE_NO_MIN;
                    }
                    else
                    {
                        CurrentGate++;
                        if (CurrentGate > GATE_NO_MAX)
                            CurrentGate = GATE_NO_MIN;
                    }
                });
            #endregion
            #region RequestLotClose
            seq.Steps["RequestLotClose"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.LOT_CLOSE_REQ command = new FAECInfo.LOT_CLOSE_REQ();
                    command.LOT_ID = ReadingLotID;
                    command.GATE = string.Format("GATE{0}", CurrentGate.ToString());
                    command.OPER_ID = Equipment.CurrentUser.Name;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.LOT_CLOSE.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                Manager.MessageWindowManager.Instance.CloseWindow("GateAlreadyWorkingWarning");
                                WriteTraceLog("LOT CLOSE OK");
                                NextModule = SuccessWayModule;
                                ecResult.ECInfo.LOT_CLOSE.CopyTo(ProductInfo.ECInfo.LOT_CLOSE);
                                actor.NextStep();
                            }
                            else if (string.IsNullOrEmpty(ecResult.ECInfo.LOT_CLOSE.MSG) == false && ecResult.ECInfo.LOT_CLOSE.MSG.IndexOf(GateAlreadyWorkingMsg) >= 0)
                            {
                                if (RetryInfoGateChangeRetry.IncreaseCount() == false)
                                {
                                    Manager.MessageWindowManager.Instance.Show(Equipment, "GateAlreadyWorkingWarning", string.Concat(ecResult.ECInfo.LOT_CLOSE.MSG, ", ", ReadingLotID));
                                    NextModule = FailureWayModule;
                                    actor.NextStep("SelectUnloadingDirection");
                                }
                                else
                                    actor.NextStep("RetryRequestLotClose");
                            }
                            else
                            {
                                string windowName = string.Empty;
                                var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] LOT CLOSE INFO EC RESULT FAIL.");
                                Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                                NextModule = FailureWayModule;
                                actor.NextStep("SelectUnloadingDirection");
                            }
                        }
                        else if (string.IsNullOrEmpty(ecResult.ECInfo.LOT_CLOSE.MSG) == false && ecResult.ECInfo.LOT_CLOSE.MSG.IndexOf(GateAlreadyWorkingMsg) >= 0)
                        {
                            if (RetryInfoGateChangeRetry.IncreaseCount() == false)
                            {
                                Manager.MessageWindowManager.Instance.Show(Equipment, "GateAlreadyWorkingWarning", string.Concat(ecResult.ECInfo.LOT_CLOSE.MSG, ", ", ReadingLotID));
                                NextModule = FailureWayModule;
                                actor.NextStep("SelectUnloadingDirection");
                            }
                            else
                                actor.NextStep("RetryRequestLotClose");
                        }
                        else
                        {
                            var msg = GetErrorMessageOfTrayLOTCLOSECheck(ecResult.ECInfo.LOT_CLOSE);
                            string windowName = string.Empty;
                            var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] EC LOT CLOSE INFO RECEIVE DATA PARSING FAIL.");
                            Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    msg,
                                    true);
                            NextModule = FailureWayModule;
                            actor.NextStep("SelectUnloadingDirection");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        string windowName = string.Empty;
                        var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] EC LOT CLOSE INFO RECEIVE FAIL.");
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "RFReaderECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                        NextModule = FailureWayModule;
                        actor.NextStep("SelectUnloadingDirection");
                    }
                });
            #endregion
            #region SelectUnloadingDirection
            seq.Steps["SelectUnloadingDirection"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (NextModule == FailureWayModule)
                    {
                        string msg = string.Empty;
                        actor.NextTerminate();
                    }
                    else
                        actor.NextStep();
                });
            #endregion
            #region PreUnloadingAction
            seq.AddItem(
                delegate(object obj)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        ProductInfo.Gate = string.Format("GATE{0}", CurrentGate);

                        var ssdCountInTray = ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X * ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y;
                        var lotQty = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY;
                        int trayCount = lotQty / ssdCountInTray;

                        if (lotQty % ssdCountInTray > 0)
                            trayCount += 1;

                        ProductInfo.VT8792ProductInfo.TrayCount = trayCount;
                        ProductInfo.VT8792ProductInfo.RemainSSDCount = lotQty % ssdCountInTray;
                    }
                });
            seq.AddItem((object obj) => NextModule = SuccessWayModule);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        if (UseTrayCoutingResultOnDryRun)
                        {
                            ProductInfo.VT8792ProductInfo.TrayCount = TrayCount - 1;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID = "TEST_LOT";
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_MARKING = "TEST";
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID = "TEST";
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X = 2;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y = 3;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = LotSmallBoxMOQ;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = LotSmallBoxMOQ;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = ProductInfo.VT8792ProductInfo.TrayCount * 2 * 3;
                            actor.NextStep();
                        }
                        else
                            actor.NextStep();
                    }
                    else
                        actor.NextStep();
                });
            seq.AddItem(
                delegate(object obj)
                {
                    string msg;
                    AddLot(ReadingLotID, out msg);
                    Equipment.LotManager.AddLot(ReadingLotID);
                });
            #endregion
        }
        public PackingMasterInfoControl()
        {
            Command = new FAECInfo.PACKING_MASTER_INFO_REQ();

            InitializeComponent();
        }
        private void MakeProcess()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = Process;

            seq.OnStart +=
                delegate
                {
                    RetryBarcodeScan.ClearCount();
                    RetryBarcodeDecoding.ClearCount();
                };

            seq.Steps.Add("ConfirmScanCompleted", new StepInfo());
            seq.Steps.Add("ConfirmLotChange", new StepInfo());
            seq.Steps.Add("PreStopperDown", new StepInfo());
            seq.Steps.Add("RetryScan", new StepInfo());

            seq.AddItem(
                delegate(object obj)
                {
                    SSDBoxInletUnit.ConveyorMotor.Run.Execute(this);
                    ProductInfo.VT5070ProductInfo.LastProductInfoInstance.TrackOutCompleted = false;
                });
            seq.Steps["ConfirmScanCompleted"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN)
                        actor.NextStep();
                    else if (string.IsNullOrEmpty(SSDBoxInletUnit.Scanner.Barcode.Barcode) == false)
                    {
                        SSDBoxInletUnit.Scanner.TriggerOff(actor);
                        ProductInfo.VT5070ProductInfo.TurnkeyBoxBarcode = SSDBoxInletUnit.Scanner.Barcode.Barcode;
                        WriteTraceLog(string.Format("T/K Box Scan Success : {0}", ProductInfo.VT5070ProductInfo.TurnkeyBoxBarcode));
                        actor.NextStep();
                    }
                    else if (TimeBarcodeScanTimeout.Time < time)
                    {
                        if (RetryBarcodeScan.IncreaseCount() == false)
                            RaiseAlarm(actor, AlarmBarcodeScanFail);

                        actor.NextStep("RetryScan");
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                        actor.NextStep();
                    else
                    {
                        actor.NextStep("ConfirmLotChange");
                    }
                });
            seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.PACKING_MASTER_INFO_REQ command = new FAECInfo.PACKING_MASTER_INFO_REQ();
                    command.SERIAL = ProductInfo.VT5070ProductInfo.TurnkeyBoxBarcode;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.PackingMasterInfo.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ecResult.ECInfo.PackingMasterInfo.CopyTo(ProductInfo.ECInfo.PackingMasterInfo);
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, ecResult.LastAlarmNo,
                                    string.Format("EC MSG : {0}\nFail Message : {1}",
                                        ecResult.ECInfo.PackingMasterInfo.MSG,
                                        ecResult.ParsingFailMessage));
                                actor.NextStep("RetryScan");
                            }
                        }
                        else
                        {
                            RaiseAlarm(actor, ecResult.LastAlarmNo,
                                    string.Format("EC MSG : {0}\nFail Message : {1}",
                                        ecResult.ECInfo.PackingMasterInfo.MSG,
                                        ecResult.ParsingFailMessage));
                            actor.NextStep("RetryScan");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        RaiseAlarm(actor, ecResult.LastAlarmNo,
                                    string.Format("EC MSG : {0}\nFail Message : {1}",
                                        ecResult.ECInfo.PackingMasterInfo.MSG,
                                        ecResult.ParsingFailMessage));
                        actor.NextStep("RetryScan");
                    }
                });
            seq.Steps["ConfirmLotChange"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    bool changedLot = false;
                    bool duplicateSerial = false;
                    bool differentLot = false;

                    if (AddLoadingCount(ProductInfo.ECInfo.PackingMasterInfo,
                        ProductInfo.VT5070ProductInfo.TurnkeyBoxBarcode,
                        out changedLot,
                        out differentLot,
                        out duplicateSerial) == true)
                    {
                        if (changedLot)
                        {
                            CurrentLastProductInfo = new VT5070ProductInfo.LastProductInfo();
                            FARobotControlModule.RobotWork work = new FARobotControlModule.RobotWork();
                            RobotControlModule.AddWork(ProductInfo.ECInfo.PackingMasterInfo, ProductInfo);
                            Equipment.ProductOutput.TrackInLot(DateTime.Now, ProductInfo.ECInfo.PackingMasterInfo.LOT_ID);
                            WriteTraceLog(string.Format("TRACK IN LOT : {0}", ProductInfo.ECInfo.PackingMasterInfo.LOT_ID));
                        }

                        ProductInfo.VT5070ProductInfo.LastProductInfoInstance = CurrentLastProductInfo;
                        Equipment.ProductOutput.AddProduct(DateTime.Now, ProductInfo.ECInfo.PackingMasterInfo.LOT_ID);
                        WriteTraceLog(string.Format("Add T/K Box : {0}", ProductInfo.VT5070ProductInfo.TurnkeyBoxBarcode));
                        actor.NextStep();
                    }
                    else
                    {
                        if (differentLot)
                            RaiseAlarm(actor, AlarmDifferentLotInput);
                        else if (duplicateSerial)
                        {
                            if (RetryBarcodeDecoding.IncreaseCount() == false)
                                RaiseAlarm(actor, AlarmDuplicationSerialInput);
                        }

                        actor.NextStep("RetryScan");
                    }
                });
            seq.Steps["PreStopperDown"].StepIndex =
                seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (SelectedStackerNo == StackerNo.Stacker2)
                    {
                        if (SSDStackerModule1.SafetyForMoving)
                            actor.NextStep();
                    }
                    else
                        actor.NextStep();
                });
            seq.AddTerminate();

            seq.Steps["RetryScan"].StepIndex = seq.AddItem(SSDBoxInletUnit.Scanner.TriggerOff);
            seq.AddItem(new FATime(FATimeType.millisecond, 300));
            seq.AddItem((object obj) => SSDBoxInletUnit.Scanner.Barcode.Clear());
            seq.AddItem(SSDBoxInletUnit.Scanner.TriggerOn);
            seq.AddItem("ConfirmScanCompleted");
        }
        private void MakeLoading()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = Loading;

            seq.OnSuspending +=
                delegate
                {
                    RetryInfoLoading.ClearCount();
                    TrayLoadingUnit.ConveyorMotor.Stop.Execute(this);
                };
            seq.OnStop +=
                delegate
                {
                    RetryInfoLoading.ClearCount();
                    TrayLoadingUnit.ConveyorMotor.Stop.Execute(this);
                };

            seq.Steps.Add("Start", new StepInfo());
            seq.Steps.Add("ConfirmRunDown", new StepInfo());
            seq.Steps.Add("ConfirmStartSignal", new StepInfo());
            seq.Steps.Add("ReceiveData", new StepInfo());
            seq.Steps.Add("ConfirmReleaseReadyOff", new StepInfo());
            seq.Steps.Add("ConfirmArrivalTray", new StepInfo());
            seq.Steps.Add("ECComm", new StepInfo());
            seq.Steps.Add("ReadyOff", new StepInfo());

            seq.Steps["Start"].StepIndex =
                seq.AddItem(TrayLoadingUnit.Stopper.Up.Sequence);
            seq.AddItem("ConfirmStartSignal");

            seq.Steps["ConfirmRunDown"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ForceLoading)
                    {
                        if (TrayLoadingUnit.InSensor.IsOn)
                        {
                            Equipment.RequestStart();
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = 1;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = 120;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = 120;

                            actor.NextStep("ConfirmArrivalTray");
                        }
                    }
                    else if (InterfaceUnit.FrontMachineAutoRunning.IsOn &&
                        InterfaceUnit.FrontMachineTransferReady.IsOn)
                    {
                        Equipment.RequestStart();
                        InterfaceUnit.TransferReady.DoTurnOn(actor);
                        actor.NextStep("ConfirmReleaseReadyOff");
                    }
                    else if (TimeRunDownTime.Time < time)
                    {
                        Equipment.SetRundown();
                    }
                });
            seq.Steps["ConfirmStartSignal"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ForceLoading)
                    {
                        if (TrayLoadingUnit.InSensor.IsOn)
                        {
                            Equipment.RequestStart();
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = 1;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = 120;
                            ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = 120;

                            actor.NextStep("ConfirmArrivalTray");
                        }
                    }
                    else if (InterfaceUnit.FrontMachineAutoRunning.IsOn &&
                        InterfaceUnit.FrontMachineTransferReady.IsOn)
                    {
                        Equipment.RequestStart();
                        InterfaceUnit.TransferReady.DoTurnOn(actor);
                        actor.NextStep();
                    }
                    else if (Equipment.LotManager.IsEmpty)
                    {
                        actor.NextStep("ConfirmRunDown");
                    }
                });
            seq.Steps["ConfirmReleaseReadyOff"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (InterfaceUnit.FrontMachineAutoRunning.IsOn &&
                        InterfaceUnit.FrontMachineTransferReady.IsOff)
                    {
                        actor.NextStep();
                    }
                });

            seq.Steps["ConfirmArrivalTray"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ForceLoading == false && InterfaceUnit.FrontMachineAutoRunning.IsOn == false)
                    {
                        TrayLoadingUnit.ConveyorMotor.Stop.Execute(actor);
                        actor.NextStep("ConfirmArrivalTray");
                    }
                    else if (TrayLoadingUnit.StopSensor.IsOn)
                    {
                        ProductInfo.ExistProduct = true;
                        TrayLoadingUnit.ConveyorMotor.Stop.Execute(actor);
                        actor.NextStep();
                    }
                    else if (TimeLoadingTimeout.Time < time)
                    {
                        if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN)
                        {
                            TrayLoadingUnit.ConveyorMotor.Stop.Execute(actor);
                            actor.NextStep();
                        }
                        else
                        {
                            if (RetryInfoLoading.IncreaseCount() == false)
                                RaiseAlarm(actor, AlarmLoadingFail, TrayLoadingUnit.StopSensor.GetInputIOStatus());

                            actor.NextStep("ConfirmArrivalTray");
                        }
                    }
                    else
                        TrayLoadingUnit.ConveyorMotor.Run.Execute(actor);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ForceLoading)
                        actor.NextTerminate();
                    else
                        actor.NextStep();
                });

            seq.Steps["ReceiveData"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (InterfaceUnit.FrontMachineAutoRunning.IsOn)
                    {
                        if (ReceivedDataFromFrontMachine.Exist == true)
                        {
                            if (ReceivedDataFromFrontMachine.Error)
                            {
                                RaiseAlarm(actor, AlarmFrontMachineDataError);
                            }
                            else
                            {
                                Equipment.RequestStart();
                                ProductInfo.ECInfo.LOT_CLOSE.LOT_ID = ReceivedDataFromFrontMachine.ReceiveData.LOT_ID;
                                ReceivedDataFromFrontMachine.Exist = false;
                                actor.NextStep();
                            }
                        }
                        else if (TimeLoadingTimeout.Time < time)
                        {
                            RaiseAlarm(actor, AlarmDataReceiveFailFromFrontMachine);
                        }
                    }
                    else
                        actor.NextStep("ReceiveData");
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        actor.NextStep();
                    }
                    else
                    {
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.L_BOX_MOQ = ReceivedDataFromFrontMachine.ReceiveData.LOT_MOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.S_BOX_MOQ = ReceivedDataFromFrontMachine.ReceiveData.LOT_MOQ;
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY = ReceivedDataFromFrontMachine.ReceiveData.LOT_QTY;
                        actor.NextStep("ReadyOff");
                    }
                });
            seq.Steps["ECComm"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.PACKING_MASTER_INFO_REQ command = new FAECInfo.PACKING_MASTER_INFO_REQ();
                    command.LOT_ID = ProductInfo.ECInfo.LOT_CLOSE.LOT_ID;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.PACKING_MASTER_INFO.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ProductInfo.VT5081ProductInfo.ProductStatus = EProductStatus.Normal;
                                ecResult.ECInfo.PACKING_MASTER_INFO.CopyTo(ProductInfo.ECInfo.PACKING_MASTER_INFO);
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, ecResult.LastAlarmNo);
                                actor.NextStep("ECComm");
                            }
                        }
                        else
                        {
                            RaiseAlarm(actor, ecResult.LastAlarmNo);
                            actor.NextStep("ECComm");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        RaiseAlarm(actor, ecResult.LastAlarmNo);
                        actor.NextStep("ECComm");
                    }
                });

            seq.Steps["ReadyOff"].StepIndex = seq.AddItem(InterfaceUnit.TransferReady.DoTurnOff);
        }
        private void MakeScanBarcode()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = ScanBarcode;

            seq.OnStart +=
                delegate { RetryInfoBarcodeScan.ClearCount(); };

            seq.Steps.Add("Start", new StepInfo());
            seq.Steps.Add("AddLoadingCount", new StepInfo());
            seq.Steps.Add("RequestPackingMasterInfo", new StepInfo());
            seq.Steps.Add("RequestSmallBoxInfo", new StepInfo());

            seq.Steps["Start"].StepIndex = seq.AddItem(SmallBoxLoadingUnit.Scanner.TriggerOn);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        ProductInfo.ECInfo.PackingMasterInfo.LOT_ID = "TEST LOT";
                        ProductInfo.ECInfo.PackingMasterInfo.PART_ID = "BRAND_BOX";
                        ProductInfo.ECInfo.PackingMasterInfo.S_BOX_MOQ = 10;
                        ProductInfo.ECInfo.PackingMasterInfo.L_BOX_MOQ = MAX_SMALLBOX_COUNT;
                        ProductInfo.ECInfo.PackingMasterInfo.LOT_QTY = 30;
                        ProductInfo.VT5080ProductInfo.Gate = Gate;

                        InputCount++;

                        if (GlobalConfigModule.RobotWorkType == ERobotWorkType.StartAtScanedFirstSmallBox)
                        {
                            if (InputCount == 1)
                            {
                                RobotControlModule.AddWork(ProductInfo);
                            }
                        }
                        else if (GlobalConfigModule.RobotWorkType == ERobotWorkType.StartAtScanedLastSmallBox)
                        {
                            if (InputCount == MAX_SMALLBOX_COUNT)
                            {
                                RobotControlModule.AddWork(ProductInfo);
                            }
                        }

                        if (InputCount == MAX_SMALLBOX_COUNT)
                            InputCount = 0;

                        actor.NextTerminate();
                    }
                    else
                    {
                        if (IsEmptyBox(LoadingCount))
                        {
                            if (TimeScanTimeout.Time < time)
                            {
                                CurrentLotInfo.CopyTo(ProductInfo.ECInfo.PackingMasterInfo);
                                WriteTraceLog("Scan Success Empty Box");
                                actor.NextStep("AddLoadingCount");
                            }
                            else if (string.IsNullOrEmpty(SmallBoxLoadingUnit.Scanner.Barcode.Barcode) == false)
                            {
                                if (RetryInfoBarcodeScan.IncreaseCount() == false)
                                    RaiseAlarm(actor, AlarmBarcodeDetectedOnAEmptyBox);

                                actor.NextStep("Start");
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(SmallBoxLoadingUnit.Scanner.Barcode.Barcode) == false)
                            {
                                LotID = SmallBoxLoadingUnit.Scanner.Barcode.Barcode;
                                ProductInfo.VT5080ProductInfo.SmallBoxID = LotID;
                                WriteTraceLog("Barcode Scan Success : " + LotID);
                                actor.NextStep();
                            }
                            else if (TimeScanTimeout.Time < time)
                            {
                                if (RetryInfoBarcodeScan.IncreaseCount() == false)
                                    RaiseAlarm(actor, AlarmBarcodeScanFail);

                                actor.NextStep("Start");
                            }
                        }
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                        actor.NextTerminate();
                    else if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        actor.NextStep();
                    }
                });
            seq.Steps["RequestPackingMasterInfo"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    bool exception = false;

                    if (string.IsNullOrEmpty(LotID) == false &&
                        LotID.Length >= 10)
                    {
                        try
                        {
                            FAECInfo.PACKING_MASTER_INFO_REQ command = new FAECInfo.PACKING_MASTER_INFO_REQ();
                            command.LOT_ID = LotID.Substring(0, 10);
                            ecResult.Clear();
                            InterfaceUnit.ECPart.AddCommand(command, ecResult);
                        }
                        catch (Exception e)
                        {
                            exception = true;
                            RaiseAlarm(actor, AlarmLotIDParsingFail, e.ToString());
                        }

                        if (exception == false)
                            actor.NextStep();
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.PackingMasterInfo.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ecResult.ECInfo.PackingMasterInfo.CopyTo(ProductInfo.ECInfo.PackingMasterInfo);
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, ecResult.LastAlarmNo);
                                actor.NextStep("RequestPackingMasterInfo");
                            }
                        }
                        else
                        {
                            RaiseAlarm(actor, ecResult.LastAlarmNo);
                            actor.NextStep("RequestPackingMasterInfo");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        RaiseAlarm(actor, ecResult.LastAlarmNo);
                        actor.NextStep("RequestPackingMasterInfo");
                    }
                });
            seq.Steps["RequestSmallBoxInfo"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    string temp = LotID;
                    FAECInfo.SBOX_INFO_REQ command = new FAECInfo.SBOX_INFO_REQ();
                    command.SBOX_ID = temp;
                    command.EQP_ID = Equipment.Config.SystemID;
                    command.GATE = ProductInfo.ECInfo.PackingMasterInfo.GATE;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.SBoxInfo.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ecResult.ECInfo.SBoxInfo.CopyTo(ProductInfo.ECInfo.SBoxInfo);
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, ecResult.LastAlarmNo);
                                actor.NextStep("RequestSmallBoxInfo");
                            }
                        }
                        else
                        {
                            RaiseAlarm(actor, ecResult.LastAlarmNo);
                            actor.NextStep("RequestSmallBoxInfo");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        RaiseAlarm(actor, ecResult.LastAlarmNo);
                        actor.NextStep("RequestSmallBoxInfo");
                    }
                });
            seq.Steps["AddLoadingCount"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    bool changedLot = false;

                    if (AddLoadingCount(ProductInfo.ECInfo.PackingMasterInfo, out changedLot) == true)
                    {
                        if (changedLot)
                        {
                            FARobotControlModule.RobotWork work = new FARobotControlModule.RobotWork();
                            ProductInfo.VT5080ProductInfo.ProductStatus = new VT5080ProductInfo.ProductStatusInfo();
                            ProductInfo.VT5080ProductInfo.Gate = Gate;
                            RobotControlModule.AddWork(ProductInfo);
                        }

                        actor.NextStep();
                    }
                    else
                    {
                        RaiseAlarm(actor, AlarmNotSameLotIDProductInput);
                        actor.NextStep("Start");
                    }
                });
            seq.AddItem(
                delegate(object obj)
                {
                    var smallBoxCount = CurrentLotLargeBoxCount() * CurrentLotInfo.L_BOX_MOQ;

                    ProductInfo.VT5080ProductInfo.SmallBoxIndex = LoadingCount - 1;

                    if (smallBoxCount == LoadingCount)
                    {
                        CurrentLotInfo.Clear();
                        LoadingCount = 0;
                    }
                });
            seq.AddTerminate();
        }
        private void MakeLoading()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();
            bool notWantConveyorRun = false;

            var seq = Loading;

            seq.Steps.Add("Start", new StepInfo());
            seq.Steps.Add("ReceiveData", new StepInfo());
            seq.Steps.Add("MoveGuideToGuidePosition", new StepInfo());
            seq.Steps.Add("RequestPackingMasterInfo", new StepInfo());

            seq.AddWatcher(
                delegate
                {
                    if (seq.State == SequenceState.Running)
                    {
                        if (notWantConveyorRun && Unloading.IsStartable())
                            LoadingUnit.ConveyorMotor.Stop.Execute(this);
                    }
                });

            seq.OnStart +=
                delegate
                {
                    notWantConveyorRun = false;
                };

            seq.OnSuspended +=
                delegate
                {
                    if (Unloading.IsStartable() || Unloading.State == SequenceState.Suspended)
                    {
                        LoadingUnit.ConveyorMotor.Stop.Execute(this);
                    }
                };
            seq.OnStop += delegate { LoadingUnit.ConveyorMotor.Stop.Execute(this); };
            seq.OnTerminate +=
                delegate
                {
                    if (Unloading.IsStartable() || Unloading.State == SequenceState.Suspended)
                        LoadingUnit.ConveyorMotor.Stop.Execute(this);

                    ProductInfo.ExistProduct = true;
                };

            seq.AddItem(
                delegate(object obj)
                {
                    notWantConveyorRun = true;
                    WriteTraceLog("CurrentLotInputCount=" + CurrentLotInputCount.ToString());

                    if (CurrentLotInputCount >= CurrentLotInfo.LOT_QTY)
                    {
                        InterfaceUnit.AMTInterfaceRequstCheck.Off.Execute(this);
                        InterfaceUnit.AMTInterFaceTransferCheck.Off.Execute(this);
                        WriteTraceLog("LOADING LOT CHANGED");
                        CurrentLotInfo.Clear();
                        CurrentLotInputCount = 0;
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (CurrentLotInputCount == 0)
                    {
                        Tact = TimeSpan.Zero;
                        actor.NextStep();
                    }
                    else
                        actor.NextStep("MoveGuideToGuidePosition");
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    ProductInfo.ECInfo.PackingMasterInfo.LOT_ID = "TEST";
                    ProductInfo.ECInfo.PackingMasterInfo.PART_ID = "TEST";
                    ProductInfo.ECInfo.PackingMasterInfo.S_BOX_MOQ = 10;
                    ProductInfo.ECInfo.PackingMasterInfo.LOT_QTY = 30;
                    ProductInfo.ECInfo.PackingMasterInfo.L_BOX_MOQ = 6;

                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        LoadingUnit.Stopper.Up.Execute(actor);
                        actor.NextStep("MoveGuideToGuidePosition");
                    }
                    else if (ManualMode)
                    {
                        if (CurrentLotInputCount == 0)
                        {
                            ProductInfo.ECInfo.PackingMasterInfo.CopyTo(CurrentLotInfo);
                        }

                        actor.NextStep("MoveGuideToGuidePosition");
                    }
                    else
                    {
                        actor.NextStep();
                    }
                });
            seq.Steps["ReceiveData"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ReceivedDataFromAMT.ReceivedData == true)
                    {
                        if (ReceivedDataFromAMT.Error)
                        {
                            RaiseAlarm(actor, AlarmFrontMachineDataError);
                        }
                        else
                        {
                            Equipment.RequestStart();
                            ProductInfo.ECInfo.PackingMasterInfo.LOT_ID = ReceivedDataFromAMT.InterfaceInfo.ReceiveData.LotID;
                            ReceivedDataFromAMT.ReceivedData = false;
                            actor.NextStep();
                        }
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (CurrentLotInputCount == 0)
                        actor.NextStep();
                    else
                        actor.NextStep("Start");
                });
            seq.Steps["RequestPackingMasterInfo"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.PACKING_MASTER_INFO_REQ command = new FAECInfo.PACKING_MASTER_INFO_REQ();
                    command.LOT_ID = ProductInfo.ECInfo.PackingMasterInfo.LOT_ID;
                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);

                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.PackingMasterInfo.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                ecResult.ECInfo.PackingMasterInfo.CopyTo(ProductInfo.ECInfo.PackingMasterInfo);
                                ProductInfo.ECInfo.PackingMasterInfo.CopyTo(CurrentLotInfo);
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, ecResult.LastAlarmNo);
                                actor.NextStep("RequestPackingMasterInfo");
                            }
                        }
                        else
                        {
                            RaiseAlarm(actor, ecResult.LastAlarmNo);
                            actor.NextStep("RequestPackingMasterInfo");
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        RaiseAlarm(actor, ecResult.LastAlarmNo);
                        actor.NextStep("RequestPackingMasterInfo");
                    }
                });
            seq.Steps["MoveGuideToGuidePosition"].StepIndex = seq.AddItem(MoveGuideToGuidePosition);

            seq.Steps["Start"].StepIndex =
                seq.AddItem(
                    delegate(FASequence actor, TimeSpan time)
                    {
                        if (LoadingReady)
                        {
                            actor.NextStep();
                        }
                    });
            seq.AddItem(LoadingUnit.Stopper.Down.Sequence);
            seq.AddItem(
                delegate(object obj)
                {
                    InterfaceUnit.AMTInterfaceRequstCheck.Off.Execute(this);
                    InterfaceUnit.AMTInterFaceTransferCheck.Off.Execute(this);
                });
            seq.AddItem(
                    delegate(FASequence actor, TimeSpan time)
                    {
                        if (InterfaceUnit.AMTInterfaceReadySignal.IsOff &&
                            InterfaceUnit.AMTInterfaceTransferSignal.IsOff)
                        {
                            actor.NextStep();
                        }
                    });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ManualMode)
                        actor.NextStep();
                    else
                    {
                        InterfaceUnit.AMTInterfaceRequstCheck.On.Execute(actor);

                        if (InterfaceUnit.AMTInterfaceReadySignal.IsOn)
                        {
                            actor.NextStep();
                        }
                    }
                });
            seq.AddItem((object obj) => notWantConveyorRun = false);
            seq.AddItem(new FASequenceAtomicInfo(LoadingBox, true));
            seq.AddItem(
                    delegate(FASequence actor, TimeSpan time)
                    {
                        if (Unloading.IsStartable())
                        {
                            actor.NextStep();
                        }
                    });
            seq.AddItem(LoadingUnit.Stopper.Up.Sequence);
            seq.AddItem(
                delegate(object obj)
                {
                    Equipment.RequestStart();
                    CurrentLotInfo.CopyTo(ProductInfo.ECInfo.PackingMasterInfo);
                    CurrentLotInputCount++;
                });
        }