4 ## This file is part of the sigrok-meter project.
6 ## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
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, write to the Free Software
20 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 from multiprocessing import Process, Queue
24 from gi.repository import Gtk, GObject
25 from sigrok.core import *
26 from sigrok.core import lowlevel as ll
28 def init_and_run(queue):
29 def datafeed_in(device, packet):
30 if packet.type is PacketType.ANALOG:
31 data = packet.payload.data
32 unit, unit_str = packet.payload.unit, ""
35 elif unit is Unit.OHM:
37 elif unit is Unit.AMPERE:
39 mqflags, mqflags_str = packet.payload.mqflags, ""
40 if QuantityFlag.AC in mqflags:
42 elif QuantityFlag.DC in mqflags:
44 for i in range(packet.payload.num_samples):
45 dev = "%s %s" % (device.vendor, device.model)
46 val = "%f%s%s" % (data[i], unit_str, mqflags_str)
50 # log.level = LogLevel.SPEW
52 drivers_to_use = ['tecpel-dmm-8061-ser']
53 drivers = [context.drivers[d] for d in drivers_to_use]
54 devices = [d.scan(conn="/dev/ttyUSB0")[0] for d in drivers]
55 # devices = [d.scan()[0] for d in drivers]
57 # dev.limit_samples = 1000
58 session = Session(context)
60 session.open_device(dev)
61 session.add_device(dev)
62 session.add_callback(datafeed_in)
69 self.builder = Gtk.Builder()
70 self.builder.add_from_file("sigrok-meter.glade")
71 self.builder.connect_signals(self)
72 self.value_label = self.builder.get_object("value_label")
73 self.value_label2 = self.builder.get_object("value_label2")
74 self.win = self.builder.get_object("mainwindow")
77 GObject.timeout_add(100, self.update_label_if_needed)
79 def update_label_if_needed(self):
81 t = self.queue.get_nowait()
82 l = self.value_label if t[0] != "Victor" else self.value_label2
83 l.set_text("%s: %s" % (t[0], t[1]))
86 GObject.timeout_add(100, self.update_label_if_needed)
88 def on_quit(self, *args):
91 def on_about(self, action):
92 about = self.builder.get_object("aboutdialog")
93 sr_pkg = ll.sr_package_version_string_get()
94 sr_lib = ll.sr_lib_version_string_get()
95 s = "Using libsigrok %s (lib version %s)." % (sr_pkg, sr_lib)
100 if __name__ == '__main__':
102 process = Process(target=init_and_run, args=(s.queue,))