//------------------------------------------------------------------------------------------------ private void fn_CheckAliveSignal() { switch (m_nCommStep) { case 0: m_tCommDelayTimer.Clear(); m_nCommStep++; return; case 1: if (!m_tCommDelayTimer.OnDelay(true, 2000)) { return; } m_bCommSignal = !m_bCommSignal; m_nCommStep = 0; return; default: m_nCommStep = 0; return; } }
//-------------------------------------------------------------------------- //Update. public void fn_Update() { bool isOk = true; for (int i = 0; i < m_iNumOfACT; i++) { Actuator[i].Update(); //Check Actuator Status. if (Err(i) == 1) { m_bRptActr[i] = false; } //Changing Timer. if (!m_bRptActrIng) { continue; } if (m_bRptActr[i]) { if (!SEQ.fn_CheckDstbActr(i, m_iRptCmd)) { m_bRptActrIng = false; continue; } MoveCyl(i, m_iRptCmd); if (!Complete(i, m_iRptCmd)) { isOk = false; } } } m_ChngActrOnTimer.OnDelay(isOk, m_iChngActrDlay); if (m_ChngActrOnTimer.Out) { m_ChngActrOnTimer.Clear(); if (m_iRptCmd == (int)EN_ACTR_CMD.Fwd) { m_iRptCmd = (int)EN_ACTR_CMD.Bwd; } else { m_iRptCmd = (int)EN_ACTR_CMD.Fwd; } } }
//-------------------------------------------------------------------------- //Update public void fn_Update(int iSeqStat) { //Local Var. int iStat = m_bTest ? m_iTestStat : iSeqStat; if (m_bFlickLamp) { m_FlickOnTimer.Clear(); if (m_FlickOffTimer.OnDelay(m_bFlickLamp, 500)) { m_bFlickLamp = false; } } else { m_FlickOffTimer.Clear(); if (m_FlickOnTimer.OnDelay(!m_bFlickLamp, 500)) { m_bFlickLamp = true; } } if (m_bFlickBuzz) { m_FlickOnTimer2.Clear(); if (m_FlickOffTimer2.OnDelay(m_bFlickBuzz, 200)) { m_bFlickBuzz = false; } } else { m_FlickOffTimer2.Clear(); if (m_FlickOnTimer2.OnDelay(!m_bFlickBuzz, 200)) { m_bFlickBuzz = true; } } if (iStat < 0 || iStat >= UserConst.MAX_LAMP_KIND) { return; } UpdateLamp(m_iYLempRed, (EN_LAMP_OPER)m_LampInfo[iStat].iRed); UpdateLamp(m_iYLempYel, (EN_LAMP_OPER)m_LampInfo[iStat].iYel); UpdateLamp(m_iYLempGrn, (EN_LAMP_OPER)m_LampInfo[iStat].iGrn); UpdateBuzz((EN_BUZZ_OPER)m_LampInfo[iStat].iBuzz); }
//--------------------------------------------------------------------------- //Update Timer private void fn_tmUpdate(object sender, EventArgs e) { //m_UpdateTimer.Stop(); // switch (m_nStep) { case 0: tbLoadMsg.Text = " Now Loading System Data..."; if (!m_tDelayTimer.OnDelay(true, 300)) { return; } m_tDelayTimer.Clear(); m_nStep++; break; case 1: //Load Default file Info. tbLoadMsg.Text = " Loading the Information..."; FM.fn_LoadLastInfo(true); tbLoadMsg.Text = " Loading the Project Info..."; FM.fn_LoadProject(true, FM._sCurrJob); tbLoadMsg.Text = " Loading the System Option..."; FM.fn_LoadSysOptn(true); tbLoadMsg.Text = " Loading the Master Option..."; FM.fn_LoadMastOptn(true); tbLoadMsg.Text = " Loading the Recipe Data..."; FM.fn_LoadRecipeInfo(true, FM._sRecipeName); tbLoadMsg.Text = " Loading the Password..."; FM.fn_LoadPassWord(true); tbLoadMsg.Text = " Loading SPC Data..."; SPC.Load(true); m_tDelayTimer.Clear(); m_nStep++; break; case 2: if (!m_tDelayTimer.OnDelay(true, 100)) { return; } tbLoadMsg.Text = " Loading the IO List..."; IO.fn_LoadIO(true); tbLoadMsg.Text = " Loading the Lamp/Buzzer Data..."; LAMP.fn_Load(true); tbLoadMsg.Text = " Loading the Actuator Data..."; ACTR.fn_Load(true); //tbLoadMsg.Text = " ACS IO Connection...(SIM)" ; IO.fn_ACSConnect(UserConst.ACS_CON_SIM); tbLoadMsg.Text = " ACS IO Connection..."; IO.fn_ACSConnect(UserConst.ACS_CON_NOR); m_tDelayTimer.Clear(); m_nStep++; break; case 3: //if (!m_tDelayTimer.OnDelay(true, 100)) return; tbLoadMsg.Text = " Loading the Error List..."; EPU.fn_LoadErrorData(true); tbLoadMsg.Text = " Loading the Lamp/Buzzer Data..."; EPU.fn_LoadLampData(true); m_tDelayTimer.Clear(); m_nStep++; break; case 4: if (!m_tDelayTimer.OnDelay(true, 500)) { return; } //tbLoadMsg.Text = " Loading the Motor List...(SIM)"; MOTR.fn_InitMotor(UserConst.ACS_CON_SIM); tbLoadMsg.Text = " Loading the Motor List..."; MOTR.fn_InitMotor(UserConst.ACS_CON_NOR); tbLoadMsg.Text = " Loading the Vision Recipe..."; g_VisionManager.fn_LoadVision(FM._sRecipeName); //tbLoadMsg.Text = " Loading the Motor Data..." ; FM.fn_LoadMastOptn(true); //tbLoadMsg.Text = " Loading the Motor DSTB..." ; MOTR.fn_LoadMotrDisturb(true); m_tDelayTimer.Clear(); m_nStep++; break; case 5: //if (!m_tDelayTimer.OnDelay(true, 500)) return; tbLoadMsg.Text = " Loading the Data Manager Map Data..."; DM.fn_LoadMap(true); tbLoadMsg.Text = " Loading the Sequence Data..."; SEQ.fn_LoadWorkInfo(true); m_tDelayTimer.Clear(); m_nStep++; break; case 6: //Row, Col Setting... tbLoadMsg.Text = " Apply Project..."; FM.ApplyProject(FM._sCurrJob); m_nStep++; break; case 7: //LoadCell tbLoadMsg.Text = " Initial Load Cell ..."; LDCBTM.fn_SetParam(); LDCBTM.fn_Open(LDCBTM._sSerialNo); //LDCBTM.fn_Open (FM.m_stMasterOpt.sLoadCellSN); LDCBTM.fn_Close(); //JUNG/201014/Retry LDCBTM.fn_Open(LDCBTM._sSerialNo); //PMC, Slurry Init //tbLoadMsg.Text = " Initial PMC IP,Port ..." ; PMC.fn_SetIpAddress(FM.m_stSystemOpt.sPMCIp, FM.m_stSystemOpt.nPMCPort); tbLoadMsg.Text = " Initial REST API ..."; REST.fn_SetURL(FM.m_stSystemOpt.sRestApiUrl); tbLoadMsg.Text = " Initial RFID Reader ..."; m_nStep++; break; case 8: if (IO._bConnect) { //RFID tbLoadMsg.Text = " Initial RFID Reader ..."; RFID.fn_Connect(); } m_nStep++; break; case 9: //if (!m_tDelayTimer.OnDelay(true, 500)) return; //Main Load fn_MainFormLoad(); m_UpdateTimer.Stop(); m_nStep++; break; default: break; } //Step Inc. pbStep.Value = m_nStep * 10; //m_UpdateTimer.Start(); }
//-------------------------------------------------------------------------- public void UpdateInput() { //Local Var. bool isXFwdID; bool isXBwdID; bool isYFwdID; bool isYBwdID; int iXfwdId; int iXbwdId; int iYfwdId; int iYbwdId; int iXfwdIndex; int iXbwdIndex; int iYfwdIndex; int iYbwdIndex; //Set I/O ID. iXfwdId = (iInv == 1) ? m_xbwdId : m_xfwdId; iXbwdId = (iInv == 1) ? m_xfwdId : m_xbwdId; iYfwdId = (iInv == 1) ? m_ybwdId : m_yfwdId; iYbwdId = (iInv == 1) ? m_yfwdId : m_ybwdId; //Set I/O Index. iXfwdIndex = (iInv == 1) ? m_xbwdIndex : m_xfwdIndex; iXbwdIndex = (iInv == 1) ? m_xfwdIndex : m_xbwdIndex; iYfwdIndex = (iInv == 1) ? m_ybwdIndex : m_yfwdIndex; iYbwdIndex = (iInv == 1) ? m_yfwdIndex : m_ybwdIndex; if (!IO._bConnect) { return; } //Check SKIP. if ((iYfwdId == SKIP4 && iYbwdId == SKIP4) || (iYfwdId == SKIP5 && iYbwdId == SKIP5)) { Rst(); return; } //Set exist ID. isXFwdID = (iXfwdId != SKIP4 && iXfwdId != SKIP5); isXBwdID = (iXbwdId != SKIP4 && iXbwdId != SKIP5); isYFwdID = (iYfwdId != SKIP4 && iYfwdId != SKIP5); isYBwdID = (iYbwdId != SKIP4 && iYbwdId != SKIP5); //I/O. if (isXFwdID) { dfx = Input(iXfwdIndex); //Detect X/Y Val. } if (isXBwdID) { dbx = Input(iXbwdIndex); } if (isYFwdID) { dfy = Output(iYfwdIndex); } if (isYBwdID) { dby = Output(iYbwdIndex); } //Virtual Input Sensor //FWD. if (isXFwdID) { vfx = dfx; } else if (isXBwdID) { vfx = !dbx; } else if (isYFwdID) { vfx = dfy; } else if (isYBwdID) { vfx = !dby; } else { vfx = !dby; } //BWD. if (isXBwdID) { vbx = dbx; } else if (isXFwdID) { vbx = !dfx; } else if (isYBwdID) { vbx = dby; } else if (isYFwdID) { vbx = !dfy; } else { vbx = !dfy; } //Virtual Output Sensor if (isYFwdID) { vfy = dfy; } else { vfy = !dby; } if (isYBwdID) { vby = dby; } else { vby = !dfy; } //OnDelay Timer. odfx = tFwdOnDelayTimer.OnDelay(vfx, nFwdOnDelayTime); odbx = tBwdOnDelayTimer.OnDelay(vbx, nBwdOnDelayTime); //Check time out by delay result. //Time out By Input bool r = true; if (odfx && !odbx) { r = false; } if (!odfx && odbx) { r = false; } if (odfx && odbx) { r = true; } if (!odfx && !odbx) { r = true; } //Time out By Output if (dfy && odbx) { r = true; } if (dfy && !odfx) { r = true; } if (dby && odfx) { r = true; } if (dby && !odbx) { r = true; } //Is timeout. ftoe = tFwdTimeOutTimer.OnDelay(ApplyTimeout && r, nFwdTimeOutDelayTime); btoe = tBwdTimeOutTimer.OnDelay(ApplyTimeout && r, nBwdTimeOutDelayTime); //if (ftoe) Ltftoe = true; //if (btoe) Ltbtoe = true; if (ftoe) //JUNG/201012/Retry { if (++nReCntFwd >= m_iRetry) { Ltftoe = true; nReCntFwd = m_iRetry; } else { tFwdTimeOutTimer.Clear(); ftoe = false; } } if (btoe) { if (++nReCntBwd >= m_iRetry) { Ltbtoe = true; nReCntBwd = m_iRetry; } else { tBwdTimeOutTimer.Clear(); btoe = false; } } //Error Action. if (ftoe || btoe) { fx = false; bx = false; } else { fx = odfx; bx = odbx; } //Apply Out Complete. if (ApplyOutComplete) { Rst(); fx = dfy; bx = dby; if (isYFwdID) { fx = dfy; } else if (isYBwdID) { fx = !dby; } else { fx = !bx; } if (isYBwdID) { bx = dby; } else if (isYFwdID) { bx = !dfy; } else { bx = !fx; } } }
//--------------------------------------------------------------------------- public void fn_Update() { // if (pmcip == string.Empty) { return; } if (pmcport < 1) { return; } printf("[OPEN PMC] ip : " + pmcip + ", port : " + pmcport); IPEndPoint localAddress = new IPEndPoint(IPAddress.Parse(pmcip), pmcport); server = new TcpListener(localAddress); server.Start(); printf("server start..."); while (true) { // if (client != null) //if (client != null && client.Connected) { m_tAliveTimer.OnDelay(m_bAlive, 5000); if (m_tAliveTimer.Out) { // fn_StopThread(); client.Close(); client = null; m_bAlive = false; } continue; } try { client = server.AcceptTcpClient(); Console.WriteLine("Accept"); fn_SetCommState(COMM_STATE.CONNECTED); //curState.CommunicationState = (int)COMM_STATE.CONNECTED; //fn_SetControlState(CONTROL_STATE.AUTO ); //curState.ControlState = (int)CONTROL_STATE.AUTO; fn_SetControlState(); printf("Accept Client : " + client.Client.RemoteEndPoint.ToString()); if (thread != null) { thread.Abort(); thread = null; } thread = new Thread(new ParameterizedThreadStart(WorkThread)); thread.Start(client); polling_thread = new Thread(new ParameterizedThreadStart(PollingThread)); polling_thread.Start(pollingQue); proc_thread = new Thread(new ParameterizedThreadStart(ProcThread)); proc_thread.Start(procQue); proc_Send = new Thread(new ThreadStart(SendThread)); proc_Send.Start(); } catch (Exception ex) { printf("[fn_OpenPMC] " + ex.Message); m_bAlive = true; } } }
//--------------------------------------------------------------------------- public bool fn_Update() { // m_bDrngSMC = m_nSeqStep != 0; m_tMainCycle.OnDelay(m_bDrngSMC, 15 * 1000); //15sec if (m_tMainCycle.Out) { m_sLog = string.Format($"SMC Update Time Out [STEP] : {m_nSeqStep}"); Console.WriteLine(m_sLog); WriteLog(m_sLog); m_nSeqStep = 0; fn_Clear(); m_tErrDelay.Clear(); return(true); } if (!m_tErrDelay.OnDelay(true, 1000)) { return(true); //Error 발생 후 1sec Delay } // if (m_nSeqStep == 0) { int nTarPos = IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]; int nReqTar = IO.REQ_EQ_TO_SMC [nIndex + (int)EN_SMC_WRITE.TARGET_POS]; //SMC Data bool xServoOn = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.SERVO_ON] == 1; bool xHomeEnd = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.HOME_COMPLETE] == 1; bool xAlarm = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.ALRAM] == 1; bool xReady = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.READY] == 1; //Request bool bReqServoOn = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.SERVO_ON] == 1; bool bReqHome = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.HOME] == 1; bool bReqMove = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.START_FLAG] == 1; bool bReqReset = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.FAULT_RESET] == 1; bool isConServoOn = bReqServoOn && !xServoOn; bool isConServoOff = !bReqServoOn && xServoOn; bool isConHome = bReqHome; //&& bReqServoOn bool isConMove = bReqMove; //&& xHomeEnd && xServoOn && xAlarm; bool isConReset = (xAlarm || !xReady) && (bReqReset || m_bReqReset); m_tDelayTime.Clear(); m_bDrngHome = false; m_bDrngServoOn = false; m_bDrngMove = false; m_bDrngReset = false; if (isConHome) { m_bDrngHome = true; m_nSeqStep = 100; m_nStep = 10; goto __GOTO_CYCLE__; } if (isConServoOn) { m_bDrngServoOn = true; m_nSeqStep = 200; m_nStep = 10; goto __GOTO_CYCLE__; } if (isConMove) { m_bDrngMove = true; m_nSeqStep = 300; m_nStep = 10; goto __GOTO_CYCLE__; } if (isConReset) { m_bDrngReset = true; m_nSeqStep = 400; m_nStep = 10; goto __GOTO_CYCLE__; } //if (isConServoOff) { m_bDrngServoOn = true; m_nSeqStep = 200; m_nStep = 30; goto __GOTO_CYCLE__; } } //Cycle Start __GOTO_CYCLE__: switch (m_nSeqStep) { case 100: if (fn_Home()) { m_nSeqStep = 0; } return(false); case 200: if (fn_SetServo()) { m_nSeqStep = 0; } return(false); case 300: if (fn_SetMove()) { m_nSeqStep = 0; } return(false); case 400: if (fn_Reset()) { m_nSeqStep = 0; } return(false); default: m_bDrngHome = false; m_bDrngServoOn = false; m_bDrngMove = false; m_bDrngReset = false; m_nSeqStep = 0; return(true); } }
//--------------------------------------------------------------------------- private bool fn_SetMove() { bool r1; bool xServoOn = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.SERVO_ON] == 1; bool xHomeEnd = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.HOME_COMPLETE] == 1; bool xAlarm = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.ALRAM] == 1; bool xReady = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.READY] == 1; int nTarPos = IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]; int nReqTar = IO.REQ_EQ_TO_SMC [nIndex + (int)EN_SMC_WRITE.TARGET_POS]; int nCurrPos = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.CURRENT_POS]; if (m_nStep < 0) { m_nStep = 0; } switch (m_nStep) { case 10: m_bDrngMove = true; // IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.START_FLAG] = 0; if (!xServoOn || !xHomeEnd || xAlarm || !xReady) { m_bDrngMove = false; IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.START_FLAG] = 0; m_nStep = 0; return(true); } if (nReqTar == nCurrPos) { m_bDrngMove = false; IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.START_FLAG] = 0; m_nStep = 0; return(true); } IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.JOG_LEFT] = 0; IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.JOG_RIGHT] = 0; // IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.POSITION_ON] = 1; //SMC_CONTROL_FLAG(0).5 = 1 IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.SPEED_ON] = 1; //SMC_CONTROL_FLAG(0).6 = 1 IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS] = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]; IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_VEL] = IO.REQ_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_VEL]; Console.WriteLine("TARGET_POS :" + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]); Console.WriteLine("TARGET_VEL :" + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_VEL]); WriteLog("[MOVE] TARGET_POS :" + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS] + "/" + "TARGET_VEL :" + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_VEL]); m_tDelayTime.Clear(); m_nStep++; return(false); case 11: if (!m_tDelayTime.OnDelay(true, DELAY_TIME)) { return(false); } IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.START_FLAG] = 1; m_tDelayTime.Clear(); m_nStep++; return(false); case 12: if (!m_tDelayTime.OnDelay(true, 500)) { return(false); } r1 = IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.INPOSITION] == 1; if (!r1) { return(false); } Console.WriteLine("[SMC] MOVE DONE : " + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]); Console.WriteLine(" CURRENT_POS : " + IO.DATA_SMC_TO_EQ[nIndex + (int)EN_SMC_READ.CURRENT_POS]); WriteLog("[SMC] MOVE DONE : " + IO.DATA_EQ_TO_SMC[nIndex + (int)EN_SMC_WRITE.TARGET_POS]); fn_Clear(); //JUNG/200523 m_bDrngMove = false; m_nStep = 0; return(true); } return(true); }