tspl2

Crates.iotspl2
lib.rstspl2
version0.3.0
sourcesrc
created_at2024-06-21 13:04:45.913183
updated_at2024-07-17 15:36:17.346102
descriptionSimple driver for TSPL/TSPLv2 compatible thermal label printers
homepage
repositoryhttps://github.com/aectaan/tspl2
max_upload_size
id1279540
size58,500
Egor Markov (aectaan)

documentation

README

tspl2

Library for handling with thermal label printers, controlled by TSPL/TSPL2 language

Examples

Rust

See: simple.rs

use anyhow::Result;
use tspl2::{Alignment, Barcode, Font, HumanReadable, NarrowWide, Printer, Rotation, Size, Tape};

fn main() -> Result<()> {
    // Get access to the printer
    std::process::Command::new("sudo")
        .args(["chmod", "777", "/dev/usb/lp0"])
        .output()?;

    let tape = Tape {
        width: Size::Metric(30.0),
        height: Some(Size::Metric(20.0)),
        gap: Size::Metric(2.0),
        gap_offset: None,
    };

    let mut printer = Printer::with_resolution("/dev/usb/lp0", tape, 300)?;
    printer
        .cls()?
        .qrcode(
            Size::Metric(9.0),
            Size::Metric(0.0),
            35,
            6,
            Rotation::NoRotation,
            None,
            "0123456789AB",
        )?
        .text(
            Size::Metric(15.0),
            Size::Metric(14.5),
            Font::Font24x32,
            Rotation::NoRotation,
            1,
            1,
            Some(Alignment::Center),
            "0123456789AB",
        )?
        .print(1, None)?;

    printer
        .cls()?
        .barcode(
            Size::Metric(15.0),
            Size::Metric(0.0),
            Barcode::Barcode39,
            Size::Metric(15.0),
            HumanReadable::ReadableAlignsToCenter,
            Rotation::NoRotation,
            NarrowWide::N1W3,
            Some(Alignment::Center),
            "0123456789AB",
        )?
        .print(1, None)?;

    Ok(())
}
Commit count: 17

cargo fmt