From f39f2c277fec39fcb6d4f21f1d30f66287258d97 Mon Sep 17 00:00:00 2001 From: Dan White Date: Fri, 2 Nov 2012 18:41:03 -0500 Subject: [PATCH] Properly close ports with provided interface --- python-lib/devboard.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/python-lib/devboard.py b/python-lib/devboard.py index 3192594..8c234f7 100644 --- a/python-lib/devboard.py +++ b/python-lib/devboard.py @@ -200,9 +200,15 @@ def close_usb(delay=0): closed, the kernel will suspend the device. This makes the SUSPEND pin go low on the usbio board and allows a circuit to cut power to the devboard. """ - print 'closing usb ports, waiting for kernel to suspend port' - for c in (spi0.context, spi1.context, i2c.context): - usbio.ftdi.usb_close(c) + print 'Closing usb ports, waiting for kernel to suspend port' + for port in (spi0, spi1, i2c): + try: + port.close() + except usbio.FTDI_Error: + #already closed, ignore + pass + global is_initialized + is_initialized = False sleep(delay) @@ -255,15 +261,13 @@ def init_devboard(name='devboard-defaults.yaml'): mux = None arb = None amux = None - is_initialized = False - # try loading config for given chip ID if isinstance(name, int): name = 'chip%02i-calibration.yaml' % name try: - load_config(name) + load_config(name, delay=1) is_initialized = True return except IOError: @@ -334,7 +338,7 @@ def init_devboard(name='devboard-defaults.yaml'): -def load_config(name): +def load_config(name, delay=0): """Given a dict or a filename containing a yaml dump of settings, load them and (re-)initialize all components. """ @@ -355,6 +359,7 @@ def load_config(name): spi0 = usbio.SPI(**cfg['spi0']) spi1 = usbio.SPI(**cfg['spi1']) i2c = usbio.I2C(**cfg['i2c']) + sleep(delay) ########################################################################## # Analog bias -- 2.25.1