diff --git a/README.md b/README.md index 46100a1..cd653c3 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +https://kernel.org/category/faq.html + +https://bugzilla.kernel.org/show_bug.cgi?id=220422 + diff --git a/src/dymott.py b/src/dymott.py index 9dbb57b..be3c526 100644 --- a/src/dymott.py +++ b/src/dymott.py @@ -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')