Skip to content

Add serial barcode scanner#1028

Open
alexjamesgodfrey wants to merge 1 commit intoPyLabRobot:v1b1from
alexjamesgodfrey:serial-barcode-scanner-v1b1
Open

Add serial barcode scanner#1028
alexjamesgodfrey wants to merge 1 commit intoPyLabRobot:v1b1from
alexjamesgodfrey:serial-barcode-scanner-v1b1

Conversation

@alexjamesgodfrey
Copy link
Copy Markdown

@alexjamesgodfrey alexjamesgodfrey commented May 8, 2026

Summary

Adds a generic serial barcode scanner implementation.

This supports barcode scanners configured as RS-232 or USB virtual COM devices, which I use to read WONE NICE scanners when configured to USB virtual COM. The implementation uses PLR's existing pylabrobot.io.Serial wrapper and exposes the existing BarcodeScanner capability through a SerialBarcodeScanner device.

WONE NICE usage

For the WONE NICE wireless scanner, I had to scan these setup barcodes from the manual so that it would stream barcodes via the com port:

  1. Restore defaults
  2. Match
  3. Instant upload Mode
  4. USB virtual COM
  5. Add Carriage Return or CR
  6. Duplicate detection-OFF
  7. Continuous Mode or Keys Trigger

After switching to USB virtual COM, unplug/replug the USB receiver. It should appear as a serial port, for example:

  • Windows: COM5
  • Linux: /dev/ttyACM0 or /dev/ttyUSB0

Example:

from pylabrobot.capabilities.barcode_scanning import SerialBarcodeScanner

scanner = SerialBarcodeScanner(
  port="COM5",
  baudrate=115200,
  symbology="Code 128 (Subset B and C)",
)

await scanner.setup()

barcode = await scanner.barcode_scanning.scan(read_time=5)
if barcode is None:
  print("No barcode read.")
else:
  print(barcode.data)

await scanner.stop()

If using VID/PID discovery instead of an explicit port:

scanner = SerialBarcodeScanner(
  vid=0x0C2E,
  pid=0x0900,
  baudrate=115200,
)

Observed WONE NICE behavior: the scanner emits barcode data when it performs a decode event. With a barcode sitting statically in front of the scanner, it may not repeatedly emit the same barcode. Moving the barcode out of and back into the scan field creates a new decode event. This is scanner firmware behavior, not PLR behavior.

What's included

  • SerialBarcodeScannerDriver

    • Owns a PLR Serial connection.
    • Supports explicit port or VID/PID serial port resolution.
    • Reads barcode lines terminated by CR and/or LF.
  • SerialBarcodeScannerBackend

    • Implements BarcodeScannerBackend.
    • Returns Barcode on successful read.
    • Returns None when the read window elapses without a barcode.
    • Supports optional trigger_command and untrigger_command for scanners with documented serial trigger commands.
  • SerialBarcodeScanner

    • v1b1 Device wiring driver + barcode scanning capability.
  • Docs/API exports for the barcode scanning capability.

  • 11 unit tests covering line reads, timeout behavior, trigger-command behavior, validation, and device lifecycle wiring.

Notes

I intentionally did not add WONE NICE-specific code. The WONE NICE works as a generic USB virtual COM barcode scanner, and the manuals I found do not document a host-side serial trigger protocol.

No native binaries, package data, HID dependencies, or Windows-specific code are added.

Validation

  • python3 -m unittest pylabrobot.capabilities.barcode_scanning.serial_tests
  • uv run --extra test pytest pylabrobot/capabilities/barcode_scanning/serial_tests.py
  • uvx ruff check pylabrobot/capabilities/barcode_scanning/serial.py pylabrobot/capabilities/barcode_scanning/serial_tests.py
  • uvx mypy --follow-imports=skip pylabrobot/capabilities/barcode_scanning/serial.py pylabrobot/capabilities/barcode_scanning/serial_tests.py

Hardware observed on WONE NICE receiver:

  • COM5
  • USB Serial Device
  • VID/PID: 0C2E:0900
  • Serial: YUNEW
  • Barcode output observed as CR-terminated serial data, e.g. 2263408636\r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant