Custom device name for nrf52840 USB dongle in pyserial

I am making an application using nrf52840 USB dongle. 

I am using a python program with pyserial. This works great. 
My only problem is that I want to have a very reliable way to identify the correct USB device.

I am using this code in python to identify the USB device.

def find_nrf_com_port():
    ports = serial.tools.list_ports.comports()
    print("dY"? Available COM ports:")
    for port in ports:
        print(port)

    for port in ports:
        if "Nestlab" in port.description or "USB Serial Device" in port.description:
            return port.device
    return None


this is returning

PS C:\Users\BjornOlsen\Documents\GitHub\nestlab_usb_stick\usb_comm> python3 .\read_serial.py
🔍 Available COM ports:
COM17 - USB Serial Device (COM17)
✅ Auto-detected COM port: COM17
Connected to COM17...

The problem here is that the device is called "USB Serial Device". Not a very descriptive name! 

In my nrf52840 I am using this prj.conf.

CONFIG_GPIO=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Nestlab USB Stick"
CONFIG_USB_DEVICE_MANUFACTURER="Malsen Medical"
CONFIG_USB_DEVICE_SN="0001"
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_CJSON_LIB=y

I was expecting that this would change the name to "Nestlab USB Stick" - but alas this does not work.
Note! I do not need it to show up in windows. I only really need the name to be unique when I list USB devices using pyserial.


  • Hi bjornolsen,

    What you found gave me a great clue to recall something. The root cause is that Windows cache the device name since the first time you connected to it. When you change VID and PID, it recognizes the device as something new, so the configured name goes through.

    Thus, this is a limitation on the host OS, Windows. There is not much that can be done from the device application, unfortunately.

Related