| Crates.io | pcsc-mon |
| lib.rs | pcsc-mon |
| version | 0.1.0 |
| created_at | 2025-06-13 09:42:29.292254+00 |
| updated_at | 2025-06-13 09:42:29.292254+00 |
| description | Monitor PC/SC smart card readers with hotplug and card event support |
| homepage | |
| repository | https://gitlab.thernamyte.eu/thernamytecandm/lib/pcsc-monitor.git |
| max_upload_size | |
| id | 1711276 |
| size | 16,395 |
A lightweight, thread-safe PC/SC monitor for detecting smart card reader and card events in Rust.
This crate provides a singleton-style interface for monitoring reader addition/removal and card insertion/removal events using pcsc. It supports hotplug detection, background monitoring, and callback registration.
pcsc::Context and pcsc::Card in callbacks.use pcsc_mon::PcscMonitor;
fn main() {
let mut monitor = PcscMonitor::instance();
monitor.on_reader_added(|reader| {
println!("Reader added: {}", reader);
});
monitor.on_reader_removed(|reader| {
println!("Reader removed: {}", reader);
});
monitor.on_card_inserted(|_ctx, card| {
match card.get_attribute(pcsc::Attribute::AtrString) {
Ok(atr) => println!("Card ATR: {:02X?}", atr),
Err(err) => eprintln!("Failed to read ATR: {:?}", err),
}
});
monitor.on_card_removed(|reader| {
println!("Card removed from reader: {}", reader);
});
monitor.start();
// Keep the main thread alive
loop {
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
MIT License © 2025 Thernamyte Cloud & Medien UG (haftungsbeschränkt)
See LICENSE for details.