#include "StdAfx.h" #include "InterfaceManager.h" #include "MulticamControl.h" #include "RadientControl.h" #include "SapControl.h" #include "SapLineGrab.h" #include "FreeImage.h" #include #include "ExpireDayDefine.h" //#define TEST_SIGNAL_PROCESS #define OFFSET_SPLINE_DATA 10 #define JPEG_RATE JPEG_QUALITYNORMAL|JPEG_OPTIMIZE #define JPEG_FULLIMAGE_RATE JPEG_QUALITYGOOD|JPEG_OPTIMIZE 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; m_pTriggerBoardControl = NULL; 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_pTriggerBoardControl != NULL) delete m_pTriggerBoardControl; m_pTriggerBoardControl=NULL; if(m_pLicense != NULL) delete m_pLicense; m_pLicense = NULL; } 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; /* if(m_pThread_NetMSG != NULL) { m_pThread_NetMSG->StopThread(); delete m_pThread_NetMSG; } m_pThread_NetMSG = NULL; if(m_pThread_Light != NULL) { m_pThread_Light->StopThread(); delete m_pThread_Light; } m_pThread_Light = 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 = 300;//((CPLCControl_Interface_B5*) 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_ON[%d] Send Control Signal : Sig %d, Val %d, Ret %d"),nCount,(int)emControlSignal,TRUE,nRet); Sleep(nSignalOnTime); nRet = m_pControlInterface->SendConstrol(emControlSignal,FALSE); g_pLog->DisplayMessage(_T("PLC Retry_OFF[%d] Send Control Signal : Sig %d, Val %d, Ret %d"),nCount,(int)emControlSignal,TRUE,nRet); bSendSignal = TRUE; } if(nCount >= nRetryCount) break; g_pLog->DisplayMessage(_T("PLC Retry_Down Check loop")); 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); g_pLog->DisplayMessage(_T("Add Disable Msg")); } } 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(); 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); CopyImageBuffer(); m_PostProcess.SetPrameter(&m_GlassData,&m_HardwareRecipe,&m_GlassRecipe,g_pStatus->GetInspectOption(),g_pStatus->GetProfileOption(),&m_TransferData,&m_ResultData); m_PostProcess.RunPostProcessing(); HISTORY_RESULT HisData; HistoryData(m_GlassData.GetJudgeDefectCount(), HisData); m_PostProcess.AddHistoryData(HisData); m_PostProcess.RunPostProcessing_SaveDefectInfo(); WritePLCResult(HisData); if(m_pThread_SendMSG != NULL) m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_ShortScanEndSuccess,TRUE); m_bGlassLoadingEnd = FALSE; m_bPLCGlassLoading = FALSE; m_GlassData.SetScanEndTime(); m_TactStopWatch.End(); g_pLog->DisplayMessage(_T("Inspection Time(GlassLoading -> End) : %.3f"),m_TactStopWatch.GetDurationMilliSecond()); AfxBeginThread(CopyImageThreadFunc, this); if(m_pView != NULL) { m_pView->AddHistory(HisData); 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); } } return TRUE; } void CInterfaceManager::CopyImageBuffer() { DWORD dwTick = GetTickCount(); CGLASS_INFO_PARM *pGlass = m_GlassRecipe.GetGlassInfo(); pINSPECTSPLINE_BUFFER pSplineBuffer; CCameraSettings *pCamera; int iCam,iScan,iPos; BOOL bSplineImg[MAX_PANEL_SIDE]; BOOL bSpline = m_GlassData.GetInsUseCheck(EM_INS_SPLINE); ZeroMemory(bSplineImg,sizeof(BOOL)*MAX_PANEL_SIDE); g_pLog->DisplayMessage(_T("Start Copy Full Image Save")); DeleteAlignProfileData(); for(iCam=0;iCam *pCamMapAlign = m_pInspect[iCam]->GetProfileAlign(iScan); if((int)pCamMapAlign->size() > 0) { CSingleLock csLock(&m_csProfile); csLock.Lock(); m_mapAlignProfile[pCamera->m_eDimension].insert(pCamMapAlign->begin(),pCamMapAlign->end()); csLock.Unlock(); } for(iPos=0;iPosGetSplineBuffer(iPos); if(pSplineBuffer == NULL) continue; if(pSplineBuffer->iType < 0 || pSplineBuffer->iType > 1) continue; if(pSplineBuffer->ePosition < INSPECTSPLINE_BUFFER::SPLINE_TOPLEFT || pSplineBuffer->ePosition > INSPECTSPLINE_BUFFER::SPLINE_BOTTOMRIGHT) continue; if(bSplineImg[pSplineBuffer->ePosition] == FALSE) { if(m_pView != NULL) { if(m_pView->SetSplineImg(pSplineBuffer->pOrg,pSplineBuffer->szOrg,pSplineBuffer->ePosition) == TRUE) bSplineImg[pSplineBuffer->ePosition] = TRUE; } } pSplineBuffer->Reset(); } } } g_pLog->DisplayMessage(_T("Copy Image Save Complete : Time[%d]"),GetTickCount()-dwTick); } 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; CGLASS_INFO_PARM *pGlassInfoPrm = &pGlsRcp->m_GlassParm; CString strFolder,strFileJpg,strPanelID; pINSPECTFULLIMAGE_BUFFER pBuffer; 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; 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); SaveFullImage2(strFileJpg,pBuffer->pImage,pBuffer->szImage.cx,pBuffer->szImage.cy,(int)pCamera->m_eDimension,0,30); } } } g_pLog->DisplayMessage(_T("Full Image Save Completed : Time[%d]"),GetTickCount()-dwTick); } void CInterfaceManager::CoordProfileJudge(HISTORY_RESULT& pHistory) { PROFILECHAMFER_RESULT_DATA* pProfileResult1 = m_GlassData.GetProfileInspectData(); pHistory.bResult = TRUE; CINSPECT_JUDGEMENT_PARM* pJudges = m_GlassRecipe.GetJudgePrm(); NgInfo ngArray[3][NG_INF_TOTAL]; BlVision_GetSoftVisionApp()->Execute(4, ngArray[0]); BlVision_GetSoftVisionApp()->Execute(5, ngArray[1]); BlVision_GetSoftVisionApp()->Execute(7, ngArray[2]); pHistory.nProAlarmResultCountB = 0; pHistory.nProAlarmResultCountA = 0; pHistory.nProAlarmResultCountD = 0; pHistory.nProAlarmResultCountC = 0; for (int i = 0; i < 3; i++) { /*A-BOT*/ if (i == 0) { for (int c = 33; c < 47; c++) { if (pProfileResult1->ProfileData[c].bUseJudge == 1) { if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[4]) { pHistory.bResult = FALSE; } if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus) { pHistory.nProAlarmResultCountA += 1; } } } for (int z = 0; z < 50; z++) { if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6) { if (ngArray[i][z].maxValuengArray[i][z].result) { pHistory.nProAlarmResultCountA += 1; if (pHistory.nProAlarmResultCountA > pJudges->nMinProfileNgCount[4] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[4]) pHistory.bResult = FALSE; } } if (ngArray[i][z].ngType == 5 && (5 < ngArray[i][z].id && ngArray[i][z].id < 11)) { if (ngArray[i][z].maxValuengArray[i][z].result) { pHistory.nProAlarmResultCountA += 1; if (pHistory.nProAlarmResultCountA > pJudges->nMinProfileNgCount[4] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[4]) pHistory.bResult = FALSE; } } } } /*B-BOT*/ if (i == 1) { for (int c = 0; c < 10; c++) { if (pProfileResult1->ProfileData[c].bUseJudge == 1) { if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[5]) { pHistory.bResult = FALSE; } if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus) { pHistory.nProAlarmResultCountB += 1; } } } for (int z = 0; z < 50; z++) { if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6) { if (ngArray[i][z].maxValuengArray[i][z].result) { pHistory.nProAlarmResultCountB += 1; if (pHistory.nProAlarmResultCountB > pJudges->nMinProfileNgCount[5] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[5]) pHistory.bResult = FALSE; } } } } /*D-BOT*/ if (i == 2) { for (int c = 23; c < 33; c++) { if (pProfileResult1->ProfileData[c].bUseJudge == 1) { if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[7]) { pHistory.bResult = FALSE; } if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus) { pHistory.nProAlarmResultCountD += 1; } } } for (int z = 0; z < 50; z++) { if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6) { if (ngArray[i][z].maxValuengArray[i][z].result) { pHistory.nProAlarmResultCountD += 1; if (pHistory.nProAlarmResultCountD > pJudges->nMinProfileNgCount[7] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[7]) pHistory.bResult = FALSE; } } } } } for (int i = 10; i < 23; i++) { if (pProfileResult1->ProfileData[i].bUseJudge == 1) { if (pHistory.nProfileDiff[i] < -1 * pProfileResult1->ProfileData[i].nJudgeMinus || pHistory.nProfileDiff[i] > pProfileResult1->ProfileData[i].nJudgePlus) { pHistory.nProAlarmResultCountC += 1; if (pHistory.nProAlarmResultCountD > pJudges->nMinProfileNgCount[6] || pHistory.nProfileDiff[i] > pJudges->nMinProfileNgCount_MinDiff[6]) pHistory.bResult = FALSE; } } } } void CInterfaceManager::WritePLCResult(HISTORY_RESULT &pHistory) { short *pResult = m_GlassData.GetGlassResultInfo(); ZeroMemory(pResult,sizeof(short)*5); if (m_HardwareRecipe.GetCoordProfileUse() == 1) { CoordProfileJudge(pHistory); if (pHistory.nDefectCnt- (pHistory.nProAlarmResultCountD+ pHistory.nProAlarmResultCountB+ pHistory.nProAlarmResultCountA+ pHistory.nProAlarmResultCountC) >0 ) pHistory.bResult = FALSE; } // 0 : OK, 1 : NG if(pHistory.bResult == TRUE) { pResult[0] = 0; g_pLog->DisplayMessage(_T("Inspection Result Glass %s - OK"),g_pBase->m_strHPanelID); } else { if (g_pLog->m_nHoleAlarmState ==TRUE) { pResult[10] = g_pLog->m_nHoleAlarmState; pResult[0] = 1; g_pLog->m_nHoleAlarmState = 0; g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG, Hole Alarm%d-NG"), g_pBase->m_strHPanelID, pResult[10]); } else { pResult[0] = 1; pResult[10] = 0; g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG"), g_pBase->m_strHPanelID); } } m_GlassData.GetStageTheta(0,pResult[1],pResult[2]); m_GlassData.GetStageTheta(1,pResult[3],pResult[4]); m_pControlInterface->SendCIMData(pResult,PLC_ADDR_GLASS_JUDEMENT,11); 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[10]:%d"),pResult[0],pResult[1],pResult[2],pResult[3],pResult[4], pResult[10]); 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); } void CInterfaceManager::HistoryData(int nDefectCnt,HISTORY_RESULT &pHistory) { CResultData *pResData = &m_ResultData; PROFILECHAMFER_RESULT_DATA *pProfileResult = m_GlassData.GetProfileInspectData(); pHistory.Reset(); int i; pHistory.bResult = TRUE; for(i=0;iProfileData[i].nProfileDiff; if(pProfileResult->ProfileData[i].bUseJudge == TRUE) pHistory.bProfileJudge[i] = pProfileResult->ProfileData[i].bProfileJudge; else pHistory.bProfileJudge[i] = TRUE; pHistory.nChamferThickUp[i] = abs(pProfileResult->ResultChamfer[i][0].nChamferCalThick); if(pProfileResult->ResultChamfer[i][0].bUseJudge == TRUE) pHistory.bChamferJudgeUp[i] = pProfileResult->ResultChamfer[i][0].bChamferJudge; else pHistory.bChamferJudgeUp[i] = TRUE; pHistory.nChamferThickDn[i] = abs(pProfileResult->ResultChamfer[i][1].nChamferCalThick); if(pProfileResult->ResultChamfer[i][1].bUseJudge == TRUE) pHistory.bChamferJudgeDn[i] = pProfileResult->ResultChamfer[i][1].bChamferJudge; else pHistory.bChamferJudgeDn[i] = TRUE; } #if 1 int nGridColumnCnt[] = { PROFILE_INSPECT_SIZE_A_C,PROFILE_INSPECT_SIZE_B_D,PROFILE_INSPECT_SIZE_A_C,PROFILE_INSPECT_SIZE_B_D,PROFILE_INSPECT_SIZE_A_C,PROFILE_INSPECT_SIZE_B_D,PROFILE_INSPECT_SIZE_B_D }; UINT eViewProfileIndex[] = { PROFILE_INSPECT_INDEX_A,PROFILE_INSPECT_INDEX_B,PROFILE_INSPECT_INDEX_C,PROFILE_INSPECT_INDEX_D,PROFILE_INSPECT_INDEX_CF,PROFILE_RCUT_INSPECT_INDEX_A,PROFILE_RCUT_INSPECT_INDEX_C }; //CString str1,str2,str3; int index, nProfileIndex; int nRowIdx, iCol; int nProfileSum, nProfileCnt; int nChamferSumUp, nChamferCntUp; int nChamferSumDn, nChamferCntDn; BOOL isBool; for (i = 0; i < MAX_VIEWINFO_GRD_CNT; i++) { isBool = FALSE; nProfileSum = nProfileCnt = 0; nChamferSumUp = nChamferCntUp = 0; nChamferSumDn = nChamferCntDn = 0; for (index = 0; index < nGridColumnCnt[i]; index++) { iCol = index + 1; nProfileIndex = eViewProfileIndex[i] + index; if (i > MAX_VIEWINFO_GRD_CNT - 3 && index > 4 && !isBool) { isBool = TRUE; pHistory.nAVGProfileDiff[i] = nProfileCnt > 0 ? (nProfileSum / nProfileCnt) : 0; pHistory.nAVGChamferThickUp[i] = nChamferCntUp > 0 ? (nChamferSumUp / nChamferCntUp) : 0; pHistory.nAVGChamferThickDn[i] = nChamferCntDn > 0 ? (nChamferSumDn / nChamferCntDn) : 0; nProfileSum = nProfileCnt = 0; nChamferSumUp = nChamferCntUp = 0; nChamferSumDn = nChamferCntDn = 0; } if (pProfileResult->ProfileData[nProfileIndex].bProfileJudge) { nProfileSum += pProfileResult->ProfileData[nProfileIndex].nProfileDiff; nProfileCnt++; } if (pProfileResult->ResultChamfer[nProfileIndex][0].bChamferJudge) { nChamferSumUp += abs(pProfileResult->ResultChamfer[nProfileIndex][0].nChamferCalThick); nChamferCntUp++; } if (pProfileResult->ResultChamfer[nProfileIndex][1].bChamferJudge) { nChamferSumDn += abs(pProfileResult->ResultChamfer[nProfileIndex][1].nChamferCalThick); nChamferCntDn++; } } //str1.Format(_T("%.3f"), nProfileCnt > 0 ? (double)(nProfileSum / nProfileCnt / 1000.) : 0.000); //str2.Format(_T("%.3f"), nChamferCntUp > 0 ? (double)(nChamferSumUp / nChamferCntUp / 1000.) : 0.000); //str3.Format(_T("%.3f"), nChamferCntDn > 0 ? (double)(nChamferSumDn / nChamferCntDn / 1000.) : 0.000); //g_pLog->DisplayMessage(_T("HistoryData AVG%d: nProfileAVG=%s,nChamferUpAVG=%s,nChamferUpAVG=%s"), i, str1, str2, str3); if (i > MAX_VIEWINFO_GRD_CNT - 3 && index > 4) { pHistory.nAVGProfileDiff[i + 2] = nProfileCnt > 0 ? (nProfileSum / nProfileCnt) : 0; pHistory.nAVGChamferThickUp[i + 2] = nChamferCntUp > 0 ? (nChamferSumUp / nChamferCntUp) : 0; pHistory.nAVGChamferThickDn[i + 2] = nChamferCntDn > 0 ? (nChamferSumDn / nChamferCntDn) : 0; } else { pHistory.nAVGProfileDiff[i] = nProfileCnt > 0 ? (nProfileSum / nProfileCnt) : 0; pHistory.nAVGChamferThickUp[i] = nChamferCntUp > 0 ? (nChamferSumUp / nChamferCntUp) : 0; pHistory.nAVGChamferThickDn[i] = nChamferCntDn > 0 ? (nChamferSumDn / nChamferCntDn) : 0; } } #endif // 1 pHistory.strHostID = g_pBase->m_strHPanelID; pHistory.strGlassID = g_pBase->m_strHPanelID; pHistory.strEndTime = pResData->m_strScanEndTime; pHistory.nDefectCnt = nDefectCnt; if(nDefectCnt > 0) pHistory.bResult = FALSE; // Profile NG if(m_GlassData.m_bOnly_Profile_NG == TRUE) // Profile NG CHECK.. { g_pLog->DisplayMessage(_T("Only Profile Defect !!!!!!!!!!!!!!!")); BOOL bProfileCountNG = FALSE; for(int i=0; inMinProfileNgCount[i]; g_pLog->DisplayMessage(_T("[Side %d] Only Profile Defect Count [recipe:%d][%d] !!!!!!!!!!!!!!!"), i, nMinNGCount, m_GlassData.m_nSide_Profile_NG_Count[i]); if(nMinNGCount <= m_GlassData.m_nSide_Profile_NG_Count[i]) bProfileCountNG = TRUE; int nMinDiff = m_GlassRecipe.GetJudgePrm()->nMinProfileNgCount_MinDiff[i]; if(nMinDiff <= m_GlassData.m_nSide_Profile_NG_Max_Diff[i]) { bProfileCountNG = TRUE; break; } } if(bProfileCountNG == FALSE) pHistory.bResult = TRUE; } pHistory.nCrackCount = pResData->m_nCrackCount; pHistory.nBrokenCount = pResData->m_nBrokenCount; pHistory.nChipCount = pResData->m_nChipCount; pHistory.nChamferCount = pResData->m_nChamferCount; pHistory.nBurrCount = pResData->m_nBurrCount; pHistory.nUnknownCount = pResData->m_nUnknownCount; } 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::InitLoadingProcess() { g_pLog->DisplayMessage(_T("Start Init Loading Process")); AfxBeginThread(DeleteProfileProcess,this); 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); } } UINT CInterfaceManager::DeleteProfileProcess(LPVOID pParam) { CInterfaceManager *pInterface = (CInterfaceManager *)pParam; pInterface->DeleteAlignProfileData(); return 0; } void CInterfaceManager::DeleteProfileData() { std::multimap::iterator it; CPoint *pPoint; for(int i=0;isecond; if(pPoint == NULL) continue; delete pPoint; pPoint = NULL; } m_mapProfile[i].clear(); } DeleteAlignProfileData(); } void CInterfaceManager::DeleteAlignProfileData() { CSingleLock csLock(&m_csProfile); csLock.Lock(); // std::multimap::iterator it; // CPoint *pPoint; for(int i=0;isecond; if(pPoint == NULL) continue; delete pPoint; pPoint = NULL; } */ m_mapAlignProfile[i].clear(); } csLock.Unlock(); } 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_GlassParm.GetOneScanTime(); 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) { 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) { if(m_pInspect[iCam] != NULL) { 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")); if(CheckExpireDay() == FALSE) { g_pLog->DisplayMessage(_T("*** Confirm Exit")); // ExitProcess(0); return TRUE; } 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.GetLoadingTime()); BOOL bGlassLoading; 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); //AddAlarmList(IToC_Alarm_InspectorError); //return FALSE; } // Trigger Control if(m_HardwareRecipe.GetTriggerBoardUse() == TRUE) SetTriggerControl(); g_pStatus->LoadProfileOpt(m_GlassRecipe.GetRecipeName()); 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")); if(m_pThread_SendMSG != NULL) { m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LoadingSuccess,TRUE); } m_GlassData.SetPostProc(FALSE); m_bGlassLoadingEnd = 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); g_pLog->DisplayMessage(_T("AutoChangeRecipe cam %d setspline"),i); m_pInspect[i]->SetSplineModel(m_SplineModel); g_pLog->DisplayMessage(_T("AutoChangeRecipe cam %d setcad"),i); m_pInspect[i]->SetCADData(m_mapProfile,m_ptOriginMapProfile); g_pLog->DisplayMessage(_T("AutoChangeRecipe cam %d setcad end"),i); } } else { m_pInspect[iCam]->SetParameter(&m_GlassRecipe,&m_HardwareRecipe); m_pInspect[iCam]->SetGlassData(&m_GlassData); m_pInspect[iCam]->SetSplineModel(m_SplineModel); m_pInspect[iCam]->SetCADData(m_mapProfile,m_ptOriginMapProfile); } 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; ////////////////////////////////////////////////////////////////////////// // Thread Init CreateThread(); SetSlashText(GLOBAL_DEFINE::emText, _T("Create Thread Complete"), RGB(0,0,0)); 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)); m_pLightManager = new CLightManager; m_pLightManager->InitLightControl(); 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)); LightTurnOnOff(TRUE); LightChangeValue(); m_pTriggerBoardControl = new CTriggerControl_Mvsol; m_pLicense = new CLicenseChecker(); g_pStatus->m_pLicenseChecker = m_pLicense; if(m_HardwareRecipe.GetTriggerBoardUse() == TRUE) m_pTriggerBoardControl->Connect(m_HardwareRecipe.GetTriggerBoardComport()); if(m_pView->GetHardwareSettingView() != NULL) m_pView->GetHardwareSettingView()->SetTriggerBoard(m_pTriggerBoardControl); 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(RCUT_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[0]; pSide->m_dPixelSizeY = pCamSetting->m_dScanResolution[1]; } 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); 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()); 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(iCam=0;iCamm_pBufferSize[iCam]; // miniled ÓÐÕâÐÐ 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]; // miniled ÓÐÕâÐÐ // Param.nBoardCh = g_pBase->m_nBoardCh[iCam]; // miniled ÓÐÕâÐÐ 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); #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()); //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È£±â ¼ÂÆÃ 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; } } else if(nLineID == 5) { switch(iCam) { case 1: nBoardId = 3; break; case 3: nBoardId = 1; break; } } Param.nBoardIdx = nBoardId; g_pLog->DisplayMessage( _T("Cam File[%d]-Init"), iCam); bRet |= m_pGrabber[iCam]->Initialize(&Param, &nErrorCode,nBoardId); g_pLog->DisplayMessage( _T("Cam File[%d]-Init End"), iCam); bRet |= m_pGrabber[iCam]->InitializeBuffer(&Param); g_pLog->DisplayMessage( _T("Cam File[%d]-Buffer End"), iCam); 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); AfxBeginThread(ReadCADData_0,this); AfxBeginThread(ReadCADData_1,this); AfxBeginThread(ReadCADData_2,this); AfxBeginThread(ReadCADData_3,this); //AfxBeginThread(ReadSplineModel,this); return TRUE; } UINT CInterfaceManager::ReadSplineModel(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); CString strRecipe = pInter->m_GlassRecipe.GetRecipeName(); pInter->ReadSplineModeldata(strRecipe); return 0; } void CInterfaceManager::ReadSplineModeldata(CString strRecipe) { CString strSide,strFile; for(int i=0;iDisplayMessage(_T("%s R-Cut Master Load Success"),strSide); } else { g_pLog->DisplayMessage(_T("%s R-Cut Master Load Fail"),strSide); } } } UINT CInterfaceManager::ReadCADData_0(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); CString strRecipe = pInter->m_GlassRecipe.GetRecipeName(); pInter->ReadProfileCADdata(0,strRecipe); return 0; } UINT CInterfaceManager::ReadCADData_1(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); CString strRecipe = pInter->m_GlassRecipe.GetRecipeName(); pInter->ReadProfileCADdata(1,strRecipe); return 0; } UINT CInterfaceManager::ReadCADData_2(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); CString strRecipe = pInter->m_GlassRecipe.GetRecipeName(); pInter->ReadProfileCADdata(2,strRecipe); return 0; } UINT CInterfaceManager::ReadCADData_3(LPVOID pParam) { CInterfaceManager *pInter = static_cast(pParam); CString strRecipe = pInter->m_GlassRecipe.GetRecipeName(); pInter->ReadProfileCADdata(3,strRecipe); return 0; } BOOL CInterfaceManager::ReadProfileCADdata(int iSide,CString strRecipe) { g_pLog->DisplayMessage(_T("Read Profile CAD Data Start : %d"),iSide); CProfileCADProc profileproc; CString strFile,strDim; int i = iSide; std::multimap::iterator it; CPoint *pPoint; switch((DimensionDir)i) { case DIMENSION_A: strDim = _T("A"); break; case DIMENSION_B: strDim = _T("B"); break; case DIMENSION_C: strDim = _T("C"); break; case DIMENSION_D: strDim = _T("D"); break; } for(it=m_mapProfile[i].begin();it!=m_mapProfile[i].end();it++) { pPoint = it->second; if(pPoint == NULL) continue; delete pPoint; pPoint = NULL; } m_mapProfile[i].clear(); profileproc.SetProfileData(&m_mapProfile[i],NULL); strFile.Format(_T("%s\\Profile\\%s_%s.prf"),PATH_INSPECTOR,strRecipe,strDim); if(profileproc.ReadProfileData(strFile) == FALSE) { g_pLog->DisplayMessage(_T("%s Profile CAD Load Fail:%s"),PANEL_SIDE[i],strFile); } else { g_pLog->DisplayMessage(_T("%s Profile CAD Load Success:%s"),PANEL_SIDE[i],strFile); } m_ptOriginMapProfile[i]= profileproc.GetProfileOrigin(); return TRUE; } 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(m_GlassRecipe.GetRecipeName(),pCamSetting->m_nLightIdx_R,pCamSetting->m_nLightIdx_R_Ch,LIGHT_TYPE_REF,TRUE,nLightVal); Sleep(10); nLightVal = m_GlassRecipe.GetLightValue(pCamSetting->m_nLightIdx_T,pCamSetting->m_nLightIdx_T_Ch); m_pLightManager->SetLightControlValue(m_GlassRecipe.GetRecipeName(),pCamSetting->m_nLightIdx_T,pCamSetting->m_nLightIdx_T_Ch,LIGHT_TYPE_TRANS,TRUE,nLightVal); Sleep(10); } } else { CCameraSettings *pCamSetting = m_HardwareRecipe.GetCameraSettings(iCamera,0); if(pCamSetting == NULL) return; m_pLightManager->SetLightControlValue(m_GlassRecipe.GetRecipeName(),pCamSetting->m_nLightIdx_R,pCamSetting->m_nLightIdx_R_Ch,LIGHT_TYPE_REF,TRUE,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); FIBITMAP *bitmap = NULL; BYTE *pBitBuffer; CString savePath = strPath; savePath += _T(".jpg"); bitmap = FreeImage_Allocate(IMAGE_WIDTH, nLineCnt,8); pBitBuffer = FreeImage_GetBits(bitmap); if(pBitBuffer == NULL) { FreeImage_Unload(bitmap); return FALSE; } LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide,ptStart.y); if(lpImg == NULL) return FALSE; CopyMemory(pBitBuffer,lpImg,IMAGE_WIDTH*nLineCnt); USES_CONVERSION; char str_filename[1024]; sprintf_s(str_filename, "%s", W2A(savePath)); FreeImage_FlipVertical(bitmap); FreeImage_Save(FIF_JPEG, bitmap, str_filename,JPEG_FULLIMAGE_RATE); FreeImage_Unload(bitmap); return TRUE; } BOOL CInterfaceManager::SaveFullImage2(CString strPath,LPBYTE lpOrigin,int nImgWidth,int nImgHeight,int iSide,int nStartY,int nQuality /*= 80*/) { if(lpOrigin == NULL) return FALSE; if(nImgHeight < 100) { g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), Height is 0"), strPath, PANEL_SIDE[iSide], nImgHeight); return FALSE; } //g_pLog->DisplayMessage(_T("Save Full Image (%s, %s, %d) 1"), strPath, PANEL_SIDE[iSide], nImgHeight); g_pStatus->CheckDirectory(strPath); //g_pLog->DisplayMessage(_T("Save Full Image (%s, %s, %d) 2"), strPath, PANEL_SIDE[iSide], nImgHeight); int p[3]; p[0] = CV_IMWRITE_JPEG_QUALITY; p[1] = nQuality; p[2] = 0; double dCompressRatio = (double) m_HardwareRecipe.m_nFullImageCompressRatio; if(dCompressRatio < 70.0 || 90.0 < dCompressRatio) dCompressRatio = 70.0; double tmp = dCompressRatio/100.0; double dRatio = 1.-tmp; IplImage *Img = cvCreateImageHeader(cvSize(nImgWidth,nImgHeight),8,1); IplImage *img2 = cvCreateImage(cvSize((int)(nImgWidth*dRatio),(int)(nImgHeight*dRatio)),8,1); //g_pLog->DisplayMessage(_T("Save Full Image (%s, %s, %d) 3"), strPath, PANEL_SIDE[iSide], nImgHeight); if(Img == NULL || img2 == 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; } //g_pLog->DisplayMessage(_T("Save Full Image (%s, %s, %d) 4"), strPath, PANEL_SIDE[iSide], nImgHeight); cvSetData(Img,lpImg,nImgWidth); cvResize(Img,img2); USES_CONVERSION; char str_filename[200]; sprintf_s(str_filename, "%s", W2A(strPath)); cvSaveImage(str_filename,img2, p); //g_pLog->DisplayMessage(_T("Save Full Image (%s, %s, %d) 5"), strPath, PANEL_SIDE[iSide], nImgHeight); cvReleaseImage(&img2); cvReleaseImageHeader(&Img); 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* Iplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE); g_pLog->DisplayMessage(_T("Image Size: %d x %d"), Iplimg->width, Iplimg->height); if (Iplimg) { if (bIsDebugImg == true) { UINT uiReadLine = 0; //lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY); //if (lpImg != NULL) { // memcpy(lpImg, &Iplimg->imageData[0], Iplimg->widthStep * Iplimg->height); //} for (int i = 0; i < Iplimg->height; i++) { lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i); if (lpImg == NULL) break; memcpy(lpImg, &Iplimg->imageData[uiReadLine], Iplimg->widthStep); uiReadLine += Iplimg->widthStep; } if (pGlassData != NULL) { INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); if (pResInfo != NULL) { pResInfo->nGlassStartLine = 0; pResInfo->nGlassEndLine = Iplimg->height + nStartY; } } nHeight = Iplimg->height; cvReleaseImage(&Iplimg); } else { //Full image const double dRatio = 1.0 - static_cast(IMAGE_COMPRESSRATIO / 100.0); IplImage* resizeImage = cvCreateImage(cvSize((int)(Iplimg->width / dRatio), (int)(Iplimg->height / dRatio)), IPL_DEPTH_8U, 1); cvResize(Iplimg, resizeImage, CV_INTER_CUBIC); lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY); if (lpImg != NULL) { memcpy(lpImg, &Iplimg->imageData[0], resizeImage->widthStep * resizeImage->height); } //UINT uiReadLine = 0; //for (int i = 0; i < resizeImage->height; i++) { // lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i); // if (lpImg == NULL) // break; // memcpy(lpImg, &resizeImage->imageData[uiReadLine], resizeImage->widthStep); // uiReadLine += resizeImage->widthStep; //} if (pGlassData != NULL) { INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); if (pResInfo != NULL) { pResInfo->nGlassStartLine = 0; pResInfo->nGlassEndLine = Iplimg->height + nStartY; } } nHeight = resizeImage->height; cvReleaseImage(&Iplimg); cvReleaseImage(&resizeImage); } 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) { INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); if (pResInfo != NULL) { pResInfo->nGlassStartLine = 0; pResInfo->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) { INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); if (pResInfo != NULL) { pResInfo->nGlassStartLine = 0; pResInfo->nGlassEndLine = resized.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); } } BOOL CInterfaceManager::CheckExpireDay() { #if OFFLINE_KEY return TRUE; #endif CFile file; CString strPath; STU_EXPIRE_DAY stuExpire; strPath.Format(_T("C:\\Windows\\SystemConfirm.bin")); if(TRUE == file.Open(strPath,CFile::modeRead)) { if(sizeof(STU_EXPIRE_DAY) == file.Read(&stuExpire, sizeof(STU_EXPIRE_DAY))) { if(stuExpire.m_nCode != 32783762) { file.Close(); return FALSE; } } file.Close(); } else return FALSE; 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.GetTriggerBoardComport()); m_pTriggerBoardControl->Connect(m_HardwareRecipe.GetTriggerBoardComport()); } 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); } }