Exemplo n.º 1
0
        private void Control_Click(object sender, EventArgs e)
        {
            if (!mc.check.READY_AUTORUN(sender))
            {
                return;
            }
            mc.check.push(sender, true);
            this.Enabled = false;

            if (sender.Equals(BT_USE_LASER))
            {
                mc.para.setting(ref mc.para.CV.trayReverseCheckMethod1, 0);
            }
            if (sender.Equals(BT_USE_PATTERN))
            {
                mc.para.setting(ref mc.para.CV.trayReverseCheckMethod1, 1);
            }
            if (sender.Equals(BT_TrayReverseCheck))
            {
                if ((int)mc.para.CV.trayReverseCheckMethod1.value == 0)
                {
                    #region Laser Method
                    //bool laserpreon;
                    double hwLaserOffsetX = mc.coor.MP.TOOL.X.LASER.value + 11500;
                    double hwLaserOffsetY = mc.coor.MP.TOOL.Y.LASER.value - 4500;
                    double posX           = mc.para.CV.trayReverseXPos.value - hwLaserOffsetX + mc.para.CAL.HDC_LASER.x.value;
                    double posY           = mc.para.CV.trayReverseYPos.value - hwLaserOffsetY + mc.para.CAL.HDC_LASER.y.value;
                    mc.hd.tool.jogMove(posX, posY, out ret.message); if (ret.message != RetMessage.OK)
                    {
                        mc.message.alarmMotion(ret.message); goto EXIT;
                    }
                    //mc.OUT.HD.LS.ON(out laserpreon, out ret.message);
                    // Laser Sensor ON
                    //mc.OUT.HD.LS.ON(true, out ret.message);
                    // Check Laser Sensor
                    //mc.OUT.HD.LS.ON(out ret.b, out ret.message);
                    //if (ret.b)
                    {
                        //mc.OUT.HD.LS.ZERO(true, out ret.message); if (ret.message != RetMessage.OK) ret.d = -1;
                        ret.d = mc.AIN.Laser(); if (ret.d < -10)
                        {
                            ret.d = -1;
                        }
                        //mc.IN.LS.ALM(out ret.b1, out ret.message); if (ret.message != RetMessage.OK) ret.d = -1;
                        //mc.IN.LS.FAR(out ret.b2, out ret.message); if (ret.message != RetMessage.OK) ret.d = -1;
                        //mc.IN.LS.NEAR(out ret.b3, out ret.message); if (ret.message != RetMessage.OK) ret.d = -1;
                    }
                    QueryTimer dwell = new QueryTimer();
                    dwell.Reset();
                    // Compare Result
                    if ((int)mc.para.CV.trayReverseResult.value == 1)
                    {
                        while (dwell.Elapsed < 10000)
                        {
                            //mc.IN.LS.ALM(out ret.b1, out ret.message);
                            ret.d = mc.AIN.Laser();
                            if (/*ret.b1 && */ ret.d != 10)
                            {
                                break;
                            }
                        }
                        mc.idle(10);
                        ret.d = mc.AIN.Laser();

                        //MessageBox.Show("검사시간 : " + Math.Round(dwell.Elapsed).ToString() + "[us]\n" + "검사결과 : " + Math.Round(ret.d, 3).ToString() + "[mm]");
                        FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.INFORMATION, String.Format(textResource.MB_CV_TRAY_REV_CHECK_RESULT, Math.Round(dwell.Elapsed), Math.Round(ret.d, 3)));
                    }
                    else
                    {
                        // 정확한 측정을 위해 4초 뒤에 측정
                        //if (laserpreon)
                        //    mc.idle(20);
                        //else
                        //    mc.idle(4000);

                        //mc.IN.LS.ALM(out ret.b1, out ret.message);
                        ret.d = mc.AIN.Laser();

                        if (/*ret.b1 == false && */ ret.d == 10)
                        {
                            FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, textResource.MB_CV_TRAY_REV_CHECK_ERROR);
                            //MessageBox.Show("트레이가 검사되지 않습니다.");
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Pattern Method
                    double posX = mc.para.CV.trayReverseXPos.value;
                    double posY = mc.para.CV.trayReverseYPos.value;
                    mc.hd.tool.jogMove(posX, posY, out ret.message); if (ret.message != RetMessage.OK)
                    {
                        mc.message.alarmMotion(ret.message); goto EXIT;
                    }
                    double rX = 0;
                    double rY = 0;
                    double rT = 0;
                    mc.hdc.LIVE = false;
                    #region HDC.req
                    if (mc.para.HDC.modelTrayReversePattern1.isCreate.value == (int)BOOL.TRUE)
                    {
                        mc.hdc.reqMode        = REQMODE.FIND_MODEL;
                        mc.hdc.reqModelNumber = (int)HDC_MODEL.TRAY_REVERSE_SHAPE1;
                    }
                    else
                    {
                        mc.hdc.reqMode = REQMODE.GRAB;
                    }
                    mc.hdc.lighting_exposure(mc.para.HDC.light[(int)LIGHTMODE_HDC.TRAY], mc.para.HDC.exposure[(int)LIGHTMODE_HDC.TRAY]);

                    mc.hdc.triggerMode = TRIGGERMODE.SOFTWARE;
                    mc.hdc.req         = true;
                    #endregion
                    mc.main.Thread_Polling();
                    #region HDC result
                    if (mc.para.HDC.modelTrayReversePattern1.isCreate.value == (int)BOOL.TRUE)
                    {
                        rX = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE1].resultX;
                        rY = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE1].resultY;
                        rT = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE1].resultAngle;
                        mc.log.debug.write(mc.log.CODE.ETC, "X : " + Math.Round(rX, 3).ToString() + ", Y : " + Math.Round(rY, 3).ToString());
                    }
                    else
                    {
                        FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.FAILURE, "Tray Reverse Pattern Model(#1) is not created!!");
                    }
                    #endregion
                    #endregion
                }
            }
            if (sender.Equals(BT_TrayReverseTeach))
            {
                mc.hd.tool.jogMove(mc.para.CV.trayReverseXPos.value, mc.para.CV.trayReverseYPos.value, out ret.message); if (ret.message != RetMessage.OK)
                {
                    mc.message.alarmMotion(ret.message); goto EXIT;
                }
                FormJogPad ff = new FormJogPad();
                ff.dataX = mc.para.CV.trayReverseXPos;
                ff.dataY = mc.para.CV.trayReverseYPos;
                if ((int)mc.para.CV.trayReverseCheckMethod1.value == 0)
                {
                    ff.jogMode = JOGMODE.LASER_TRAYREVERSE;
                    ff.ShowDialog();
                }
                else
                {
                    ff.jogMode = JOGMODE.PATTERN_TRAYREVERSE1;
                    ff.Show();
                    while (true)
                    {
                        mc.idle(100); if (ff.IsDisposed)
                        {
                            break;
                        }
                    }
                }
                mc.para.setting(ref mc.para.CV.trayReverseXPos, ff.dataX.value);
                mc.para.setting(ref mc.para.CV.trayReverseYPos, ff.dataY.value);
            }
            if (sender.Equals(BT_USE_LASER2))
            {
                mc.para.setting(ref mc.para.CV.trayReverseCheckMethod2, 0);
            }
            if (sender.Equals(BT_USE_PATTERN2))
            {
                mc.para.setting(ref mc.para.CV.trayReverseCheckMethod2, 1);
            }
            if (sender.Equals(BT_TrayReverseCheck2))
            {
                if ((int)mc.para.CV.trayReverseCheckMethod2.value == 0)
                {
                    #region Laser Method
                    bool laserpreon;
                    // move to Laser Check Position(Head Camera Position)
                    //double posX = mc.para.CV.trayReverseXPos.value - mc.coor.MP.TOOL.X.LASER.value - mc.para.CAL.HDC_LASER.x.value;
                    //double posY = mc.para.CV.trayReverseYPos.value - mc.coor.MP.TOOL.Y.LASER.value - mc.para.CAL.HDC_LASER.y.value;
                    double posX = mc.para.CV.trayReverseXPos2.value - mc.coor.MP.TOOL.X.LASER.value + mc.para.CAL.HDC_LASER.x.value;
                    double posY = mc.para.CV.trayReverseYPos2.value - mc.coor.MP.TOOL.Y.LASER.value + mc.para.CAL.HDC_LASER.y.value;
                    mc.hd.tool.jogMove(posX, posY, out ret.message); if (ret.message != RetMessage.OK)
                    {
                        mc.message.alarmMotion(ret.message); goto EXIT;
                    }

                    mc.OUT.HD.LS.ON(out laserpreon, out ret.message);
                    // Laser Sensor ON
                    //mc.OUT.HD.LS
                    mc.OUT.HD.LS.ON(true, out ret.message);

                    // Check Laser Sensor
                    mc.OUT.HD.LS.ON(out ret.b, out ret.message);
                    if (ret.b)
                    {
                        mc.OUT.HD.LS.ZERO(true, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            ret.d = -1;
                        }
                        ret.d = mc.AIN.Laser(); if (ret.d < -10)
                        {
                            ret.d = -1;
                        }
                        mc.IN.LS.ALM(out ret.b1, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            ret.d = -1;
                        }
                        mc.IN.LS.FAR(out ret.b2, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            ret.d = -1;
                        }
                        mc.IN.LS.NEAR(out ret.b3, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            ret.d = -1;
                        }
                    }
                    QueryTimer dwell = new QueryTimer();
                    dwell.Reset();
                    // Compare Result
                    if ((int)mc.para.CV.trayReverseResult2.value == 1)
                    {
                        while (dwell.Elapsed < 10000)
                        {
                            mc.IN.LS.ALM(out ret.b1, out ret.message);
                            ret.d = mc.AIN.Laser();
                            if (ret.b1 && ret.d != 10)
                            {
                                break;
                            }
                        }
                        mc.idle(10);
                        ret.d = mc.AIN.Laser();

                        //MessageBox.Show("검사시간 : " + Math.Round(dwell.Elapsed).ToString() + "[us]\n" + "검사결과 : " + Math.Round(ret.d, 3).ToString() + "[mm]");
                        FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.INFORMATION, String.Format(textResource.MB_CV_TRAY_REV_CHECK_RESULT, Math.Round(dwell.Elapsed), Math.Round(ret.d, 3)));
                    }
                    else
                    {
                        // 정확한 측정을 위해 4초 뒤에 측정
                        if (laserpreon)
                        {
                            mc.idle(20);
                        }
                        else
                        {
                            mc.idle(4000);
                        }

                        mc.IN.LS.ALM(out ret.b1, out ret.message);
                        ret.d = mc.AIN.Laser();

                        if (ret.b1 == false && ret.d == 10)
                        {
                            FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, textResource.MB_CV_TRAY_REV_CHECK_ERROR);
                            //MessageBox.Show("트레이가 검사되지 않습니다.");
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Pattern Method
                    double posX = mc.para.CV.trayReverseXPos2.value;
                    double posY = mc.para.CV.trayReverseYPos2.value;
                    mc.hd.tool.jogMove(posX, posY, out ret.message); if (ret.message != RetMessage.OK)
                    {
                        mc.message.alarmMotion(ret.message); goto EXIT;
                    }
                    double rX = 0;
                    double rY = 0;
                    double rT = 0;
                    mc.hdc.LIVE = false;
                    #region HDC.req
                    if (mc.para.HDC.modelTrayReversePattern2.isCreate.value == (int)BOOL.TRUE)
                    {
                        mc.hdc.reqMode        = REQMODE.FIND_MODEL;
                        mc.hdc.reqModelNumber = (int)HDC_MODEL.TRAY_REVERSE_SHAPE2;
                    }
                    else
                    {
                        mc.hdc.reqMode = REQMODE.GRAB;
                    }
                    mc.hdc.lighting_exposure(mc.para.HDC.light[(int)LIGHTMODE_HDC.TRAY], mc.para.HDC.exposure[(int)LIGHTMODE_HDC.TRAY]);

                    mc.hdc.triggerMode = TRIGGERMODE.SOFTWARE;
                    mc.hdc.req         = true;
                    #endregion
                    mc.main.Thread_Polling();
                    #region HDC result
                    if (mc.para.HDC.modelTrayReversePattern2.isCreate.value == (int)BOOL.TRUE)
                    {
                        rX = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE2].resultX;
                        rY = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE2].resultY;
                        rT = mc.hdc.cam.model[(int)HDC_MODEL.TRAY_REVERSE_SHAPE2].resultAngle;
                        mc.log.debug.write(mc.log.CODE.ETC, "X : " + Math.Round(rX, 3).ToString() + ", Y : " + Math.Round(rY, 3).ToString());
                    }
                    else
                    {
                        FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.FAILURE, "Tray Reverse Pattern Model(#2) is not created!!");
                    }
                    #endregion
                    #endregion
                }
            }
            if (sender.Equals(BT_TrayReverseTeach2))
            {
                mc.hd.tool.jogMove(mc.para.CV.trayReverseXPos2.value, mc.para.CV.trayReverseYPos2.value, out ret.message); if (ret.message != RetMessage.OK)
                {
                    mc.message.alarmMotion(ret.message); goto EXIT;
                }
                FormJogPad ff = new FormJogPad();
                ff.dataX = mc.para.CV.trayReverseXPos2;
                ff.dataY = mc.para.CV.trayReverseYPos2;
                if ((int)mc.para.CV.trayReverseCheckMethod1.value == 0)
                {
                    ff.jogMode = JOGMODE.LASER_TRAYREVERSE2;
                    ff.ShowDialog();
                }
                else
                {
                    ff.jogMode = JOGMODE.PATTERN_TRAYREVERSE2;
                    ff.Show();
                    while (true)
                    {
                        mc.idle(100); if (ff.IsDisposed)
                        {
                            break;
                        }
                    }
                }
                mc.para.setting(ref mc.para.CV.trayReverseXPos2, ff.dataX.value);
                mc.para.setting(ref mc.para.CV.trayReverseYPos2, ff.dataY.value);
            }
EXIT:
            mc.para.write(out ret.b); if (!ret.b)
            {
                mc.message.alarm("para write error");
            }
            refresh();
            mc.main.Thread_Polling();
            mc.check.push(sender, false);
            this.Enabled = true;
        }
Exemplo n.º 2
0
        private void Control_Click(object sender, EventArgs e)
        {
            if (sender.Equals(BT_Start))
            {
                if (!RB_ByPassMode.Checked)
                {
                    if (!mc.check.READY_AUTORUN(sender))
                    {
                        return;
                    }
                }
                mc.check.push(sender, true, (int)SelectedMenu.DEFAULT);


                mc.para.selMode2 = mc.para.selMode;
                mc.para.selMode  = (int)CenterRightSelMode.None;

                if (mc.para.selMode2 != 0 && mc.para.selMode != mc.para.selMode2 && mc.para.ChangePara((int)mc.para.selMode2)) // 1. 메뉴가 바뀌었다. 2. 파라미터가 바뀌었다.
                {
                    ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.YesNo, DIAG_ICON_MODE.QUESTION, textResource.MB_ETC_PARA_SAVE_BEFORE_START);
                    if (ret.usrDialog == DIAG_RESULT.No)
                    {
                        mc.para.SetInitPara((int)mc.para.selMode2);
                        mc.para.selMode     = mc.para.selMode2;
                        BT_PowerOff.Enabled = true;
                        EVENT.refresh();
                        mc.check.push(sender, false, (int)SelectedMenu.DEFAULT);
                        return;
                    }
                    else
                    {
                        mc.para.writeRecipe(mc.para.ETC.recipeName.description);
                        mc.main.mainThread.req = true;
                        EVENT.refresh();
                    }
                }
                else
                {
                    mc.para.writeRecipe(mc.para.ETC.recipeName.description);
                    mc.main.mainThread.req = true;
                    EVENT.refresh();
                }
            }

            if (sender.Equals(BT_PowerOff))
            {
                if (!mc.check.READY_PUSH(sender))
                {
                    return;
                }
                mc.check.push(sender, true, (int)SelectedMenu.DEFAULT);
                mc.para.selMode2 = mc.para.selMode;
                mc.para.selMode  = (int)CenterRightSelMode.None;

                ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.YesNo, DIAG_ICON_MODE.QUESTION, textResource.MB_ETC_EXIT_SW);
                if (ret.usrDialog == DIAG_RESULT.No)
                {
                    mc.para.selMode = mc.para.selMode2;
                    mc.error.CHECK();
                    mc.check.push(sender, false);
                    return;
                }
                if (ret.usrDialog == DIAG_RESULT.Yes)
                {
                    if (mc.para.selMode2 != 0 && mc.para.selMode != mc.para.selMode2 && mc.para.ChangePara((int)mc.para.selMode2)) // 1. 메뉴가 바뀌었다. 2. 파라미터가 바뀌었다.
                    {
                        ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.YesNo, DIAG_ICON_MODE.QUESTION, textResource.MB_ETC_PARA_SAVE_BEFORE_EXIT);
                        if (ret.usrDialog == DIAG_RESULT.No)
                        {
                            mc.para.SetInitPara((int)mc.para.selMode2);
                            mc.para.selMode = mc.para.selMode2;
                            mc.error.CHECK();
                            mc.check.push(sender, false);
                            return;
                        }
                        else
                        {
                            mc.hd.tool.triggerHDC.output(false, out ret.message);
                            mc.hd.tool.triggerULC.output(false, out ret.message);
                            mc.OUT.HD.LS.ON(false, out ret.message);
                        }
                    }
                    else
                    {
                        mc.hd.tool.triggerHDC.output(false, out ret.message);
                        mc.hd.tool.triggerULC.output(false, out ret.message);
                        mc.OUT.HD.LS.ON(false, out ret.message);
                    }
                }

                mc.check.push(sender, true, (int)SelectedMenu.DEFAULT);
                mc.OUT.MAIN.T_RED(false, out ret.message);
                mc.OUT.MAIN.T_YELLOW(false, out ret.message);
                mc.OUT.MAIN.T_GREEN(false, out ret.message);
                mc.commMPC.SVIDReport();                 //20130624. kimsong.
                mc.commMPC.EventReport((int)eEVENT_LIST.eEV_POWER_OFF);
                mc.commMPC.req = false;
                mc.commMPC.sqc = SQC.STOP;
                mc.commMPC.deactivate(out ret.message);

                // 버튼 스레드 종료
                mc.main.mainThread.req         = false;
                mc.main.mainThread.reqPowerOff = true;

                // Program이 Off된 상태에서 Motor 버튼을 OFF한 뒤 축을 손으로 움직이고 다시 On하면 굉장한 일이 벌어지기 때문에 이를 방지하기 위함.
                mc.hd.tool.motorAbort(out ret.message);
                mc.pd.motorAbort(out ret.message);
                mc.sf.motorAbort(out ret.message);

                EVENT.powerOff();
            }

            //mc.main.Thread_Polling();
            mc.check.push(sender, false);
        }
Exemplo n.º 3
0
        private void Reject_Click(object sender, EventArgs e)
        {
            if (!mc.check.READY_PUSH(sender))
            {
                return;
            }
            mc.check.push(sender, true, (int)SelectedMenu.BOTTOM_RIGHT);
            #region Reject
            if (sender.Equals(BT_Reject_LoadingZone))
            {
                if (mc.board.boardType(BOARD_ZONE.LOADING) == BOARD_TYPE.INVALID)
                {
                    goto EXIT;
                }
                ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.OKCancel, DIAG_ICON_MODE.QUESTION, String.Format(textResource.MB_CV_TRAY_REJECT, textResource.CV_INPUT_AREA));
                //mc.message.OkCancel("[입구버퍼] 트레이를 제거할까요?", out ret.dialog);
                if (ret.usrDialog == DIAG_RESULT.Cancel)
                {
                    goto EXIT;
                }
                //SNS_CHECK:
                mc.IN.CV.BD_IN(out ret.b1, out ret.message);
                mc.IN.CV.BD_BUF(out ret.b2, out ret.message);
                if (ret.b1)
                {
                    FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, String.Format(textResource.MB_CV_TRAY_EXIST, textResource.CV_INPUT_AREA));
                    //mc.message.alarm("[입구] 센서가 감지되고 있습니다. 트레이를 손으로 제거하세요.");
                    //goto SNS_CHECK;
                }
                if (ret.b2)
                {
                    FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, String.Format(textResource.MB_CV_TRAY_EXIST, textResource.CV_INPUT_BUFFER));
                    //mc.message.alarm("[버퍼] 센서가 감지되고 있습니다. 트레이를 손으로 제거하세요.");
                    //goto SNS_CHECK;
                }
                mc.log.debug.write(mc.log.CODE.WARN, "Reject Loading Zone");
                mc.board.reject(BOARD_ZONE.LOADING, out ret.b);
            }
            if (sender.Equals(BT_Reject_WorkingZone))
            {
                // Data유무를 떠나서, 물리적으로 보드가 존재하는 경우가 발생한다.
                if (mc.board.boardType(BOARD_ZONE.WORKING) == BOARD_TYPE.INVALID)
                {
                    goto EXIT;
                }
                //mc.IN.CV.BD_NEAR(out ret.b, out ret.message);
                //if (!ret.b)
                //{
                //    MessageBox.Show("There is NO board on Working Zone!");
                //    goto EXIT;
                //}
                ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.OKCancel, DIAG_ICON_MODE.QUESTION, String.Format(textResource.MB_CV_TRAY_REJECT, textResource.CV_WORK_AREA));
                //mc.message.OkCancel("[작업영역] 트레이를 제거할까요?", out ret.dialog);
                if (ret.usrDialog == DIAG_RESULT.Cancel)
                {
                    goto EXIT;
                }
                mc.OUT.CV.SIDE_PUSHER(false, out ret.message);
                mc.OUT.CV.BD_STOP(false, out ret.message);
                //SNS_CHECK:
                mc.IN.CV.BD_NEAR(out ret.b, out ret.message);
                if (ret.b)
                {
                    FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, String.Format(textResource.MB_CV_TRAY_EXIST, textResource.CV_WORK_AREA));
                    //mc.message.alarm("[작업영역] 센서가 감지되고 있습니다. 트레이를 손으로 제거하세요.");
                    //goto SNS_CHECK;
                }
                mc.log.debug.write(mc.log.CODE.WARN, "Reject Working Zone");
                mc.board.reject(BOARD_ZONE.WORKING, out ret.b);
            }
            if (sender.Equals(BT_Reject_UnloadingZone))
            {
                if (mc.board.boardType(BOARD_ZONE.UNLOADING) == BOARD_TYPE.INVALID)
                {
                    goto EXIT;
                }
                ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.OKCancel, DIAG_ICON_MODE.QUESTION, String.Format(textResource.MB_CV_TRAY_REJECT, textResource.CV_OUTPUT_AREA));
                //mc.message.OkCancel("[출구버퍼] 트레이를 제거할까요?", out ret.dialog);
                if (ret.usrDialog == DIAG_RESULT.Cancel)
                {
                    goto EXIT;
                }
                //SNS_CHECK:
                mc.IN.CV.BD_OUT(out ret.b, out ret.message);
                mc.IN.PS.END(out ret.b1, out ret.message);
                if (ret.b || ret.b1)
                {
                    FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, String.Format(textResource.MB_CV_TRAY_EXIST, textResource.CV_OUTPUT_AREA));
                    //mc.message.alarm("[출구] 센서가 감지되고 있습니다. 트레이를 손으로 제거하세요.");
                    //goto SNS_CHECK;
                }
                mc.log.debug.write(mc.log.CODE.WARN, "Reject Unloading Zone");
                mc.board.reject(BOARD_ZONE.UNLOADING, out ret.b);
            }
            #endregion
EXIT:
            mc.main.Thread_Polling();
            mc.check.push(sender, false);
        }
Exemplo n.º 4
0
        private void Feeding_Click(object sender, EventArgs e)
        {
            if (!mc.check.READY_AUTORUN(sender))
            {
                return;
            }
            mc.check.push(sender, true, (int)SelectedMenu.BOTTOM_RIGHT);
            #region Feeding

            // 기존 Error 발생한 것을 초기화해준다.
            if (mc.init.success.HD)
            {
                mc.hd.clear(); mc.hd.tool.clear();
            }
            if (mc.init.success.PD)
            {
                mc.pd.clear();
            }
            if (mc.init.success.CV)
            {
                mc.cv.clear();
            }

            if (mc.para.ETC.unloaderControl.value == 1)
            {
                if (mc.init.success.PS)
                {
                    mc.ps.clear();
                }
                if (mc.init.success.MG)
                {
                    mc.unloader.clear(); mc.unloader.Elev.clear();
                }
            }

            if (sender.Equals(BT_Feeding_ToLoadingZone))
            {
                // board 상태 확인..
                bool     instate, bufstate;
                RetValue ret;
                mc.IN.CV.BD_IN(out instate, out ret.message);
                mc.IN.CV.BD_BUF(out bufstate, out ret.message);
                if (instate == true && bufstate == true)
                {
                    // board 두장 감지
                    mc.OUT.MAIN.T_BUZZER(true, out ret.message);
                    FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.WARNING, textResource.MB_CV_TRAY_EXIST_SENSOR);
                    //mc.message.alarm("[입구]와 [버퍼] 센서가 동시에 감지되었습니다.\n상태 확인후 다시 시도하세요!");
                    mc.OUT.MAIN.T_BUZZER(false, out ret.message);
                    mc.check.push(sender, false);
                    return;
                }
                if (instate == false && bufstate == false)
                {
                    // board 없음
                    // 앞장비로부터 SMEMA로 보드를 받을 수 있도록 구성되어 있으므로..에러를 발생시키지 않는다.
                    // 그런데, 수동으로 앞장비에서 보드를 받아도 되나? 뭐 필요하면 받을 수도 있겠지..Test도 가능하니까..
                    // 다만, 확인하도록 messagebox하나는 띄워주자.
                    mc.OUT.MAIN.T_BUZZER(true, out ret.message);
                    Thread.Sleep(300);
                    mc.OUT.MAIN.T_BUZZER(false, out ret.message);
                    ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.OKCancel, DIAG_ICON_MODE.QUESTION, textResource.MB_CV_TRAY_TRANSFER);
                    //mc.message.OkCancel("컨베이어 상에 트레이가 감지되지 않았습니다.\n이전 장비로부터 이송을 시도할까요?", out ret.dialog);
                    if (ret.usrDialog == DIAG_RESULT.Cancel)
                    {
                        mc.check.push(sender, false); return;
                    }
                }
                if (bufstate == true)
                {
                    // sequence내에서 TMS file을 읽는 부분이 있으므로 그냥 구동한다.
                }
                ret.usrDialog = FormMain.UserMessageBox2(DIAG_SEL_MODE.TmsManualPressCancel, DIAG_ICON_MODE.QUESTION, textResource.MB_CV_TRAY_LOADING_INFO);
                //mc.message.YesNoCancel("PAD 장착 정보를 읽는 경로를 선택해 주세요.\n(YES) -> TMS File\n(NO) -> 초기화 상태.", out ret.dialog);
                if (ret.usrDialog == DIAG_RESULT.Cancel)
                {
                    mc.check.push(sender, false); return;
                }
                else if (ret.usrDialog == DIAG_RESULT.Tms)
                {
                    mc.cv.toLoading.loadPadState = 0;
                }
                else if (ret.usrDialog == DIAG_RESULT.Manual)
                {
                    mc.cv.toLoading.loadPadState = 1;
                }
                else if (ret.usrDialog == DIAG_RESULT.Press)
                {
                    mc.cv.toLoading.loadPadState = 2;
                }
                mc.cv.toLoading.req     = true;
                mc.cv.toLoading.reqMode = REQMODE.DUMY;
            }
            if (sender.Equals(BT_Feeding_ToWorkingZone))
            {
                mc.cv.toWorking.req = true; mc.cv.toWorking.reqMode = REQMODE.DUMY;
            }
            if (sender.Equals(BT_Feeding_ToUnloadingZone))
            {
                mc.cv.toUnloading.req = true; mc.cv.toUnloading.reqMode = REQMODE.DUMY;
            }
            if (sender.Equals(BT_Feeding_ToNextMC))
            {
                mc.cv.toNextMC.req = true; mc.cv.toNextMC.reqMode = REQMODE.DUMY;
                mc.unloader.req    = true; mc.unloader.reqMode = REQMODE.DUMY;
            }
            #endregion
            mc.main.Thread_Polling();
            mc.check.push(sender, false);
        }
Exemplo n.º 5
0
        private void Control_Click(object sender, EventArgs e)
        {
            if (!mc.check.READY_PUSH(sender))
            {
                return;
            }
            mc.check.push(sender, true);

            if (sender.Equals(BT_CLEAR))
            {
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        btnClicked[x, y] = false;
                    }
                }
            }
            else if (sender.Equals(BT_LoadWorkArea))
            {
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        if (WorkAreaControl.workArea[x, y] == 0)
                        {
                            btnClicked[x, y] = false;
                        }
                        else if (WorkAreaControl.workArea[x, y] == 1)
                        {
                            btnClicked[x, y] = true;
                        }
                    }
                }
            }
            else if (sender.Equals(BT_TOPBOTTOM))
            {
                halfPos = row / 2;

                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        if (mc.para.mcType.FrRr == McTypeFrRr.FRONT)
                        {
                            if (y >= halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                        else
                        {
                            if (y < halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                    }
                }
            }
            else if (sender.Equals(BT_BOTTOMTOP))
            {
                halfPos = row / 2;
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        if (mc.para.mcType.FrRr == McTypeFrRr.FRONT)
                        {
                            if (y < halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                        else
                        {
                            if (y >= halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                    }
                }
            }
            else if (sender.Equals(BT_LEFTRIGHT))
            {
                halfPos = col / 2;
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        if (mc.para.mcType.FrRr == McTypeFrRr.FRONT)
                        {
                            if (x <= halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                        else
                        {
                            if (x >= halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                    }
                }
            }
            else if (sender.Equals(BT_RIGHTLEFT))
            {
                halfPos = col / 2;
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        if (mc.para.mcType.FrRr == McTypeFrRr.FRONT)
                        {
                            if (x > halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                        else
                        {
                            if (x < halfPos)
                            {
                                btnClicked[x, y] = true;
                            }
                            else
                            {
                                btnClicked[x, y] = false;
                            }
                        }
                    }
                }
            }
            else if (sender.Equals(BT_ALL))
            {
                for (int x = 0; x < col; x++)
                {
                    for (int y = 0; y < row; y++)
                    {
                        btnClicked[x, y] = true;
                    }
                }
            }
            else if (sender.Equals(BT_Apply))
            {
                string filePath = "", tempfile = "", tmpvalue = "";
                string section, key;
                int    index, j;
                int    tmpindex;
                int    padX, padY;
                bool   rst;

                filePath = "C:\\data\\";
                tempfile = filePath + "TMS_RePress.ini";

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }

                section = "TMS_INFO";
                key     = "LOTID";
                inifile.IniWriteValue(section, key, tempfile, "RePress");

                key = "TRAYID";
                inifile.IniWriteValue(section, key, tempfile, "Invalid");

                key = "LOTQTY";
                inifile.IniWriteValue(section, key, tempfile, "1");

                key = "TRAYTYPE";
                inifile.IniWriteValue(section, key, tempfile, "2");                     // normal tray

                key = "COL";
                inifile.IniWriteValue(section, key, tempfile, col.ToString());

                key = "ROW";
                inifile.IniWriteValue(section, key, tempfile, row.ToString());

                section = "TMS_MAPINFO";
                for (index = 0; index < row; index++)
                {
                    key = "ROW_" + index.ToString();
                    for (j = 0; j < col; j++)
                    {
                        mc.commMPC.getPadIndex(col, row, j, index, out tmpindex, out rst);

                        if (mc.para.mcType.FrRr == McTypeFrRr.FRONT)
                        {
                            padX = j;
                            padY = row - index - 1;
                        }
                        else
                        {
                            padX = col - j - 1;
                            padY = index;
                        }
                        //if(btnClicked[padX, padY]) tmpvalue += Convert.ToChar(TMSCODE.PRESS_READY);
                        //else tmpvalue += Convert.ToChar(TMSCODE.SKIP);
                    }

                    inifile.IniWriteValue(section, key, tempfile, tmpvalue);
                    tmpvalue = "";
                }

                section = "2D_BARCODE";
                for (index = 0; index < mc.board.working.padCount.I; index++)
                {
                    key = "Package_" + index.ToString();
                    inifile.IniWriteValue(section, key, tempfile, mc.board.working.tmsInfo.pre_barcode[index].S);
                }
                FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.INFORMATION, textResource.MB_HD_PRESS_CREATE_TMS);
            }
            refresh();
            mc.check.push(sender, false);
        }
Exemplo n.º 6
0
        private void Control_Click(object sender, EventArgs e)
        {
            if (!mc.check.READY_PUSH(sender))
            {
                return;
            }
            mc.check.push(sender, true);

            #region search
            if (sender.Equals(BT_Search1st_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.search.enable, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_Search1st_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.search.enable, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_Search1st_Level))
            {
                mc.para.setting(mc.para.HD.pick.search.level, out mc.para.HD.pick.search.level);
            }
            if (sender.Equals(TB_Search1st_Speed))
            {
                mc.para.setting(mc.para.HD.pick.search.vel, out mc.para.HD.pick.search.vel);
            }
            if (sender.Equals(TB_Search1st_Delay))
            {
                mc.para.setting(mc.para.HD.pick.search.delay, out mc.para.HD.pick.search.delay);
            }
            #endregion
            #region search2
            if (sender.Equals(BT_Search2nd_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.search2.enable, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_Search2nd_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.search2.enable, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_Search2nd_Level))
            {
                mc.para.setting(mc.para.HD.pick.search2.level, out mc.para.HD.pick.search2.level);
            }
            if (sender.Equals(TB_Search2nd_Speed))
            {
                mc.para.setting(mc.para.HD.pick.search2.vel, out mc.para.HD.pick.search2.vel);
            }
            if (sender.Equals(TB_Search2nd_Delay))
            {
                mc.para.setting(mc.para.HD.pick.search2.delay, out mc.para.HD.pick.search2.delay);
            }
            #endregion
            #region delay
            if (sender.Equals(TB_Delay))
            {
                mc.para.setting(mc.para.HD.pick.delay, out mc.para.HD.pick.delay);
            }
            if (sender.Equals(TB_Force))
            {
                mc.para.setting(mc.para.HD.pick.force, out mc.para.HD.pick.force);
            }
            #endregion
            #region driver
            if (sender.Equals(BT_Drive1st_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.driver.enable, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_Drive1st_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.driver.enable, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_Drive1st_Level))
            {
                mc.para.setting(mc.para.HD.pick.driver.level, out mc.para.HD.pick.driver.level);
            }
            if (sender.Equals(TB_Drive1st_Speed))
            {
                mc.para.setting(mc.para.HD.pick.driver.vel, out mc.para.HD.pick.driver.vel);
            }
            if (sender.Equals(TB_Drive1st_Delay))
            {
                mc.para.setting(mc.para.HD.pick.driver.delay, out mc.para.HD.pick.driver.delay);
            }
            #endregion
            #region driver2
            if (sender.Equals(BT_Drive2nd_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.driver2.enable, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_Drive2nd_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.driver2.enable, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_Drive2nd_Level))
            {
                mc.para.setting(mc.para.HD.pick.driver2.level, out mc.para.HD.pick.driver2.level);
            }
            if (sender.Equals(TB_Drive2nd_Speed))
            {
                mc.para.setting(mc.para.HD.pick.driver2.vel, out mc.para.HD.pick.driver2.vel);
            }
            if (sender.Equals(TB_Drive2nd_Delay))
            {
                mc.para.setting(mc.para.HD.pick.driver2.delay, out mc.para.HD.pick.driver2.delay);
            }
            #endregion
            #region offset
            if (sender.Equals(BT_PositionOffset_SelectSF1))
            {
                slectOffsetSF = UnitCodeSF.SF1;
            }
            if (sender.Equals(BT_PositionOffset_SelectSF2))
            {
                slectOffsetSF = UnitCodeSF.SF2;
            }
            if (sender.Equals(BT_PositionOffset_SelectSF3))
            {
                if (mc.swcontrol.mechanicalRevision == 0)
                {
                    slectOffsetSF = UnitCodeSF.SF3;
                }
                else
                {
                    slectOffsetSF = UnitCodeSF.SF5;
                }
            }
            if (sender.Equals(BT_PositionOffset_SelectSF4))
            {
                if (mc.swcontrol.mechanicalRevision == 0)
                {
                    slectOffsetSF = UnitCodeSF.SF4;
                }
                else
                {
                    slectOffsetSF = UnitCodeSF.SF6;
                }
            }
            if (sender.Equals(BT_PositionOffset_SelectSF5))
            {
                slectOffsetSF = UnitCodeSF.SF5;
            }
            if (sender.Equals(BT_PositionOffset_SelectSF6))
            {
                slectOffsetSF = UnitCodeSF.SF6;
            }
            if (sender.Equals(BT_PositionOffset_SelectSF7))
            {
                slectOffsetSF = UnitCodeSF.SF7;
            }
            if (sender.Equals(BT_PositionOffset_SelectSF8))
            {
                slectOffsetSF = UnitCodeSF.SF8;
            }
            if (sender.Equals(TB_PositionOffset_X))
            {
                mc.para.setting(mc.para.HD.pick.offset[(int)slectOffsetSF].x, out mc.para.HD.pick.offset[(int)slectOffsetSF].x);
            }
            if (sender.Equals(TB_PositionOffset_Y))
            {
                mc.para.setting(mc.para.HD.pick.offset[(int)slectOffsetSF].y, out mc.para.HD.pick.offset[(int)slectOffsetSF].y);
            }
            //if (sender.Equals(TB_PositionOffset_Z)) mc.para.setting(mc.para.HD.pick.offset[(int)slectOffsetSF].z, out mc.para.HD.pick.offset[(int)slectOffsetSF].z);
            if (sender.Equals(BT_PositionOffset_Jog))
            {
                double posX, posY, posZ, posT;
                #region moving
                posX = mc.hd.tool.tPos.x[(int)UnitCodeHead.HD1].PICK(slectOffsetSF);
                posY = mc.hd.tool.tPos.y[(int)UnitCodeHead.HD1].PICK(slectOffsetSF);
                posZ = mc.hd.tool.tPos.z[(int)UnitCodeHead.HD1].PICK(slectOffsetSF);
                posT = mc.hd.tool.tPos.t[(int)UnitCodeHead.HD1].ZERO;
                mc.hd.tool.jogMove((int)UnitCodeHead.HD1, posX, posY, posZ, posT, out ret.message); if (ret.message != RetMessage.OK)
                {
                    mc.message.alarmMotion(ret.message); goto EXIT;
                }
                #endregion
                FormJogPadXYZ ff = new FormJogPadXYZ();
                #region jogMode
                if (slectOffsetSF == UnitCodeSF.SF1)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF1;
                }
                else if (slectOffsetSF == UnitCodeSF.SF2)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF2;
                }
                else if (slectOffsetSF == UnitCodeSF.SF3)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF3;
                }
                else if (slectOffsetSF == UnitCodeSF.SF4)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF4;
                }
                else if (slectOffsetSF == UnitCodeSF.SF5)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF5;
                }
                else if (slectOffsetSF == UnitCodeSF.SF6)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF6;
                }
                else if (slectOffsetSF == UnitCodeSF.SF7)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF7;
                }
                else if (slectOffsetSF == UnitCodeSF.SF8)
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF8;
                }
                else
                {
                    ff.jogMode = JOGXYZ_MODE.HD_PICK_OFFSET_SF1;
                }
                #endregion
                ff.dataX = mc.para.HD.pick.offset[(int)slectOffsetSF].x;
                ff.dataY = mc.para.HD.pick.offset[(int)slectOffsetSF].y;
                ff.dataZ = mc.para.HD.pick.offset[(int)slectOffsetSF].z;
                ff.ShowDialog();
                mc.para.setting(ref mc.para.HD.pick.offset[(int)slectOffsetSF].x, ff.dataX.value);
                mc.para.setting(ref mc.para.HD.pick.offset[(int)slectOffsetSF].y, ff.dataY.value);
                mc.para.setting(ref mc.para.HD.pick.offset[(int)slectOffsetSF].z, ff.dataZ.value);
                #region moving
                posX = mc.hd.tool.cPos.x.REF0;
                posY = mc.hd.tool.cPos.y.REF0;;
                posZ = mc.hd.tool.tPos.z[(int)UnitCodeHead.HD1].XY_MOVING;
                posT = mc.hd.tool.tPos.t[(int)UnitCodeHead.HD1].ZERO;
                mc.hd.tool.jogMove((int)UnitCodeHead.HD1, posX, posY, posZ, posT, out ret.message); if (ret.message != RetMessage.OK)
                {
                    mc.message.alarmMotion(ret.message); goto EXIT;
                }
                #endregion
            }
            if (sender.Equals(BT_PositionOffset_AllClear))
            {
                ret.usrDialog = FormMain.UserMessageBox(DIAG_SEL_MODE.OKCancel, DIAG_ICON_MODE.QUESTION, textResource.MB_HD_PICK_INIT_OFFSET_XYZ);
                //mc.message.OkCancel("모든 Pick Offset X,Y,Z 값은 초기화 됩니다. 계속 진행할까요?", out ret.dialog);
                if (ret.usrDialog == DIAG_RESULT.Cancel)
                {
                    goto EXIT;
                }
                for (int i = 0; i < 8; i++)
                {
                    mc.para.setting(ref mc.para.HD.pick.offset[i].x, 0);
                    mc.para.setting(ref mc.para.HD.pick.offset[i].y, 0);
                    mc.para.setting(ref mc.para.HD.pick.offset[i].z, 0);
                }
            }
            if (sender.Equals(BT_AutoPickCompenClear))
            {
                FormUserMessage ff = new FormUserMessage();
                ff.SetDisplayItems(DIAG_SEL_MODE.YesNo, DIAG_ICON_MODE.WARNING, textResource.MB_HD_PICK_INIT_AUTO_TRACK);
                ff.ShowDialog();

                ret.usrDialog = FormUserMessage.diagResult;
                if (ret.usrDialog == DIAG_RESULT.Yes)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        mc.para.HD.pick.pickPosComp[i].x.value = 0;
                        mc.para.HD.pick.pickPosComp[i].y.value = 0;
                    }
                    ff.SetDisplayItems(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.INFORMATION, textResource.MB_HD_PICK_INIT_FINISH);
                    ff.ShowDialog();
                }
            }
            if (sender.Equals(BT_PickOffsetZCal))
            {
                mc.log.debug.write(mc.log.CODE.CAL, "Pick Z Offset Calibration START");
                double   posX, posY, posZ, posT;
                int      moveCase;
                double   startZPos, sensor1Pos, sensor2Pos;
                bool     pos1Done;
                bool     pos2Done;
                bool     teachDone    = false;
                double[] tempval      = new double[5];
                int      stackFeedNum = 8;
                int      sfTemp       = 0;
                if (mc.swcontrol.mechanicalRevision == 1)
                {
                    stackFeedNum = 4;
                }
                for (int i = 0; i < stackFeedNum; i++)
                {
                    if (mc.swcontrol.mechanicalRevision == 1 && i >= 2)
                    {
                        sfTemp = i + 2;
                    }
                    mc.log.debug.write(mc.log.CODE.CAL, String.Format("Stack Feeder Move to {0} position", sfTemp + 1));
                    for (int k = 0; k < 5; k++)
                    {
                        #region move stack feeder
                        mc.sf.req           = true; mc.sf.reqMode = REQMODE.READY;
                        mc.sf.reqTubeNumber = (UnitCodeSF)sfTemp;
                        mc.main.Thread_Polling();                               // make stack feeder to be ready for picking
                        if (mc.sf.ERROR)
                        {
                            mc.log.debug.write(mc.log.CODE.ERROR, "CANNOT run calibration process. Stack Feeder Error");
                            goto EXIT;
                        }
                        #endregion

                        #region move to pick position
                        posX = mc.hd.tool.tPos.x[(int)UnitCodeHead.HD1].PICK((UnitCodeSF)sfTemp);
                        posY = mc.hd.tool.tPos.y[(int)UnitCodeHead.HD1].PICK((UnitCodeSF)sfTemp);
                        posZ = mc.hd.tool.tPos.z[(int)UnitCodeHead.HD1].RAWPICK;
                        posT = mc.hd.tool.tPos.t[(int)UnitCodeHead.HD1].ZERO;

                        mc.hd.tool.jogMove((int)UnitCodeHead.HD1, posX, posY, posZ, posT, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            mc.message.alarmMotion(ret.message); goto EXIT;
                        }
                        mc.idle(100);
                        #endregion

                        #region sensor check
                        //mc.IN.HD.LOAD_CHK(out ret.b1, out ret.message);
                        //mc.IN.HD.LOAD_CHK2(out ret.b2, out ret.message);

                        if (ret.b1 == false && ret.b2 == true)
                        {
                            moveCase = 0;                                                                       // touch가 안되어 있거나 살짝 눌린 상태
                        }
                        else if (ret.b1 == true && ret.b2 == true)
                        {
                            moveCase = 1;                                                                       // 200~350um 눌린 상태
                        }
                        else if (ret.b1 == true && ret.b2 == false)
                        {
                            moveCase = 2;                                                                       // 350um이상 눌린 상태
                        }
                        else
                        {
                            moveCase = 3;                              // 몰라...이런 상태는 없어...
                            mc.message.alarm("Load Sensor Error : Sensor ALL OFF"); goto EXIT;
                        }
                        #endregion

                        if (moveCase > 0)
                        {
                            FormMain.UserMessageBox(DIAG_SEL_MODE.OK, DIAG_ICON_MODE.FAILURE, "Pick Position이 너무 낮습니다.\nPick Position값을 먼저 설정해 주세요.");
                            //mc.message.alarm("Pick Position is too LOW. Please change pick position."); goto EXIT;
                        }

                        mc.hd.tool.Z[(int)UnitCodeHead.HD1].actualPosition(out startZPos, out ret.message);
                        teachDone = false;

                        for (int j = 0; j < 3; j++)
                        {
                            if (teachDone)
                            {
                                break;
                            }

                            mc.hd.tool.Z[(int)UnitCodeHead.HD1].move(posZ - 600 * (j + 1), mc.speed.checkSpeed, out ret.message);

                            dwell.Reset();
                            sensor1Pos = 0;
                            sensor2Pos = 0;
                            pos1Done   = false;
                            pos2Done   = false;
                            while (true)
                            {
//                              mc.IN.HD.LOAD_CHK(out ret.b1, out ret.message);
//                              mc.IN.HD.LOAD_CHK2(out ret.b2, out ret.message);
                                if (ret.b1 && !pos1Done)
                                {
                                    mc.hd.tool.Z[(int)UnitCodeHead.HD1].actualPosition(out sensor1Pos, out ret.message);
                                    pos1Done = true;
                                }
                                if (ret.b1 && !ret.b2 && !pos2Done)
                                {
                                    mc.hd.tool.Z[(int)UnitCodeHead.HD1].actualPosition(out sensor2Pos, out ret.message);
                                    pos2Done = true;
                                }
                                mc.hd.tool.Z[(int)UnitCodeHead.HD1].AT_TARGET(out ret.b, out ret.message); if (ret.message != RetMessage.OK)
                                {
                                    mc.message.alarmMotion(ret.message); goto EXIT;
                                }
                                if (ret.b)
                                {
                                    break;
                                }
                                if (dwell.Elapsed > 20000)
                                {
                                    ret.message = RetMessage.TIMEOUT; mc.message.alarmMotion(ret.message); goto EXIT;
                                }
                            }
                            if (sensor1Pos == 0)
                            {
                                mc.log.debug.write(mc.log.CODE.TRACE, "Cannot find in search " + (j + 1).ToString());
                            }
                            else
                            {
                                mc.log.debug.write(mc.log.CODE.TRACE, "1st Pos : " + Math.Round((startZPos - sensor1Pos), 3).ToString("f3") + ", 2nd Pos : " + Math.Round((startZPos - sensor2Pos), 3).ToString("f3"));
                            }
                            dwell.Reset();
                            while (true)
                            {
                                if (dwell.Elapsed > 500)
                                {
                                    ret.message = RetMessage.TIMEOUT; mc.message.alarmMotion(ret.message); goto EXIT;
                                }
                                mc.hd.tool.Z[(int)UnitCodeHead.HD1].AT_DONE(out ret.b, out ret.message); if (ret.message != RetMessage.OK)
                                {
                                    mc.message.alarmMotion(ret.message); goto EXIT;
                                }
                                if (ret.b)
                                {
                                    break;
                                }
                            }
                            if (sensor1Pos != 0)
                            {
                                double offset = Math.Round(sensor1Pos - startZPos) - mc.para.CAL.z.sensor1.value;
                                mc.log.debug.write(mc.log.CODE.CAL, "SF" + (sfTemp + 1).ToString() + " Offset: " + offset.ToString() + "[um]");
                                tempval[k] = offset;
                                teachDone  = true;
                                break;
                            }
                            else
                            {
                                mc.idle(100);
                            }
                        }
                        posZ = mc.hd.tool.tPos.z[(int)UnitCodeHead.HD1].XY_MOVING;
                        mc.hd.tool.jogMove((int)UnitCodeHead.HD1, posZ, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            mc.message.alarmMotion(ret.message); goto EXIT;
                        }

                        double curSFZPos;
                        mc.sf.Z.actualPosition(out curSFZPos, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            mc.message.alarmMotion(ret.message); goto EXIT;
                        }
                        mc.sf.jogMoveZ(curSFZPos - 300, out ret.message); if (ret.message != RetMessage.OK)
                        {
                            mc.message.alarmMotion(ret.message); goto EXIT;
                        }
                    }
                    mc.log.debug.write(mc.log.CODE.TRACE, "1st[" + tempval[0].ToString() + "], 2nd[" + tempval[1].ToString() + "], 3rd[" + tempval[2].ToString() + "], 4th[" + tempval[3].ToString() + "], 5th[" + tempval[4].ToString() + "]");
                    double sum = tempval[0] + tempval[1] + tempval[2] + tempval[3] + tempval[4];
                    mc.log.debug.write(mc.log.CODE.CAL, "SF" + (sfTemp + 1).ToString() + " Offset RESULT : " + Math.Round(sum / 5).ToString());

                    mc.para.setting(ref mc.para.HD.pick.offset[sfTemp].z, Math.Round(sum / 5));
                }
                mc.sf.req           = true; mc.sf.reqMode = REQMODE.DOWN;
                mc.sf.reqTubeNumber = UnitCodeSF.SF1;
                mc.main.Thread_Polling();
                mc.log.debug.write(mc.log.CODE.CAL, "Pick Z Offset Calibration END");
            }
            if (sender.Equals(TB_PickOffsetZ1))
            {
                mc.para.setting(mc.para.HD.pick.offset[0].z, out mc.para.HD.pick.offset[0].z);
            }
            if (sender.Equals(TB_PickOffsetZ2))
            {
                mc.para.setting(mc.para.HD.pick.offset[1].z, out mc.para.HD.pick.offset[1].z);
            }
            if (sender.Equals(TB_PickOffsetZ3))
            {
                mc.para.setting(mc.para.HD.pick.offset[2].z, out mc.para.HD.pick.offset[2].z);
            }
            if (sender.Equals(TB_PickOffsetZ4))
            {
                mc.para.setting(mc.para.HD.pick.offset[3].z, out mc.para.HD.pick.offset[3].z);
            }
            if (sender.Equals(TB_PickOffsetZ5))
            {
                mc.para.setting(mc.para.HD.pick.offset[4].z, out mc.para.HD.pick.offset[4].z);
            }
            if (sender.Equals(TB_PickOffsetZ6))
            {
                mc.para.setting(mc.para.HD.pick.offset[5].z, out mc.para.HD.pick.offset[5].z);
            }
            if (sender.Equals(TB_PickOffsetZ7))
            {
                mc.para.setting(mc.para.HD.pick.offset[6].z, out mc.para.HD.pick.offset[6].z);
            }
            if (sender.Equals(TB_PickOffsetZ8))
            {
                mc.para.setting(mc.para.HD.pick.offset[7].z, out mc.para.HD.pick.offset[7].z);
            }
            #endregion
            #region suction
            if (sender.Equals(BT_SuctionMode_Select_MovingLevelOn))
            {
                mc.para.setting(ref mc.para.HD.pick.suction.mode, (int)PICK_SUCTION_MODE.MOVING_LEVEL_ON);
            }
            if (sender.Equals(BT_SuctionMode_Select_SearchLevelOn))
            {
                mc.para.setting(ref mc.para.HD.pick.suction.mode, (int)PICK_SUCTION_MODE.SEARCH_LEVEL_ON);
            }
            if (sender.Equals(BT_SuctionMode_Select_PickLevelOn))
            {
                mc.para.setting(ref mc.para.HD.pick.suction.mode, (int)PICK_SUCTION_MODE.PICK_LEVEL_ON);
            }
            if (sender.Equals(TB_SuctionMode_Level))
            {
                mc.para.setting(mc.para.HD.pick.suction.level, out mc.para.HD.pick.suction.level);
            }
            if (sender.Equals(BT_SuctionCheck_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.suction.check, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_SuctionCheck_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.suction.check, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_SuctionCheckLimit_HD1))
            {
                mc.para.setting(mc.para.HD.pick.pickupVacLimit[(int)UnitCodeHead.HD1], out mc.para.HD.pick.pickupVacLimit[(int)UnitCodeHead.HD1]);
            }
            if (sender.Equals(TB_SuctionCheckLimit_HD2))
            {
                mc.para.setting(mc.para.HD.pick.pickupVacLimit[(int)UnitCodeHead.HD2], out mc.para.HD.pick.pickupVacLimit[(int)UnitCodeHead.HD2]);
            }
            if (sender.Equals(TB_SuctionCheck_Time))
            {
                mc.para.setting(mc.para.HD.pick.suction.checkLimitTime, out mc.para.HD.pick.suction.checkLimitTime);
            }
            #endregion
            #region missCheck
            if (sender.Equals(BT_MissCheck_SelectOnOff_On))
            {
                mc.para.setting(ref mc.para.HD.pick.missCheck.enable, (int)ON_OFF.ON);
            }
            if (sender.Equals(BT_MissCheck_SelectOnOff_Off))
            {
                mc.para.setting(ref mc.para.HD.pick.missCheck.enable, (int)ON_OFF.OFF);
            }
            if (sender.Equals(TB_MissCheck_Retry))
            {
                mc.para.setting(mc.para.HD.pick.missCheck.retry, out mc.para.HD.pick.missCheck.retry);
            }
            #endregion
EXIT:
            mc.para.write(out ret.b); if (!ret.b)
            {
                mc.message.alarm("para write error");
            }
            refresh();
            mc.main.Thread_Polling();
            mc.check.push(sender, false);
        }