Sample code for 30+ languages & platforms
Rust

PC/SC List Smart Card Readers (and USB Tokens)

See more SCard Examples

Demonstrates how to list the smart card readers and USB tokens connected to the computer.

Note: This functionality was introduced in Chilkat v9.5.0.87.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let scard = chilkat::SCard::new();

// First establish a context to the PC/SC Resource Manager
if scard.establish_context("user").is_err() {
    println!("{}", scard.last_error_text());
    return;
}

let st_readers = chilkat::StringTable::new();
if scard.list_readers(&st_readers).is_err() {
    println!("{}", scard.last_error_text());
    return;
}

let num_readers = st_readers.count();
let mut i = 0;
while i < num_readers {
    println!("{}: {}", i, st_readers.string_at(i).unwrap_or_default());
    i = i + 1;
}

// Sample output:
// 0: Alcor Micro USB Smart Card Reader 0
// 1: FS USB Token 0
// 2: FT Java Token 0
// 3: SCM Microsystems Inc. SCR33x USB Smart Card Reader 0
// 4: Yubico YubiKey OTP+FIDO+CCID 0

// Applications should always release the context when finished.
if scard.release_context().is_err() {
    println!("{}", scard.last_error_text());
}