Ver Fonte

Added pyusb control.py

  For some very odd reason this is having horrible times working.

  See pyserial command.py
david há 3 anos atrás
pai
commit
85e1fbc4dc
1 ficheiros alterados com 66 adições e 0 exclusões
  1. 66 0
      control.py

+ 66 - 0
control.py

@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+import usb.core as core
+import usb.util as util
+from usb.core import USBError
+
+from remotes import tv
+
+# Use usb-devices to find the Arduino
+dev = core.find(idVendor=0x2341, idProduct=0x0043)
+detached = False
+
+if dev is None:
+    raise ValueError("Device Not Found!")
+
+
+if dev.is_kernel_driver_active(0):
+    try:
+        dev.detach_kernel_driver(0)
+        detached = True
+        print("Kernel detached")
+    except USBError as e:
+        exit("Failed detaching kernel driver!")
+else:
+    print("No Kernel Attached!")
+
+try:
+    util.claim_interface(dev, 0)
+    print("Claimed Device!")
+except:
+    endpoint = dev[0][(0,0)][0]
+    data = dev.read(endpoint.bEndpointAddress, 0x0040)
+    print(type(data))
+    print(data)
+
+if detached:
+    dev.attach_kernel_driver(0)
+    print("Kernel attached")
+
+exit()
+#print(type(dev))
+#print(dev)
+
+# Setup the device
+# https://github.com/pyusb/pyusb/issues/357
+#dev.set_configuration()
+
+# Get the config
+cfg = dev.get_active_configuration()
+
+print(cfg)
+
+# Index the config for interfaces
+intf = cfg[(0, 0)]
+
+# If you don't know the endpoint
+# Obatains the endpoint out
+ep = util.find_descriptor(
+    intf,
+    custom_match = \
+    lambda e: \
+        util.endpoint_direction(e.bEndpointAddress) == \
+        util.ENDPOINT_OUT)
+
+assert ep is not None
+
+ep.write('0x57E3E817,32,1\n')