almost make new binary protocol work with python (up to fetching and parsing the JSON)

This commit is contained in:
Samuel Sadok
2017-10-23 23:15:56 +02:00
parent 03854e3b35
commit c19a693fe9
20 changed files with 460 additions and 266 deletions
+3 -29
View File
@@ -1,9 +1,6 @@
# requires pyusb
# pip install --pre pyusb
import time
import usb.core
import usb.util
# Exceptions
class ODriveError(Exception):
@@ -12,33 +9,10 @@ class ODriveError(Exception):
class ODriveNotConnectedError(ODriveError):
pass
# ODrive generic 1209:0D31
USBID_VID_ODRIVE = 0x1209
USBID_PID_ODRIVE = 0x0D31
# ODrive rev 3.1 1209:0D31
USBID_VID_ODRIVE_3_1 = USBID_VID_ODRIVE
USBID_PID_ODRIVE_3_1 = USBID_PID_ODRIVE
USB_DEV_ODRIVE_3_1 = (USBID_VID_ODRIVE_3_1, USBID_PID_ODRIVE_3_1)
USB_DEV_ODRIVE_3_1 = (0x1209, 0x0D31)
USB_DEV_ODRIVE_3_3 = (0x1209, 0x0D33)
# all devices
all_devices = [USB_DEV_ODRIVE_3_1]
# device messages
DEVICE_NOT_FOUND = 'ODrive Not Found'
DEVICE_FOUND = 'ODrive Found!'
USB_VID_PID_PAIRS = [USB_DEV_ODRIVE_3_1, USB_DEV_ODRIVE_3_3]
def noprint(x):
pass
def poll_odrive_device(devices=all_devices, intv=1, printer=noprint):
while 1:
time.sleep(intv)
for device in devices:
try:
idVendor = device[0]
idProduct = device[1]
dev = usb.core.find(idVendor=idVendor, idProduct=idProduct)
if dev is not None:
printer(DEVICE_FOUND)
return device
except:
printer(DEVICE_NOT_FOUND)