From 47654338b1560630b3e16d8fd0915ba1888eed3f Mon Sep 17 00:00:00 2001 From: wp Date: Fri, 8 Aug 2025 21:53:16 -0500 Subject: [PATCH] add usbprinter device_id string --- .gitignore | 1 + README.md | 12 ++++++++++++ src/dymott.py | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5fdc8e3..0f0d0ca 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ *.egg-info *.bak2 .venv +dymott diff --git a/README.md b/README.md index cd653c3..59b03db 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,16 @@ print(f"Dymo 450 string result as bytes: {usb.control.get_descriptor(dymott,254, The Twin-Turbo serial is supposed to be 006103010161575. Due to the extra 0 byte `b'\x30'`, the rest of the return data becomes shifted and is interpreted like `b'\x30\x30\x00\x36\x00\x31\x00\x30\x00\x33\x00\x30\x00\x31\x00\x30\x00\x31\x00\x36\x00\x31\x00\x35\x00\x37\x00\x35'.decode('utf-16-le')` or literally unicode values `\x3500\x3700\x3500\x3100\x3600\x3100\x3000\x3100\x3000\x3300\x3000\x3100\x3600\x3030` +Dymo 450 GET_DEVICE_ID example string: +``` +'MFG:DYMO;CMD: ;MDL:LabelWriter 450;CLASS:PRINTER;DESCRIPTION:DYMO LabelWriter 450;SERN:01010112345600;' +``` + +Dymo Twin Turbo GET_DEVICE_ID example string (note the null byte before ERN:): +``` +'MFG:DYMO;CMD: ;MDL:LabelWriter Twin Turbo;CLASS:PRINTER;DESCRIPTION:DYMO LabelWriter Twin Turbo;\x00ERN:006103010161575' +``` + Note: Linux Mint 22.1 <- Ubuntu 24.04 Noble <- Debian Trixie/sid <- Kernel 6.8.0-71-generic; pyusb version 1.3.1; python version 3.12.3 References @@ -66,3 +76,5 @@ https://kernel.org/category/faq.html https://bugzilla.kernel.org/show_bug.cgi?id=220422 +https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/LegacyCollaterals/01233a.pdf + diff --git a/src/dymott.py b/src/dymott.py index 7b59907..11582a7 100644 --- a/src/dymott.py +++ b/src/dymott.py @@ -38,6 +38,19 @@ dymo_450_serialdata = usb.control.get_descriptor(dymo_450, 30, 0x03, 0x03, 1033) def get_serial_raw(dev): return usb.control.get_descriptor(dev, 254, usb.DT_STRING, dev.iSerialNumber, dev.langids[0]) +def get_device_id(dev): + # Get the IEEE 1284 Device ID string + # ref: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/LegacyCollaterals/01233a.pdf + GET_DEVICE_ID = 0xa1 # USBPRINTER protocol bmRequestType printer protocol request + bRequest = 0x00 # USBPRINTER protocol bRequest get_device_id + GET_PORT_STATUS = 0x01 # USBPRINTER protocol bRequest get_port_status (returns 1 byte) + SOFT_RESET = 0x21 # USBPRINTER protocol bmRequestType soft reset + wValue = 0 # USBPRINTER protocol Config Index + wIndex = 0 # USBPRINTER protocol interface index and alt setting + wLength = 1023 # Max buffer length + # ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, msg or buffsize) + return dev.ctrl_transfer(GET_DEVICE_ID, bRequest, wValue, wIndex, wLength) + def get_serial(dev): rawserial = get_serial_raw(dev) # Return just the data portion of the descriptor data @@ -67,7 +80,8 @@ def fix_serial(uri_line): # CUPS output looks like: # direct usb://DYMO/... "DYMO LabelWriter Twin Turbo" usb://... # We'll add a stable dummy fallback here - dummy_serial = "DYMOFIX-" + str(abs(hash(uri_line)) % 10000) + #dummy_serial = "DYMOFIX-" + str(abs(hash(uri_line)) % 10000) + new_serial = get_serial() uri_line = uri_line.replace(f"serial={serial}", f"serial={dummy_serial}") return uri_line