#printing #thermal #pos #bindings #tokio #interface #synchronous

epson

support for communicating with Epson brand thermal POS printers

8 releases

0.1.7 Mar 28, 2024
0.1.6 Mar 28, 2024
0.1.4 Feb 23, 2024
0.1.3 Jan 23, 2024

#622 in Images

Download history 13/week @ 2024-01-17 1/week @ 2024-01-24 158/week @ 2024-02-21 13/week @ 2024-02-28 1/week @ 2024-03-06 155/week @ 2024-03-13 5/week @ 2024-03-20 326/week @ 2024-03-27 40/week @ 2024-04-03

372 downloads per month

MIT license

33KB
410 lines

epson: rust bindings to the Epson thermal printer line encoding scheme

epson-rs are Rust bindings to the Epson Point of Sale (POS) thermal printers' printer format.

Currently, this library supports a limited number of commands, and some basic interfaces for both synchronous Rust as well as async Rust through tokio, behind the tokio feature.

Docs can be found on docs.rs, and information about the latest release can be found on crates.io.

Example Programs

Check the examples directory for some program that use the epson library to print things to a printer.


lib.rs:

The epson crate contains Rust bindings to the Epson Point of Sale (POS) thermal printers' printer format.

Currently, this library supports a limited number of commands, and some basic interfaces for both synchronous Rust as well as async Rust through tokio, behind the tokio feature.

Docs can be found on docs.rs, and information about the latest release can be found on crates.io.

Supported Models

Specific makes/models of thermal printers will be added as I either get my hands on them, or someone maintains the model for the package. If your make/model isn't supported, you can use models::Model::Generic.

Model Type Description
T20II models::Model::T20II Epson TM-T20II Thermal Printer

Writing to a std::io::Write

We can write to a std::io::Write traited object (such as a TcpStream, but maybe something like a Serial device?), you can use a [Writer] to handle writing commands to the printer.

// IP address of the printer
let stream = TcpStream::connect("192.168.0.12:9100").unwrap();
let mut pos = epson::Writer::open(Model::T20II, Box::new(stream)).unwrap();

pos.speed(5).unwrap();
pos.write_all(b"HACK THE PLANET\n").unwrap();
pos.feed(5).unwrap();
pos.cut().unwrap();

Writing to a tokio::io::AsyncWrite

In addition to the std::io support, the epson crate also contains tokio support to write to a tokio::io::AsyncWrite using an [AsyncWriter].

This requires the tokio feature.

let stream = TcpStream::connect("192.168.0.12:9100").await.unwrap();
let mut pos = epson::AsyncWriter::open(Model::T20II, Box::new(stream)).await.unwrap();

pos.speed(5).await.unwrap();
pos.write_all(b"HACK THE PLANET\n").await.unwrap();
pos.feed(5).await.unwrap();
pos.cut().await.unwrap();

Dependencies

~12MB
~71K SLoC