Rely on the internal `.load_from_config()` methods to do that for us.
This reduces duplication (e.g. device filename only set in config
defaults, not in doctests too). It also makes it posible to use
several devices to build your AFM interface, where the old doctests
would only work with all the communication going through a single
card.
>>> import os
>>> import tempfile
- >>> from pycomedi.device import Device
>>> from pycomedi import constant
>>> import pypiezo.config
>>> import pyafm.config
>>> fd,filename = tempfile.mkstemp(suffix='.h5', prefix='pyafm-')
>>> os.close(fd)
- >>> device = Device('/dev/comedi0')
- >>> device.open()
+ >>> devices = []
>>> config = pyafm.config.AFMConfig()
>>> config['piezo'] = pypiezo.config.PiezoConfig()
>>> config['temperature'] = pyafm.config.TemperatureConfig()
>>> config['temperature']['name'] = 'test temperature'
- >>> afm = AFM(config=config, devices=[device])
+ >>> afm = AFM(config=config, devices=devices)
>>> afm.setup_config()
>>> afm.get_temperature() # doctest: +SKIP
test temperature
<HDF5 dataset "units": shape (), type "|S7">
Celsius
- >>> afm2 = pyafm.storage.load_afm(filename=filename, devices=[device])
+ >>> afm2 = pyafm.storage.load_afm(filename=filename, devices=devices)
>>> afm2.get_temperature() # doctest: +SKIP
297.37
It's hard to test anything else without pugging into an actual AFM.
- >>> device.close()
+ >>> for device in devices:
+ ... device.close()
Cleanup our temporary config file.
class DigitalPort (object):
"""A digital input/output port (i.e. cluster of channels).
- >>> from pycomedi.device import Device
>>> from pyafm.config import DigitalPortConfig
- >>> device = Device('/dev/comedi0')
- >>> device.open()
+ >>> devices = []
>>> config = DigitalPortConfig()
>>> config['channels'] = [1, 2, 3, 4]
>>> config['name'] = 'test port'
- >>> port = DigitalPort(config=config, devices=[device])
+ >>> port = DigitalPort(config=config, devices=devices)
>>> port.write_bitfield(13)
>>> port.write([1, 0, 1, 0])
>>> port.write_bitfield(0)
- >>> device.close()
+ >>> for device in devices:
+ ... device.close()
"""
def __init__(self, config, devices=None):
self.config = config
Uses `DigitalPort` for transmitting the output.
- >>> from pycomedi.device import Device
>>> from pycomedi import constant as _constant
>>> from pyafm.config import StepperConfig, DigitalPortConfig
- >>> device = Device('/dev/comedi0')
- >>> device.open()
+ >>> devices = []
>>> config = StepperConfig()
>>> config['port'] = DigitalPortConfig()
>>> config['port']['name'] = 'stepper port'
>>> config['name'] = 'test stepper'
- >>> s = Stepper(config=config, devices=[device])
+ >>> s = Stepper(config=config, devices=devices)
>>> s.position
0
>>> s.single_step(1)
>>> s.position
2
- >>> device.close()
+ >>> for device in devices:
+ ... device.close()
"""
def __init__(self, config, devices=None):
self.config = config