1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//! # escpos - A ESCPOS implementation in Rust
//!
//! This crate implements a subset of Epson's ESC/POS protocol for thermal receipt printers.
//! It allows you to generate and print documents with basic text formatting, cutting, barcodes,
//! QR codes and raster images on a compatible printer.
//!
//! ## Examples
//! The `examples` folder contains various examples of how to use `escpos`.
//! The [docs](https://docs.rs/escpos) (will) also provide lots of code snippets and examples.
//! The list of all the examples can be found [here](examples/EXAMPLES.md).
//!
//! ### Simple text formatting
//!
//! ```rust
//! use escpos::printer::Printer;
//! use escpos::printer_options::PrinterOptions;
//! use escpos::utils::*;
//! use escpos::{driver::*, errors::Result};
//!
//! fn main() -> Result<()> {
//! // env_logger::init();
//!
//! // let driver = NetworkDriver::open("192.168.1.248", 9100, None)?;
//! let driver = ConsoleDriver::open(true);
//! Printer::new(driver, Protocol::default(), Some(PrinterOptions::default()))
//! .debug_mode(Some(DebugMode::Dec))
//! .init()?
//! .smoothing(true)?
//! .bold(true)?
//! .underline(UnderlineMode::Single)?
//! .writeln("Bold underline")?
//! .justify(JustifyMode::CENTER)?
//! .reverse(true)?
//! .bold(false)?
//! .writeln("Hello world - Reverse")?
//! .feed()?
//! .justify(JustifyMode::RIGHT)?
//! .reverse(false)?
//! .underline(UnderlineMode::None)?
//! .size(2, 3)?
//! .writeln("Hello world - Normal")?
//! .print_cut()?; // print() or print_cut() is mandatory to send the data to the printer
//!
//! Ok(())
//! }
//! ```
//!
//! ### EAN13 (with `barcode` feature enabled)
//!
//! ```rust
//! use escpos::printer::Printer;
//! use escpos::utils::*;
//! use escpos::{driver::*, errors::Result};
//!
//! fn main() -> Result<()> {
//! // env_logger::init();
//!
//! // let driver = NetworkDriver::open("192.168.1.248", 9100, None)?;
//! let driver = ConsoleDriver::open(true);
//! Printer::new(driver, Protocol::default(), None)
//! .debug_mode(Some(DebugMode::Hex))
//! .init()?
//! .ean13_option(
//! "1234567890265",
//! BarcodeOption::new(
//! BarcodeWidth::M,
//! BarcodeHeight::S,
//! BarcodeFont::A,
//! BarcodePosition::Below,
//! )
//! )?
//! .feed()?
//! .print()?; // print() or print_cut() is mandatory to send the data to the printer
//!
//! Ok(())
//! }
//! ```
//!
//! ### QR Code (with `codes_2d` feature enabled)
//!
//! ```rust
//! use escpos::printer::Printer;
//! use escpos::utils::*;
//! use escpos::{driver::*, errors::Result};
//!
//! fn main() -> Result<()> {
//! // env_logger::init();
//!
//! // let driver = NetworkDriver::open("192.168.1.248", 9100, None)?;
//! let driver = ConsoleDriver::open(true);
//! Printer::new(driver, Protocol::default(), None)
//! .debug_mode(Some(DebugMode::Hex))
//! .init()?
//! .qrcode_option(
//! "https://www.google.com",
//! QRCodeOption::new(QRCodeModel::Model1, 6, QRCodeCorrectionLevel::M),
//! )?
//! .feed()?
//! .print_cut()?; // print() or print_cut() is mandatory to send the data to the printer
//!
//! Ok(())
//! }
//! ```
//!
//! ### Bit image (with `graphics` feature enabled)
//!
//! ```rust
//! use escpos::printer::Printer;
//! use escpos::utils::*;
//! use escpos::{driver::*, errors::Result};
//!
//! fn main() -> Result<()> {
//! // env_logger::init();
//!
//! // let driver = NetworkDriver::open("192.168.1.248", 9100, None)?;
//! let driver = ConsoleDriver::open(true);
//! let mut printer = Printer::new(driver, Protocol::default(), None);
//! printer.debug_mode(Some(DebugMode::Hex))
//! .init()?
//! .bit_image_option(
//! "./resources/images/rust-logo-small.png",
//! BitImageOption::new(Some(128), None, BitImageSize::Normal)?,
//! )?
//! .feed()?
//! .print_cut()?; // print() or print_cut() is mandatory to send the data to the printer
//!
//! Ok(())
//! }
//! ```
//!
//! ### Check printer status
//!
//! ```rust,ignore
//! use escpos::printer::Printer;
//! use escpos::utils::*;
//! use escpos::{driver::*, errors::Result};
//!
//! fn main() -> Result<()> {
//! // env_logger::init();
//!
//! // let driver = NetworkDriver::open("192.168.1.248", 9100, None)?;
//! let driver = ConsoleDriver::open(true);
//! Printer::new(driver.clone(), Protocol::default(), None)
//! .debug_mode(Some(DebugMode::Dec))
//! .real_time_status(RealTimeStatusRequest::Printer)?
//! .real_time_status(RealTimeStatusRequest::RollPaperSensor)?
//! .send_status()?;
//!
//! let mut buf = [0; 1];
//! driver.read(&mut buf)?;
//!
//! let status = RealTimeStatusResponse::parse(RealTimeStatusRequest::Printer, buf[0])?;
//! println!(
//! "Printer online: {}",
//! status.get(&RealTimeStatusResponse::Online).unwrap_or(&false)
//! );
//!
//! Ok(())
//! }
//! ```
//!
//! ## Features list
//!
//! | Name | Description | Default |
//! | ------------- | ---------------------------------------------------------------------- | :-----: |
//! | `barcodes` | Print barcodes (UPC-A, UPC-E, EAN8, EAN13, CODE39, ITF or CODABAR) | ✅ |
//! | `codes_2d` | Print 2D codes (QR Code, PDF417, GS1 DataBar, DataMatrix, Aztec, etc.) | ✅ |
//! | `graphics` | Print raster images | ❌ |
//! | `usb` | Enable USB feature | ❌ |
//! | `native_usb` | Enable native USB feature | ❌ |
//! | `hidapi` | Enable HidApi feature | ❌ |
//! | `serial_port` | Enable Serial port feature | ❌ |
//! | `ui` | Enable ui feature (UI components) | ❌ |
//! | `full` | Enable all features | ❌ |
//!
//! ## External resources
//!
//! - [Epson documentation](https://download4.epson.biz/sec_pubs/pos/reference_en/escpos)
/// Error module
pub
/// Print document
/// Printer options
/// Utils module contains protocol and all needed constants and enums
/// UI components like lines, tables, etc.
/// Drivers used to send data to the printer (Network or USB)
pub use driver;