Only call figure.show if it exits.
[pypiezo.git] / pypiezo / afm.py
index 5cf5569365f29cf3c7e239ee64c7820ef6826943..6e00347a26e6f2195148407750a1c5ee919ff8a4 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of pypiezo.
 #
@@ -42,13 +42,11 @@ class AFMPiezo (_base.Piezo):
     deflection measurements.
 
     >>> from pprint import pprint
-    >>> from pycomedi.device import Device
     >>> from pycomedi.constant import AREF
     >>> from . import config
     >>> from . import surface
 
-    >>> d = Device('/dev/comedi0')
-    >>> d.open()
+    >>> devices = []
 
     >>> piezo_config = config.PiezoConfig()
     >>> piezo_config['name'] = 'Molly'
@@ -70,10 +68,8 @@ class AFMPiezo (_base.Piezo):
     >>> piezo_config['axes'][0].update(
     ...     {'gain':20, 'sensitivity':8e-9, 'minimum':-9})
 
-    >>> a = _base.PiezoAxis(config=piezo_config['axes'][0], devices=[d])
-    >>> c = _base.InputChannel(config=piezo_config['inputs'][0], devices=[d])
-
-    >>> p = AFMPiezo(config=piezo_config, axes=[a], inputs=[c])
+    >>> p = AFMPiezo(config=piezo_config)
+    >>> p.load_from_config(devices=devices)
     >>> p.setup_config()
 
     >>> deflection = p.read_deflection()
@@ -85,9 +81,8 @@ class AFMPiezo (_base.Piezo):
     We need to know where we are before we can move somewhere
     smoothly.
 
-    >>> pos = _base.convert_volts_to_bits(p.config.select_config(
-    ...     'axes', 'z', get_attribute=_base.get_axis_name)['channel'], 0)
-    >>> p.jump('z', pos)
+    >>> zeros = p.zero(axis_names=['z'])
+    >>> pos = zeros[0]
 
     Usually `.move_to_pos_or_def` is used to approach the surface, but
     for testing we assume the z output channel is connected directly
@@ -142,7 +137,8 @@ class AFMPiezo (_base.Piezo):
     >>> abs(e.left_slope-1) < 0.1
     True
 
-    >>> d.close()
+    >>> for device in devices:
+    ...     device.close()
     """
     def _deflection_channel(self):
         return self.channel_by_name(name='deflection', direction='input')
@@ -263,7 +259,11 @@ class AFMPiezo (_base.Piezo):
             axes.set_title('step approach %s' % timestamp)
             axes.plot(pos_array, def_array, '.', label=timestamp)
             #_pylab.legend(loc='best')
-            figure.show()
+            figure.canvas.draw()
+            if hasattr(figure, 'show'):
+                figure.show()
+            if not _matplotlib.is_interactive():
+                _matplotlib_pyplot.show()
 
         if return_data:
             data = {