Skip to main content

BarcodeScanner

Struct BarcodeScanner 

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

Implementations§

Source§

impl BarcodeScanner

Source

pub fn new(serial_port_name: &str) -> Result<Self>

open the serial port and initialize the necessary device options for scanning

§Arguments
  • serial_port_name the device name of the serial port to open
§Examples
use anyhow::Result;
use waveshare_barcodescanner::interface::BarcodeScanner;
 
fn main() -> Result<()> {
    let scanner = BarcodeScanner::new("/dev/serial0")?;
    Ok(())
}
§Notes

The device is expected to be in UART mode, with the serial options set to 9600,8,N,1 (factory default).

Source

pub fn get_hw_version(&mut self) -> Result<String>

return the hardware version of the attached barcode scanner

§Examples
use anyhow::Result;
use waveshare_barcodescanner::interface::BarcodeScanner;
 
fn main() -> Result<()> {
    let mut scanner = BarcodeScanner::new("/dev/serial0")?;
    println!("Detected barcode scanner hardware version: {}", scanner.get_hw_version()?);
    Ok(())
}
Source

pub fn get_sw_version(&mut self) -> Result<String>

return the software version of the attached barcode scanner

§Examples
use anyhow::Result;
use waveshare_barcodescanner::interface::BarcodeScanner;
 
fn main() -> Result<()> {
    let mut scanner = BarcodeScanner::new("/dev/serial0")?;
    println!("Detected barcode scanner software version: {}", scanner.get_sw_version()?);
    Ok(())
}
Source

pub fn get_sw_date(&mut self) -> Result<NaiveDate>

return the software date of the attached barcode scanner

§Examples
use anyhow::Result;
use waveshare_barcodescanner::interface::BarcodeScanner;
 
fn main() -> Result<()> {
    let mut scanner = BarcodeScanner::new("/dev/serial0")?;
    println!("Detected barcode scanner software build date: {}", scanner.get_sw_date()?.format("%Y/%m/%d"));
    Ok(())
}
Source

pub fn start_scan(&mut self) -> Result<()>

start scanning for barcodes

§Examples
use anyhow::Result;
use waveshare_barcodescanner::interface::BarcodeScanner;
 
fn main() -> Result<()> {
    let mut scanner = BarcodeScanner::new("/dev/serial0")?;
    println!("Please scan your badge for identification.");
    scanner.start_scan()?;
    match scanner.read_barcode()? {
        Some(barcode) => println!("data scanned: {}", barcode),
        None => println!("Please try again. Make sure the barcode on your badge is at the center of the green scanning light."),
    }
    Ok(())
}
Source

pub fn stop_scan(&mut self) -> Result<()>

stop scanning for barcodes

§Notes

When a barcode has been scanned, the scanner automatically stops scanning in manual and command mode.

Source

pub fn read_barcode(&mut self) -> Result<Option<Barcode>>

waits for a barcode payload to be returned from the scanner

will return immediately when the payload has been read or the scan_timeout has been reached

Source

pub fn set_mode( &mut self, enable_led_indication_on_successful_scan: bool, enable_buzzer: bool, target_light_mode: TargetLightMode, illumination_mode: IlluminationMode, operation_mode: OperationMode, ) -> Result<()>

set the mode of operation and light/buzzer parameters

§Arguments
  • enable_led_indication_on_successful_scan if true the LED on the circuit board will light up shortly after a successful scan
  • enable_buzzer if true a successful scan will be confirmed with a short tone
  • target_light_mode specifies how the green target light is used
  • illumination_mode specifies how the white LED light will operate
  • operation_mode defines the scanning mode
§Note

Only manual and command scanning operations are currently supported.

Source

pub fn set_scan_area_and_barcodes( &mut self, scan_area: ScanArea, allowed_barcodes: Barcodes, ) -> Result<()>

set the scanning area and barcodes allowed

§Arguments
  • scan_area defines the area of the camera view where barcodes are detected
  • allowed_barcodes specifies which barcode types are recognized based on the barcode scanner model
Source

pub fn set_scan_timeout(&mut self, scan_timeout: Duration) -> Result<()>

set the maximum time for a manual or command scan before the scanner goes inactive again

§Arguments
  • scan_timeout the duration to activate scanning for, allowed range is 1ms to 25.5s
§Note

By default the barcode scanner is set to 5s of scanning duration

Source

pub fn allow_ean13(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: EAN13

Source

pub fn allow_ean8(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: EAN8

Source

pub fn allow_rss_stack(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: GS1 Databar Stacked(RSS)

Source

pub fn allow_rss14(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: GS1 Databar(RSS-14)

Source

pub fn allow_limited_rss(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: GS1 Databar Limited(RSS)

Source

pub fn allow_expanded_rss( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: GS1 Databar Expanded(RSS)

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_msi( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: MSI-Plessey

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_code11( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Code11

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_matrix2of5( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Matrix 2of5

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_industrial( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Industrial

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_codebar( &mut self, enable: bool, with_start_stop_character: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: CodeBar

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_code128( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Code128

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_code39( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Code39

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_code93( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Code93

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn allow_upca(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: UPCA

Source

pub fn allow_upce0(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: UPCE0

Source

pub fn allow_upce1(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: UPCE1

Source

pub fn allow_pdf417(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: PDF417

Source

pub fn allow_micro_pdf417(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: Micro PDF417

Source

pub fn allow_micro_isbn(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: ISBN

Source

pub fn allow_micro_issn(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: ISSN

Source

pub fn allow_dotmatrix(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: Dot Matrix code

Source

pub fn allow_qr(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: QR code

Source

pub fn allow_microqr(&mut self, enable: bool) -> Result<()>

enable/disable barcode type: Micro QR

Source

pub fn allow_interleaved2of5( &mut self, enable: bool, min_length: Option<u8>, max_length: Option<u8>, ) -> Result<()>

enable/disable barcode type: Interleaved 2 of 5

optionally specify the minimum and/or maximum number of characters expected in a valid barcode, all others will be ignored

Source

pub fn disable_setting_scanning(&mut self) -> Result<()>

disable setting changes via barcode scanning (seems like a really good idea for production use)

Source

pub fn enable_setting_scanning(&mut self) -> Result<()>

enable setting changes via barcode scanning

Source

pub fn save_to_flash(&mut self) -> Result<()>

save all pending changes to flash

Source

pub fn factory_reset(&mut self) -> Result<()>

set the barcode scanner to factory defaults

§Note

Make sure to afterwards enable UART mode via the corresponding barcode again.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more