Properly close ports with provided interface
authorDan White <dan@whiteaudio.com>
Fri, 2 Nov 2012 23:41:03 +0000 (18:41 -0500)
committerDan White <dan@whiteaudio.com>
Fri, 2 Nov 2012 23:41:03 +0000 (18:41 -0500)
python-lib/devboard.py

index 319259435981fabed942729ee07706ce3126cd30..8c234f778b5d3437ac30aeb07a7b5748423e0881 100644 (file)
@@ -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