3 ## This file is part of the sigrok-meter project.
5 ## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com>
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
27 default_drivers = [('demo:analog_channels=4', 'samplerate=4')]
30 parser = argparse.ArgumentParser(
31 description='Simple sigrok GUI for multimeters and dataloggers.',
32 epilog=textwrap.dedent('''\
33 The DRIVER string is the same as for sigrok-cli(1). Multiple
34 DRIVER and CONFIG items can be supplied. The nth CONFIG is applied
35 to the nth DRIVER. If there are more drivers than configs, the
36 remaining drivers use the default configuration.
40 %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0
42 %(prog)s --driver uni-t-ut61e:conn=1a86.e008
44 %(prog)s --driver demo:analog_channels=1 \\
45 --config samplerate=10
47 %(prog)s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\
48 --driver uni-t-ut61d:conn=1a86.e008 \\
49 --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1
51 formatter_class=argparse.RawDescriptionHelpFormatter)
53 parser.add_argument('-d', '--driver',
56 help='The driver to use')
57 parser.add_argument('-c', '--config',
60 help='Specify device configuration options')
61 parser.add_argument('-l', '--loglevel',
64 help='Set loglevel (5 is most verbose)')
65 parser.add_argument('--pyside',
68 help='Force use of PySide (default is to use PyQt4)')
69 args = parser.parse_args()
71 if len(args.config) > len(args.driver):
72 sys.exit('Error: More configurations than drivers given.')
74 # Merge drivers and configurations into a list of tuples.
75 setattr(args, 'drivers', [])
77 args.drivers = default_drivers
78 sys.stderr.write('No driver given, using demo driver.\n')
80 args.config.extend([''] * (len(args.driver) - len(args.config)))
81 args.drivers = zip(args.driver, args.config)
87 if __name__ == '__main__':
88 signal.signal(signal.SIGINT, signal.SIG_DFL)
93 qtcompat.load_modules(args.pyside)
94 QtCore = qtcompat.QtCore
95 QtGui = qtcompat.QtGui
97 app = QtGui.QApplication([])
100 import sigrok.core as sr
101 except Exception as e:
102 QtGui.QMessageBox.critical(None, 'Error starting sigrok-meter',
103 'Unable to use the sigrok Python bindings:\n{}.'.format(e))
106 # Initialize modules that need a QApplication to exist.
112 context = sr.Context_create()
114 if args.loglevel != None:
116 loglevel = sr.LogLevel.get(args.loglevel)
117 settings.logging.level.setValue(loglevel)
119 sys.exit('Error: invalid log level.')
122 s = mainwindow.MainWindow(context, args.drivers)
125 sys.exit(app.exec_())