Демонстрирует поиск карт, уведомление о поднесении/удалении карты.
#include <stdio.h>
#include <iomanip>
#include <iostream>
#define ILR_LOG_FILE
using namespace ilr;
#ifdef ILR_LOG
const char kLogLevelChars[] = {'-', 'E', 'W', 'I', 'D'};
const char kLogFileName[] = "ilreaders.log";
#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
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
{
std::cout << "Поиск считывателя..." << std::endl;
#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] <<
": "
}
std::stringstream ss;
ss << kReaderModelNames[rInfo.
nModel];
ss <<
" с/н:" << rInfo.
nSn;
ss <<
" прошивка:" <<
ReaderVersionToStr(rInfo.
nFwVersion);
std::cout << "Считыватель успешно подключён [" << ss.str() << ']' << std::endl;
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;
}
Класс для инициализации/финализации библиотеки SDK.
Definition: ilr_cpp_helpers.h:2607
CReaderSearch GetSearch()
Создаёт дескриптор поиска считывателей.
Definition: ilr_cpp_helpers.h:2761
CReader GetReader(ilr_port_type nPortType, const char *pszPortName)
Создаёт дескриптор считывателя.
Definition: ilr_cpp_helpers.h:2767
Класс поиска считывателей.
Definition: ilr_cpp_helpers.h:583
Класс считывателя.
Definition: ilr_cpp_helpers.h:996
void SetAutoScan(bool fEnable=true, bool fWait=true)
Включает/выключает автоматическое сканирование карт.
Definition: ilr_cpp_helpers.h:2242
void SetMessageCallback(ilr_reader_message_callback pCallback, void *pUserData=nullptr)
Устанавливает функцию обратного вызова для уведомлений считывателя.
Definition: ilr_cpp_helpers.h:2175
void Connect(bool fReconnect=false)
Подключается к считывателю.
Definition: ilr_cpp_helpers.h:2197
void GetReaderInfo(ilr_reader_info &rInfo) const
Возвращает информацию о считывателе.
Definition: ilr_cpp_helpers.h:2223
ilr_reader_msg
Сообщение считывателя.
Definition: ilreaders.h:502
@ ILR_MF_PLUS_UNKNOWN
Не известно.
Definition: ilreaders.h:583
@ ILR_READER_MSG_CARD_FOUND
Definition: ilreaders.h:517
@ ILR_READER_MSG_CARD_LOST
Definition: ilreaders.h:521
@ ILR_MF_PLUS_SL_UNKNOWN
Не известно.
Definition: ilreaders.h:571
@ ILR_READER_CCID
Definition: ilreaders.h:467
Заголовочный файл SDK Readers с классами-помощниками C++.
Заголовочный файл API SDK Readers.
#define ILR_CALL
Макрос, определяющий соглашение о вызове функций.
Definition: ilreaders.h:56
ilr_log_level
Уровень лога.
Definition: ilreaders.h:319
@ ILR_LOG_LEVEL_DEBUG
Отладочные сообщения.
Definition: ilreaders.h:349
@ ILR_READER_MODEL_UNKNOWN
Definition: ilreaders.h:213
Информация о карте.
Definition: ilreaders.h:596
ilr_card_type nType
Тип карты.
Definition: ilreaders.h:597
ilr_mf_plus_sl nSL
Уровень безопасности Mifare Plus.
Definition: ilreaders.h:600
ilr_mf_plus_type nMpType
Тип Mifare Plus.
Definition: ilreaders.h:601
ilr_card_uid rUID
Номер карты.
Definition: ilreaders.h:598
Информация о считывателе.
Definition: ilreaders.h:295
ilr_reader_model nModel
Definition: ilreaders.h:304
uint32_t nFwVersion
Definition: ilreaders.h:310
const char * pszConnect
Definition: ilreaders.h:302
const char * pszPortName
Definition: ilreaders.h:299
int64_t nFwBuildDate
Definition: ilreaders.h:313
ilr_port_type nPortType
Definition: ilreaders.h:297
int nSn
Definition: ilreaders.h:306
Настройки поиска считывателей.
Definition: ilreaders.h:474
uint32_t nReaderTypes
Definition: ilreaders.h:479