vpaeder / pymcp2221

A python driver for the Microchip MCP2221/MCP2221A USB 2.0 to I2C/UART protocol converters
https://pypi.org/project/pymcp2221
MIT License
5 stars 2 forks source link

Question, length of Product and Manufacturer strings #11

Closed harkwoodservices closed 1 year ago

harkwoodservices commented 1 year ago

This library is exactly what I'm looking for, so I can update the MCP2221A details without needing the Windows .DLL's, great work.

However, I am finding that when trying to use write_usb_product_descriptor and write_usb_manufacturer_descriptor the whole string is not always updated.

If I use write_usb_product_descriptor("Product-Name Version 2"), what I get written is "Product-Name Version", it is always truncated after the 20th character.

mcp = MCP2221(find_devices()[0])
mcp.write_usb_product_descriptor("Product-Name Version 2")
mcp.reset_chip()
time.sleep(10)
print(find_devices(vendor_id=1240, product_id=221))

Gets the result

[{'path': b'DevSrvsID:4295226701', 'vendor_id': 1240, 'product_id': 221, 'serial_number': '', 'release_number': 256, 'manufacturer_string': '', 'product_string': 'ˇProduct-Name Version ', 'usage_page': 65280, 'usage': 1, 'interface_number': 2}]

If I use write_usb_product_descriptor("12345678901234567890123456789") it works fine

I'm probably missing something simple, any pointers are welcome.

vpaeder commented 1 year ago

This is because strings shorter than 29 characters must be terminated (with \0). I changed the code to do that automatically.

harkwoodservices commented 1 year ago

That would explain it. Thanks for the quick fix.