You can download this code by clicking the button below.
This code is now available for download.
This function is used to find and return the first USB device that matches the specified Vendor ID (vid) and Product ID (pid). If no matching device is found, it returns None.
Technology Stack : PyUSB
Code Type : Function
Code Difficulty : Intermediate
import usb.core
import usb.util
def find_first_device_byVIDPID(vid, pid):
# Find devices matching vid and pid
devices = usb.core.find(find_all=False, idVendor=vid, idProduct=pid)
# Return the first device found
return devices[0] if devices else None