From b36536b48bbabae4bec5973cb693e1438afcc7de Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Mon, 29 May 2017 17:43:03 -0400 Subject: [PATCH] add function to reset USB devices --- auxilary.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/auxilary.py b/auxilary.py index 3d3e44f..b69a1b6 100644 --- a/auxilary.py +++ b/auxilary.py @@ -1,4 +1,4 @@ -import time, psutil, yaml +import time, psutil, yaml, os from subprocess import check_output, DEVNULL, CalledProcessError from threading import Thread, Event @@ -82,5 +82,13 @@ def freeBusyPath(path, logger=None): logger.warning('Failed to terminate PID %s. Sending SIGKILL', p.pid) p.kill() +# crude way to 'unplug and plug back in' for USB device +def resetUSBDevice(device): + devpath = os.path.join('/sys/bus/usb/devices/' + device + '/authorized') + with open(devpath, 'w') as f: + f.write('0') + with open(devpath, 'w') as f: + f.write('1') + def fallbackLogger(module, loglevel, msg): print('[{}] [{}] [FALLBACK LOGGER]: {}'.format(module, loglevel, msg))