.. _thorlabs_usb_piezo_controller_config:

Thorlabs MDT69xx USB Configuration
==================================

**Problem**

The USB chip in the Thorlabs MDT69xx series (e.g., MDT693B) may identify as a **Human Interface Device (HID)**.
If the ``usbhid`` kernel driver binds to it, the device cannot be accessed via a serial interface, rendering it non-functional.

**Solution: udev Rule**

1. **Identify Vendor and Product IDs**

   Run the following command to list all USB devices and locate the Thorlabs device::

      lsusb

   Example output::

      Bus 001 Device 003: ID xxxx:xxxx Thorlabs MDT693B

   Note the ``xxxx`` values for ``idVendor`` and ``idProduct``.

2. **Find the USB Kernel Path**

   Use ``udevadm`` to inspect the device attributes and locate the **kernel path** (e.g., ``1-8:1.0``)::

      udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/XXX/YYY)

   Replace ``XXX`` and ``YYY`` with the bus and device numbers from ``lsusb``.
   This command will print a lot of information. You are looking for a line like::

      looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:046A:B090.0002/hidraw/hidraw1':

   Here, the ``1-8:1.0`` is what you are looking for.

3. **Create the udev Rule**

   Edit or create a new udev rules file (e.g., ``/etc/udev/rules.d/99-thorlabs-piezo.rules``) and add the following rule::

      # Thorlabs piezo controller MDT693B
      ACTION=="add", DRIVERS=="usb", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", SYMLINK+="USB_PIEZO_CTRL_1", RUN+="echo -n 'kernel_path' > /sys/bus/usb/drivers/usbhid/unbind"

   Replace:

   - ``xxxx`` with the **Vendor and Product IDs** from Step 1.
   - ``kernel_path`` with the **USB kernel path** from Step 2 (e.g., ``1-5.1.2.3:1.0``).

4. **Reload udev Rules**

   Apply the changes by reloading the udev rules::

      sudo udevadm control --reload-rules
      sudo udevadm trigger --action add
