{ "cells": [ { "cell_type": "markdown", "id": "a23709b6", "metadata": {}, "source": [ "# KX2 barcode reader\n", "\n", "The optional barcode reader is an independent serial device. Configure the reader for external triggering before connecting; PLR leaves its stored mode, symbologies and firmware read window unchanged. See [installation](installation.md) for finding the serial port." ] }, { "cell_type": "code", "execution_count": null, "id": "1d1e367c", "metadata": {}, "outputs": [], "source": [ "from pylabrobot.paa.kx2 import KX2BarcodeReader\n", "\n", "reader = KX2BarcodeReader(port=\"/dev/ttyUSB0\")" ] }, { "cell_type": "markdown", "id": "a19f2be0", "metadata": {}, "source": [ "## Connect\n", "\n", "Setup opens 9600-baud, 8-N-1 serial with no RTS/CTS and requests the firmware version." ] }, { "cell_type": "code", "execution_count": null, "id": "27ce8e67", "metadata": {}, "outputs": [], "source": [ "await reader.setup()" ] }, { "cell_type": "markdown", "id": "cd0ebce3", "metadata": {}, "source": [ "## Scan\n", "\n", "Place the label in the reading area. `read_time` is a host deadline in seconds, not a change to the scanner's firmware read window. A no-read returns `None`; errors propagate. The trigger is switched off on success, timeout, failure and cancellation." ] }, { "cell_type": "code", "execution_count": null, "id": "274f8d7a", "metadata": {}, "outputs": [], "source": [ "barcode = await reader.scan_barcode(read_time=5)\n", "barcode" ] }, { "cell_type": "markdown", "id": "464ad870", "metadata": {}, "source": [ "## Read firmware version" ] }, { "cell_type": "code", "execution_count": null, "id": "1ea3c392", "metadata": {}, "outputs": [], "source": [ "await reader.request_software_version()" ] }, { "cell_type": "markdown", "id": "2cdefb98", "metadata": {}, "source": [ "## Disconnect\n", "\n", "Stop joins any scan's trigger cleanup and closes the port." ] }, { "cell_type": "code", "execution_count": null, "id": "0bf89968", "metadata": {}, "outputs": [], "source": [ "await reader.stop()" ] }, { "cell_type": "markdown", "id": "d7fecf0d", "metadata": {}, "source": [ "## Use the reader attached to an arm\n", "\n", "You can instead construct `KX2(barcode_port=\"/dev/ttyUSB0\")`; the arm then manages the reader lifecycle and exposes `await kx2.scan_barcode(read_time=5)`. Do not open the same serial port with both objects." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }