add function to reset USB devices

This commit is contained in:
petrucci4prez 2017-05-29 17:43:03 -04:00
parent f75cbc1fa5
commit b36536b48b
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import time, psutil, yaml import time, psutil, yaml, os
from subprocess import check_output, DEVNULL, CalledProcessError from subprocess import check_output, DEVNULL, CalledProcessError
from threading import Thread, Event 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) logger.warning('Failed to terminate PID %s. Sending SIGKILL', p.pid)
p.kill() 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): def fallbackLogger(module, loglevel, msg):
print('[{}] [{}] [FALLBACK LOGGER]: {}'.format(module, loglevel, msg)) print('[{}] [{}] [FALLBACK LOGGER]: {}'.format(module, loglevel, msg))