channel_config = axis_config['channel']
return channel_config['name']
-def _load_device(filename, devices):
+def load_device(filename, devices):
"""Return an open device from `devices` which has a given `filename`.
Sometimes a caller will already have the required `Device`, in
>>> from pycomedi.device import Device
>>> devices = [Device('/dev/comedi0')]
- >>> device = _load_device(filename='/dev/comedi0', devices=devices)
+ >>> device = load_device(filename='/dev/comedi0', devices=devices)
>>> device.filename
'/dev/comedi0'
>>> device.file is not None
>>> device.close()
>>> devices = []
- >>> device = _load_device(filename='/dev/comedi0', devices=devices)
+ >>> device = load_device(filename='/dev/comedi0', devices=devices)
>>> devices == [device]
True
>>> device.filename
We try and return helpful errors when things go wrong:
- >>> device = _load_device(filename='/dev/comedi0', devices=None)
+ >>> device = load_device(filename='/dev/comedi0', devices=None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
- >>> device = _load_device(filename='/dev/comedi0', devices=tuple())
+ >>> device = load_device(filename='/dev/comedi0', devices=tuple())
Traceback (most recent call last):
...
ValueError: none of the available devices ([]) match /dev/comedi0, and we cannot append to ()
- >>> device = _load_device(filename='/dev/comediX', devices=[])
+ >>> device = load_device(filename='/dev/comediX', devices=[])
Traceback (most recent call last):
...
PyComediError: comedi_open (/dev/comediX): No such file or directory (None)
def _load_channel_from_config(channel, devices, subdevice_type):
c = channel.config # reduce verbosity
if not channel.channel:
- device = _load_device(filename=c['device'], devices=devices)
+ device = load_device(filename=c['device'], devices=devices)
if c['subdevice'] < 0:
subdevice = device.find_subdevice_by_type(
subdevice_type, factory=StreamingSubdevice)