|
@@ -1,17 +1,44 @@
|
|
|
import usb.core
|
|
|
import time
|
|
|
|
|
|
+hid_usb_dev = None
|
|
|
+
|
|
|
+
|
|
|
+def usb_find():
|
|
|
+ global hid_usb_dev
|
|
|
+ hid_usb_dev = usb.core.find(idVendor=1155, idProduct=22352)
|
|
|
+ print(hid_usb_dev)
|
|
|
+ if hid_usb_dev is None:
|
|
|
+ raise ValueError("Device not found")
|
|
|
+
|
|
|
|
|
|
def main():
|
|
|
- dev = usb.core.find(idVendor=1155, idProduct=22352)
|
|
|
- if dev is None:
|
|
|
- raise ValueError('Device not found')
|
|
|
- else:
|
|
|
- print(dev)
|
|
|
+
|
|
|
+ global hid_usb_dev
|
|
|
+ is_device = False
|
|
|
|
|
|
while True:
|
|
|
- ret = dev.read(0x81, 64, 100)
|
|
|
- print(*ret)
|
|
|
+ if is_device:
|
|
|
+ print("Try to read from device...")
|
|
|
+ try:
|
|
|
+ ret = hid_usb_dev.read(0x81, 64, 100)
|
|
|
+ print(*ret)
|
|
|
+ except:
|
|
|
+ is_device = False
|
|
|
+ print("Reading error")
|
|
|
+
|
|
|
+ if not is_device:
|
|
|
+ print("Try to find stm32 HID")
|
|
|
+ try:
|
|
|
+ usb_find()
|
|
|
+ except:
|
|
|
+ print("Can't find from usb_hid")
|
|
|
+ is_device = False
|
|
|
+ else:
|
|
|
+ print("Device found")
|
|
|
+ is_device = True
|
|
|
+
|
|
|
+
|
|
|
time.sleep(1)
|
|
|
|
|
|
|