Facebook
From Tohfa Akib, 2 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 159
  1. import usb.core
  2. import usb.util
  3.  
  4. # The Vendor and Product ID of the Huawei E3372
  5. VENDOR_ID = 0x12d1
  6. PRODUCT_ID = 0x14dc
  7.  
  8. def reset_usb_device(vendor_id, product_id):
  9.     # Find the USB device
  10.     dev = usb.core.find(idVendor=vendor_id, idProduct=product_id)
  11.     if dev is None:
  12.         raise ValueError('Device not found')
  13.    
  14.     # Reset the device
  15.     try:
  16.         dev.reset()
  17.         print("Device reset successfully.")
  18.     except Exception as e:
  19.         print(f"Failed to reset device: {e}")
  20.  
  21. if __name__ == "__main__":
  22.     try:
  23.         reset_usb_device(VENDOR_ID, PRODUCT_ID)
  24.     except ValueError as e:
  25.         print(e)