Skip to main content

Printer

Struct Printer 

Source
pub struct Printer { /* private fields */ }

Implementations§

Source§

impl Printer

Source

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 instance
  • Err(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)?;
Source

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 successfully
  • Err(Error) - Communication error
§Example
let printer = Printer::new(config)?;
printer.cancel()?; // Cancel any ongoing job
Source

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 information
  • Err(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),
}
Source

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 of Matrix (Vec<Vec<u8>>) containing 1-bit bitmap data
§Returns
  • Ok(()) - Print job completed successfully
  • Err(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())?;
Source

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 of TwoColorMatrix containing black and red image data
§Returns
  • Ok(()) - Print job completed successfully
  • Err(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())?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.