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'
>>> 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()
>>> 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')
Opening from the config alone:
- >>> p = PiezoAxis(config=config, devices=[d])
+ >>> p = PiezoAxis(config=config)
+ >>> p.load_from_config(devices=[d])
>>> p.axis_channel # doctest: +ELLIPSIS
<pycomedi.channel.AnalogChannel object at 0x...>
>>> p.monitor_channel # doctest: +ELLIPSIS
>>> d.close()
"""
- def __init__(self, config, axis_channel=None, monitor_channel=None,
- devices=None):
+ def __init__(self, config, axis_channel=None, monitor_channel=None):
self.config = config
self.axis_channel = axis_channel
self.monitor_channel = monitor_channel
- self.load_from_config(devices=devices)
def load_from_config(self, devices):
c = self.config # reduce verbosity
'({} and {})').format(
c['channel']['device'], c['monitor']['device']))
if not self.axis_channel:
- self.axis_channel = OutputChannel(
- config=c['channel'], devices=devices).channel
+ output = OutputChannel(config=c['channel'])
+ output.load_from_config(devices=devices)
+ self.axis_channel = output.channel
if c['monitor'] and not self.monitor_channel:
- self.monitor_channel = InputChannel(
- config=c['monitor'], devices=devices).channel
+ monitor = InputChannel(config=c['monitor'])
+ monitor.load_from_config(devices=devices)
+ self.monitor_channel = monitor.channel
self.name = c['channel']['name']
def setup_config(self):
Opening from the config alone:
- >>> c = OutputChannel(config=channel_config, devices=[d])
+ >>> c = OutputChannel(config=channel_config)
+ >>> c.load_from_config(devices=[d])
>>> c.channel # doctest: +ELLIPSIS
<pycomedi.channel.AnalogChannel object at 0x...>
>>> d.close()
"""
- def __init__(self, config, channel=None, devices=None):
+ def __init__(self, config, channel=None):
self.config = config
self.channel = channel
- self.load_from_config(devices=devices)
def load_from_config(self, devices):
_load_channel_from_config(
Opening from the config alone:
- >>> c = InputChannel(config=channel_config, devices=[d])
+ >>> c = InputChannel(config=channel_config)
+ >>> c.load_from_config(devices=[d])
>>> c.channel # doctest: +ELLIPSIS
<pycomedi.channel.AnalogChannel object at 0x...>
>>> d.close()
"""
- def __init__(self, config, channel=None, devices=None):
+ def __init__(self, config, channel=None):
self.config = config
self.channel = channel
- self.load_from_config(devices=devices)
def load_from_config(self, devices):
_load_channel_from_config(
>>> axis_config['channel']['name'] = 'z'
>>> axis_config['monitor'] = _config.InputChannelConfig()
>>> axis_config['monitor']['analog-reference'] = AREF.diff
- >>> a = PiezoAxis(config=axis_config, devices=[d])
+ >>> a = PiezoAxis(config=axis_config)
+ >>> a.load_from_config(devices=[d])
>>> a.setup_config()
>>> input_config = _config.InputChannelConfig()
>>> input_config['analog-reference'] = AREF.diff
>>> input_config['name'] = 'some-input'
- >>> c = InputChannel(config=input_config, devices=[d])
+ >>> c = InputChannel(config=input_config)
+ >>> c.load_from_config(devices=[d])
>>> c.setup_config()
>>> config = _config.PiezoConfig()
Opening from the config alone:
- >>> p = Piezo(config=config, devices=[d])
+ >>> p = Piezo(config=config)
+ >>> p.load_from_config(devices=[d])
>>> for axis in p.axes:
... print(axis.axis_channel)
... print(axis.monitor_channel)
>>> d.close()
"""
- def __init__(self, config, axes=None, inputs=None, devices=None):
+ def __init__(self, config, axes=None, inputs=None):
self.config=config
self.axes = axes
self.inputs = inputs
self.last_output = {}
- self.load_from_config(devices=devices)
def load_from_config(self, devices):
if not self.axes:
self.axes = []
for config in self.config['axes']:
- self.axes.append(PiezoAxis(config=config, devices=devices))
+ axis = PiezoAxis(config=config)
+ axis.load_from_config(devices=devices)
+ self.axes.append(axis)
self.last_output.clear()
if not self.inputs:
self.inputs = []
for config in self.config['inputs']:
- self.inputs.append(
- InputChannel(config=config, devices=devices))
+ input = InputChannel(config=config)
+ input.load_from_config(devices=devices)
+ self.inputs.append(input)
self.name = self.config['name']
def setup_config(self):