Reader (C++)
Application class for rf IDEAS readers. Extends AbstractReader with reader-specific functionality.
Namespace
namespace Rik
Class Definition
class Reader final : public AbstractReader
All methods throw ReaderException on failure unless otherwise noted.
Creating an Instance
ReaderDefinition readerDef;
readerDef.DeviceId.VendorId = 0x0C27;
readerDef.DeviceId.ProductId = 0x3BFA;
readerDef.ProtocolType = PROTOCOL_TYPE_FEATURE_REPORT;
auto handle = AbstractReader::CreateReaderInstance(readerDef, 3);
auto* reader = static_cast<Reader*>(
AbstractReader::GetInstance(handle)
);
reader->Init();
Initialization
Init
void Init() override;
Initializes the reader connection. Must be called before any other instance methods. Sets up the reader-specific capability profile and establishes communication.
Beeper
Beep
void Beep(uint8_t beepCount, RikProtocol::BEEP_DURATION duration) const;
| Parameter | Type | Description |
|---|---|---|
beepCount | uint8_t | Number of beeps (1–5 for short, 1–2 for long) |
duration | RikProtocol::BEEP_DURATION | BEEP_DURATION_SHORT or BEEP_DURATION_LONG |
reader->Beep(2, RikProtocol::BEEP_DURATION_SHORT);
reader->Beep(1, RikProtocol::BEEP_DURATION_LONG);
GetBeeperVolume
void GetBeeperVolume(RikProtocol::BeepVolume& volume) const;
| Parameter | Type | Description |
|---|---|---|
volume | RikProtocol::BeepVolume& | Output: current volume level |
SetBeeperVolume
void SetBeeperVolume(RikProtocol::BeepVolume volume) const;
| Parameter | Type | Description |
|---|---|---|
volume | RikProtocol::BeepVolume | Desired volume level |
// Read current volume
RikProtocol::BeepVolume volume;
reader->GetBeeperVolume(volume);
// Set volume to high
reader->SetBeeperVolume(RikProtocol::BEEP_VOLUME_HIGH);
Card Data
GetCardData
Reads the current card data from the reader.
void GetCardData(CardData& cardData) const;
| Parameter | Type | Description |
|---|---|---|
cardData | CardData& | Output: card data read from the reader |
CardData cardData;
reader->GetCardData(cardData);
GetSupportedCardTypes
Retrieves the list of card types supported by the reader.
void GetSupportedCardTypes(std::vector<RikCommon::CardType>& cardTypes) const;
| Parameter | Type | Description |
|---|---|---|
cardTypes | std::vector<RikCommon::CardType>& | Output: supported card types |
OnCredentialPresented
Registers a callback that fires when a card is presented to the reader. The library polls for card data on a background thread and invokes the callback on the leading edge of card presence.
uint32_t OnCredentialPresented(std::function<void(CardData&)> callback);
| Parameter | Type | Description |
|---|---|---|
callback | std::function<void(CardData&)> | Function called with card data when a credential is detected |
Returns: Subscription ID used to unsubscribe later.
Multiple callbacks can be registered simultaneously. Each receives an independent subscription ID.
UnsubscribeCredentialCallback
Removes a previously registered credential callback.
void UnsubscribeCredentialCallback(uint32_t subscriptionId);
| Parameter | Type | Description |
|---|---|---|
subscriptionId | uint32_t | ID returned by OnCredentialPresented |
// Register a credential callback
auto subId = reader->OnCredentialPresented([](CardData& card) {
std::cout << "Card detected: " << card.AsString() << std::endl;
});
// Later, unsubscribe
reader->UnsubscribeCredentialCallback(subId);
Reader Configuration
Readers support multiple configuration slots, typically numbered 0 through 3. Each slot stores independent settings such as card type, bit format, and keystroke behavior. The total number of slots varies per reader and is reported by ConfigurationCount in reader metadata. Only one slot is active at a time.
GetReaderConfiguration
Reads configuration from a specific slot.
void GetReaderConfiguration(
uint8_t configurationNumber,
RikCommon::ReaderConfiguration& configuration,
RikCommon::ExtendedConfiguration& extendedConfiguration) const;
| Parameter | Type | Description |
|---|---|---|
configurationNumber | uint8_t | Configuration slot number |
configuration | RikCommon::ReaderConfiguration& | Output: reader configuration |
extendedConfiguration | RikCommon::ExtendedConfiguration& | Output: extended configuration |
SetReaderConfiguration
Writes configuration to a specific slot.
void SetReaderConfiguration(
uint8_t configurationNumber,
const RikCommon::ReaderConfiguration& configuration,
const RikCommon::ExtendedConfiguration& extendedConfiguration,
const RikCommon::HashData& hashData) const;
| Parameter | Type | Description |
|---|---|---|
configurationNumber | uint8_t | Configuration slot number |
configuration | const RikCommon::ReaderConfiguration& | Configuration to write |
extendedConfiguration | const RikCommon::ExtendedConfiguration& | Extended configuration to write |
hashData | const RikCommon::HashData& | Contains two 16-byte AES keys (Key A and Key B) used for hashing card ID data during keystroking in extended mode |
// Read configuration from slot 0
RikCommon::ReaderConfiguration config;
RikCommon::ExtendedConfiguration extConfig;
reader->GetReaderConfiguration(0, config, extConfig);
// Modify and write back
RikCommon::HashData hashData;
reader->SetReaderConfiguration(0, config, extConfig, hashData);
ResetReaderConfiguration
Resets configuration to a checkpoint.
void ResetReaderConfiguration(CheckpointType checkpointType) const;
| Parameter | Type | Description |
|---|---|---|
checkpointType | CheckpointType | Type of configuration reset to perform |
WriteUserDefaultsToReader
Writes user default configuration to the reader.
void WriteUserDefaultsToReader() const;
WriteHwgFileToReader
Writes a HWG configuration file (.hwg+) to the reader. HWG files are text-based configuration templates that store one configuration per slot, with optional CRC validation. The number of configurations in the file must match the reader's ConfigurationCount.
void WriteHwgFileToReader(const std::string& fileName) const;
| Parameter | Type | Description |
|---|---|---|
fileName | const std::string& | Path to the HWG file |
ReadHwgFileFromReader
Reads the current configuration from the reader into an HWG file.
void ReadHwgFileFromReader(const std::string& fileName, bool secureHwgFormat = true);
| Parameter | Type | Description |
|---|---|---|
fileName | const std::string& | Output file path for the HWG data |
secureHwgFormat | bool | If true (default), writes AES-128 encrypted format |
WriteSmartCardConfigurationToReader
Writes a smart card configuration file to the reader.
void WriteSmartCardConfigurationToReader(const std::string& fileName) const;
| Parameter | Type | Description |
|---|---|---|
fileName | const std::string& | Path to the smart card configuration file |
ConfigureBaudRate
Configures the serial port baud rate for the reader.
void ConfigureBaudRate(RikCommon::SerialPortBaudRate baudRate) const;
| Parameter | Type | Description |
|---|---|---|
baudRate | RikCommon::SerialPortBaudRate | Desired baud rate |
LED Configuration
GetLedConfiguration
Reads LED configuration from a specific slot.
void GetLedConfiguration(
uint8_t configurationNumber,
LedConfiguration& ledConfiguration) const;
| Parameter | Type | Description |
|---|---|---|
configurationNumber | uint8_t | Configuration slot number |
ledConfiguration | LedConfiguration& | Output: LED configuration |
SetLedConfiguration
Writes LED configuration to a specific slot.
void SetLedConfiguration(
uint8_t configurationNumber,
const LedConfiguration& ledConfiguration) const;
| Parameter | Type | Description |
|---|---|---|
configurationNumber | uint8_t | Configuration slot number |
ledConfiguration | const LedConfiguration& | LED configuration to write |
// Read LED configuration from slot 0
LedConfiguration ledConfig;
reader->GetLedConfiguration(0, ledConfig);
// Modify and write back
reader->SetLedConfiguration(0, ledConfig);
LUID (Logical Unit ID)
The LUID is a 16-bit identifier (0x0000--0xFFFF) stored on the reader. It can be used to distinguish individual readers in multi-reader deployments. The LUID is persisted to flash when the configuration is written.
GetLuid
Gets the Logical Unit ID of the reader.
void GetLuid(RikProtocol::LuidResponseInformation& luidInformation) const;
| Parameter | Type | Description |
|---|---|---|
luidInformation | RikProtocol::LuidResponseInformation& | Output: LUID information |
SetLuid
Sets the Logical Unit ID of the reader.
void SetLuid(uint16_t luid) const;
| Parameter | Type | Description |
|---|---|---|
luid | uint16_t | Logical Unit ID to set |
// Read LUID
RikProtocol::LuidResponseInformation luidInfo;
reader->GetLuid(luidInfo);
// Set LUID
reader->SetLuid(42);
Module State
GetModuleState
Gets the state of a reader module.
void GetModuleState(
RikProtocol::ReaderModuleId moduleId,
RikProtocol::ReaderModuleState& state) const;
| Parameter | Type | Description |
|---|---|---|
moduleId | RikProtocol::ReaderModuleId | Module to query |
state | RikProtocol::ReaderModuleState& | Output: current module state |
SetModuleState
Sets the state of a reader module.
void SetModuleState(
RikProtocol::ReaderModuleId moduleId,
RikProtocol::ReaderModuleState state) const;
| Parameter | Type | Description |
|---|---|---|
moduleId | RikProtocol::ReaderModuleId | Module to configure |
state | RikProtocol::ReaderModuleState | Desired module state |
Operating Modes
EnableKeystroking
Enables or disables keystroking output mode. When keystroking is enabled, the reader emulates an HID keyboard and "types" card ID data as keystrokes to the host computer. Disabling keystroking is typical when using the SDK to read card data programmatically. This setting is applied across all configuration slots.
void EnableKeystroking(bool enable) const;
| Parameter | Type | Description |
|---|---|---|
enable | bool | true to enable, false to disable |
BLE Configuration
ReadBleConfigurationFromReader
Reads BLE configuration from the reader and saves it to a file.
void ReadBleConfigurationFromReader(
RikCommon::BleDataType dataType,
const std::string& fileName);
| Parameter | Type | Description |
|---|---|---|
dataType | RikCommon::BleDataType | Type of BLE data to read |
fileName | const std::string& | Output file path |
WriteBleConfigurationToReader
Writes BLE configuration from a file to the reader.
void WriteBleConfigurationToReader(
RikCommon::BleDataType dataType,
const std::string& fileName) const;
| Parameter | Type | Description |
|---|---|---|
dataType | RikCommon::BleDataType | Type of BLE data to write |
fileName | const std::string& | Path to the BLE configuration file |
// Read BLE configuration to file
reader->ReadBleConfigurationFromReader(
RikCommon::BleDataType::Data, "ble_config.hwg+");
// Write BLE configuration from file
reader->WriteBleConfigurationToReader(
RikCommon::BleDataType::Data, "ble_config.hwg+");
Complete Example
#include <iostream>
#include "Reader/Reader.h"
int main() {
using namespace Rik;
using namespace RikCommon;
ReaderHandle handle = nullptr;
try {
// Setup
ReaderDefinition readerDef;
readerDef.DeviceId.VendorId = 0x0C27;
readerDef.DeviceId.ProductId = 0x3BFA;
readerDef.ProtocolType = PROTOCOL_TYPE_FEATURE_REPORT;
handle = AbstractReader::CreateReaderInstance(readerDef, 3);
auto* reader = static_cast<Reader*>(
AbstractReader::GetInstance(handle)
);
reader->Init();
// Metadata
auto metadata = reader->GetMetadataStruct();
std::cout << "Connected: " << metadata.PartNumber << std::endl;
// Beep twice
reader->Beep(2, RikProtocol::BEEP_DURATION_SHORT);
// Read and set beeper volume
RikProtocol::BeepVolume volume;
reader->GetBeeperVolume(volume);
reader->SetBeeperVolume(RikProtocol::BEEP_VOLUME_HIGH);
// Read card data
CardData cardData;
reader->GetCardData(cardData);
// Read configuration from slot 0
RikCommon::ReaderConfiguration config;
RikProtocol::ExtendedConfiguration extConfig;
reader->GetReaderConfiguration(0, config, extConfig);
// Read LED configuration
LedConfiguration ledConfig;
reader->GetLedConfiguration(0, ledConfig);
// Read LUID
RikProtocol::LuidResponseInformation luidInfo;
reader->GetLuid(luidInfo);
// Cleanup
reader->Close();
AbstractReader::DestroyInstance(handle);
handle = nullptr;
return 0;
} catch (const ReaderException& e) {
std::cerr << "Error: " << e.Message << std::endl;
if (handle) {
AbstractReader::DestroyInstance(handle);
}
return 1;
}
}