]> sigrok.org Git - sigrok-meter.git/blame_incremental - sigrok-meter
Use the new Quantity et al classes.
[sigrok-meter.git] / sigrok-meter
... / ...
CommitLineData
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
22from multiprocessing import Process, Queue
23from gi.repository import Gtk, GObject
24from sigrok.core import *
25
26def init_and_run(queue):
27 def datafeed_in(device, packet):
28 if packet.type is PacketType.ANALOG:
29 data = packet.payload.data
30 unit, unit_str = packet.payload.unit, ""
31 if unit is Unit.VOLT:
32 unit_str = " V"
33 elif unit is Unit.OHM:
34 unit_str = " Ohm"
35 elif unit is unit.AMPERE:
36 unit_str = " A"
37 mqflags, mqflags_str = packet.payload.mqflags, ""
38 if QuantityFlag.AC in mqflags:
39 mqflags_str = " AC"
40 elif QuantityFlag.DC in mqflags:
41 mqflags_str = " DC"
42 for i in range(packet.payload.num_samples):
43 dev = "%s" % device.vendor
44 val = "%f%s%s" % (data[i], unit_str, mqflags_str)
45 queue.put((dev, val))
46
47 # log = Log()
48 # log.level = LogLevel.SPEW
49 context = Context()
50 drivers_to_use = ['voltcraft-vc820', 'victor-dmm']
51 drivers = [context.drivers[d] for d in drivers_to_use]
52 devices = [d.scan()[0] for d in drivers]
53 for dev in devices:
54 dev.limit_samples = 1000
55 session = Session(context)
56 for dev in devices:
57 session.add_device(dev)
58 session.add_callback(datafeed_in)
59 session.start()
60 session.run()
61 session.stop()
62
63class SigrokMeter:
64 def __init__(self):
65 self.builder = Gtk.Builder()
66 self.builder.add_from_file("sigrok-meter.glade")
67 self.builder.connect_signals(self)
68 self.value_label = self.builder.get_object("value_label")
69 self.value_label2 = self.builder.get_object("value_label2")
70 self.win = self.builder.get_object("mainwindow")
71 self.win.show_all()
72 self.queue = Queue()
73 GObject.timeout_add(100, self.update_label_if_needed)
74
75 def update_label_if_needed(self):
76 try:
77 t = self.queue.get_nowait()
78 l = self.value_label if t[0] != "Victor" else self.value_label2
79 l.set_text("%s: %s" % (t[0], t[1]))
80 except:
81 pass
82 GObject.timeout_add(100, self.update_label_if_needed)
83
84 def on_quit(self, *args):
85 Gtk.main_quit(*args)
86
87 def on_about(self, action):
88 about = self.builder.get_object("aboutdialog")
89 sr_pkg = ll.sr_package_version_string_get()
90 sr_lib = ll.sr_lib_version_string_get()
91 s = "Using libsigrok %s (lib version %s)." % (sr_pkg, sr_lib)
92 about.set_comments(s)
93 about.run()
94 about.hide()
95
96if __name__ == '__main__':
97 s = SigrokMeter()
98 process = Process(target=init_and_run, args=(s.queue,))
99 process.start()
100 Gtk.main()
101 process.terminate()
102