Skip to main content

AbstractReader (C++)

Base class for all RIK reader application instances. Provides factory methods for instance creation and common reader operations.

Namespace

namespace Rik

Handle Type

typedef void* ReaderHandle;

An opaque handle representing an application instance. Returned by factory methods and used to retrieve or destroy instances.

Static Methods

CreateReaderInstance

Creates a reader instance.

static ReaderHandle CreateReaderInstance(
const RikCommon::ReaderDefinition& readerDefinition,
int retryCount = 3);
ParameterTypeDescription
readerDefinitionconst RikCommon::ReaderDefinition&Reader connection parameters (VID, PID, protocol)
retryCountintConnection retry attempts (default: 3)

Returns: ReaderHandle to the created instance.

Throws: ReaderException if the instance cannot be created.

DestroyInstance

Destroys an application instance and releases all associated resources.

static void DestroyInstance(ReaderHandle handle);
ParameterTypeDescription
handleReaderHandleHandle to the instance to destroy
warning

Always call Close() on the instance before calling DestroyInstance().

GetInstance

Retrieves the application object pointer from a handle.

static AbstractReader* GetInstance(ReaderHandle handle);
ParameterTypeDescription
handleReaderHandleHandle returned by a Create method

Returns: Pointer to the AbstractReader instance. Cast to the appropriate subclass (Reader*) to access reader-specific methods.

GetLibraryInfo

Retrieves RIK library version information.

static RikResult GetLibraryInfo(LibraryInfo& info);
ParameterTypeDescription
infoLibraryInfo&Output parameter populated with version data

Returns: RikResult indicating success or failure.

LibraryInfo info;
auto result = AbstractReader::GetLibraryInfo(info);
if (!result.HasException) {
std::cout << "Version: " << info.VersionString << std::endl;
}

GetLibraryInfoAsString

Retrieves a pre-formatted string representation of the library version information.

static RikResult GetLibraryInfoAsString(char* infoString, size_t bufferSize);
ParameterTypeDescription
infoStringchar*Output buffer for the formatted info string
bufferSizesize_tSize of the output buffer

Returns: RikResult indicating success or failure.

Instance Methods

Init

Initializes the connection to the reader device.

virtual void Init();

Throws: ReaderException on connection failure.

Must be called before any other instance method. Establishes communication and populates the capability profile.

Close

Closes the connection to the reader device.

virtual void Close();

Releases communication resources. Call before DestroyInstance().

RefreshMetadata

Forces a refresh of cached metadata by querying the device.

void RefreshMetadata();

GetMetadataStruct

Returns reader metadata (part number, serial number, firmware version, etc.).

ReaderMetadataStruct GetMetadataStruct(bool forceRefresh = false);
ParameterTypeDescription
forceRefreshboolIf true, bypasses cache and queries the device

Returns: ReaderMetadataStruct containing reader metadata fields.

GetReaderCapabilityProfile

Returns the capability profile describing what features the connected reader supports.

virtual const ReaderCapabilityProfile& GetReaderCapabilityProfile() const;

Returns: Const reference to the ReaderCapabilityProfile for the connected reader.

Complete Example

#include <iostream>
#include "Reader/AbstractReader.h"

int main() {
using namespace Rik;
using namespace RikCommon;

ReaderHandle handle = nullptr;

try {
// Configure reader connection
ReaderDefinition readerDef;
readerDef.DeviceId.VendorId = 0x0C27;
readerDef.DeviceId.ProductId = 0x3BFA;
readerDef.ProtocolType = PROTOCOL_TYPE_FEATURE_REPORT;

// Create and initialize
handle = AbstractReader::CreateReaderInstance(readerDef, 3);
auto* app = AbstractReader::GetInstance(handle);
app->Init();

// Read metadata
auto metadata = app->GetMetadataStruct();
std::cout << "Part: " << metadata.PartNumber << std::endl;
std::cout << "Serial: " << metadata.ESN << std::endl;

// Check capabilities
auto caps = app->GetReaderCapabilityProfile();

// Force-refresh metadata from device
auto fresh = app->GetMetadataStruct(true);

// Clean shutdown
app->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;
}
}

Thread Safety

All methods are thread-safe. Internal locking ensures safe concurrent access from multiple threads.


ReaderDiscovery (C++)

Utility class for discovering connected rf IDEAS USB readers. Returns ready-to-use ReaderDefinition objects that can be passed directly to AbstractReader::CreateReaderInstance.

Namespace

namespace Rik
#include "Reader/ReaderDiscovery.h"

Static Methods

DiscoverUsbReaders

Discovers all connected rf IDEAS USB readers.

[[nodiscard]] static std::vector<RikCommon::ReaderDefinition> DiscoverUsbReaders();

Returns: Vector of ReaderDefinition objects, one per discovered reader. Each has DeviceId.VendorId, DeviceId.ProductId, DeviceId.UsbPath, DeviceId.SerialNumber, and ProtocolType populated.

Throws: ReaderException if USB enumeration fails.

#include "Reader/ReaderDiscovery.h"

auto readers = Rik::ReaderDiscovery::DiscoverUsbReaders();

for (const auto& readerDef : readers) {
std::cout << "VID:PID: " << std::hex
<< readerDef.DeviceId.VendorId << ":"
<< readerDef.DeviceId.ProductId << std::dec << "\n";
std::cout << "Path: " << readerDef.DeviceId.UsbPath << "\n";
std::cout << "Serial: " << readerDef.DeviceId.SerialNumber << "\n\n";

// Connect directly using the returned ReaderDefinition
auto handle = AbstractReader::CreateReaderInstance(readerDef, 3);
// ...
}
note

ReaderDiscovery is a utility class with no constructors -- all methods are static. For the C API equivalent, see Rik_DiscoverUsbReaders.

See Discovering USB Readers for full examples including the C API two-call pattern and platform-specific alternatives.

See Also