pub struct BarcodeScanner { /* private fields */ }Implementations§
Source§impl BarcodeScanner
impl BarcodeScanner
Sourcepub fn new(serial_port_name: &str) -> Result<Self>
pub fn new(serial_port_name: &str) -> Result<Self>
open the serial port and initialize the necessary device options for scanning
§Arguments
serial_port_namethe 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).
Sourcepub fn get_hw_version(&mut self) -> Result<String>
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(())
}Sourcepub fn get_sw_version(&mut self) -> Result<String>
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(())
}Sourcepub fn get_sw_date(&mut self) -> Result<NaiveDate>
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(())
}Sourcepub fn start_scan(&mut self) -> Result<()>
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(())
}Sourcepub fn stop_scan(&mut self) -> Result<()>
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.
Sourcepub fn read_barcode(&mut self) -> Result<Option<Barcode>>
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
Sourcepub 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<()>
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_scanif true the LED on the circuit board will light up shortly after a successful scanenable_buzzerif true a successful scan will be confirmed with a short tonetarget_light_modespecifies how the green target light is usedillumination_modespecifies how the white LED light will operateoperation_modedefines the scanning mode
§Note
Only manual and command scanning operations are currently supported.
Sourcepub fn set_scan_area_and_barcodes(
&mut self,
scan_area: ScanArea,
allowed_barcodes: Barcodes,
) -> Result<()>
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_areadefines the area of the camera view where barcodes are detectedallowed_barcodesspecifies which barcode types are recognized based on the barcode scanner model
Sourcepub fn set_scan_timeout(&mut self, scan_timeout: Duration) -> Result<()>
pub fn set_scan_timeout(&mut self, scan_timeout: Duration) -> Result<()>
Sourcepub fn allow_ean13(&mut self, enable: bool) -> Result<()>
pub fn allow_ean13(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: EAN13
Sourcepub fn allow_ean8(&mut self, enable: bool) -> Result<()>
pub fn allow_ean8(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: EAN8
Sourcepub fn allow_rss_stack(&mut self, enable: bool) -> Result<()>
pub fn allow_rss_stack(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: GS1 Databar Stacked(RSS)
Sourcepub fn allow_rss14(&mut self, enable: bool) -> Result<()>
pub fn allow_rss14(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: GS1 Databar(RSS-14)
Sourcepub fn allow_limited_rss(&mut self, enable: bool) -> Result<()>
pub fn allow_limited_rss(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: GS1 Databar Limited(RSS)
Sourcepub fn allow_expanded_rss(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_msi(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_code11(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_matrix2of5(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_industrial(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_codebar(
&mut self,
enable: bool,
with_start_stop_character: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_code128(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_code39(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_code93(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn allow_upca(&mut self, enable: bool) -> Result<()>
pub fn allow_upca(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: UPCA
Sourcepub fn allow_upce0(&mut self, enable: bool) -> Result<()>
pub fn allow_upce0(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: UPCE0
Sourcepub fn allow_upce1(&mut self, enable: bool) -> Result<()>
pub fn allow_upce1(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: UPCE1
Sourcepub fn allow_pdf417(&mut self, enable: bool) -> Result<()>
pub fn allow_pdf417(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: PDF417
Sourcepub fn allow_micro_pdf417(&mut self, enable: bool) -> Result<()>
pub fn allow_micro_pdf417(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: Micro PDF417
Sourcepub fn allow_micro_isbn(&mut self, enable: bool) -> Result<()>
pub fn allow_micro_isbn(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: ISBN
Sourcepub fn allow_micro_issn(&mut self, enable: bool) -> Result<()>
pub fn allow_micro_issn(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: ISSN
Sourcepub fn allow_dotmatrix(&mut self, enable: bool) -> Result<()>
pub fn allow_dotmatrix(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: Dot Matrix code
Sourcepub fn allow_microqr(&mut self, enable: bool) -> Result<()>
pub fn allow_microqr(&mut self, enable: bool) -> Result<()>
enable/disable barcode type: Micro QR
Sourcepub fn allow_interleaved2of5(
&mut self,
enable: bool,
min_length: Option<u8>,
max_length: Option<u8>,
) -> Result<()>
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
Sourcepub fn disable_setting_scanning(&mut self) -> Result<()>
pub fn disable_setting_scanning(&mut self) -> Result<()>
disable setting changes via barcode scanning (seems like a really good idea for production use)
Sourcepub fn enable_setting_scanning(&mut self) -> Result<()>
pub fn enable_setting_scanning(&mut self) -> Result<()>
enable setting changes via barcode scanning
Sourcepub fn save_to_flash(&mut self) -> Result<()>
pub fn save_to_flash(&mut self) -> Result<()>
save all pending changes to flash
Sourcepub fn factory_reset(&mut self) -> Result<()>
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.