cdtx / mcp2200

Python interface to the MCP2200
MIT License
6 stars 6 forks source link

Read and Write Product String and Manufacturer String #11

Open csparkresearch opened 2 years ago

csparkresearch commented 2 years ago

It would be nice for this utility to have an option to perform the undocumented ability to modify the product and manufacturer strings. This was reverse engineered and documented in this wonderful answer - https://stackoverflow.com/a/23106926

I am pasting a Python port of a function to be added to the class MCP2200Device which someone someday might find useful. I wish I could raise a PR, but I'm used to PyQt5 instead of PySide2, and will at some point try to port the UI as well.

    def write_string(self,prod, stringtype = 'prod'):
        if(stringtype=='manu'):
            tp = self.MCP2200_CFG_MANU
        else:
            tp = self.MCP2200_CFG_PROD
        l = len(prod)*2 + 2        
        prodStr = "{:<64}".format(chr(l)+prod)
        print('Writing ',prodStr)
        wlist = []
        row=[0]*16
        tmp=0x03
        print('len = ',ord(prodStr[0]))
        for i in range(16):
            row[0] = self.MCP2200_SECRET_CONFIGURE
            row[1] = tp
            row[2] = i
            row[3] = ord(prodStr[i*4])
            row[4] = tmp
            row[5] = ord(prodStr[i*4+1])
            row[6] = 0x00
            row[7] = ord(prodStr[i*4+2])
            row[8] = 0x00
            row[9] = ord(prodStr[i*4+3])
            row[10] = 0x00
            row[11] = 0xff
            row[12] = 0xff
            row[13] = 0xff
            row[14] = 0xff
            row[15] = 0xff
            wlist.append(row)
            self.write(row)
            tmp=0x00

devices = MCP2200Device.discover(MCP2200_VID, MCP2200_PID)
print(devices)
if(len(devices)):
    device = MCP2200Device()
    device.connect(MCP2200_VID, MCP2200_PID, 0)
    print(device.read_all())
    print(device.write_string("New Product String"))
    print(device.write_string("New Manufacturer String", 'manu'))

Tested. Works.

[666158.213099] usb 1-2: new full-speed USB device number 36 using xhci_hcd
[666158.386426] usb 1-2: New USB device found, idVendor=04d8, idProduct=00df, bcdDevice= 1.01
[666158.386435] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[666158.386439] usb 1-2: Product: Test and Measurement Utility
[666158.386442] usb 1-2: Manufacturer: CSpark Research Pvt Ltd
[666158.386444] usb 1-2: SerialNumber: 0004260205
[666158.398901] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[666158.407048] hid-generic 0003:04D8:00DF.0022: hiddev0,hidraw1: USB HID v1.11 Device [CSpark Research Pvt Ltd Test and Measurement Utility] on usb-0000:08:00.3-2/input2

The Originally linked answer has documented the ability to modify VID and PID as well.

Cheers, @jithinbp

cdtx commented 2 years ago

Hi, thanks for this proposal. I'm ok to implement this as soon as I have the time to.