Skip to main content

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;
ParameterTypeDescription
beepCountuint8_tNumber of beeps (1–5 for short, 1–2 for long)
durationRikProtocol::BEEP_DURATIONBEEP_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;
ParameterTypeDescription
volumeRikProtocol::BeepVolume&Output: current volume level

SetBeeperVolume

void SetBeeperVolume(RikProtocol::BeepVolume volume) const;
ParameterTypeDescription
volumeRikProtocol::BeepVolumeDesired 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;
ParameterTypeDescription
cardDataCardData&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;
ParameterTypeDescription
cardTypesstd::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);
ParameterTypeDescription
callbackstd::function<void(CardData&)>Function called with card data when a credential is detected

Returns: Subscription ID used to unsubscribe later.

tip

Multiple callbacks can be registered simultaneously. Each receives an independent subscription ID.

UnsubscribeCredentialCallback

Removes a previously registered credential callback.

void UnsubscribeCredentialCallback(uint32_t subscriptionId);
ParameterTypeDescription
subscriptionIduint32_tID 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;
ParameterTypeDescription
configurationNumberuint8_tConfiguration slot number
configurationRikCommon::ReaderConfiguration&Output: reader configuration
extendedConfigurationRikCommon::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;
ParameterTypeDescription
configurationNumberuint8_tConfiguration slot number
configurationconst RikCommon::ReaderConfiguration&Configuration to write
extendedConfigurationconst RikCommon::ExtendedConfiguration&Extended configuration to write
hashDataconst 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;
ParameterTypeDescription
checkpointTypeCheckpointTypeType 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;
ParameterTypeDescription
fileNameconst 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);
ParameterTypeDescription
fileNameconst std::string&Output file path for the HWG data
secureHwgFormatboolIf true (default), writes AES-128 encrypted format

WriteSmartCardConfigurationToReader

Writes a smart card configuration file to the reader.

void WriteSmartCardConfigurationToReader(const std::string& fileName) const;
ParameterTypeDescription
fileNameconst 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;
ParameterTypeDescription
baudRateRikCommon::SerialPortBaudRateDesired baud rate

LED Configuration

GetLedConfiguration

Reads LED configuration from a specific slot.

void GetLedConfiguration(
uint8_t configurationNumber,
LedConfiguration& ledConfiguration) const;
ParameterTypeDescription
configurationNumberuint8_tConfiguration slot number
ledConfigurationLedConfiguration&Output: LED configuration

SetLedConfiguration

Writes LED configuration to a specific slot.

void SetLedConfiguration(
uint8_t configurationNumber,
const LedConfiguration& ledConfiguration) const;
ParameterTypeDescription
configurationNumberuint8_tConfiguration slot number
ledConfigurationconst 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;
ParameterTypeDescription
luidInformationRikProtocol::LuidResponseInformation&Output: LUID information

SetLuid

Sets the Logical Unit ID of the reader.

void SetLuid(uint16_t luid) const;
ParameterTypeDescription
luiduint16_tLogical 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;
ParameterTypeDescription
moduleIdRikProtocol::ReaderModuleIdModule to query
stateRikProtocol::ReaderModuleState&Output: current module state

SetModuleState

Sets the state of a reader module.

void SetModuleState(
RikProtocol::ReaderModuleId moduleId,
RikProtocol::ReaderModuleState state) const;
ParameterTypeDescription
moduleIdRikProtocol::ReaderModuleIdModule to configure
stateRikProtocol::ReaderModuleStateDesired 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;
ParameterTypeDescription
enablebooltrue 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);
ParameterTypeDescription
dataTypeRikCommon::BleDataTypeType of BLE data to read
fileNameconst 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;
ParameterTypeDescription
dataTypeRikCommon::BleDataTypeType of BLE data to write
fileNameconst 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;
}
}

See Also