add python handler

This commit is contained in:
wp
2025-08-07 20:14:02 -05:00
parent c0fa9d7901
commit 163750f3b3
2 changed files with 50 additions and 3 deletions

View File

@@ -62,4 +62,7 @@ https://github.com/torvalds/linux/blob/master/drivers/usb/core/quirks.c
https://docs.kernel.org/admin-guide/reporting-issues.html
https://kernel.org/category/faq.html
https://kernel.org/category/faq.html
https://bugzilla.kernel.org/show_bug.cgi?id=220422

View File

@@ -1,6 +1,50 @@
import usb.core
import usb.util
dymo_vid = 0x0922
dymo_tt_pid = 0x0018
dymo_vid = 0x0922 # Dymo vendor ID
dymo_tt_pid = 0x0018 # Dymo Twin Turbo Product ID
dymo_450_pid = 0x0020 # Dymo 450 Product ID
dymo_tt = usb.core.find(idVendor=dymo_vid, idProduct=dymo_tt_pid)
dymo_450 = usb.core.find(idVendor=dymo_vid, idProduct=dymo_450_pid)
#dymo_tt.serial_number # Prints device unique ID
#dymo_tt.langids # Returns language IDs (1033,) for english
# Get descriptor for serial number
# fields: dymo_tt - reference to device to get the data from
# 254 - max buffer for received data (254 max, 30 expected for serial number)
# 0x03 - Data type - 0x03 = string data
# dymo_tt.iSerialNumber - index of serial number data (0x03)
# dymo_tt.langids[0] - First item from supported languages (1033)
#usb.control.get_descriptor(dymo_tt, 254, 0x03, dymo_tt.iSerialNumber, dymo_tt.langids[0])
#usb.control.get_descriptor(dymo_450, 254, 0x03, dymo_450.iSerialNumber, dymo_450.langids[0])
dymo_tt_serialdata = usb.control.get_descriptor(dymo_tt, 30, 0x03, 0x03, 1033)
dymo_450_serialdata = usb.control.get_descriptor(dymo_450, 30, 0x03, 0x03, 1033)
#print(dymo_tt_serialdata.hex())
#print(dymo_450_serialdata.hex())
# returns the string representation of the serial number received from the device
#print(dymo_tt_serialdata[2:len(dymo_tt_serialdata)].decode('utf-16-le'))
#print(dymo_450_serialdata[2:30].decode('utf-16-le'))
# returns raw bytes representation of encoded data
#print(dymo_tt_serialdata[2:30].decode('utf-8'))
#print(dymo_450_serialdata[2:30].decode('utf-8'))
def get_serial_raw(dev):
return usb.control.get_descriptor(dev, 254, usb.DT_STRING, dev.iSerialNumber, dev.langids[0])
def get_serial(dev):
rawserial = get_serial_raw(dev)
# Return just the data portion of the descriptor data
# First byte is length of returned data, second byte is type of returned data (30 and 3 expected)
rawserial = rawserial[2:len(rawserial)].tobytes()
if dev.idVendor == 0x0922 and dev.idProduct == 0x0018:
# Because the Twin Turbo returns invalid serial data, we drop the first 2 bytes
# and decode the remainder as utf-16-be (big-endian)
return rawserial[2:len(rawserial)].decode('utf-16-be')
else:
return rawserial.decode('utf-16-le')