📄 card_scanner.cpp
字号:
#include "inkit/jaya_reader/JayaReaderRegistry.h"#include "inkit/jaya_reader/JayaReader.h"#include "inkit/common/simu_launcher.h"#include "inkit/jaya_reader/jaya_utils.h"#include "common/str_hex.h"#include "common/jlog.h"#include "common/portability.h"#include <stdio.h>using namespace Jayacard;#include <string>#include <vector>JayaReaderRegistry * reg = JayaReaderRegistry::instance();JayaReader * rd = NULL;int please_quit = 0;void done(){ if (rd != NULL) rd->close(); printf("Done\n"); getchar(); getchar(); stop_simulator(); exit(0);}void report_error( const char * msg, jresult ret){ if (ret == JY_OK) return; printf("%s : %s\n", msg, jerror_msg(ret) ); done();}string select_rd(){ vector<string> readerList = reg->getReaderList(); printf("Choose your reader:\n"); for( int i=0; i< readerList.size(); i++) { printf("%2d: %s\n", i+1, readerList[i].c_str() ); } int idx; printf("\nYour choice (0 to exit) : "); scanf( "%d", &idx ); if (idx == 0) { done(); return string(); } return readerList[idx-1];}void card_present( JayaReader * rd ){ Block atr; jresult ret;// printf("Card present\n"); ret = rd->powerOn( atr ); printf("ATR = %s\n", atr.c_str() );}void scan_card( const char * readerName ){ jresult ret; rd = reg->getReader( readerName, &ret ); report_error( "Get Reader", ret ); ContactlessReader * cl = rd->getContactlessReader(); if (cl != NULL) { printf("ContactlessReader detected!\n"); } printf("\n%s : Scanning\n", readerName); while(1) { if (rd->isCardPresent()) { card_present( rd ); } usleep( 100 ); printf("."); if (please_quit) break; }}#ifdef WIN32BOOL WINAPI ControlHandler ( DWORD dwCtrlType ){ switch( dwCtrlType ) { case CTRL_BREAK_EVENT: /* use Ctrl+C or Ctrl+Break to simulate */ case CTRL_C_EVENT: please_quit = 1; return TRUE; default: break; } return FALSE;}#elsevoid sigint_handler(int signum){ done();}#endifint main(){ string readerName; #ifdef WIN32 SetConsoleCtrlHandler( ControlHandler, TRUE ); #else signal( SIGINT, sigint_handler ); #endif readerName = select_rd(); if (strncmp( readerName.c_str(), "SimuReader", 10 ) == 0) { launch_simulator(); } scan_card( readerName.c_str() ); done(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -