Skip to main content

Crate cashcode

Crate cashcode 

Source
Expand description

§cashcode

A Rust driver for CashCode bill validators using the CCNET serial protocol (RS-232, 9600 baud, 8N1).

§Quick start

use cashcode::{CashcodeDevice, DeviceState};
use std::time::Duration;

fn main() -> cashcode::Result<()> {
    let mut dev = CashcodeDevice::open("/dev/ttyUSB0", None, None)?;

    dev.initialize()?;

    loop {
        match dev.poll()? {
            DeviceState::EscrowPosition { bill_type } => {
                let table = dev.bill_table()?;

                if let Some(entry) = table.get(bill_type) {
                    println!("Accepted: {entry}");
                }

                dev.stack()?;
            }
            DeviceState::BillStacked { .. } => println!("Bill stacked."),
            _ => {}
        }

        std::thread::sleep(Duration::from_millis(200));
    }
}

§Protocol overview

Every message uses the frame layout:

┌──────┬─────┬─────┬────────────┬───────┬───────┐
│ SYNC │ ADR │ LNG │  DATA ...  │ CRC_L │ CRC_H │
│ 0x02 │ 1 B │ 1 B │ 0–250 B    │ 1 B   │ 1 B   │
└──────┴─────┴─────┴────────────┴───────┴───────┘
  • LNG is the total frame length (all 6+ bytes included).
  • CRC is CRC-KERMIT (reflected poly 0x8408, init 0x0000), transmitted LSB-first, covering every byte from SYNC through the last DATA byte.

Re-exports§

pub use bill_table::BillEntry;
pub use bill_table::BillTable;
pub use command::BillMask;
pub use command::Command;
pub use command::SecurityLevel;
pub use device::CashcodeDevice;
pub use device::Identification;
pub use device::POLL_INTERVAL;
pub use error::Error;
pub use error::Result;
pub use frame::Frame;
pub use frame::crc16;
pub use status::DeviceState;
pub use status::FailureCode;
pub use status::RejectReason;

Modules§

bill_table
command
device
error
frame
status