from pycomedi.subdevice import StreamingSubdevice as _StreamingSubdevice
from pycomedi.channel import AnalogChannel as _AnalogChannel
from pycomedi.chanspec import ChanSpec as _ChanSpec
-from pycomedi.utility import Reader as _Reader
+import pycomedi.utility as _utility
def open_channels(device, subdevice, channels, range, aref):
print '\t'.join(str(x) for x in data[row,:])
def read(device, subdevice=None, channels=[0], range=0, aref=0, period=0,
- num_scans=2, physical=False):
+ num_scans=2, reader=_utility.Reader, physical=False):
"""Read ``num_scans`` samples from each specified channel.
"""
subdevice,channels = open_channels(
read_buffer = _numpy.zeros(
(num_scans, len(channels)),
dtype=subdevice.get_dtype())
- reader = _Reader(subdevice, read_buffer)
+ reader = reader(subdevice=subdevice, buffer=read_buffer, name='Reader')
start = _time.time()
_LOG.info('start time: {}'.format(start))
subdevice.command()
args = pycomedi_demo_args.parse_args(
description=__doc__,
- argnames=['filename', 'subdevice', 'channels', 'aref', 'range', 'num-scans',
- 'frequency', 'physical', 'verbose'])
+ argnames=['filename', 'subdevice', 'channels', 'aref', 'range',
+ 'num-scans', 'mmap', 'frequency', 'physical', 'verbose'])
_LOG.info(('measuring device={0.filename} subdevice={0.subdevice} '
'channels={0.channels} range={0.range} '
'analog-reference={0.aref}'
).format(args))
+ if args.mmap:
+ reader = _utility.MMapReader
+ else:
+ reader = _utility.Reader
+
device = _Device(filename=args.filename)
device.open()
try:
read(
device=device, subdevice=args.subdevice, channels=args.channels,
range=args.range, aref=args.aref, period=args.period,
- num_scans=args.num_scans, physical=args.physical)
+ num_scans=args.num_scans, reader=reader, physical=args.physical)
finally:
device.close()
args = pycomedi_demo_args.parse_args(
description=__doc__,
- argnames=['filename', 'subdevice', 'channel', 'aref', 'range', 'num-scans',
- 'verbose'])
+ argnames=['filename', 'subdevice', 'channel', 'aref', 'range',
+ 'num-scans', 'verbose'])
+ print(args)
_LOG.info(('measuring device={0.filename} subdevice={0.subdevice} '
'channel={0.channel} range={0.range} analog reference={0.aref}'
).format(args))
'action':'store_const',
'const':True,
'help':'convert input to physical values before printing'}),
+ 'mmap':(
+ ['--mmap'],
+ {'default':False,
+ 'action':'store_const',
+ 'const':True,
+ 'help':'use a memory-mapped reader rather than reading the input subdevice directly'}),
'verbose':(
['-v', '--verbose'],
{'action':_IncrementVerbosityAction}),
def parse_args(description, argnames):
parser = _argparse.ArgumentParser(description=description)
- for argument in ['filename', 'subdevice', 'channels', 'aref', 'range',
- 'num-scans', 'frequency', 'physical', 'verbose']:
+ for argument in argnames:
args,kwargs = ARGUMENTS[argument]
parser.add_argument(*args, **kwargs)
- return parser.parse_args()
+ args = parser.parse_args()
+ if 'frequency' in argnames and not hasattr(args, 'period'):
+ args.period = 0
+ return args