##
import qtcompat
+import re
import sigrok.core as sr
QtCore = qtcompat.QtCore
self.sampling = False
+ def parse_driverstring(self, ds):
+ '''Dissects the driver string and returns a tuple consiting of
+ the driver name and the options (as a dictionary).'''
+
+ def parse_option(k, v):
+ '''Parse the value for a single option.'''
+ try:
+ ck = sr.ConfigKey.get_by_identifier(k)
+ except:
+ raise ValueError('No option named "{}".'.format(k))
+
+ try:
+ val = ck.parse_string(v)
+ except:
+ raise ValueError(
+ 'Invalid value "{}" for option "{}"'.format(v, k))
+
+ return (k, val)
+
+ m = re.match('(?P<name>[^:]+)(?P<opts>(:[^:=]+=[^:=]+)*)$', ds)
+ if not m:
+ raise ValueError('"{}" is not a valid driver string.'.format(ds))
+
+ opts = m.group('opts').split(':')[1:]
+ opts = [tuple(kv.split('=')) for kv in opts]
+ opts = [parse_option(k, v) for (k, v) in opts]
+ opts = dict(opts)
+
+ return (m.group('name'), opts)
+
@QtCore.Slot()
def start_sampling(self):
devices = []
- for name, options in self.drivers:
+ for ds in self.drivers:
try:
- dr = self.context.drivers[name]
- devices.append(dr.scan(**options)[0])
- except:
+ (name, opts) = self.parse_driverstring(ds)
+ if not name in self.context.drivers:
+ raise RuntimeError('No driver called "{}".'.format(name))
+
+ driver = self.context.drivers[name]
+ devs = driver.scan(**opts)
+ if not devs:
+ raise RuntimeError('No devices found.')
+ devices.append(devs[0])
+ except Exception as e:
self.error.emit(
- 'Unable to get device for driver "{}".'.format(name))
+ 'Error processing driver string:\n{}'.format(e))
return
self.session = self.context.create_session()
##
import argparse
-import re
import sigrok.core as sr
import sys
import textwrap
-default_drivers = [('demo', {'analog_channels': 4})]
+default_drivers = ['demo:analog_channels=4']
default_loglevel = sr.LogLevel.WARN
def parse_cli():
}
if args.driver:
- result['drivers'] = []
- for d in args.driver:
- m = re.match('(?P<name>[^:]+)(?P<opts>(:[^:=]+=[^:=]+)*)', d)
- if not m:
- sys.exit('error parsing option "{}"'.format(d))
-
- opts = m.group('opts').split(':')[1:]
- opts = [tuple(kv.split('=')) for kv in opts]
- opts = dict(opts)
-
- result['drivers'].append((m.group('name'), opts))
+ result['drivers'] = args.driver
if args.loglevel != None:
try: