#include "StdAfx.h" #include "InterfaceManager.h" #include "MulticamControl.h" #include "RadientControl.h" #include "SoliosControl.h" #include "SapControl.h" #include "SapLineGrab.h" #include "FrameBufferController.h" #include "FreeImage.h" #include #include "ExpireDayDefine.h" #if USE_WEBSOCKET #include #endif // USE_WEBSOCKET #define OFFSET_SPLINE_DATA 10 #define JPEG_RATE JPEG_QUALITYNORMAL|JPEG_OPTIMIZE #define JPEG_FULLIMAGE_RATE JPEG_QUALITYGOOD|JPEG_OPTIMIZE typedef struct _DefectInfo { int SideIdx; int DefectIndex; int PosX; int PosY; int Length; int Depth; } DefectInfo; CInterfaceManager::CInterfaceManager(void) { m_pLogManager = new CLogManager(0,_T("LOGVIEW")); m_pView = NULL; m_bPLCGlassLoading = FALSE; m_pControlInterface = NULL; m_pTransDataManager = NULL; m_pLightManager = NULL; for(int i=0;im_nWSClientThreadURI[i], g_pBase->m_nWSClientThreadCount[i]); } #endif // USE_WEBSOCKET #if USE_AI_DETECT //m_bUseAIDetect = AiDetectEx::instance().startServer(); #endif // USE_AI_DETECT } CInterfaceManager::~CInterfaceManager(void) { for(int i=0;iSetProcessEnd(); Sleep(100); m_pInspect[i]->ReleaseThread(); delete m_pInspect[i]; } m_pInspect[i] = NULL; } DeinitGrabber(); if(m_pTransDataManager != NULL) delete m_pTransDataManager; m_pTransDataManager = NULL; if(m_pControlInterface != NULL) delete m_pControlInterface; m_pControlInterface = NULL; if(m_pLightManager != NULL) delete m_pLightManager; m_pLightManager = NULL; if(m_pLogManager != NULL) delete m_pLogManager; m_pLogManager=NULL; if(m_pLicense != NULL) delete m_pLicense; m_pLicense = NULL; if(m_pTriggerBoardControl != NULL) delete m_pTriggerBoardControl; m_pTriggerBoardControl = NULL; #if USE_WEBSOCKET for (size_t i = 0; i < MAX_CAMERA_COUNT; i++) { DestroyWebSocketClients(&m_wsClients[i]); } #endif // USE_WEBSOCKET #if USE_AI_DETECT //AiDetectEx::instance().stopServer(); #endif // USE_AI_DETECT } BOOL CInterfaceManager::DestroyThread() { if(m_pThread_SendMSG != NULL) { m_pThread_SendMSG->StopThread(); delete m_pThread_SendMSG; } m_pThread_SendMSG = NULL; if(m_pThread_CheckSequence != NULL) { m_pThread_CheckSequence->StopThread(); delete m_pThread_CheckSequence; } m_pThread_CheckSequence = NULL; if(m_pThread_ViewRefresh != NULL) { m_pThread_ViewRefresh->StopThread(); delete m_pThread_ViewRefresh; } m_pThread_ViewRefresh = NULL; return TRUE; } UINT CInterfaceManager::PLCSignalThreadFunc(LPVOID pParam) { CInterfaceManager *pInter = (CInterfaceManager*)pParam; pInter->PLCSignalRetry(pInter->m_emPLCSection,pInter->m_emPLCSendSignal,pInter->m_emPLCControlSignal); return 0; } // End SignalÀ» PLC¿¡¼­ Àß ¸ø¹Þ¾Æ¼­ Retry ³Ö¾úÀ½ void CInterfaceManager::PLCSignalRetry(SEND_MESSAGE_SECTION emSection,InspectToControlSignal emSendSignal,enInterface_Send_Control emControlSignal) { if(m_HardwareRecipe.m_nPLCSignalRetry <= 0) return; switch(emSendSignal) { case IToC_Ack_LoadingSuccess: case IToC_Ack_ShortScanEndSuccess: case IToC_Ack_ShortScanEndFail: case IToC_Ack_LongScanEndSuccess: case IToC_Ack_LongScanEndFail: break; default: return; } int nRetryCount = m_HardwareRecipe.m_nPLCSignalRetry; int nSignalOnTime = m_pControlInterface->GetSignalOnTime(emSendSignal); DWORD dwTick = GetTickCount(); DWORD dwWaitTick; DWORD dwWaitTime = nSignalOnTime+200; int nCount = 0; BOOL bSendSignal = FALSE; while(TRUE) { dwWaitTick = GetTickCount() - dwTick; if(dwWaitTime < dwWaitTick) { nCount++; bSendSignal = FALSE; dwTick = GetTickCount(); } switch(emSendSignal) { case IToC_Ack_LoadingSuccess: break; case IToC_Ack_ShortScanEndSuccess: case IToC_Ack_ShortScanEndFail: if(m_bPLCGlassLoading == TRUE) { g_pLog->DisplayMessage(_T(" Ack Short PLC End : Rcv GlassLoading PLC Signal %d"),m_bPLCGlassLoading); return; } break; case IToC_Ack_LongScanEndSuccess: case IToC_Ack_LongScanEndFail: if(m_bShortPLCScanStart == TRUE) { g_pLog->DisplayMessage(_T("Ack Long PLC End : Rcv Short Start PLC Signal %d"),m_bShortPLCScanStart); return; } break; default: return; } if(bSendSignal == FALSE) { int nRet = m_pControlInterface->SendConstrol(emControlSignal,TRUE); g_pLog->DisplayMessage(_T("PLC Retry[%d] Send Control Signal : Sig %d, Val %d, Ret %d"),nCount,(int)emControlSignal,TRUE,nRet); Sleep(nSignalOnTime); nRet = m_pControlInterface->SendConstrol(emControlSignal,FALSE); bSendSignal = TRUE; } if(nCount >= nRetryCount) break; Sleep(1); } } void CInterfaceManager::SendMsgInspectToControlSignal(CPostSendMessage *pNetMSG) { InspectToControlSignal emSendSignal = static_cast(pNetMSG->nSignal); int nValue = pNetMSG->nValue; CString str; enInterface_Send_Control emControlSignal = enInterface_None; if(nValue == TRUE) str = _T("On"); else str = _T("Off"); switch(emSendSignal) { case IToC_Ack_LoadingSuccess: case IToC_Ack_LoadingFail: g_pLog->DisplayMessage(_T("Send Control Signal : Ack Signal Glass Loading %s"),(TCHAR*)(LPCTSTR)str); emControlSignal = GLASSLOADING_HANDSHAKE; break; case IToC_Ack_ShortScanStartSuccess: case IToC_Ack_ShortScanStartFail: emControlSignal = SHORT_SCANSTART_HANDSHAKE; g_pLog->DisplayMessage(_T("Send Control Signal : Ack Signal Short Scan Start %s"),(TCHAR*)(LPCTSTR)str); break; case IToC_Ack_ShortScanEndSuccess: case IToC_Ack_ShortScanEndFail: #ifdef TEST_SIGNAL_PROCESS Sleep(2000); #endif emControlSignal = SHORT_SCANEND_HANDSHAKE; g_pLog->DisplayMessage(_T("Send Control Signal : Ack Signal Short Scan End %s"),(TCHAR*)(LPCTSTR)str); break; case IToC_Ack_LongScanStartSuccess: case IToC_Ack_LongScanStartFail: emControlSignal = LONG_SCANSTART_HANDSHAKE; g_pLog->DisplayMessage(_T("Send Control Signal : Ack Signal Long Scan Start %s"),(TCHAR*)(LPCTSTR)str); break; case IToC_Ack_LongScanEndSuccess: case IToC_Ack_LongScanEndFail: #ifdef TEST_SIGNAL_PROCESS Sleep(2000); #endif emControlSignal = LONG_SCANEND_HANDSHAKE; g_pLog->DisplayMessage(_T("Send Control Signal : Ack Signal Long Scan End %s"),(TCHAR*)(LPCTSTR)str); break; default: return; } WaitEndSignal(emSendSignal); if(emControlSignal < enInterface_None) { int nDelayTime = m_pControlInterface->GetSignalDelayTime(pNetMSG->nSignal); if(nDelayTime != 0) Sleep(nDelayTime); if(m_HardwareRecipe.m_nPLCSignalRetry > 0) { switch(emSendSignal) { case IToC_Ack_LoadingSuccess: case IToC_Ack_ShortScanEndSuccess: case IToC_Ack_ShortScanEndFail: case IToC_Ack_LongScanEndSuccess: case IToC_Ack_LongScanEndFail: { CSingleLock myLock(&m_csPLCSignal); myLock.Lock(); m_emPLCSection = pNetMSG->emSection; m_emPLCSendSignal = emSendSignal; m_emPLCControlSignal = emControlSignal; AfxBeginThread(PLCSignalThreadFunc,this); myLock.Unlock(); break; } default: { int nRet = m_pControlInterface->SendConstrol(emControlSignal,nValue); g_pLog->DisplayMessage(_T("Send Control Signal : Sig %d, Val %d, Ret %d"),(int)emControlSignal,nValue,nRet); if(nValue == TRUE && m_pThread_SendMSG != NULL) { int nSignalOnTime = m_pControlInterface->GetSignalOnTime(pNetMSG->nSignal); m_pThread_SendMSG->AddDisableMSG(pNetMSG->emSection,pNetMSG->nSignal,FALSE,nSignalOnTime); } } break; } } else { int nRet = m_pControlInterface->SendConstrol(emControlSignal,nValue); g_pLog->DisplayMessage(_T("Send Control Signal : Sig %d, Val %d, Ret %d"),(int)emControlSignal,nValue,nRet); if(nValue == TRUE && m_pThread_SendMSG != NULL) { int nSignalOnTime = m_pControlInterface->GetSignalOnTime(pNetMSG->nSignal); m_pThread_SendMSG->AddDisableMSG(pNetMSG->emSection,pNetMSG->nSignal,FALSE,nSignalOnTime); } } } } void CInterfaceManager::SendMsgInspectToControlAlarm(CPostSendMessage *pNetMSG) { InspectToControlAlarm emSendAlarm = static_cast(pNetMSG->nSignal); int nValue = pNetMSG->nValue; enInterface_Send_Control emControlSignal = enInterface_None; switch(emSendAlarm) { case IToC_Alarm_InspectorError: break; case IToC_Alarm_InspectOverflow: break; case IToC_Alarm_EdgeCrack: break; case IToC_Alarm_NoRecipe: break; case IToC_Alarm_FindEdgeFail: break; case IToC_Alarm_LightError: break; case IToC_Alarm_UpperLimit: break; case IToC_Alarm_LowestLimit: break; case IToC_Alarm_NoImage: break; case IToC_Alarm_GlassDetectFail: break; case IToC_Alarm_TransferData: break; case IToC_Alarm_InternalValue: break; default: return; } if(emControlSignal < enInterface_None) { int nRet = m_pControlInterface->SendConstrol(emControlSignal,nValue); g_pLog->DisplayMessage(_T("Send Control Alarm : Sig %d, Val %d, Ret %d"),(int)emControlSignal,nValue,nRet); } } void CInterfaceManager::SendMSG_Received(CPostSendMessage *pSendMSG) { if(pSendMSG == NULL) return; switch(pSendMSG->emSection) { case SEND_MESSAGE_CONTROLSIGNAL: SendMsgInspectToControlSignal(pSendMSG); break; case SEND_MESSAGE_ALARM: SendMsgInspectToControlAlarm(pSendMSG); break; } } void CInterfaceManager::II2S_InspectionEnd(int iCamID,int iScan) { if(iCamID < 0 || iCamID >= MAX_CAMERA_COUNT) return; if(iScan < 0 || iScan >= MAX_SCAN_COUNT) return; m_GlassData.SetScanEndCamera(iCamID,iScan); DimensionDir eDimension = m_HardwareRecipe.GetCameraSettings(iCamID,iScan)->m_eDimension; g_pLog->DisplayMessage( _T("%s Inspection end Count! Scan %d, Cam %d StartCnt %d,End %d"),PANEL_SIDE[eDimension],iScan,iCamID,m_GlassData.GetScanStartCount(),m_GlassData.GetScanEndCameraCount()); if(m_GlassData.GetScanEndCameraCount() == m_GlassData.GetScanStartCount() && m_bPostProcess == FALSE) { m_bPostProcess = TRUE; g_pLog->DisplayMessage(_T("%s inspection end complete : Scan %d"),PANEL_SIDE[eDimension], iScan); g_pLog->DisplayMessage( _T("==========================================================")); m_GlassData.SetScanStart(FALSE); for(int i=0;iSetProcessEnd(); PostProcess(); //AfxBeginThread(ScanEndProcess,this); } else if(m_GlassData.GetScanEndCameraCount() == m_GlassData.GetScanStartCount()/2) { g_pLog->DisplayMessage(_T("%s One Scan inspection end complete : Scan %d"),PANEL_SIDE[eDimension], iScan); g_pLog->DisplayMessage( _T("==========================================================")); m_GlassData.SetScanEnd(iScan,TRUE); } } UINT CInterfaceManager::ScanEndProcess(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); g_pLog->DisplayMessage(_T("========= Start Glass Inspection End Processing")); pInter->PostProcess(); g_pLog->DisplayMessage(_T("========= End Glass Inspection End Processing")); g_pLog->DisplayMessage( _T("==========================================================")); return 0; } UINT CInterfaceManager::ScanTimeOut(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); pInter->ScanOverTimeSignal(); return 0; } void CInterfaceManager::ScanOverTimeSignal() { g_pLog->DisplayMessage(_T("Scan Over Time - Post Processing Start")); m_GlassData.SetScanStart(FALSE); for(int i=0;iGrabScanStop(); m_pInspect[iCam]->SetProcessEnd(); } m_pThread_SendMSG->ClearMSG(); Sleep(500); PostProcess(); } BOOL CInterfaceManager::PostProcess() { g_pLog->DisplayMessage(_T("Start PostProcess()")); if(m_pThread_CheckSequence != NULL) m_pThread_CheckSequence->ClearMessage(); if(m_GlassData.IsPostProcStart() == TRUE) { g_pLog->DisplayMessage(_T("Already Post Processing Start")); return TRUE; } m_GlassData.SetPostProc(TRUE); m_PostProcess.SetPrameter(&m_GlassData,&m_HardwareRecipe,&m_GlassRecipe,&m_TransferData); m_PostProcess.SetView((void*) m_pView); m_PostProcess.RunPostProcessing(); // ¹Ýµå½Ã Scan End ½ÅÈ£ º¸³»±â Àü¿¡ ÇØÁà¾ßÇÑ´Ù... Scan End ½ÅÈ£ º¸³¾¶§ LoadingÀÌ ¿Ï·á ¾ÈµÇ¸é ¾Èº¸³»Áö°Ô ¸·ÇôÀÖÀ½.. m_bGlassLoadingEnd = FALSE; m_bPLCGlassLoading = FALSE; int nDefectCount = m_GlassData.GetJudgeDefectCount(); CString strText; strText.Format(_T("Save %d defect images, please wait..."), nDefectCount); SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0, 0, 0)); SetSlashText(GLOBAL_DEFINE::emText, strText, RGB(0, 0, 0)); // Save Defect Image.. m_PostProcess.RunPostProcessing_SaveDefectInfo(); m_GlassData.SetScanEndTime(); m_TactStopWatch.End(); SetSlashText(GLOBAL_DEFINE::emHide, _T(""), RGB(0, 0, 0)); if (m_pView != NULL) { m_pView->SetGlassData(&m_GlassData); m_pView->RefreshDefect(m_PostProcess.GetResultPath(EM_RESULT_DEFECT)); if (m_pThread_ViewRefresh != NULL) { m_pThread_ViewRefresh->AddViewMSG(0, 0, VIEW_REFRESH_INSPECT_END, 0); } } //CheckExpireDay(); // Check License Defect.. WritePLCResult(); // Loading Ack // m_pControlInterface->SendControlBit(emSnd_Short_ScanEnd_Ack, TRUE); if (m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL, IToC_Ack_ShortScanEndSuccess, TRUE); if (0 == nDefectCount) { AfxBeginThread(CopyImageThreadFunc, this); } else { Save_FullImg(); } #if MINI_LED m_PostProcess.RunPostProcessing_SaveFiltImage(); #endif g_pLog->DisplayMessage(_T("Inspection Time(GlassLoading -> End) : %ld us"), GetCurrentTimestamp() - m_nStartTime); return TRUE; } void CInterfaceManager::Send_ViewRefresh(CScheduleViewMessage *pMSG) { if(m_pView != NULL) { m_pView->ViewRefresh(pMSG->ProcMsg); } } UINT CInterfaceManager::CopyImageThreadFunc(LPVOID pParam) { CInterfaceManager *pMain = static_cast(pParam); pMain->Save_FullImg(); return 0; } void CInterfaceManager::Save_FullImg() { DWORD dwTick = GetTickCount(); g_pLog->DisplayMessage(_T("Full Image Save Start")); int iCam,iScan; CHardwareSettings *pHard = &m_HardwareRecipe; CCameraSettings *pCamera; CGlassRecipe *pGlsRcp = &m_GlassRecipe; CString strFolder,strFileJpg,strPanelID; pINSPECTFULLIMAGE_BUFFER pBuffer; int nQuality = pHard->m_nSaveImageQuality; if (nQuality < 0 || nQuality > 100) { nQuality = 30; } strFolder.Format(_T("%s"),m_PostProcess.GetResultPath(EM_RESULT_FULL)); CreateDirectory(strFolder,NULL); strPanelID = g_pBase->m_strHPanelID; if (strPanelID.IsEmpty() == TRUE) { strPanelID = _T("TestGlass"); } for(iCam=0;iCamGetCameraCount();iCam++) { for(iScan=0;iScanGetCameraSettings(iCam,iScan); if (pCamera == NULL) { continue; } pBuffer = m_pInspect[iCam]->GetFullImgBuffer(iScan); if (pBuffer == NULL) { continue; } g_pLog->DisplayMessage(_T("Sava %s iCam=%d, iScan=%d, szImage.cx=%ld, pBuffer->szImage.cy=%ld"), PANEL_SIDE[pCamera->m_eDimension], iCam, iScan, pBuffer->szImage.cx, pBuffer->szImage.cy); if(pBuffer->pImage != NULL && pBuffer->szImage.cx > 100 && pBuffer->szImage.cy > 100) { strFileJpg.Format(_T("%s\\%s_%s_%s.jpg"),strFolder, strPanelID, PANEL_SIDE[pCamera->m_eDimension],g_pBase->m_strLoadingTime); SaveFullImageModern(strFileJpg, pBuffer->pImage, pBuffer->szImage.cx, pBuffer->szImage.cy, (int)pCamera->m_eDimension, 0, nQuality); } } } g_pLog->DisplayMessage(_T("Full Image Save Completed : Time[%d]"),GetTickCount()-dwTick); } void CInterfaceManager::CheckSeqMSG_Received(CCheckSeqMessage *pCheckSeq) { switch(pCheckSeq->emCheckSeq) { case CHECKSEQ_SHORT_SCANSTART_OVERTIME: g_pLog->DisplayMessage(_T("Check ScanStart TimeOut : start inspection! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_ShortScanStartSuccess,TRUE); break; case CHECKSEQ_SHORT_SCANSTART_COMPLETE: if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_ShortScanStartSuccess,TRUE); g_pLog->DisplayMessage(_T("All PC - start inspection! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); break; case CHECKSEQ_LONG_SCANSTART_OVERTIME: g_pLog->DisplayMessage(_T("Check ScanStart TimeOut : start inspection! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LongScanStartSuccess,TRUE); break; case CHECKSEQ_LONG_SCANSTART_COMPLETE: if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LongScanStartSuccess,TRUE); g_pLog->DisplayMessage(_T("All PC - start inspection! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); break; case CHECKSEQ_ONESCAN_OVERTIME: //m_pThread_NetMSG->AddNetMSG(NET_MESSAGE_INSPECTOR,INSPECTOR_MESSAGE_SCANDISPLAY,pCheckSeq->iScan,0); g_pLog->DisplayMessage(_T("Scan End TimeOut! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); break; case CHECKSEQ_ONESCAN_COMPLETE: // m_pThread_NetMSG->AddNetMSG(NET_MESSAGE_INSPECTOR,INSPECTOR_MESSAGE_SCANDISPLAY,pCheckSeq->iScan,0); g_pLog->DisplayMessage(_T("All PC - One scan Complete! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); //m_pView->UpdateSequence(SEQUENCE_SCANEND,(float)pCheckSeq->dwDuration); break; case CHECKSEQ_GLASS_INSPECTION_OVERTIME: g_pLog->DisplayMessage(_T("Glass Inspection TimeOut : Start PostProcess! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); AfxBeginThread(ScanTimeOut,this); //ScanOverTimeSignal(); break; case CHECKSEQ_GLASS_INSPECTION_COMPLETE: //m_pThread_NetMSG->AddNetMSG(NET_MESSAGE_INSPECTOR,INSPECTOR_MESSAGE_POSTPROCESSING,pCheckSeq->iScan,0); g_pLog->DisplayMessage(_T("All PC - Inspection Complete! : Start PostProcess! : %d,%d"),pCheckSeq->iScan,pCheckSeq->dwDuration); break; } } void CInterfaceManager::IMI2P_PLC_ReceiveSignalValue(int nSignalIndex, int nValue) { if(m_pLicense != NULL) { if(m_pLicense->Check() == FALSE) { m_pView->View_LicenseInfo(); return; } } switch(nSignalIndex) { case C2I_Loading: g_pLog->DisplayMessage(_T("=================[GlassLoading Start]=================")); GlassLoadingProcess(); g_pLog->DisplayMessage(_T("=================[ GlassLoading End ]=================")); break; case C2I_ShortScanStart: g_pLog->DisplayMessage(_T("=================[ Short Scan Start Start ]=================")); ScanStartProcess(C2I_ShortScanStart); g_pLog->DisplayMessage(_T("=================[ Short Scan Start End ]=================")); break; case C2I_ShortScanEnd: g_pLog->DisplayMessage(_T("=================[ Short Scan End Start ]=================")); PLCScanEndProcess(C2I_ShortScanEnd); g_pLog->DisplayMessage(_T("=================[ Short Scan End End ]=================")); break; case C2I_LongScanStart: g_pLog->DisplayMessage(_T("=================[ Long Scan Start Start ]=================")); ScanStartProcess(C2I_LongScanStart); g_pLog->DisplayMessage(_T("=================[ Long Scan Start End ]=================")); break; case C2I_LongScanEnd: g_pLog->DisplayMessage(_T("=================[ Long Scan End Start ]=================")); PLCScanEndProcess(C2I_LongScanEnd); g_pLog->DisplayMessage(_T("=================[ Long Scan End End ]=================")); break; case C2I_EMOGrabStop: g_pLog->DisplayMessage(_T("=================[ EMO Grab Stop Start ]=================")); EMOGrabStopProcess(C2I_EMOGrabStop); g_pLog->DisplayMessage(_T("=================[ EMO Grab Stop End ]=================")); break; } } /* void CInterfaceManager::IControl2P_ReceiveSignalValue(emInterface_Rcv_Control emSignal, BOOL bValue) { if(m_pLicense != NULL) { if(m_pLicense->Check() == FALSE) { m_pView->View_LicenseInfo(); return; } } if(bValue == TRUE) { switch(emSignal) { case emRcv_PLC_Alive: break; case emRcv_Loading: g_pLog->DisplayMessage(_T("=================[GlassLoading Start]=================")); GlassLoadingProcess(); g_pLog->DisplayMessage(_T("=================[ GlassLoading End ]=================")); break; case emRcv_Short_Start: g_pLog->DisplayMessage(_T("=================[ Short Scan Start Start ]=================")); ScanStartProcess(C2I_ShortScanStart); g_pLog->DisplayMessage(_T("=================[ Short Scan Start End ]=================")); break; case emRcv_Short_End: g_pLog->DisplayMessage(_T("=================[ Short Scan End Start ]=================")); PLCScanEndProcess(C2I_ShortScanEnd); g_pLog->DisplayMessage(_T("=================[ Short Scan End End ]=================")); break; case emRcv_Long_Start: g_pLog->DisplayMessage(_T("=================[ Long Scan Start Start ]=================")); ScanStartProcess(C2I_LongScanStart); g_pLog->DisplayMessage(_T("=================[ Long Scan Start End ]=================")); break; case emRcv_Long_End: g_pLog->DisplayMessage(_T("=================[ Long Scan End Start ]=================")); PLCScanEndProcess(C2I_LongScanEnd); g_pLog->DisplayMessage(_T("=================[ Long Scan End End ]=================")); break; case emRcv_Grab_Stop_EMO: g_pLog->DisplayMessage(_T("=================[ EMO Grab Stop Start ]=================")); EMOGrabStopProcess(C2I_EMOGrabStop); g_pLog->DisplayMessage(_T("=================[ EMO Grab Stop End ]=================")); break; } } else { switch(emSignal) { case emRcv_PLC_Alive: break; case emRcv_Loading: g_pLog->DisplayMessage(_T("=================[ Snd Loading Signal OFF ]=================")); m_pControlInterface->SendControlBit(emSnd_Loading_Ack, FALSE); break; case emRcv_Short_Start: g_pLog->DisplayMessage(_T("=================[ Snd Short Scan Start Signal OFF ]=================")); m_pControlInterface->SendControlBit(emSnd_Short_ScanStart_Ack, FALSE); break; case emRcv_Short_End: g_pLog->DisplayMessage(_T("=================[ Snd Short Scan End Signal OFF ]=================")); m_pControlInterface->SendControlBit(emSnd_Short_ScanEnd_Ack, FALSE); break; case emRcv_Long_Start: g_pLog->DisplayMessage(_T("=================[ Snd Long Scan Start Signal OFF ]=================")); m_pControlInterface->SendControlBit(emSnd_Long_ScanStart_Ack, FALSE); break; case emRcv_Long_End: g_pLog->DisplayMessage(_T("=================[ Snd Long Scan End Signal OFF ]=================")); m_pControlInterface->SendControlBit(emSnd_Long_ScanEnd_Ack, FALSE); break; case emRcv_Grab_Stop_EMO: break; } } } */ void CInterfaceManager::InitLoadingProcess() { m_nStartTime = GetCurrentTimestamp(); g_pLog->DisplayMessage(_T("Start Init Loading Process")); g_pStatus->InitGlassLoading(); m_GlassData.ResetGlass(); m_bPostProcess = FALSE; if(m_pView != NULL) { m_pView->ResetViewAll(); /*m_pView->SetRecipeSettings(&m_GlassRecipe);*/ m_pView->SetGlassData(&m_GlassData); m_pView->SetTransferData(&m_TransferData); } } BOOL CInterfaceManager::EMOGrabStopProcess(ControlToInspect emSendSignal) { return TRUE; } BOOL CInterfaceManager::PLCScanEndProcess(ControlToInspect emSendSignal) { switch(emSendSignal) { case C2I_ShortScanEnd: { g_pLog->DisplayMessage(_T("Short Scan End Signal")); m_bShortPLCEnd = TRUE; } break; case C2I_LongScanEnd: { g_pLog->DisplayMessage(_T("Long Scan End Signal")); if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LongScanEndSuccess,TRUE); m_bLongPLCEnd = TRUE; } break; } return TRUE; } BOOL CInterfaceManager::ScanStartProcess(ControlToInspect emSendSignal) { if(m_bGlassLoadingEnd == FALSE) { g_pLog->DisplayMessage(_T("GlassLoading Not End : Skip Scan Start Signal")); return FALSE; } m_GlassData.SetScanStart(TRUE); m_nScanStartCount = 0; switch(emSendSignal) { case C2I_ShortScanStart: { g_pLog->DisplayMessage(_T("Short Scan Start Signal")); m_bShortPLCScanStart = TRUE; g_pStatus->m_iScanIdx = 1; AfxBeginThread(ScanStartCam_0,this); AfxBeginThread(ScanStartCam_1,this); AfxBeginThread(ScanStartCam_2,this); AfxBeginThread(ScanStartCam_3,this); AfxBeginThread(CheckScanStart,this); } break; case C2I_LongScanStart: { g_pLog->DisplayMessage(_T("Long Scan Start Signal")); m_GlassData.SetScanStartTime(); g_pStatus->m_iScanIdx = 0; AfxBeginThread(ScanStartCam_0,this); AfxBeginThread(ScanStartCam_1,this); AfxBeginThread(ScanStartCam_2,this); AfxBeginThread(ScanStartCam_3,this); AfxBeginThread(CheckScanStart,this); m_GlassData.SetScanStartCount(MAX_DIMENSION_COUNT); } break; } return TRUE; } UINT CInterfaceManager::CheckScanStart(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); double CurTime = GetTickCount(); do { if (GetTickCount() - CurTime > 10000) { g_pLog->DisplayMessage(_T("Scan Start Ack TimeOut : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount); break; } if(pInter->m_nScanStartCount == MAX_CAMERA_COUNT) { g_pLog->DisplayMessage(_T("Scan Start Ack Ok : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount); break; } Sleep(0); } while (1); g_pLog->DisplayMessage(_T("Scan Start Ack Signal Send : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount); if(g_pStatus->m_iScanIdx == 0) { if(pInter->m_pThread_SendMSG != NULL) pInter->m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LongScanStartSuccess,TRUE); } else { if(pInter->m_pThread_SendMSG != NULL) pInter->m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_ShortScanStartSuccess,TRUE); } pInter->SetGlassTimeOut(); return 0; } void CInterfaceManager::SetGlassTimeOut() { if(m_pThread_CheckSequence != NULL) { double dOneScanTime = m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec; m_pThread_CheckSequence->SetC2M(static_cast(this),&m_GlassData); m_pThread_CheckSequence->AddCheckSeqMSG(CHECKSEQ_GLASS_INSPECTION_OVERTIME,(int)(dOneScanTime * 1000.),m_HardwareRecipe.GetScanCount()-1); } } void CInterfaceManager::ScanStartCamera(int iCam) { BOOL bFreerun = m_HardwareRecipe.m_bUseFreerun; int nPeriod = m_HardwareRecipe.m_nFreerunPeriod; int nExposureTime = m_HardwareRecipe.m_nFreerunExposureTime; CCameraSettings *pCamSettings = m_HardwareRecipe.GetCameraSettings(iCam,g_pStatus->m_iScanIdx); g_pStatus->SetGrabFrametoScan(g_pStatus->m_iScanIdx,pCamSettings->m_nGrabFrameCount); if(m_pGrabber[iCam] != NULL) { m_pGrabber[iCam]->GrabScanStart(g_pStatus->m_iScanIdx,bFreerun,nPeriod,nExposureTime); } if(m_pInspect[iCam] != NULL) { m_pInspect[iCam]->SetSimulation(FALSE); m_pInspect[iCam]->SetViewScanHWnd(m_pView->GetViewScanHWnd()); if(m_pInspect[iCam]->ScanStart(g_pStatus->m_iScanIdx) == FALSE) { g_pLog->DisplayMessage(_T("Cam %d Scan %d Start Fail"),iCam,g_pStatus->m_iScanIdx); } } CSingleLock cLock(&m_csScanStart); cLock.Lock(); m_nScanStartCount++; cLock.Unlock(); } UINT CInterfaceManager::ScanStartCam_0(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); pInter->ScanStartCamera(0); return 0; } UINT CInterfaceManager::ScanStartCam_1(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); pInter->ScanStartCamera(1); return 0; } UINT CInterfaceManager::ScanStartCam_2(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); pInter->ScanStartCamera(2); return 0; } UINT CInterfaceManager::ScanStartCam_3(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); pInter->ScanStartCamera(3); return 0; } BOOL CInterfaceManager::ScanStartGrabManual(int iCam,int iScan) { if(m_pGrabber[iCam] != NULL) { m_pGrabber[iCam]->GrabScanStart(iScan,FALSE,0,0,FALSE); } return TRUE; } BOOL CInterfaceManager::ScanStartManual(int iCam,int iScan, BOOL bRecipe/*=FALSE*/) { if(m_pInspect[iCam] != NULL) { if(bRecipe == TRUE) m_pInspect[iCam]->SetViewScanHWnd(m_pView->GetViewRecipeHWnd()); else m_pInspect[iCam]->SetViewScanHWnd(m_pView->GetViewScanHWnd()); m_pInspect[iCam]->SetSimulation(TRUE); if(m_pInspect[iCam]->ScanStart(iScan) == FALSE) { g_pLog->DisplayMessage(_T("Manual Cam %d Scan %d Start Fail"),iCam,iScan); } } return TRUE; } BOOL CInterfaceManager::GlassLoadingProcess() { g_pLog->DisplayMessage(_T("===============================================")); g_pLog->DisplayMessage(_T("Start Glass Loading Process")); m_bGlassLoadingEnd = FALSE; m_bPLCGlassLoading = TRUE; InitLoadingProcess(); m_GlassData.SetLoadingTime(); m_TactStopWatch.Start(); g_pBase->m_strRecipeName = m_GlassRecipe.GetRecipeName(); g_pBase->m_strLoadingDay = m_GlassData.GetLoadingDayFileName(); g_pBase->m_strLoadingTime = m_GlassData.GetLoadingTimeFileName(); g_pBase->m_strHPanelID.Format(_T("Manual_%s"),m_GlassData.GetLoadingTimeString()); BOOL bGlassLoading = Glass_Loading(); g_pLog->DisplayMessage(_T("Glass Loading Process Glass ID : %s"),g_pBase->m_strHPanelID); if(bGlassLoading == FALSE) g_pLog->DisplayMessage(_T("GlassLoading Fail %s : Inspection does not proceed."),g_pBase->m_strHPanelID); // Trigger Control if(m_HardwareRecipe.m_bUse_MvsolTriggerControl == TRUE) SetTriggerControl(); // m_pView->SetRecipeSettings(&m_GlassRecipe); m_pView->SetGlassData(&m_GlassData); if(m_pThread_CheckSequence != NULL) m_pThread_CheckSequence->ClearMessage(); m_pView->UpdateTransferData(); m_bShortPLCEnd = FALSE; m_bLongPLCEnd = FALSE; m_bShortPLCScanStart = FALSE; g_pLog->DisplayMessage(_T("Start Glass Loading Process 5")); // result init if(m_pControlInterface != NULL) { short pResult[5] = {}; m_pControlInterface->SendCIMData(pResult,PLC_ADDR_GLASS_JUDEMENT,5); } if(g_pBase->m_bAutoDefectView == TRUE) m_pView->SwitchView(EV_VIEW_IMAGE); m_GlassData.SetPostProc(FALSE); m_bGlassLoadingEnd = TRUE; // Loading Ack // m_pControlInterface->SendControlBit(emSnd_Loading_Ack, TRUE); if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LoadingSuccess,TRUE); return TRUE; } int CInterfaceManager::Glass_Loading() { g_pLog->DisplayMessage(_T("===================================================")); g_pLog->DisplayMessage(_T("Glass Loading Start!!!")); if(ReadTransferData(TRANSITEM_FILEPATH_B5) == FALSE) { g_pLog->DisplayMessage(_T("Read Transfer File Fail")); //return FALSE; } g_pLog->DisplayMessage(_T("ReadTransferData Process")); if(AutoChangeRecipe() == FALSE) { g_pLog->DisplayMessage(_T("Recipe Change Fail")); // return FALSE; } g_pLog->DisplayMessage(_T("AutoChangeRecipe Process")); if(SendGlassRecipe() == FALSE) { g_pLog->DisplayMessage(_T("Send Recipe Fail")); //return FALSE; } return TRUE; } BOOL CInterfaceManager::SendGlassRecipe(BOOL bAll,int iCam) { int i; if(bAll == TRUE) { for(i=0;iSetParameter(&m_GlassRecipe,&m_HardwareRecipe); g_pLog->DisplayMessage(_T("AutoChangeRecipe cam %d SetGlass"),i); m_pInspect[i]->SetGlassData(&m_GlassData); } } else { m_pInspect[iCam]->SetParameter(&m_GlassRecipe,&m_HardwareRecipe); m_pInspect[iCam]->SetGlassData(&m_GlassData); } g_pLog->DisplayMessage(_T("AutoChangeRecipe Process End")); return TRUE; } CString CInterfaceManager::GetRecipeName(int iRcpNo) { if(iRcpNo < 0) return _T("*"); CConfig cfg; if(cfg.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)LINK_FILE_NAME, FileMap_Mode) == FALSE) return _T("*"); int nUpperPPIDNumber; cfg.GetItemValue(_T("UPPER_NUMBER"), nUpperPPIDNumber, 0); if(nUpperPPIDNumber <= 0 || nUpperPPIDNumber >= 1000) return _T("*"); int i; CString strValue = _T(""); CString strRecipe; strRecipe.Format(_T("%d"),iRcpNo); for(i = 0; i < nUpperPPIDNumber; i++) { cfg.GetItemValue(i, _T("UPPER_NAME"), strValue, _T("NoName")); strValue.MakeUpper(); strValue.TrimLeft(_T(" ")); strValue.TrimRight(_T(" ")); if(strRecipe.CompareNoCase(strValue) == 0) { cfg.GetItemValue(i, _T("INS_NAME"), strValue, _T("NoName")); strValue.MakeUpper(); return strValue; } } return _T("*"); } BOOL CInterfaceManager::AutoChangeRecipe() { CString strRcp; strRcp = GetRecipeName(m_TransferData.m_nRecipeNo); if(!m_strReserveRecipe.IsEmpty()) { g_pLog->DisplayMessage(_T("Apply reserve Recipe Loading - [%s]"), m_strReserveRecipe); if (LoadGlassRecipe(m_strReserveRecipe,TRUE)) // °°Àº Recipe¶óµµ Àû¿ë ¿¹¾àµÇ¾î ÀÖÀ¸¸é ´Ù½Ã ·ÎµùÇÑ´Ù. { g_pLog->DisplayMessage(_T("Apply reserve Recipe Loading - [%s] : Success"), m_strReserveRecipe); } return TRUE; } if(strRcp.CompareNoCase(_T("*")) == 0) { g_pLog->DisplayMessage(_T("Recipe Link Fail...!")); strRcp = "LinkFail"; return FALSE; } if (strRcp.CompareNoCase(m_GlassRecipe.GetRecipeName()) != 0) // strRecipeName ¹Ù²î¸é ·ÎµùÇÑ´Ù. { if (LoadGlassRecipe(strRcp,TRUE) == FALSE) { g_pLog->DisplayMessage(_T("Recipe[%s] Read Fail!"),strRcp); return FALSE; } } m_strReserveRecipe.Empty(); return TRUE; } BOOL CInterfaceManager::ReadTransferData(CString strTransItemFile) { if(m_pTransDataManager == NULL || m_pControlInterface == NULL) return FALSE; if(strTransItemFile.IsEmpty() == TRUE) return FALSE; char lpTransBuffer[2048]; int nTransSize = 0; ZeroMemory(lpTransBuffer,sizeof(char)*2048); if(m_pTransDataManager->LoadTransItemFromFile(strTransItemFile) == FALSE) { g_pLog->DisplayMessage(_T("TransferData Read Fail! 1 :%s"),(TCHAR*)(LPCTSTR)strTransItemFile); return FALSE; } if(m_pControlInterface->ReadTransferData(m_pTransDataManager,lpTransBuffer,PLC_TRASFERDATA_ADDR) == FALSE) { g_pLog->DisplayMessage(_T("TransferData Read Fail! 2 :%s"),(TCHAR*)(LPCTSTR)strTransItemFile); return FALSE; } if(m_TransferData.SetManagerToData(m_pTransDataManager) == FALSE) { g_pLog->DisplayMessage(_T("TransferData Read Fail! 3 :%s"),(TCHAR*)(LPCTSTR)strTransItemFile); return FALSE; } return TRUE; } void CInterfaceManager::SetSlashText(EmSplashCmd emCommand, CString strLog, UINT nColor) { CString strText = _T(" "); strText += strLog; switch(emCommand) { case emShow: m_splash.ShowSplash(); break; case emHide: m_splash.CloseSplash(); break; case emText: m_splash.SetText(strText, nColor); break; default: break; } } BOOL CInterfaceManager::ReadHardwareSetting() { m_HardwareRecipe.Reset(); // return m_HardwareRecipe.ReadHardwareSettingsRegistry(); return m_HardwareRecipe.ReadHardwareSettingsFile(HARDWARE_SETTING_PATH); } BOOL CInterfaceManager::InterfaceInit() { BOOL bIsInit = TRUE; // Trans Data Manager m_pTransDataManager = new CTransDataManager; SetSlashText(GLOBAL_DEFINE::emText, _T("Load TransData Complete"), RGB(0,0,0)); // Thread Init CreateThread(); SetSlashText(GLOBAL_DEFINE::emText, _T("Create Thread Complete"), RGB(0,0,0)); // Control Interface m_pControlInterface = new CControl_Interface(); m_pControlInterface->SetI2M(static_cast(this)); if(m_pControlInterface != NULL) m_pControlInterface->ConnectToControl(); SetSlashText(GLOBAL_DEFINE::emText, _T("PLC Connection Complete"), RGB(0,0,0)); // Light Control m_pLightManager = new CLightManager; m_pLightManager->SetHardware(&m_HardwareRecipe); m_pLightManager->ConnectToLight(); SetSlashText(GLOBAL_DEFINE::emText, _T("Light Control Complete"), RGB(0,0,0)); InitGrabber(); SetSlashText(GLOBAL_DEFINE::emText, _T("Grabber Complete"), RGB(0,0,0)); InitInspect(); SetSlashText(GLOBAL_DEFINE::emText, _T("Inspect Complete"), RGB(0,0,0)); m_LanguageControl.LoadRecipeLanguageSet(); SetSlashText(GLOBAL_DEFINE::emText, _T("Language Complete"), RGB(0,0,0)); LightTurnOnOff(TRUE); LightChangeValue(); SetSlashText(GLOBAL_DEFINE::emText, _T("Trigger Board Connect"), RGB(0,0,0)); m_pTriggerBoardControl = new CTriggerControl_Mvsol; if(m_HardwareRecipe.m_bUse_MvsolTriggerControl == TRUE) m_pTriggerBoardControl->Connect(m_HardwareRecipe.m_nPort_MvsolTriggerControl); SetSlashText(GLOBAL_DEFINE::emText, _T("License Check"), RGB(0,0,0)); m_pLicense = new CLicenseChecker(); g_pStatus->m_pControlInterface = m_pControlInterface; g_pStatus->m_pLightManager = m_pLightManager; g_pStatus->m_pTransData = &m_TransferData; g_pStatus->m_pGlassData = &m_GlassData; g_pStatus->m_pRecipe = &m_GlassRecipe; g_pStatus->m_pHWSettings = &m_HardwareRecipe; g_pStatus->m_pLanguageControl = &m_LanguageControl; g_pStatus->m_pLicenseChecker = m_pLicense; setLineCameraParamToSDK(); return bIsInit; } void CInterfaceManager::setLineCameraParamToSDK(void) { /* code */ #if HALCON_VISION_KEY CString strRecipePath = RECIPE_PATH; CT2A ansiString(strRecipePath); BlVision_GetVisionRecipe()->setWorkDir(ansiString); for (int iCam = 0; iCam < MAX_CAMERA_COUNT; iCam++) { BlVision_GetVisionRecipe()->setGrabberControl(m_pGrabber[iCam], iCam); } int nCount = (int)(DIMENSION_NONE); int iCam = -1; int iScan = -1; for (int i = 0; i < nCount; i++) { DimensionDir eDir = (DimensionDir)(i); iCam = m_HardwareRecipe.GetCameraIndexToDimension(eDir); iScan = m_HardwareRecipe.GetScanToDimension(eDir); BlVision_GetVisionRecipe()->setCameraSetting(eDir, iCam, iScan); } BlVision_GetVisionRecipe()->setRecipeType(EI_VISION_RECIPE); BlVision_GetVisionRecipe()->init(); for (int i = 0; i < nCount; i++) { //ÉèÖ÷ֱæÂÊ DimensionDir eDir = (DimensionDir)(i); CBlSideData *pSide = BlVision_GetVisionRecipe()->getSideData(eDir); int iCam = m_HardwareRecipe.GetCameraIndexToDimension(eDir); int iScan = m_HardwareRecipe.GetScanToDimension(eDir); CCameraSettings* pCamSetting = m_HardwareRecipe.GetCameraSettings(iCam, iScan); pSide->m_dPixelSizeX = pCamSetting->m_dConvResolution[m_GlassData.GetStageNo()]; pSide->m_dPixelSizeY = pCamSetting->m_dScanResolution[m_GlassData.GetStageNo()]; } SetSlashText(GLOBAL_DEFINE::emText, _T("Vision Library Load"), RGB(0, 0, 0)); #endif } BOOL CInterfaceManager::InitInspect() { int iCam; for(iCam=0;iCamInitInspect(MAX_THREAD,MAX_DEFECT_COUNT_SIDE); m_pInspect[iCam]->SetParameter(&m_GlassRecipe,&m_HardwareRecipe); m_pInspect[iCam]->SetGrabber(m_pGrabber[iCam]); m_pInspect[iCam]->SetGlassData(&m_GlassData); m_pInspect[iCam]->SetI2S(static_cast(this)); m_pInspect[iCam]->SetViewScanHWnd(m_pView->GetViewScanHWnd()); #if USE_WEBSOCKET m_pInspect[iCam]->SetWebSocketClients(m_wsClients[iCam]); #endif // USE_WEBSOCKET #if USE_AI_DETECT //m_pInspect[iCam]->SetUseAIDetect(m_bUseAIDetect); #endif // USE_AI_DETECT m_PostProcess.SetInspectCamera(iCam,m_pInspect[iCam]); } return TRUE; } BOOL CInterfaceManager::InitGrabber() { g_pLog->DisplayMessage( _T("CreateCamera Start!")); ////////////////////////////////////////////////////////////////////////// // Camera Handle »ý¼º. int iCam; BOOL bRet = TRUE; // for test //m_HardwareRecipe.m_nBoardType = GRAB_LINK_BOARD; for(iCam=0;iCamm_pBufferSize[iCam]; Param.nGrabBufCount = g_pBase->m_pMemFrameNo[iCam]; Param.nFrameWidth = g_pBase->m_pFrameWidth[iCam]; Param.nFrameHeight = g_pBase->m_pFrameHeight[iCam]; Param.nConnectPort = g_pBase->m_pCameraPort[iCam]; Param.nScanCount = g_pBase->m_nScanCount; Param.nBoardIdx = g_pBase->m_nBoardID[iCam]; Param.nBoardCh = g_pBase->m_nBoardCh[iCam]; Param.nImgFlipX = 0; Param.nBoardCh = 0; Param.nCameraIdx = iCam; Param.nCameraScan = 0; CCameraSettings *pCamera = m_HardwareRecipe.GetCameraSettings(iCam,0); if(pCamera != NULL) Param.nImgFlipX = (int)pCamera->m_nImgFlipx; Param.nExposureDelay = m_HardwareRecipe.m_nFreerunPeriod; Param.nExposure = m_HardwareRecipe.m_nFreerunExposureTime; #ifdef _UNICODE ZeroMemory(Param.cDCFPath, MAX_DFC_PATH); if(MAX_DFC_PATH < g_pBase->m_strCamCCA[iCam].GetLength()) { delete m_pGrabber[iCam]; m_pGrabber[iCam] = NULL; return FALSE; } int nSize = WideCharToMultiByte(CP_ACP, 0, g_pBase->m_strCamCCA[iCam].GetBuffer(), -1, NULL, 0, NULL,NULL); WideCharToMultiByte(CP_ACP, 0, g_pBase->m_strCamCCA[iCam].GetBuffer(), -1, Param.cDCFPath, nSize, NULL, NULL); ZeroMemory(Param.cVICPath, MAX_DFC_PATH); if(MAX_DFC_PATH > g_pBase->m_strCamCVI[iCam].GetLength()) { int nSize = WideCharToMultiByte(CP_ACP, 0, g_pBase->m_strCamCVI[iCam].GetBuffer(), -1, NULL, 0, NULL,NULL); WideCharToMultiByte(CP_ACP, 0, g_pBase->m_strCamCVI[iCam].GetBuffer(), -1, Param.cVICPath, nSize, NULL, NULL); } #else ZeroMemory(Param.cDCFPath, MAX_DFC_PATH); if(MAX_DFC_PATH < g_pBase->m_strCamCCA[iCam].GetLength()) { delete m_pGrabber[iCam]; m_pGrabber[iCam] = NULL; return FALSE; } CopyMemory(Param.cDCFPath, g_pBase->m_strCamCCA[iCam].GetBuffer(0), g_pBase->m_strCamCCA[iCam].GetLength()); ZeroMemory(Param.cVICPath, MAX_DFC_PATH); if(MAX_DFC_PATH > g_pBase->m_strCamCVI[iCam].GetLength()) { CopyMemory(Param.cVICPath, g_pBase->m_strCamCVI[iCam].GetBuffer(0), g_pBase->m_strCamCVI[iCam].GetLength()); } //Param.cDCFPath = (LPCTSTR)(TCHAR*)(g_pBase->m_strCamCCA); #endif g_pLog->DisplayMessage( _T("Cam File[%d]-%s"), iCam, (CString) Param.cDCFPath); int nErrorCode; int nBoardId = iCam; // B5 4È£±â ¼ÂÆÃ g_pBase->m_strSBKLine = m_HardwareRecipe.GetLineID(); g_pBase->m_strSBKLine.Append(_T("#")); int nLineID = _ttoi(m_HardwareRecipe.GetLineID()); if(nLineID == 4) { switch(iCam) { case 0: nBoardId = 2; break; case 1: nBoardId = 0; break; case 2: nBoardId = 3; break; case 3: nBoardId = 1; break; } Param.nBoardIdx = nBoardId; } else if(nLineID == 5) { switch(iCam) { case 1: nBoardId = 3; break; case 3: nBoardId = 1; break; } Param.nBoardIdx = nBoardId; } if(Param.nBoardIdx < 0) Param.nBoardIdx = nBoardId; g_pLog->DisplayMessage( _T("Grabber Board ID[%d-%d]-Init"), Param.nBoardIdx, iCam); bRet |= m_pGrabber[iCam]->Initialize(&Param, &nErrorCode,nBoardId); g_pLog->DisplayMessage( _T("Grabber Board ID[%d-%d]-Init End, ret %d"), Param.nBoardIdx, iCam, bRet); bRet |= m_pGrabber[iCam]->InitializeBuffer(&Param); g_pLog->DisplayMessage( _T("Grabber Board ID[%d-%d]-Buffer End, ret %d"), Param.nBoardIdx, iCam, bRet); g_pStatus->SetFrameBuffer(iCam,m_pGrabber[iCam]->GetFrameBuffer()); } g_pLog->DisplayMessage( _T("CreateCamera Success!")); return bRet; } BOOL CInterfaceManager::DeinitGrabber() { for(int i=0;iGrabScanStop(); m_pGrabber[i]->Deinitialize(); delete m_pGrabber[i]; m_pGrabber[i] = NULL; } } return TRUE; } BOOL CInterfaceManager::LoadGlassRecipe(CString strRecipe,BOOL bReadProfile) { if(strRecipe.IsEmpty()) return FALSE; m_GlassRecipe.Reset(); if (!m_GlassRecipe.MakeRecipeFileName(strRecipe)) return FALSE; if (!m_GlassRecipe.ReadRecipeFile()) return FALSE; m_GlassData.SetGlassRecipe(&m_GlassRecipe); // 22. 7. 11, Recipe UI Update.. if(m_pView != NULL) { m_pView->SetRecipeSettings(&m_GlassRecipe); } // Light Control... LightSetRecipeValue(); return TRUE; } void CInterfaceManager::LightSetRecipeValue() { if(m_pLightManager == NULL) return; CLIGHT_PARM* pLightParam = &m_GlassRecipe.m_LightParm; for(int i=0; im_nContValue[i][j]; m_pLightManager->SetLightControlValue(i, j, nValue); } } } void CInterfaceManager::LightTurnOnOff(BOOL bOn) { if(m_pLightManager == NULL) return; for(int iCam=0;iCamLampTurnOnOff(pCamSetting->m_nLightIdx_R,pCamSetting->m_nLightIdx_R_Ch,TRUE); Sleep(10); m_pLightManager->LampTurnOnOff(pCamSetting->m_nLightIdx_T,pCamSetting->m_nLightIdx_T_Ch,TRUE); Sleep(10); } } void CInterfaceManager::LightChangeValue(int iCamera,int nValue) { if(m_pLightManager == NULL) return; if(iCamera == -1) { for(int iCam=0;iCamm_nLightIdx_R,pCamSetting->m_nLightIdx_R_Ch); m_pLightManager->SetLightControlValue(pCamSetting->m_nLightIdx_R, pCamSetting->m_nLightIdx_R_Ch, nLightVal); Sleep(10); nLightVal = m_GlassRecipe.GetLightValue(pCamSetting->m_nLightIdx_T,pCamSetting->m_nLightIdx_T_Ch); m_pLightManager->SetLightControlValue(pCamSetting->m_nLightIdx_T, pCamSetting->m_nLightIdx_T_Ch, nLightVal); Sleep(10); } } else { CCameraSettings *pCamSetting = m_HardwareRecipe.GetCameraSettings(iCamera,0); if(pCamSetting == NULL) return; m_pLightManager->SetLightControlValue(pCamSetting->m_nLightIdx_R,pCamSetting->m_nLightIdx_R_Ch,nValue); } } BOOL CInterfaceManager::WaitEndSignal(InspectToControlSignal emSendSignal) { DWORD dwTick = GetTickCount(); DWORD dwWaitTick; DWORD dwWaitTime = 5000; while(TRUE) { dwWaitTick = GetTickCount() - dwTick; if(dwWaitTime < dwWaitTick) break; switch(emSendSignal) { case IToC_Ack_ShortScanEndSuccess: case IToC_Ack_ShortScanEndFail: if(m_bShortPLCEnd == TRUE) { g_pLog->DisplayMessage(_T("Ack Short PLC End : %d"),m_bShortPLCEnd); return TRUE; } break; case IToC_Ack_LongScanEndSuccess: case IToC_Ack_LongScanEndFail: if(m_bLongPLCEnd == TRUE) { g_pLog->DisplayMessage(_T("Ack Long PLC End : %d"),m_bShortPLCEnd); return TRUE; } break; default: return TRUE; } Sleep(1); } return TRUE; } void CInterfaceManager::SetInspectionEnd() { for(int i=0;iSetProcessEnd(); } } Sleep(500); } BOOL CInterfaceManager::IsScanNow() { BOOL bScanStart = m_GlassData.GetScanStart(); BOOL bScanEnd = m_GlassData.GetScanEnd(m_HardwareRecipe.GetScanCount()-1); if (bScanStart && !bScanEnd) return TRUE; return FALSE; } void CInterfaceManager::CreateThread() { m_pThread_SendMSG = new CThread_SendMSG(); if(m_pThread_SendMSG != NULL) { m_pThread_SendMSG->SetIN2P(static_cast(this)); m_pThread_SendMSG->CreateThread(); } m_pThread_CheckSequence = new CThread_CheckSequence(); if(m_pThread_CheckSequence != NULL) { m_pThread_CheckSequence->SetC2M(static_cast(this),&m_GlassData); m_pThread_CheckSequence->CreateThread(); } m_pThread_ViewRefresh = new CThread_ViewRefresh(); if(m_pThread_ViewRefresh != NULL) { m_pThread_ViewRefresh->SetIN2P(static_cast(this)); m_pThread_ViewRefresh->CreateThread(); } /* m_pThread_NetMSG = new CThread_NetMSG(); if(m_pThread_NetMSG != NULL) { m_pThread_NetMSG->SetIN2P(static_cast(this)); m_pThread_NetMSG->CreateThread(); } m_pThread_Light = new CThread_Light(); if(m_pThread_Light != NULL) { m_pThread_Light->CreateThread(); } */ } LPBYTE CInterfaceManager::GetGrabBuffer(DimensionDir eDir,int iVline) { int iCam = m_HardwareRecipe.GetCameraIndexToDimension(eDir); int iScan = m_HardwareRecipe.GetScanToDimension(eDir); if(iCam < 0 || iCam >= MAX_CAMERA_COUNT) return NULL; if(iScan < 0 || iScan >= MAX_SCAN_COUNT) return NULL; if(m_pGrabber[iCam] == NULL) return NULL; return m_pGrabber[iCam]->GetFrameHeaderLine(iScan,iVline); } BOOL CInterfaceManager::SaveFullImage(CString strPath,int iSide,CPoint ptStart,int nLineCnt) { g_pStatus->CheckDirectory(strPath); CString strSavePath = strPath; strSavePath += _T(".jpg"); Lock(); FIBITMAP* bitmap = FreeImage_Allocate(IMAGE_WIDTH, nLineCnt, 8); if (bitmap == NULL) { Unlock(); return FALSE; } BYTE* pBitBuffer = FreeImage_GetBits(bitmap); if (pBitBuffer == NULL) { FreeImage_Unload(bitmap); Unlock(); return FALSE; } LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, ptStart.y); if (lpImg == NULL) { Unlock(); return FALSE; } CopyMemory(pBitBuffer, lpImg, IMAGE_WIDTH * nLineCnt); USES_CONVERSION; char str_filename[1024]; sprintf_s(str_filename, "%s", W2A(strSavePath)); FreeImage_FlipVertical(bitmap); FreeImage_Save(FIF_JPEG, bitmap, str_filename, JPEG_FULLIMAGE_RATE); FreeImage_Unload(bitmap); Unlock(); } BOOL CInterfaceManager::SaveFullImageModern(CString strPath,LPBYTE lpOrigin,int nImgWidth,int nImgHeight,int iSide,int nStartY,int nQuality /*= 80*/) { if (!lpOrigin || nImgHeight < 100) { g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), Invalid image or height"), strPath, PANEL_SIDE[iSide], nImgHeight); return FALSE; } g_pStatus->CheckDirectory(strPath); int p[3]; p[0] = CV_IMWRITE_JPEG_QUALITY; p[1] = nQuality; p[2] = 0; double tmp = 70 / 100.0; double dRatio = 1. - tmp; dRatio = dRatio - 0.01 < 0.0 ? 1.0 : dRatio; #if 0 IplImage* pImg = cvCreateImageHeader(cvSize(nImgWidth, nImgHeight), 8, 1); IplImage* pImgNew = cvCreateImage(cvSize((int)(nImgWidth * dRatio), (int)(nImgHeight * dRatio)), 8, 1); if (pImg == NULL || pImgNew == NULL) { g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), img pointer is null"), strPath, PANEL_SIDE[iSide], nStartY); return FALSE; } g_pLog->DisplayMessage(_T("Save Full Image Start(%s, %s, %d, %d, %d)"), strPath, PANEL_SIDE[iSide], nStartY, nImgHeight, nQuality); if (nStartY < 0 || iSide < 0 || iSide >= MAX_DIMENSION_COUNT) { g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d)"), strPath, PANEL_SIDE[iSide], nStartY); return FALSE; } LPBYTE lpImg = lpOrigin + (nStartY * nImgWidth); if (lpImg == NULL) { g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), Buffer is NULL"), strPath, PANEL_SIDE[iSide], nStartY); return FALSE; } cvSetData(pImg, lpImg, nImgWidth); cvResize(pImg, pImgNew); USES_CONVERSION; char str_filename[200]; sprintf_s(str_filename, "%s", W2A(strPath)); cvSaveImage(str_filename, pImgNew, p); cvReleaseImage(&pImgNew); cvReleaseImageHeader(&pImg); #else Lock(); // ԭʼͼÏñÊý¾Ýת cv::Mat cv::Mat origin(nImgHeight, nImgWidth, CV_8UC1, lpOrigin + (nImgWidth * nStartY)); // Ëõ·ÅͼÏñ cv::Size szNew(static_cast(nImgWidth * dRatio), static_cast(nImgHeight * dRatio)); cv::Mat resized; cv::resize(origin, resized, szNew, 0, 0, cv::INTER_LINEAR); // ÉèÖà JPEG ѹËõ²ÎÊý std::vector params = { cv::IMWRITE_JPEG_QUALITY, nQuality }; USES_CONVERSION; std::string strFilename = W2A(strPath); if (!cv::imwrite(strFilename, resized, params)) { Unlock(); g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), imwrite failed"), strPath, PANEL_SIDE[iSide], nStartY); return FALSE; } Unlock(); #endif g_pLog->DisplayMessage(_T("Save Full Image Success(%s, %s, %d, %d, %d)"), strPath, PANEL_SIDE[iSide], nStartY, nImgHeight, nQuality); return TRUE; } #define IMAGE_COMPRESSRATIO 50 int CInterfaceManager::LoadFullImage(CString strPath,int iSide,int nStartY, CGlass_Data *pGlassData,const bool bIsDebugImg) { int nHeight = -1; if (strPath.IsEmpty() || iSide < 0 || iSide > MAX_DIMENSION_COUNT) { g_pLog->DisplayMessage(_T("Load Full Image Fail(%s, %d)"), strPath, iSide); return nHeight; } #if 0 USES_CONVERSION; char str_filename[200]; sprintf_s(str_filename, "%s", W2A(strPath)); LPBYTE lpImg = NULL; IplImage *pIplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE); if(pIplimg) { if(bIsDebugImg == true) { //Debug image UINT uiReadLine = 0; lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY); if (lpImg != NULL) { memcpy(lpImg, &pIplimg->imageData[0], pIplimg->widthStep * pIplimg->height); } for(int i = 0; i < pIplimg->height; i++) { lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY+i); if (lpImg == NULL) { break; } memcpy(lpImg, &pIplimg->imageData[uiReadLine] , pIplimg->widthStep); uiReadLine += pIplimg->widthStep; } if(pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide); if(pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = pIplimg->height + nStartY; } } nHeight = pIplimg->height; cvReleaseImage(&pIplimg); } else { //Full image const double dRatio = 1.0 - static_cast(IMAGE_COMPRESSRATIO / 100.0); IplImage *pResizeImage = cvCreateImage(cvSize((int)(pIplimg->width/dRatio), (int)(pIplimg->height/dRatio)), IPL_DEPTH_8U, 1); cvResize(pIplimg, pResizeImage, CV_INTER_CUBIC); lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY); if(lpImg != NULL) { memcpy(lpImg, &pIplimg->imageData[0] , pResizeImage->widthStep * pResizeImage->height); } UINT uiReadLine = 0; for (int i = 0; i < pResizeImage->height; i++) { lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i); if (lpImg == NULL) { break; } memcpy(lpImg, &pResizeImage->imageData[uiReadLine], pResizeImage->widthStep); uiReadLine += pResizeImage->widthStep; } if(pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide); if(pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = pIplimg->height + nStartY; } } nHeight = pResizeImage->height; cvReleaseImage(&pIplimg); cvReleaseImage(&pResizeImage); } strPath.Append(_T("_OK")); } else { strPath.Append(_T("_NG")); } #else // ¼ÓÔØ»Ò¶ÈͼÏñ std::string strFilename = CT2A(strPath); cv::Mat img = cv::imread(strFilename, cv::IMREAD_GRAYSCALE); if (!img.empty()) { g_pLog->DisplayMessage(_T("Image Size: %d x %d"), img.cols, img.rows); if (bIsDebugImg) { for (int i = 0; i < img.rows; ++i) { LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i); if (lpImg == NULL) { break; } memcpy(lpImg, img.ptr(i), img.cols); } if (pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide); if (pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = img.rows + nStartY; } } nHeight = img.rows; } else { // °´±ÈÀýËõ·Å const double dRatio = 1.0 - static_cast(IMAGE_COMPRESSRATIO) / 100.0; int newWidth = static_cast(img.cols / dRatio); int newHeight = static_cast(img.rows / dRatio); cv::Size newSize(newWidth, newHeight); cv::Mat resized; cv::resize(img, resized, newSize, 0, 0, cv::INTER_CUBIC); LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY); if (lpImg != NULL) { memcpy(lpImg, resized.data, resized.cols * resized.rows); } if (pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide); if (pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = img.rows + nStartY; } } nHeight = resized.rows; } strPath.Append(_T("_OK")); } else { strPath.Append(_T("_NG")); } #endif // 0 g_pLog->DisplayMessage(_T("%s"),(TCHAR*)(LPCTSTR)strPath); SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0)); return nHeight; } BOOL CInterfaceManager::SetLiveGrabCommand(DimensionDir eDir,BOOL bStop) { int iCam = m_HardwareRecipe.GetCameraIndexToDimension(eDir); g_pLog->DisplayMessage(_T("Live Grab Cam %d Start : Inter"),iCam); if(iCam < 0 || iCam >= MAX_CAMERA_COUNT) return FALSE; if(m_pGrabber[iCam] == NULL) return FALSE; BOOL bRet = TRUE; if(bStop == TRUE) bRet = m_pGrabber[iCam]->GrabScanStop(); else { bRet = m_pGrabber[iCam]->SetTriggerMode(FALSE); bRet = m_pGrabber[iCam]->GrabLiveStart(); } g_pLog->DisplayMessage(_T("Live Grab Cam %d End : Inter"),iCam); return bRet; } void CInterfaceManager::WriteLogManager(TCHAR *str) { if(m_pLogManager != NULL) { m_pLogManager->WriteLog(0,(TCHAR*)(LPCTSTR)str); } } void CInterfaceManager::WritePLCResult() { short pResult[5] = {}; ZeroMemory(pResult, sizeof(pResult)); int nDefectCount = m_GlassData.GetJudgeDefectCount(); double dTFTXOff = 0; //double dSumTFTXOff = 0; //int nCountTFTXOff = 0; //for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++) //{ // if (m_GlassData.GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue; // dSumTFTXOff += m_GlassData.GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx]; // nCountTFTXOff++; //} //if (nCountTFTXOff > 0) // dTFTXOff = dSumTFTXOff / nCountTFTXOff; double dTFTYOff = 0; //double dSumTFTYOff = 0; //int nCountTFTYOff = 0; //for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++) //{ // if (m_GlassData.GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue; // dSumTFTYOff += m_GlassData.GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx]; // nCountTFTYOff++; //} //if (nCountTFTYOff > 0) // dTFTYOff = dSumTFTYOff / nCountTFTYOff; // Panel Size.. int pCimData[74] = {}; std::fill_n(pCimData, 74, 0); pCimData[0] = (int) ((m_GlassData.GetSideData(DIMENSION_B)->m_nGlassEndLine - m_GlassData.GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_GlassData.GetSideData(DIMENSION_B)->m_dPixelSizeY / 1000.0); pCimData[1] = (int) ((m_GlassData.GetSideData(DIMENSION_A)->m_nGlassEndLine - m_GlassData.GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_GlassData.GetSideData(DIMENSION_A)->m_dPixelSizeY / 1000.0); pCimData[2] = (int) (((m_GlassData.GetSideData(DIMENSION_B)->m_nGlassEndLine - m_GlassData.GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_GlassData.GetSideData(DIMENSION_B)->m_dPixelSizeY - dTFTXOff) / 1000.0); pCimData[3] = (int) (((m_GlassData.GetSideData(DIMENSION_A)->m_nGlassEndLine - m_GlassData.GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_GlassData.GetSideData(DIMENSION_A)->m_dPixelSizeY - dTFTYOff) / 1000.0); pCimData[4] = MeasrueCutLineResult(DIMENSION_A); pCimData[5] = MeasrueCutLineResult(DIMENSION_B); pCimData[6] = MeasrueCutLineResult(DIMENSION_C); pCimData[7] = MeasrueCutLineResult(DIMENSION_D); pCimData[8] = MeasrueCutLineResult(DIMENSION_A_DN); pCimData[9] = MeasrueCutLineResult(DIMENSION_B_DN); pCimData[10] = MeasrueCutLineResult(DIMENSION_C_DN); pCimData[11] = MeasrueCutLineResult(DIMENSION_D_DN); pCimData[12] = MeasrueChamferResult(DIMENSION_A); pCimData[13] = MeasrueChamferResult(DIMENSION_B); pCimData[14] = MeasrueChamferResult(DIMENSION_C); pCimData[15] = MeasrueChamferResult(DIMENSION_D); pCimData[16] = MeasrueChamferResult(DIMENSION_A_DN); pCimData[17] = MeasrueChamferResult(DIMENSION_B_DN); pCimData[18] = MeasrueChamferResult(DIMENSION_C_DN); pCimData[19] = MeasrueChamferResult(DIMENSION_D_DN); pCimData[20] = m_GlassData.GetSideData(DIMENSION_C)->m_nTopCornerHeight; //C1 pCimData[21] = m_GlassData.GetSideData(DIMENSION_A)->m_nTopCornerHeight; //C2 pCimData[22] = m_GlassData.GetSideData(DIMENSION_A)->m_nBottomCornerHeight;//C3 pCimData[23] = m_GlassData.GetSideData(DIMENSION_C)->m_nBottomCornerHeight;//C4 BOOL bPutTeethNG = FALSE; CGlassRecipe* pRecipe = m_GlassData.GetGlassRecipe(); if (pRecipe != NULL) { g_pLog->DisplayMessage(_T("USE_SEND_CHIP_TO_CIM=%d"), g_pBase->m_bUseChipCIM); std::vector vecChip; int nChipCount = g_pBase->m_nChipCount; int nChipMinDep = g_pBase->m_nChipMinDep; int nChipMaxDep = g_pBase->m_nChipMaxDep; int nChipMinLen = g_pBase->m_nChipMinLen; int nChipMaxLen = g_pBase->m_nChipMaxLen; if (g_pBase->m_bUseChipCIM) { MapDefectIt it; MapDefect* pMapDefect = m_GlassData.GetMapDefect_OK(); for (it = pMapDefect->begin(); it != pMapDefect->end(); it++) { CDefect* pDefect = static_cast(it->second); if (pDefect == NULL) continue; if (pDefect->m_bJudge_NG == TRUE) continue; CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc]; if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0) && vecChip.size() < nChipCount) { if (static_cast(round(pDefect->m_dSizeX_um)) < nChipMinDep || static_cast(round(pDefect->m_dSizeX_um)) > nChipMaxDep) continue; if (static_cast(round(pDefect->m_dSizeY_um)) < nChipMinLen || static_cast(round(pDefect->m_dSizeY_um)) > nChipMaxLen) continue; DefectInfo tmpInfo; tmpInfo.SideIdx = pDefect->m_DefectInfo.m_nSideIdx; tmpInfo.Depth = static_cast(round(pDefect->m_dSizeX_um)); tmpInfo.Length = static_cast(round(pDefect->m_dSizeY_um)); #if HALCON_VISION_KEY Point2I pos2I = BlVision_GetSoftVisionApp()->getPose(pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl.x, pDefect->m_DefectInfo.m_ptDefectPos_pxl.y); tmpInfo.PosX = std::abs(pos2I.y); tmpInfo.PosY = std::abs(pos2I.x); #else CPoint pos2I = m_GlassData.TransformToGlobal((DimensionDir)tmpInfo.SideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl); tmpInfo.PosX = std::abs(pos2I.x); tmpInfo.PosY = std::abs(pos2I.y); #endif // HALCON_VISION_KEY tmpInfo.DefectIndex = (int)(vecChip.size()) + 1; vecChip.push_back(tmpInfo); } } } { MapDefectIt it; MapDefect* pMapDefect = m_GlassData.GetMapDefect_NG(); for (it = pMapDefect->begin(); it != pMapDefect->end(); it++) { CDefect* pDefect = static_cast(it->second); if (pDefect == NULL) continue; if (pDefect->m_bJudge_NG == FALSE) continue; CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc]; if (strDefectType.Compare(_T("Chip")) == 0 && g_pBase->m_bPutTeethChip != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Crack")) == 0 && g_pBase->m_bPutTeethCrack != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Burr")) == 0 && g_pBase->m_bPutTeethBurr != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Chamfer")) == 0 && g_pBase->m_bPutTeethChamfer != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("In_Chip")) == 0 && g_pBase->m_bPutTeethInChip != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("In_Crack")) == 0 && g_pBase->m_bPutTeethInCrack != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("In_Burr")) == 0 && g_pBase->m_bPutTeethInBurr != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("In_Chamfer")) == 0 && g_pBase->m_bPutTeethInChamfer != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Top_Corner")) == 0 && g_pBase->m_bPutTeethTopCorner != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Bot_Corner")) == 0 && g_pBase->m_bPutTeethBotCorner != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Corner_Dimension")) == 0 && g_pBase->m_bPutTeethCornerDimension != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Dimension")) == 0 && g_pBase->m_bPutTeethDimension != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Notch")) == 0 && g_pBase->m_bPutTeethNotch != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Notch_Dimension")) == 0 && g_pBase->m_bPutTeethNotchDimension != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Notch_Chamfer")) == 0 && g_pBase->m_bPutTeethNotchChamfer != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Notch_Radius")) == 0 && g_pBase->m_bPutTeethNotchRadius != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("User_Defect")) == 0 && g_pBase->m_bPutTeethUserDefect != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Mark")) == 0 && g_pBase->m_bPutTeethMark != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("Exception")) == 0 && g_pBase->m_bPutTeethException != 0) bPutTeethNG = TRUE; else if (strDefectType.Compare(_T("License")) == 0 && g_pBase->m_bPutTeethLicense != 0) bPutTeethNG = TRUE; if (g_pBase->m_bUseChipCIM) { if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0) && vecChip.size() < nChipCount) { if (static_cast(round(pDefect->m_dSizeX_um)) < nChipMinDep || static_cast(round(pDefect->m_dSizeX_um)) > nChipMaxDep) continue; if (static_cast(round(pDefect->m_dSizeY_um)) < nChipMinLen || static_cast(round(pDefect->m_dSizeY_um)) > nChipMaxLen) continue; DefectInfo tmpInfo; tmpInfo.SideIdx = pDefect->m_DefectInfo.m_nSideIdx; tmpInfo.Depth = static_cast(round(pDefect->m_dSizeX_um)); tmpInfo.Length = static_cast(round(pDefect->m_dSizeY_um)); CPoint pos2I = m_GlassData.TransformToGlobal((DimensionDir)tmpInfo.SideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl); tmpInfo.PosX = std::abs(pos2I.x); tmpInfo.PosY = std::abs(pos2I.y); tmpInfo.DefectIndex = (int)(vecChip.size()) + 1; vecChip.push_back(tmpInfo); } } else { if (bPutTeethNG) break; } } } pCimData[24] = (int)(vecChip.size()); int nIndex = 25; for (auto item : vecChip) { if (nIndex + 6 > 74) break; pCimData[nIndex++] = item.SideIdx; pCimData[nIndex++] = item.DefectIndex; pCimData[nIndex++] = item.PosX; pCimData[nIndex++] = item.PosY; pCimData[nIndex++] = item.Length; pCimData[nIndex++] = item.Depth; } } //m_pControlInterface->SendIntArrayPLCData('D', PLC_ADDR_PROFILE_JUDEMENT, pCimData, 74); m_pControlInterface->SendCIMData((short*)pCimData, PLC_ADDR_PROFILE_JUDEMENT, sizeof(pCimData)); /* INS_PROFILE_RESULT_INFO *pProfileResult = m_GlassData.GetProfileResultInfo(); for(int i=0;inProfileData[i] = pHistory.nProfileDiff[i]; pProfileResult->nChamferUp[i] = pHistory.nChamferThickUp[i]; pProfileResult->nChamferDn[i] = pHistory.nChamferThickDn[i]; } m_pControlInterface->SendCIMData((short*)pProfileResult,PLC_ADDR_PROFILE_JUDEMENT,MAX_PROFILE_SETTING_COUNT*3); g_pLog->DisplayMessage(_T("write PLC Profile Data : %d"),MAX_PROFILE_SETTING_COUNT*3); */ // 2 : OK, 1 : NG if (nDefectCount == 0) { m_GlassData.SetGlassJudge(FALSE); pResult[0] = 2; g_pLog->DisplayMessage(_T("Inspection Result Glass %s - OK"), g_pBase->m_strHPanelID); } else { m_GlassData.SetGlassJudge(TRUE); // NG Defect View.. if (g_pBase->m_bAutoDefectView == TRUE) m_pView->SwitchView(EV_VIEW_DEFECT); if (bPutTeethNG) pResult[0] = 3; else pResult[0] = 1; g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG"), g_pBase->m_strHPanelID); } m_GlassData.SetInspectComplete(TRUE); m_GlassData.GetStageTheta(0, pResult[1], pResult[2]); m_GlassData.GetStageTheta(1, pResult[3], pResult[4]); m_pControlInterface->SendCIMData(pResult, PLC_ADDR_GLASS_JUDEMENT, 5); g_pLog->DisplayMessage(_T("write PLC Result Data : Resut %d,1_L_Theat %d,1_S_Theat %d,2_L_Theat %d,2_S_Theat %d"), pResult[0], pResult[1], pResult[2], pResult[3], pResult[4]); } BOOL CInterfaceManager::CheckExpireDay() { CTime currentTime = CTime::GetCurrentTime(); if(currentTime.GetHour() < 13 || 17 < currentTime.GetHour()) // CHECK TIME : 13~17 return TRUE; BOOL bLicense = FALSE; CFile file; CString strPath; STU_EXPIRE_DAY stuExpire; strPath.Format(_T("%s\\Config\\SISConfirm.bin"), PATH_INSPECTOR); if(TRUE == file.Open(strPath,CFile::modeRead)) { if(sizeof(STU_EXPIRE_DAY) == file.Read(&stuExpire, sizeof(STU_EXPIRE_DAY))) { CTime timeExpire(stuExpire.m_nYear,stuExpire.m_nMonth,stuExpire.m_nDay,0,0,0); CTimeSpan expirediff = timeExpire-currentTime; int nDiffHour = expirediff.GetTotalHours(); CString str; str.Format(_T("======== Check : %d-%d-%d, Diff %d"),stuExpire.m_nYear,stuExpire.m_nMonth,stuExpire.m_nDay,nDiffHour); g_pLog->DisplayMessage(str); if(0 < nDiffHour) bLicense = TRUE; } file.Close(); } if(bLicense == FALSE) { for(int i=0; im_DefectInfo.m_nScanIdx = 0; pNewDefect->m_DefectInfo.m_nSideIdx = i; pNewDefect->m_DefectInfo.m_DefectLoc = DefectLoc_License; pNewDefect->m_bJudge_NG = TRUE; if(m_GlassData.SetDefect(pNewDefect) == FALSE) delete pNewDefect; } } return TRUE; } void CInterfaceManager::SetTriggerControl() { g_pLog->DisplayMessage(_T("Set Trigger Control : Stage %d"), g_pBase->m_nStageNo); if(m_pTriggerBoardControl == NULL) m_pTriggerBoardControl = new CTriggerControl_Mvsol; if(m_pTriggerBoardControl->IsConnect() == FALSE) { g_pLog->DisplayMessage(_T("Trigger Board Connect : Com Port = %d"), m_HardwareRecipe.m_nPort_MvsolTriggerControl); m_pTriggerBoardControl->Connect(m_HardwareRecipe.m_nPort_MvsolTriggerControl); } if(g_pBase->m_nStageNo == 0) { g_pLog->DisplayMessage(_T("Trigger Control Digital Input OFF !")); m_pTriggerBoardControl->SetSelectEncoder(0); } else { g_pLog->DisplayMessage(_T("Trigger Control Digital Input ON !")); m_pTriggerBoardControl->SetSelectEncoder(1); } } int CInterfaceManager::MeasrueCutLineResult(DimensionDir dir) { if (m_GlassData.GetGlassRecipe() == NULL) return 0; double dSun = 0; int nCount = m_GlassData.GetGlassRecipe()->m_SideParam[dir].m_nSideDimensionCount; if (nCount > 0) { for (int i = 0; i < nCount; i++) { dSun += (m_GlassData.GetSideData(dir)->m_dSideMeasrue_CutLine_Result_mm[i] + m_GlassData.GetSideData(dir)->m_dSideMeasrue_CutLine_Offset_mm[i]); } return ((int)(dSun * 1000 / nCount)); } return 0; } int CInterfaceManager::MeasrueChamferResult(DimensionDir dir) { if (m_GlassData.GetGlassRecipe() == NULL) return 0; double dSun = 0; int nCount = m_GlassData.GetGlassRecipe()->m_SideParam[dir].m_nSideDimensionCount; if (nCount > 0) { for (int i = 0; i < nCount; i++) { dSun += m_GlassData.GetSideData(dir)->m_dSideMeasrue_Chamfer_Result_mm[i]; } return ((int)(dSun * 1000 / nCount)); } return 0; } #if USE_WEBSOCKET void CInterfaceManager::CreateWebSocketClients(WebSocketClientPool** wsClients, CString cstrURI, int nThreadCount) { if ((*wsClients) != nullptr) { (*wsClients)->exit_clients(); delete wsClients; } USES_CONVERSION; std::string uri = W2A(cstrURI); *wsClients = new WebSocketClientPool(nThreadCount); std::vector uris; for (size_t i = 0; i < nThreadCount; i++) { uris.push_back(uri); } (*wsClients)->init_clients(uris); } void CInterfaceManager::DestroyWebSocketClients(WebSocketClientPool** wsClients) { if ((*wsClients) != nullptr) { (*wsClients)->exit_clients(); delete (*wsClients); (*wsClients) = nullptr; } } #endif // USE_WEBSOCKET long long CInterfaceManager::GetCurrentTimestamp() { auto now = std::chrono::system_clock::now(); auto microseconds = std::chrono::duration_cast(now.time_since_epoch()).count(); return microseconds; }