{ "cells": [ { "cell_type": "markdown", "id": "serial-barcode-title", "metadata": {}, "source": [ "# Line-oriented serial barcode scanners\n", "\n", "`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](https://www.amazon.com/dp/B00LE5VV1C), configured for USB virtual COM.\n", "\n", "| Property | Default |\n", "|---|---|\n", "| Serial settings | 9600 baud, 8 data bits, no parity, 1 stop bit |\n", "| Line terminators | Carriage return or newline |\n", "| Read mode | Passive, with optional trigger and untrigger commands |" ] }, { "cell_type": "markdown", "id": "serial-barcode-protocol", "metadata": {}, "source": [ "## How it talks\n", "\n", "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." ] }, { "cell_type": "markdown", "id": "serial-barcode-physical-setup", "metadata": {}, "source": [ "## Physical setup\n", "\n", "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." ] }, { "cell_type": "markdown", "id": "serial-barcode-setup-heading", "metadata": {}, "source": [ "## Connect\n", "\n", "Create the scanner with the settings from its manual, then open the serial connection." ] }, { "cell_type": "code", "execution_count": null, "id": "serial-barcode-setup-code", "metadata": {}, "outputs": [], "source": [ "from pylabrobot.generic import SerialBarcodeScanner\n", "\n", "scanner = SerialBarcodeScanner(port=\"COM5\", baudrate=115200)\n", "await scanner.setup()" ] }, { "cell_type": "markdown", "id": "serial-barcode-scan-heading", "metadata": {}, "source": [ "## Scan a barcode\n", "\n", "Scan a label within the read window. A timeout returns `None`." ] }, { "cell_type": "code", "execution_count": null, "id": "serial-barcode-scan-code", "metadata": {}, "outputs": [], "source": [ "barcode = await scanner.scan_barcode(read_time=5)\n", "print(\"No barcode received\" if barcode is None else f\"Scanned: {barcode.data}\")" ] }, { "cell_type": "markdown", "id": "serial-barcode-stop-heading", "metadata": {}, "source": [ "## Disconnect\n", "\n", "Close the serial connection when scanning is complete." ] }, { "cell_type": "code", "execution_count": null, "id": "serial-barcode-stop-code", "metadata": {}, "outputs": [], "source": [ "await scanner.stop()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }