Line-oriented serial barcode scanners#
SerialBarcodeScanner supports barcode scanners that send one decoded barcode followed by a line terminator over RS-232 or a USB virtual COM port. One tested example is the WONE NICE wireless scanner, configured for USB virtual COM.
Property |
Default |
|---|---|
Serial settings |
9600 baud, 8 data bits, no parity, 1 stop bit |
Line terminators |
Carriage return or newline |
Read mode |
Passive, with optional trigger and untrigger commands |
How it talks#
The scanner sends the decoded barcode as a line of text. The driver waits for a carriage return or newline, removes that terminator, and returns a Barcode. Scanners that require software triggering can be configured with their documented raw trigger commands.
Physical setup#
Connect the scanner through RS-232 or its USB virtual COM interface. Configure it to append a carriage return or newline to every scan, and note its port and serial settings.
Connect#
Create the scanner with the settings from its manual, then open the serial connection.
from pylabrobot.generic import SerialBarcodeScanner
scanner = SerialBarcodeScanner(port="COM5", baudrate=115200)
await scanner.setup()
Scan a barcode#
Scan a label within the read window. A timeout returns None.
barcode = await scanner.scan_barcode(read_time=5)
print("No barcode received" if barcode is None else f"Scanned: {barcode.data}")
Disconnect#
Close the serial connection when scanning is complete.
await scanner.stop()