#!/usr/bin/python3 ## ## This file is part of the sigrok-meter project. ## ## Copyright (C) 2013 Uwe Hermann ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## from multiprocessing import Process, Queue from gi.repository import Gtk, GObject from sigrok.core import * def init_and_run(queue): def datafeed_in(device, packet): if packet.type is PacketType.ANALOG: data = packet.payload.data unit, unit_str = packet.payload.unit, "" if unit is Unit.VOLT: unit_str = " V" elif unit is Unit.OHM: unit_str = " Ohm" elif unit is unit.AMPERE: unit_str = " A" mqflags, mqflags_str = packet.payload.mqflags, "" if QuantityFlag.AC in mqflags: mqflags_str = " AC" elif QuantityFlag.DC in mqflags: mqflags_str = " DC" for i in range(packet.payload.num_samples): dev = "%s" % device.vendor val = "%f%s%s" % (data[i], unit_str, mqflags_str) queue.put((dev, val)) # log = Log() # log.level = LogLevel.SPEW context = Context() drivers_to_use = ['voltcraft-vc820', 'victor-dmm'] drivers = [context.drivers[d] for d in drivers_to_use] devices = [d.scan()[0] for d in drivers] for dev in devices: dev.limit_samples = 1000 session = Session(context) for dev in devices: session.add_device(dev) session.add_callback(datafeed_in) session.start() session.run() session.stop() class SigrokMeter: def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file("sigrok-meter.glade") self.builder.connect_signals(self) self.value_label = self.builder.get_object("value_label") self.value_label2 = self.builder.get_object("value_label2") self.win = self.builder.get_object("mainwindow") self.win.show_all() self.queue = Queue() GObject.timeout_add(100, self.update_label_if_needed) def update_label_if_needed(self): try: t = self.queue.get_nowait() l = self.value_label if t[0] != "Victor" else self.value_label2 l.set_text("%s: %s" % (t[0], t[1])) except: pass GObject.timeout_add(100, self.update_label_if_needed) def on_quit(self, *args): Gtk.main_quit(*args) def on_about(self, action): about = self.builder.get_object("aboutdialog") sr_pkg = ll.sr_package_version_string_get() sr_lib = ll.sr_lib_version_string_get() s = "Using libsigrok %s (lib version %s)." % (sr_pkg, sr_lib) about.set_comments(s) about.run() about.hide() if __name__ == '__main__': s = SigrokMeter() process = Process(target=init_and_run, args=(s.queue,)) process.start() Gtk.main() process.terminate()