風
風
Unregistered / Unconfirmed
GUEST, unregistred user!
DWORD WINAPIdo
ProcThread(LPVOID p ){ CWriteTagDlg *pDlg = (CWriteTagDlg*)p; BYTE pEPCData[200]; int reReadTimes=0; while( !bTheadExit ) { BYTE antenna =1; bExit = false; while(!SAAT_Auto_CheckPauseKey(pDlg->m_pHandle,antenna)) { if(bExit || bTheadExit ) break; else
{ Sleep(3000); continue; } } TRACE("%s/n","進入等待/n");// if( WAIT_OBJECT_0 == WaitForSingleObject(hRecvSingle,INFINITE) )// { TRACE("%s/n","等待完了/n"); //發送讀卡命令 Sleep(2000); if(!SAAT_6CReadEPCCode(pDlg->m_pHandle,antenna,0x01,1)) { MessageBox(NULL,"發送讀卡命令失敗,請重啟程序!","提示",MB_OK); bTheadExit=true; continue; } TRACE("%s/n","發送讀卡命令成功/n"); //開始讀卡 ZeroMemory(pEPCData,200); BYTE pEPCLength = 200; CString strEpc; bool bWriteState = false; while( !bExit) { strEpc = ""; bWriteState = false; int readEPCSucceed=SAAT_6CRevEPCMsg(pDlg->m_pHandle,&antenna,pEPCData,&pEPCLength); TRACE("讀卡返回:%d ,長度:%d/n",readEPCSucceed,pEPCLength); if( 1 == readEPCSucceed && pEPCLength == 0 ) { SAAT_PowerOff(pDlg->m_pHandle);// 有異常了 bExit = true; break; } if(1 == readEPCSucceed && pEPCLength != 0 ) { for( int i = 0 ;i < pEPCLength ;i ++) { CString strTemp ; strTemp.Format("%02x",pEPCData); strEpc +=strTemp; } //來一張寫一張 EpcIter iter; //if ((iter=m_mapReadEpcCard.find(strEpc)) != m_mapReadEpcCard.end()) //{ // continue; //}// 注銷掉是否已發卡的判斷-11-30 ////新寫入的卡不理// if ((iter=m_mapWriteEpcCard.find(strEpc)) != m_mapWriteEpcCard.end())// { // continue;// }//結束注銷-11-30 //Beep(1000,50); TRACE("%s","讀到卡了/n"); //1.讀到一張,停止讀卡 SAAT_PowerOff(pDlg->m_pHandle); TRACE("%s","關閉讀卡/n"); //Sleep(1000); //2.寫卡操作 int nSize = pDlg->m_strNowWriteCard.GetLength(); TRACE("卡號長度:%d/n",nSize); BYTE nType = 0x00; BYTE btPsw[4] ={0,0,0,0}; BYTE btEcp[52]; memcpy(btEcp,(char*)(LPCTSTR)pDlg->m_strNowWriteCard,nSize); int reWriteTimes=0; for(reWriteTimes = 0 ;
reWriteTimes < pDlg->m_nReWriteCount ;
reWriteTimes++ ) { bWriteState = SAAT_6CWriteEPCCode ( pDlg->m_pHandle, 1, nType, btPsw, btEcp, nSize ); if( bWriteState ) { Beep(3500, 50); //Sleep(3000); bool pushcard=SAAT_Auto_Push_OK(pDlg->m_pHandle,antenna); if(pushcard) TRACE("%s/n","發卡成功吐卡成功!/n"); else
TRACE("%s/n","發卡成功吐卡失敗!/n"); break; } Sleep(200); } //判斷是否循環了最大次數,如果是最大次數就說明連續多次發卡失敗,直接吐出卡片 if(reWriteTimes>=pDlg->m_nReWriteCount) { bool pushcard=SAAT_Auto_Push(pDlg->m_pHandle,antenna); TRACE("連續發卡%d次失敗,直接吐出卡片/n",reWriteTimes); if(pushcard) TRACE("%s/n","發卡失敗吐卡成功/n"); else
TRACE("%s/n","發卡失敗吐卡失敗/n"); } //3.完成發消息 SendMessage(pDlg->m_hWnd,WM_INSERT_LIST,(WPARAM)bWriteState,(LPARAM)&strEpc); TRACE("%s/n","操作完,發消息了/n"); bExit = true;// Sleep(1500);}/[= } reReadTimes++; if(0 == readEPCSucceed && reReadTimes>16)//長時間沒讀到卡 { SAAT_PowerOff(pDlg->m_pHandle);// 有異常了 bool checkcard=SAAT_Auto_CheckCard(pDlg->m_pHandle,antenna); if(checkcard)//有卡,是死卡 { bool pushcard=SAAT_Auto_Push(pDlg->m_pHandle,antenna); TRACE("有壞卡,直接吐出卡片/n"); if(pushcard) TRACE("%s/n","有壞卡,吐卡成功"); else
TRACE("%s/n","有壞卡,吐卡失敗"); bExit = true; } else
//沒卡,就檢查卡箱有沒卡 { bool checkcardbox=true; TRACE("%s/n","讀卡位置沒卡,檢查卡箱"); while(checkcardbox) { bool checkcardbox=SAAT_Auto_CheckCardBox(pDlg->m_pHandle,antenna); if(bTheadExit || checkcardbox) { TRACE("%s/n","卡箱有卡或程序要求退出"); bExit = true; break;//卡箱有卡 } if(!checkcardbox) { TRACE("%s/n","卡箱無卡,等待再查詢卡箱"); Sleep(2000); } } } reReadTimes=0; } Sleep(20); } //} Sleep(20); } SetEvent(hThreadExitEvent); TRACE("%s/n","線程退出了..."); return 0;}
ProcThread(LPVOID p ){ CWriteTagDlg *pDlg = (CWriteTagDlg*)p; BYTE pEPCData[200]; int reReadTimes=0; while( !bTheadExit ) { BYTE antenna =1; bExit = false; while(!SAAT_Auto_CheckPauseKey(pDlg->m_pHandle,antenna)) { if(bExit || bTheadExit ) break; else
{ Sleep(3000); continue; } } TRACE("%s/n","進入等待/n");// if( WAIT_OBJECT_0 == WaitForSingleObject(hRecvSingle,INFINITE) )// { TRACE("%s/n","等待完了/n"); //發送讀卡命令 Sleep(2000); if(!SAAT_6CReadEPCCode(pDlg->m_pHandle,antenna,0x01,1)) { MessageBox(NULL,"發送讀卡命令失敗,請重啟程序!","提示",MB_OK); bTheadExit=true; continue; } TRACE("%s/n","發送讀卡命令成功/n"); //開始讀卡 ZeroMemory(pEPCData,200); BYTE pEPCLength = 200; CString strEpc; bool bWriteState = false; while( !bExit) { strEpc = ""; bWriteState = false; int readEPCSucceed=SAAT_6CRevEPCMsg(pDlg->m_pHandle,&antenna,pEPCData,&pEPCLength); TRACE("讀卡返回:%d ,長度:%d/n",readEPCSucceed,pEPCLength); if( 1 == readEPCSucceed && pEPCLength == 0 ) { SAAT_PowerOff(pDlg->m_pHandle);// 有異常了 bExit = true; break; } if(1 == readEPCSucceed && pEPCLength != 0 ) { for( int i = 0 ;i < pEPCLength ;i ++) { CString strTemp ; strTemp.Format("%02x",pEPCData); strEpc +=strTemp; } //來一張寫一張 EpcIter iter; //if ((iter=m_mapReadEpcCard.find(strEpc)) != m_mapReadEpcCard.end()) //{ // continue; //}// 注銷掉是否已發卡的判斷-11-30 ////新寫入的卡不理// if ((iter=m_mapWriteEpcCard.find(strEpc)) != m_mapWriteEpcCard.end())// { // continue;// }//結束注銷-11-30 //Beep(1000,50); TRACE("%s","讀到卡了/n"); //1.讀到一張,停止讀卡 SAAT_PowerOff(pDlg->m_pHandle); TRACE("%s","關閉讀卡/n"); //Sleep(1000); //2.寫卡操作 int nSize = pDlg->m_strNowWriteCard.GetLength(); TRACE("卡號長度:%d/n",nSize); BYTE nType = 0x00; BYTE btPsw[4] ={0,0,0,0}; BYTE btEcp[52]; memcpy(btEcp,(char*)(LPCTSTR)pDlg->m_strNowWriteCard,nSize); int reWriteTimes=0; for(reWriteTimes = 0 ;
reWriteTimes < pDlg->m_nReWriteCount ;
reWriteTimes++ ) { bWriteState = SAAT_6CWriteEPCCode ( pDlg->m_pHandle, 1, nType, btPsw, btEcp, nSize ); if( bWriteState ) { Beep(3500, 50); //Sleep(3000); bool pushcard=SAAT_Auto_Push_OK(pDlg->m_pHandle,antenna); if(pushcard) TRACE("%s/n","發卡成功吐卡成功!/n"); else
TRACE("%s/n","發卡成功吐卡失敗!/n"); break; } Sleep(200); } //判斷是否循環了最大次數,如果是最大次數就說明連續多次發卡失敗,直接吐出卡片 if(reWriteTimes>=pDlg->m_nReWriteCount) { bool pushcard=SAAT_Auto_Push(pDlg->m_pHandle,antenna); TRACE("連續發卡%d次失敗,直接吐出卡片/n",reWriteTimes); if(pushcard) TRACE("%s/n","發卡失敗吐卡成功/n"); else
TRACE("%s/n","發卡失敗吐卡失敗/n"); } //3.完成發消息 SendMessage(pDlg->m_hWnd,WM_INSERT_LIST,(WPARAM)bWriteState,(LPARAM)&strEpc); TRACE("%s/n","操作完,發消息了/n"); bExit = true;// Sleep(1500);}/[= } reReadTimes++; if(0 == readEPCSucceed && reReadTimes>16)//長時間沒讀到卡 { SAAT_PowerOff(pDlg->m_pHandle);// 有異常了 bool checkcard=SAAT_Auto_CheckCard(pDlg->m_pHandle,antenna); if(checkcard)//有卡,是死卡 { bool pushcard=SAAT_Auto_Push(pDlg->m_pHandle,antenna); TRACE("有壞卡,直接吐出卡片/n"); if(pushcard) TRACE("%s/n","有壞卡,吐卡成功"); else
TRACE("%s/n","有壞卡,吐卡失敗"); bExit = true; } else
//沒卡,就檢查卡箱有沒卡 { bool checkcardbox=true; TRACE("%s/n","讀卡位置沒卡,檢查卡箱"); while(checkcardbox) { bool checkcardbox=SAAT_Auto_CheckCardBox(pDlg->m_pHandle,antenna); if(bTheadExit || checkcardbox) { TRACE("%s/n","卡箱有卡或程序要求退出"); bExit = true; break;//卡箱有卡 } if(!checkcardbox) { TRACE("%s/n","卡箱無卡,等待再查詢卡箱"); Sleep(2000); } } } reReadTimes=0; } Sleep(20); } //} Sleep(20); } SetEvent(hThreadExitEvent); TRACE("%s/n","線程退出了..."); return 0;}