add usbprinter device_id string

This commit is contained in:
wp
2025-08-08 21:53:16 -05:00
parent 19ff9151a7
commit 47654338b1
3 changed files with 28 additions and 1 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ __pycache__
*.egg-info *.egg-info
*.bak2 *.bak2
.venv .venv
dymott

View File

@@ -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 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` `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 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 References
@@ -66,3 +76,5 @@ https://kernel.org/category/faq.html
https://bugzilla.kernel.org/show_bug.cgi?id=220422 https://bugzilla.kernel.org/show_bug.cgi?id=220422
https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/LegacyCollaterals/01233a.pdf

View File

@@ -38,6 +38,19 @@ dymo_450_serialdata = usb.control.get_descriptor(dymo_450, 30, 0x03, 0x03, 1033)
def get_serial_raw(dev): def get_serial_raw(dev):
return usb.control.get_descriptor(dev, 254, usb.DT_STRING, dev.iSerialNumber, dev.langids[0]) 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): def get_serial(dev):
rawserial = get_serial_raw(dev) rawserial = get_serial_raw(dev)
# Return just the data portion of the descriptor data # Return just the data portion of the descriptor data
@@ -67,7 +80,8 @@ def fix_serial(uri_line):
# CUPS output looks like: # CUPS output looks like:
# direct usb://DYMO/... "DYMO LabelWriter Twin Turbo" usb://... # direct usb://DYMO/... "DYMO LabelWriter Twin Turbo" usb://...
# We'll add a stable dummy fallback here # 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}") uri_line = uri_line.replace(f"serial={serial}", f"serial={dummy_serial}")
return uri_line return uri_line