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