>>> from pprint import pprint
>>> from pycomedi.device import Device
- >>> from pycomedi.subdevice import StreamingSubdevice
- >>> from pycomedi.channel import AnalogChannel
- >>> from pycomedi.constant import AREF, SUBDEVICE_TYPE, UNIT
+ >>> from pycomedi.constant import AREF
>>> from . import config
>>> from . import surface
>>> d = Device('/dev/comedi0')
>>> d.open()
- >>> s_in = d.find_subdevice_by_type(SUBDEVICE_TYPE.ai,
- ... factory=StreamingSubdevice)
- >>> s_out = d.find_subdevice_by_type(SUBDEVICE_TYPE.ao,
- ... factory=StreamingSubdevice)
-
- >>> axis_channel = s_out.channel(
- ... 0, factory=AnalogChannel, aref=AREF.ground)
- >>> input_channel = s_in.channel(0, factory=AnalogChannel, aref=AREF.diff)
- >>> for chan in [axis_channel, input_channel]:
- ... chan.range = chan.find_range(unit=UNIT.volt, min=-10, max=10)
+ >>> piezo_config = config.PiezoConfig()
+ >>> piezo_config['name'] = 'Molly'
+ >>> piezo_config['axes'] = [config.AxisConfig()]
+ >>> piezo_config['axes'][0]['channel'] = config.OutputChannelConfig()
+ >>> piezo_config['axes'][0]['channel']['analog-reference'] = AREF.ground
+ >>> piezo_config['axes'][0]['channel']['name'] = 'z'
+ >>> piezo_config['inputs'] = [config.InputChannelConfig()]
+ >>> piezo_config['inputs'][0]['analog-reference'] = AREF.diff
+ >>> piezo_config['inputs'][0]['name'] = 'deflection'
We set the minimum voltage for the `z` axis to -9 (a volt above
the minimum possible voltage) to help with testing
first few surface approaching steps, which could lead to an
`EdgeKink` error instead of a `FlatFit` error.
- >>> axis_config = config.AxisConfig()
- >>> axis_config.update(
+ >>> piezo_config['axes'][0].update(
... {'gain':20, 'sensitivity':8e-9, 'minimum':-9})
- >>> axis_config['channel'] = config.OutputChannelConfig()
- >>> axis_config['channel']['name'] = 'z'
- >>> input_config = config.InputChannelConfig()
- >>> input_config['name'] = 'deflection'
-
- >>> a = _base.PiezoAxis(config=axis_config, axis_channel=axis_channel)
- >>> a.setup_config()
- >>> c = _base.InputChannel(config=input_config, channel=input_channel)
- >>> c.setup_config()
+ >>> a = _base.PiezoAxis(config=piezo_config['axes'][0], devices=[d])
+ >>> c = _base.InputChannel(config=piezo_config['inputs'][0], devices=[d])
- >>> p = AFMPiezo(axes=[a], inputs=[c], name='Molly')
+ >>> p = AFMPiezo(config=piezo_config, axes=[a], inputs=[c])
+ >>> p.setup_config()
>>> deflection = p.read_deflection()
>>> deflection # doctest: +SKIP
>>> d = Device('/dev/comedi0')
>>> d.open()
- >>> s_in = d.find_subdevice_by_type(SUBDEVICE_TYPE.ai,
- ... factory=StreamingSubdevice)
- >>> s_out = d.find_subdevice_by_type(SUBDEVICE_TYPE.ao,
- ... factory=StreamingSubdevice)
-
- >>> axis_channel = s_out.channel(
- ... 0, factory=AnalogChannel, aref=AREF.ground)
- >>> monitor_channel = s_in.channel(
- ... 0, factory=AnalogChannel, aref=AREF.diff)
- >>> input_channel = s_in.channel(1, factory=AnalogChannel, aref=AREF.diff)
- >>> for chan in [axis_channel, monitor_channel, input_channel]:
- ... chan.range = chan.find_range(unit=UNIT.volt, min=-10, max=10)
-
>>> axis_config = _config.AxisConfig()
- >>> axis_config.update({'gain':20, 'sensitivity':8e-9})
+ >>> axis_config['gain'] = 20.0
+ >>> axis_config['sensitivity'] = 8e-9
>>> axis_config['channel'] = _config.OutputChannelConfig()
+ >>> axis_config['channel']['analog-reference'] = AREF.ground
>>> axis_config['channel']['name'] = 'z'
>>> axis_config['monitor'] = _config.InputChannelConfig()
- >>> input_config = _config.InputChannelConfig()
- >>> input_config['name'] = 'some-input'
-
- >>> a = PiezoAxis(config=axis_config, axis_channel=axis_channel,
- ... monitor_channel=monitor_channel)
+ >>> axis_config['monitor']['analog-reference'] = AREF.diff
+ >>> a = PiezoAxis(config=axis_config, devices=[d])
>>> a.setup_config()
- >>> c = InputChannel(config=input_config, channel=input_channel)
+ >>> input_config = _config.InputChannelConfig()
+ >>> input_config['analog-reference'] = AREF.diff
+ >>> input_config['name'] = 'some-input'
+ >>> c = InputChannel(config=input_config, devices=[d])
>>> c.setup_config()
- >>> p = Piezo(axes=[a], inputs=[c], name='Charlie')
+ >>> config = _config.PiezoConfig()
+ >>> config['name'] = 'Charlie'
+
+ >>> p = Piezo(config=config, axes=[a], inputs=[c])
+ >>> p.setup_config()
>>> inputs = p.read_inputs()
>>> pprint(inputs) # doctest: +SKIP
{'some-input': 34494L, 'z-monitor': 32669L}
'z': array([ 0, 3276, ..., 32760], dtype=uint16),
'z-monitor': array([ 3102, 6384, ..., 32647], dtype=uint16)}
+ Opening from the config alone:
+
+ >>> p = Piezo(config=config, devices=[d])
+ >>> for axis in p.axes:
+ ... print(axis.axis_channel)
+ ... print(axis.monitor_channel)
+ ... # doctest: +ELLIPSIS
+ <pycomedi.channel.AnalogChannel object at 0x...>
+ <pycomedi.channel.AnalogChannel object at 0x...>
+ >>> for input in p.inputs:
+ ... print(input.channel)
+ ... # doctest: +ELLIPSIS
+ <pycomedi.channel.AnalogChannel object at 0x...>
+
>>> d.close()
"""
- def __init__(self, axes, inputs, name=None):
+ def __init__(self, config, axes=None, inputs=None, devices=None):
+ self.config=config
self.axes = axes
self.inputs = inputs
- self.config = _config.PiezoConfig()
- self.name = name
- self.config['name'] = name
- self.config['axes'] = [x.config for x in axes]
- self.config['inputs'] = [x.config for x in 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))
+ self.last_output.clear()
+ if not self.inputs:
+ self.inputs = []
+ for config in self.config['inputs']:
+ self.inputs.append(
+ InputChannel(config=config, devices=devices))
+ self.name = self.config['name']
+
+ def setup_config(self):
+ "Initialize the axis and input configs."
+ for x in self.axes + self.inputs:
+ x.setup_config()
+ self.config['axes'] = [x.config for x in self.axes]
+ self.config['inputs'] = [x.config for x in self.inputs]
def axis_by_name(self, name):
"Get an axis by its name."