#printing #thermal #pos #bindings #tokio #interface #point

epson

support for communicating with Epson brand thermal POS printers

9 releases

0.1.8 Oct 6, 2024
0.1.7 Mar 28, 2024
0.1.4 Feb 23, 2024
0.1.3 Jan 23, 2024

#638 in Asynchronous

26 downloads per month

MIT license

33KB
407 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
T30II models::Model::T30II Epson TM-T30II 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

~2.5–8MB
~73K SLoC