Finding the First Connected USB Device in Python

  • Share this:

Code introduction


This function is used to find and return the first connected USB device. If no devices are found, it returns None.


Technology Stack : PyUSB

Code Type : The type of code

Code Difficulty :


                
                    
import usb.core
import usb.util

def find_first_usb_device():
    # This function finds and returns the first connected USB device.
    devices = usb.core.find(find_all=False)
    if devices is None:
        return None
    return devices                
              
Tags: