cashcode
A Rust driver for CashCode bill validators using the CCNET serial protocol.
Features
- Full CCNET command set:
RESET,POLL,ENABLE_BILL_TYPES,STACK,RETURN,HOLD,IDENTIFICATION,GET_BILL_TABLE - Typed
DeviceStateenum covering all device states, bill events, rejection reasons, and hardware failures - CRC-KERMIT validation on every frame (reflected poly
0x8408, init0x0000) BillTableparsing — denomination and ISO currency code for up to 24 bill typesBillMasktype for fine-grained per-denomination enable/disable control- Synchronous API — no async runtime required; wrap in a thread when needed
- Cross-platform: Linux, Windows (macOS for development)
Installation
[]
= "0.1"
Quick start
use ;
use Duration;
Serial port
| Parameter | Value |
|---|---|
| Baud rate | 9600 (default) or 19200 |
| Data bits | 8 |
| Parity | None |
| Stop bits | 1 |
Port name examples:
| OS | Example |
|---|---|
| Linux | /dev/ttyUSB0, /dev/ttyS0 |
| Windows | COM3 |
| macOS | /dev/cu.usbserial-XXXX |
API overview
// Open
let mut dev = open?;
// Initialisation
dev.reset?;
dev.wait_for_ready?;
dev.get_bill_table?;
dev.enable_bill_types?;
// — or all at once —
dev.initialize?;
// Fine-grained control: enable only bill type 0 and 2
let mut mask = NONE;
mask.0 = 0b0000_0101;
dev.enable_bill_types?;
// Escrow decisions
dev.stack?; // accept the bill
dev.return_bill?; // return to customer
dev.hold?; // extend hold timer (~10 s)
// Device info
let id = dev.identify?;
println!;
Device states
PowerUp ──► Initializing ──► Idling ──► Accepting
│ ▲ │
SET_SECURITY │ EscrowPosition
│ ┌────┴────┐
│ Stack() Return()
│ │ │
│ Stacking Returning
│ │ │
│ BillStacked BillReturned
│ └────┬────┘
│ UnitDisabled
└──── enable_bill_types()
After every bill stacked or returned the device disables itself (UnitDisabled). The host must call enable_bill_types() to return to Idling.
Error states: CassetteFull, CassetteOutOfPosition, ValidatorJammed, CassetteJammed, Cheated, Paused, Failure.
Logging
The crate uses the log facade. Enable debug output with any compatible backend:
RUST_LOG=debug
Platform notes
Linux — requires libudev-dev:
Windows — no extra dependencies; uses the Win32 serial API.
License
MIT