pub struct Printer { /* private fields */ }Implementations§
Source§impl Printer
impl Printer
Sourcepub fn new(config: Config) -> Result<Self, Error>
pub fn new(config: Config) -> Result<Self, Error>
Create a new printer instance with the specified configuration.
This constructor handles USB device enumeration, connection, and initialization. It will search for a Brother P-Touch printer matching the model and serial number specified in the configuration.
§Arguments
config- Printer configuration containing model, serial, media, and print settings
§Returns
Ok(Printer)- Successfully connected printer instanceErr(Error)- Connection failed, device not found, or USB error
§Example
let config = Config::new(Model::QL820NWB, "E8N117P02180".to_string(),
Media::Continuous(ContinuousType::Continuous62));
let printer = Printer::new(config)?;Sourcepub fn cancel(&self) -> Result<(), Error>
pub fn cancel(&self) -> Result<(), Error>
Cancel current print job and reset printer state.
Sends an initialization command to cancel any ongoing print job and reset the printer to a ready state.
§Returns
Ok(())- Cancel command sent successfullyErr(Error)- Communication error
§Example
let printer = Printer::new(config)?;
printer.cancel()?; // Cancel any ongoing jobSourcepub fn check_status(&self) -> Result<Status, Error>
pub fn check_status(&self) -> Result<Status, Error>
Read current printer status including media type, errors, and phase.
This method is convenient for inspection when a new media is added or to check for printer errors before starting a print job.
§Returns
Ok(Status)- Current printer status informationErr(Error)- Communication error or timeout
§Example
let printer = Printer::new(config)?;
match printer.check_status() {
Ok(status) => println!("Printer ready: {:?}", status),
Err(e) => eprintln!("Printer error: {:?}", e),
}Sourcepub fn print(&self, images: impl Iterator<Item = Matrix>) -> Result<(), Error>
pub fn print(&self, images: impl Iterator<Item = Matrix>) -> Result<(), Error>
Print single-color labels.
This method prints labels using black ink only. For two-color printing,
use print_two_color() method instead.
§Arguments
images- Iterator ofMatrix(Vec<Vec<u8>>) containing 1-bit bitmap data
§Returns
Ok(())- Print job completed successfullyErr(Error)- Printer error, communication error, or media mismatch
§Image Format
- Width: 720 pixels (90 bytes) for normal printers, 1296 pixels for wide printers
- Height: Variable, depends on label length
- Format: 1-bit bitmap packed into bytes (8 pixels per byte)
§Example
let config = Config::new(Model::QL820NWB, "serial".to_string(),
Media::Continuous(ContinuousType::Continuous62));
let printer = Printer::new(config)?;
// Create simple black and white pattern
let image_data: Matrix = vec![vec![0xFF; 90]; 300]; // 300 lines of solid black
printer.print(vec![image_data].into_iter())?;Sourcepub fn print_two_color(
&self,
images: impl Iterator<Item = TwoColorMatrix>,
) -> Result<(), Error>
pub fn print_two_color( &self, images: impl Iterator<Item = TwoColorMatrix>, ) -> Result<(), Error>
Print two-color labels using black and red colors.
This method is specifically designed for QL-820NWB printers with
red/black tape installed. The configuration must have two_colors(true)
enabled for this method to work.
§Arguments
images- Iterator ofTwoColorMatrixcontaining black and red image data
§Returns
Ok(())- Print job completed successfullyErr(Error)- Printer error, communication error, or invalid configuration
§Example
let config = Config::new(Model::QL820NWB, "serial".to_string(),
Media::Continuous(ContinuousType::Continuous62Red))
.two_colors(true);
let printer = Printer::new(config)?;
// Create two-color image data
let black_data = vec![vec![0u8; 90]; 300];
let red_data = vec![vec![0u8; 90]; 300];
let two_color = TwoColorMatrix::new(black_data, red_data)?;
printer.print_two_color(vec![two_color].into_iter())?;