Connection Module
The connection module provides connection implementations for USB and network communication with Brother P-touch printers.
USB Device Selection
When multiple USB printers are connected, you can select a specific device using:
product_id- USB product ID to match a specific printer modelserial- USB serial number to match a specific device
Example:
from ptouch import ConnectionUSB
# Connect to specific device by serial number
connection = ConnectionUSB(product_id=0x2086, serial="A1B2C3D4E5")
USB URI Format
The parse_usb_uri function parses USB device URIs for CLI usage:
from ptouch import parse_usb_uri
# Parse various URI formats
vendor, product, serial = parse_usb_uri("usb://0x04f9:0x2086/A1B2C3D4E5")
vendor, product, serial = parse_usb_uri("usb://:0x2086/A1B2C3D4E5")
vendor, product, serial = parse_usb_uri("usb://:0x2086")
Supported formats:
usb://vendor:product- Vendor and product IDusb://vendor:product/serial- With serial numberusb://:product- Product ID only (default vendor)usb://:product/serial- Product and serial (default vendor)
Exception Classes
The module defines a hierarchy of exception classes for connection errors:
PrinterConnectionError- Base exception for all connection errorsPrinterNotFoundError- Printer device not foundPrinterPermissionError- Permission denied (USB requires sudo/udev rules)PrinterNetworkError- Network connection/communication errorsPrinterTimeoutError- Connection or operation timeoutPrinterWriteError- Failed to write data to printer
All specific exceptions inherit from PrinterConnectionError, allowing you to catch all connection-related errors with a single except clause.
See Also
Quick Start - Basic connection examples
User Guide - Connection management patterns
Exceptions - Exception handling details