Add --mmap argument to cmd.py demo and fix some pycomedi_demo_args.py bugs.
authorW. Trevor King <wking@drexel.edu>
Tue, 20 Mar 2012 01:16:06 +0000 (21:16 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 20 Mar 2012 01:16:06 +0000 (21:16 -0400)
doc/demo/cmd.py
doc/demo/insn.py
doc/demo/pycomedi_demo_args.py

index 3ee20fd5c693ce7a087b7261e9e63ea317bc5a96..0ea1e5a665f9d121a6eb68f185c04f26c5bef467 100755 (executable)
@@ -22,7 +22,7 @@ from pycomedi.device import Device as _Device
 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):
@@ -76,7 +76,7 @@ def print_data(channels, data, physical=False):
         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(
@@ -89,7 +89,7 @@ def read(device, subdevice=None, channels=[0], range=0, aref=0, period=0,
     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()
@@ -106,20 +106,25 @@ if __name__ == '__main__':
 
     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()
index 52133cf5cbb46bbbf34e898cab14bf626f0a247e..8d84d545c625159017dd1a96c3e08067db3a46a7 100755 (executable)
@@ -20,9 +20,10 @@ if __name__ == '__main__':
 
     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))
index 83f9f5d66cfe9963d3454b1d496f4adab0f88ae4..cfa0d89ff33955082fef8ebd5721a5a67b918a3e 100644 (file)
@@ -69,6 +69,12 @@ ARGUMENTS = {
          '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}),
@@ -76,8 +82,10 @@ ARGUMENTS = {
 
 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