Skip to main content

C# API

The C# facade wraps the RIK native library in idiomatic .NET classes with IDisposable support and managed exceptions.

Installation

dotnet add package rfIDEAS.ReaderIntegrationKit
note

The NuGet package includes pre-built native libraries for Windows x64, Linux x64, Linux ARM64, Linux ARMhf, and macOS (Intel + Apple Silicon, Monterey 12+). No additional native library setup is needed. The package targets .NET 8.0 and .NET 10.0.

Supported platforms

PlatformRuntime identifierNative library path (inside package)
Windows x64win-x64runtimes/win-x64/native/ReaderIntegrationKit.dll
Linux x64linux-x64runtimes/linux-x64/native/libReaderIntegrationKit.so
Linux ARM64 (generic)linux-arm64runtimes/linux-arm64/native/libReaderIntegrationKit.so
Linux ARM64 (Raspberry Pi 5)linux-arm64runtimes/linux-arm64/native/libReaderIntegrationKit.pi5.so
Linux ARM 32-bit (ARMhf)linux-armruntimes/linux-arm/native/libReaderIntegrationKit.so
macOS x64osx-x64runtimes/osx-x64/native/libReaderIntegrationKit.dylib
macOS ARM64 (Apple Silicon)osx-arm64runtimes/osx-arm64/native/libReaderIntegrationKit.dylib
macOS universal fallback

The package also includes the same dylib at runtimes/osx-universal/native/libReaderIntegrationKit.dylib. The NativeLibraryLocator in the C# facade probes the RID-specific path (osx-x64 or osx-arm64) first and falls back to osx-universal automatically. Consumer projects do not need to reference osx-universal directly.

ARM64: generic vs Raspberry Pi 5

The package ships two ARM64 builds under runtimes/linux-arm64/native/:

  • libReaderIntegrationKit.so — portable aarch64 build for any ARMv8-A device
  • libReaderIntegrationKit.pi5.so — build optimized for Raspberry Pi 5 (-mcpu=cortex-a76)

At runtime the loader uses the RIK_ARM_VARIANT environment variable when set (pi5 or generic); otherwise it reads /proc/device-tree/model and falls back to generic. Set RIK_ARM_VARIANT=pi5 to force the Pi 5 build, or generic for the portable build.

Namespace

using rfIDEAS.ReaderIntegrationKit;
using rfIDEAS.ReaderIntegrationKit.Objects;
using rfIDEAS.ReaderIntegrationKit.Enum;

AbstractReader (abstract)

Base class for all reader applications. Implements IDisposable.

Methods

MethodReturnsDescription
Init()voidInitialize connection to the reader
RefreshMetadata()voidForce a metadata refresh from the device
GetMetadata(bool forceRefresh = false)ReaderMetadataStructGet reader metadata (cached unless forceRefresh is true)
GetLibraryInfo()LibraryInfoStatic. Get library version info (no instance required)
Dispose()voidRelease native resources

Reader : AbstractReader

Application class for rf IDEAS readers.

Constructor

new Reader(ReaderDefinition readerDefinition, int retryCount = 3)
ParameterTypeDescription
readerDefinitionReaderDefinitionReader connection parameters
retryCountintConnection retry attempts (default: 3)

Methods

Beeper

MethodReturnsDescription
Beep(int beepCount, BeepDuration duration)voidSound the beeper
GetBeeperVolume()BeepVolumeGet current volume
SetBeeperVolume(BeepVolume volume)voidSet volume

Card Data

MethodReturnsDescription
GetCardData(out CardData cardData, GetCardDataSizeParameters sizeParameter = GetCardDataSizeParameters.Read32Bytes)voidRead card data from the reader
8-byte reads truncate silently

GetCardDataSizeParameters.Read8Bytes returns at most the first 8 bytes of the credential. The CardData buffer is still 32 bytes: bytes 0–7 hold the returned data and bytes 8–31 are zero. BitCount always reports the full credential width, so a bit count greater than 64 means the card carries more data than was returned. Prefer GetCardDataSizeParameters.Read32Bytes. See GetCardDataSizeParameters.

Credential Callbacks

MethodReturnsDescription
OnCredentialPresented(CredentialCallback callback, GetCardDataSizeParameters sizeParameter = GetCardDataSizeParameters.Read32Bytes)uintSubscribe to credential events. Returns a subscription ID.
UnsubscribeCredentialCallback(uint subscriptionId)voidUnsubscribe a previously registered callback

The CredentialCallback delegate is defined as:

public delegate void CredentialCallback(CardData cardData);
tip

When a card is presented to the reader, the callback fires on a background thread with the card data. Multiple callbacks can be registered simultaneously.

Read size is shared across subscribers

There is one read size per reader instance. A later OnCredentialPresented call with a different sizeParameter changes the payload delivered to all existing subscribers on that reader.

Configuration

MethodReturnsDescription
GetReaderConfiguration(byte configurationNumber)(ReaderConfigurationStruct, ExtendedConfiguration)Read configuration slot
SetReaderConfiguration(byte configurationNumber, ReaderConfigurationStruct config, ExtendedConfiguration extendedConfig, HashData hashData)voidWrite configuration slot
WriteUserDefaultsToReader()voidCopy the active flash configuration to stored (user-default) flash
ResetReaderConfiguration(CheckpointType checkpointType)voidReset configuration to a checkpoint (CheckpointType.FactoryDefaults or CheckpointType.UserSettings)
note

If the extended configuration header is invalid, SetReaderConfiguration logs a warning and skips writing the extended configuration. The standard ReaderConfigurationStruct is still written. This path does not throw.

LED

MethodReturnsDescription
GetLedConfiguration(int configurationNumber)LedConfigurationRead LED configuration
SetLedConfiguration(int configurationNumber, LedConfiguration ledConfig)voidWrite LED configuration

LUID

MethodReturnsDescription
GetLuid()LuidResponseInformationGet Logical Unit ID
SetLuid(int luid)voidSet Logical Unit ID

Module Control

MethodReturnsDescription
GetModuleState(ReaderModuleId moduleId)ReaderModuleStateGet module power state
SetModuleState(ReaderModuleId moduleId, ReaderModuleState state)voidSet module power state

Modes

MethodReturnsDescription
EnableKeystroking(bool enable)voidEnable or disable keystroking
EnableTransparentMode(bool enable, bool writeToFlash)voidEnable or disable transparent mode
GetTransparentModeStatus(out TransparentModeState state, out TransparentModeStatus status)voidGet transparent mode state and readiness

Card Types

MethodReturnsDescription
GetSupportedCardTypes()IEnumerable<CardTypeInfo>List supported card types

BLE Configuration

MethodReturnsDescription
ReadBleConfigurationFromReader(BleDataType dataType, string fileName)voidRead BLE config to file
WriteBleConfigurationToReader(BleDataType dataType, string fileName)voidWrite BLE config from file

HWG Configuration

MethodReturnsDescription
WriteHwgFileToReader(string fileName)voidWrite an HWG configuration file to the reader
ReadHwgFileFromReader(string fileName, bool secureHwgFormat = true)voidRead configuration from the reader and save to an HWG file

Smart Card Configuration

MethodReturnsDescription
WriteSmartCardConfigurationToReader(string filePath)voidWrite smart card configuration from an INI file to the reader
ReadSmartCardConfigurationFromReader(ref SmartCardConfigurationStruct configStruct)voidRead smart card configuration from the reader

ReaderDiscovery (static)

Discovers connected rf IDEAS USB readers. Returns ready-to-use ReaderDefinition objects that can be passed directly to the Reader constructor.

Methods

MethodReturnsDescription
DiscoverUsbReaders()List<ReaderDefinition>Static. Discovers all connected rf IDEAS USB readers

Throws: ReaderException if USB enumeration fails.

using rfIDEAS.ReaderIntegrationKit;

var readers = ReaderDiscovery.DiscoverUsbReaders();

foreach (var readerDef in readers)
{
Console.WriteLine($"VID:PID: 0x{readerDef.DeviceId.VendorId:X4}:0x{readerDef.DeviceId.ProductId:X4}");
Console.WriteLine($"Path: {readerDef.DeviceId.UsbPathString}");
Console.WriteLine($"Serial: {readerDef.DeviceId.SerialNumberString}");
}

See Discovering USB Readers for full examples including discover-then-connect patterns.


Key Types

Defined in rfIDEAS.ReaderIntegrationKit.Objects.

ReaderDefinition

PropertyTypeDescription
DeviceIdDeviceIdVendor and product identifiers
ProtocolTypeProtocolTypeCommunication protocol
SerialPortSettingsSerialPortSettingsSerial port configuration (serial connections only)

DeviceId

PropertyTypeDescription
VendorIdushortUSB vendor ID
ProductIdushortUSB product ID
UsbPathbyte[512]USB device path as UTF-8 byte array (optional). Read back via UsbPathString helper property.
SerialNumberbyte[256]USB serial number as UTF-8 byte array (optional). Read back via SerialNumberString helper property.

SerialPortSettings

PropertyType
BaudRateSerialPortBaudRate
ParitySerialPortParity
FlowControlSerialPortFlowControl
PortNamestring
ByteSizeint
DataBitsSerialPortDataBits
StopBitsSerialPortStopBits

ReaderMetadataStruct

Contains string fields (part number, serial number, model name, etc.), firmware version structs, hardware capability flags, Has* boolean flags indicating which fields were populated, and an AdvancedAttributes struct with read-only hardware capabilities. See Structures for full details.

CardData

PropertyTypeDescription
Databyte[]Raw card data bytes
BitCountintNumber of valid bits
IsEmpty()boolReturns true if bit count is zero and all data bytes are zero
AsHexString()stringHex representation of the data

LibraryInfo

Contains 27+ string fields with library version and build metadata (version string, build date, compiler, platform, etc.).

LedConfiguration

PropertyTypeDescription
ColorLedColorLED color
SoftwareControlEnabledboolWhether software LED control is active

ReaderException

Thrown on any native library error.

PropertyTypeDescription
MessagestringError description
FileNamestringSource file
LineNumberintSource line
FunctionNamestringSource function
HasProtocolExceptionboolWhether protocol-level details are available
ProtocolMessagestringProtocol error description

Enums

Defined in rfIDEAS.ReaderIntegrationKit.Enum.

ProtocolType

ValueDescription
InvalidNot set
FeatureReportUSB HID feature report
SerialBinarySerial binary protocol
UnknownUnrecognized

BeepDuration

ValueDescription
BeepDurationShortShort beep
BeepDurationLongLong beep

BeepVolume

ValueDescription
OffMuted
LowLow volume
MediumMedium volume
HighHigh volume
UnknownUnknown / unset

LedColor

ValueDescription
InvalidNot set
OffLED off
RedRed
GreenGreen
AmberAmber
UnknownUnknown / unset

ReaderModuleId

ValueDescription
InvalidNot set
LowFrequencyRadio125 kHz radio
HighFrequencyRadio13.56 MHz radio
BleRadioBluetooth Low Energy radio

ReaderModuleState

ValueHexDescription
Invalid0x00Not set
PowerOff0x80Module powered off
PowerOnNormal0x81Module powered on, normal operation

BleDataType

ValueIntDescription
Data1BLE data payload
Key2Encrypted key
UnencryptedKey3Unencrypted key

CheckpointType

ValueIntDescription
Undefined0Not set
FactoryDefaults1Reset configuration to factory defaults
UserSettings2Reset configuration to the stored user defaults

GetCardDataSizeParameters

ValueHexDescription
Undefined0x00Invalid / unset — do not pass
Read8Bytes0x018-byte read
Read32Bytes0x0232-byte read (default)

CardCategory

ValueIntDescription
Off0Category not applicable / disabled
Secure1Secure credential
NonSecure2Non-secure credential
Bluetooth3Bluetooth / mobile credential

CardFrequency

ValueIntDescription
Na0Frequency not applicable
Ble1Bluetooth Low Energy RF
High2High frequency
Low3Low frequency
Dual4Dual frequency

Examples

Basic Connection

using rfIDEAS.ReaderIntegrationKit;
using rfIDEAS.ReaderIntegrationKit.Objects;
using rfIDEAS.ReaderIntegrationKit.Enum;

var readerDef = new ReaderDefinition
{
DeviceId = new DeviceId { VendorId = 0x0C27, ProductId = 0x3BFA },
ProtocolType = ProtocolType.FeatureReport
};

using var app = new Reader(readerDef);
app.Init();

var metadata = app.GetMetadata();
Console.WriteLine($"Part: {metadata.PartNumber}");
Console.WriteLine($"Serial: {metadata.ESN}");

Beep

using var app = new Reader(readerDef);
app.Init();

app.Beep(2, BeepDuration.BeepDurationShort);
app.SetBeeperVolume(BeepVolume.High);

Read Card Data

using var app = new Reader(readerDef);
app.Init();

// Default: 32-byte path
app.GetCardData(out var card);
if (!card.IsEmpty())
{
Console.WriteLine($"Bits: {card.BitCount}");
Console.WriteLine($"Hex: {card.AsHexString()}");
}
using var app = new Reader(readerDef);
app.Init();

// 8-byte read
app.GetCardData(out var card, GetCardDataSizeParameters.Read8Bytes);
if (!card.IsEmpty())
{
if (card.BitCount > 64)
Console.WriteLine("Warning: card data was truncated (BitCount > 64)");
Console.WriteLine($"Hex: {card.AsHexString()}");
}

Library Info (No Reader Required)

var info = AbstractReader.GetLibraryInfo();
Console.WriteLine($"Version: {info.VersionString}");

Thread Safety

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

See Also