]> sigrok.org Git - sigrok-meter.git/blame - sigrok-meter
Acquire data from two DMMs at the same time.
[sigrok-meter.git] / sigrok-meter
CommitLineData
c09ca11b
UH
1#!/usr/bin/python3
2##
3## This file is part of the sigrok-meter project.
4##
5## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
6##
7## This program is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## This program is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with this program; if not, write to the Free Software
19## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20##
21
13e332b7
UH
22from multiprocessing import Process, Queue
23from gi.repository import Gtk, GObject
774c3953 24from sigrok.core import Context, Driver, Device, Session, Packet, Log
13e332b7
UH
25from sigrok.core import lowlevel as ll
26
27def init_and_run(queue):
28 def datafeed_in(device, packet):
29 if packet.type == Packet.ANALOG:
30 data = packet.payload.data
31 unit, unit_str = packet.payload.unit, ""
32 if unit == ll.SR_UNIT_VOLT:
33 unit_str = " V"
34 elif unit == ll.SR_UNIT_OHM:
35 unit_str = " Ohm"
36 elif unit == ll.SR_UNIT_AMPERE:
37 unit_str = " A"
49e0ee28 38 mqflags, mqflags_str = packet.payload.mqflags, ""
13e332b7
UH
39 if mqflags & ll.SR_MQFLAG_AC:
40 mqflags_str = " AC"
41 elif mqflags & ll.SR_MQFLAG_DC:
42 mqflags_str = " DC"
43 for i in range(packet.payload.num_samples):
49e0ee28
UH
44 dev = "%s" % device.vendor
45 val = "%f%s%s" % (data[i], unit_str, mqflags_str)
46 queue.put((dev, val))
13e332b7 47
774c3953
UH
48 # log = Log()
49 # log.level = Log.SPEW
13e332b7 50 context = Context()
49e0ee28
UH
51 drivers_to_use = ['voltcraft-vc820', 'victor-dmm']
52 drivers = [context.drivers[d] for d in drivers_to_use]
53 devices = [d.scan()[0] for d in drivers]
54 for dev in devices:
55 dev.limit_samples = 1000
13e332b7 56 session = Session(context)
49e0ee28
UH
57 for dev in devices:
58 session.add_device(dev)
13e332b7
UH
59 session.add_callback(datafeed_in)
60 session.start()
61 session.run()
62 session.stop()
c09ca11b 63
730cbd1f
UH
64class SigrokMeter:
65 def __init__(self):
66 self.builder = Gtk.Builder()
67 self.builder.add_from_file("sigrok-meter.glade")
68 self.builder.connect_signals(self)
13e332b7 69 self.value_label = self.builder.get_object("value_label")
49e0ee28 70 self.value_label2 = self.builder.get_object("value_label2")
fd029d02 71 self.win = self.builder.get_object("mainwindow")
730cbd1f 72 self.win.show_all()
13e332b7
UH
73 self.queue = Queue()
74 GObject.timeout_add(100, self.update_label_if_needed)
75
76 def update_label_if_needed(self):
77 try:
78 t = self.queue.get_nowait()
49e0ee28
UH
79 l = self.value_label if t[0] != "Victor" else self.value_label2
80 l.set_text("%s: %s" % (t[0], t[1]))
13e332b7
UH
81 except:
82 pass
83 GObject.timeout_add(100, self.update_label_if_needed)
730cbd1f 84
fd029d02 85 def on_quit(self, *args):
2f5ef701 86 Gtk.main_quit(*args)
730cbd1f 87
fd029d02 88 def on_about(self, action):
730cbd1f 89 about = self.builder.get_object("aboutdialog")
13e332b7
UH
90 sr_pkg = ll.sr_package_version_string_get()
91 sr_lib = ll.sr_lib_version_string_get()
a683a5e2
UH
92 s = "Using libsigrok %s (lib version %s)." % (sr_pkg, sr_lib)
93 about.set_comments(s)
dd73092b
UH
94 about.run()
95 about.hide()
2f5ef701 96
730cbd1f 97if __name__ == '__main__':
13e332b7
UH
98 s = SigrokMeter()
99 process = Process(target=init_and_run, args=(s.queue,))
100 process.start()
a683a5e2 101 Gtk.main()
13e332b7 102 process.terminate()
c09ca11b 103