Демонстрирует поиск карт, уведомление о поднесении/удалении карты.
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include "../ilr_cpp_helpers.h"
#define ILR_LOG_FILE
using namespace ilr;
#ifdef ILR_LOG
const char kLogLevelChars[] = {'-', 'E', 'W', 'I', 'D'};
const char kLogFileName[] = "ilreaders.log";
void LogCallback(
ilr_log_level level,
const char* pContext,
const char* pMessage,
void*) {
#ifdef ILR_LOG_FILE
std::ofstream file(kLogFileName, std::ios_base::out | std::ios_base::app);
auto& out = file;
#else
auto& out = std::cout;
#endif
auto t = std::time(nullptr);
auto tmb = std::localtime(&t);
out << std::put_time(tmb, "%d-%m-%Y %H:%M:%S") << " [" << kLogLevelChars[level] << ' '
<< pContext << "] " << pMessage << std::endl;
}
#endif
void MessageCallback(
ilr_reader_msg nMsg,
const void* pMsgData,
void*) {
try {
std::stringstream ss;
ss <<
" " << kMpTypeNames[pInfo->
nMpType];
ss <<
" SL" <<
static_cast<int>(pInfo->
nSL);
std::cout <<
"{!} Карта найдена " << kCardTypeNames[pInfo->
nType] <<
' '
<< CardUIDToStr(pInfo->
nType, pInfo->
rUID) << ss.str() << std::endl;
else
std::cout <<
"{!} Карта потеряна " << kCardTypeNames[pInfo->
nType] <<
' '
<< CardUIDToStr(pInfo->
nType, pInfo->
rUID) << ss.str() << std::endl;
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
}
int main() {
try {
#ifdef ILR_LOG
#ifdef ILR_LOG_FILE
std::ofstream file(kLogFileName, std::ios_base::out | std::ios_base::trunc);
file.close();
#endif
CILR::SetLogCallback(LogCallback);
#endif
CILR oILR;
CReader oReader;
{
std::cout << "Поиск считывателя..." << std::endl;
CReaderSearch oSearch(oILR.GetSearch());
#if 0
oSearch.GetOptions(rOptions);
oSearch.SetOptions(rOptions);
#endif
oSearch.Scan();
auto nCount = oSearch.GetReaderCount();
bool fFound = false;
for (size_t i = 0; i < nCount; i++) {
oSearch.GetReaderInfo(i, rInfo);
continue;
fFound = true;
break;
}
if (!fFound) {
std::cout << "Считыватель не найден" << std::endl;
return 0;
}
std::cout <<
"Подключение к считывателю [" << kPortTypeNames[rInfo.
nPortType] <<
": "
oReader.Connect();
}
oReader.GetReaderInfo(rInfo);
std::stringstream ss;
ss << kReaderModelNames[rInfo.
nModel];
ss <<
" с/н:" << rInfo.
nSn;
ss <<
" прошивка:" << ReaderVersionToStr(rInfo.
nFwVersion);
std::cout << "Считыватель успешно подключён [" << ss.str() << ']' << std::endl;
oReader.SetMessageCallback(MessageCallback, &oReader);
oReader.SetAutoScan(true, false);
std::cout << "Ожидание поднесения карты..." << std::endl;
std::cout << "Нажмите <Enter> для выхода..." << std::endl;
std::cin.get();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
ilr_reader_msg
Сообщение считывателя.
Definition: ilreaders.h:489
@ ILR_MF_PLUS_UNKNOWN
Не известно.
Definition: ilreaders.h:570
@ ILR_READER_MSG_CARD_FOUND
Definition: ilreaders.h:504
@ ILR_READER_MSG_CARD_LOST
Definition: ilreaders.h:508
@ ILR_MF_PLUS_SL_UNKNOWN
Не известно.
Definition: ilreaders.h:558
@ ILR_READER_CCID
Definition: ilreaders.h:454
Заголовочный файл API SDK Readers.
ilr_log_level
Уровень лога.
Definition: ilreaders.h:306
@ ILR_LOG_LEVEL_DEBUG
Отладочные сообщения.
Definition: ilreaders.h:336
@ ILR_READER_MODEL_UNKNOWN
Definition: ilreaders.h:200
Информация о карте.
Definition: ilreaders.h:583
ilr_card_type nType
Тип карты.
Definition: ilreaders.h:584
ilr_mf_plus_sl nSL
Уровень безопасности Mifare Plus.
Definition: ilreaders.h:587
ilr_mf_plus_type nMpType
Тип Mifare Plus.
Definition: ilreaders.h:588
ilr_card_uid rUID
Номер карты.
Definition: ilreaders.h:585
Информация о считывателе.
Definition: ilreaders.h:282
ilr_reader_model nModel
Definition: ilreaders.h:291
uint32_t nFwVersion
Definition: ilreaders.h:297
const char * pszConnect
Definition: ilreaders.h:289
const char * pszPortName
Definition: ilreaders.h:286
int64_t nFwBuildDate
Definition: ilreaders.h:300
ilr_port_type nPortType
Definition: ilreaders.h:284
int nSn
Definition: ilreaders.h:293
Настройки поиска считывателей.
Definition: ilreaders.h:461
uint32_t nReaderTypes
Definition: ilreaders.h:466