]> sigrok.org Git - sigrok-meter.git/commitdiff
Initial working display of multimeter values.
authorUwe Hermann <redacted>
Thu, 18 Apr 2013 17:20:10 +0000 (19:20 +0200)
committerUwe Hermann <redacted>
Thu, 18 Apr 2013 17:20:10 +0000 (19:20 +0200)
This currently hardcodes various things, such as the DMM used (the
Voltcraft VC-820 using the UT-D02 USB/HID cable), which will be
fixed later.

sigrok-meter
sigrok-meter.glade

index 6ef32835896ac2cda587e9d4538caffcc1a95475..d53a288a2eb7d560943df6aee9e8461ea3f53681 100755 (executable)
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-from gi.repository import Gtk
-import libsigrok
+from multiprocessing import Process, Queue
+from gi.repository import Gtk, GObject
+from sigrok.core import Context, Driver, Device, Session, Packet
+from sigrok.core import lowlevel as ll
+
+def init_and_run(queue):
+    def datafeed_in(device, packet):
+        if packet.type == Packet.ANALOG:
+            data = packet.payload.data
+            unit, unit_str = packet.payload.unit, ""
+            if unit == ll.SR_UNIT_VOLT:
+                unit_str = " V"
+            elif unit == ll.SR_UNIT_OHM:
+                unit_str = " Ohm"
+            elif unit == ll.SR_UNIT_AMPERE:
+                unit_str = " A"
+            mqflags, mqflags_str = packet.payload.unit, ""
+            if mqflags & ll.SR_MQFLAG_AC:
+                mqflags_str = " AC"
+            elif mqflags & ll.SR_MQFLAG_DC:
+                mqflags_str = " DC"
+            for i in range(packet.payload.num_samples):
+                queue.put("%f%s%s" % (data[i], unit_str, mqflags_str))
+
+    # ll.sr_log_loglevel_set(5)
+    context = Context()
+    driver = context.drivers['voltcraft-vc820']
+    device = driver.scan()[0]
+    device.limit_samples = 1000
+    session = Session(context)
+    session.add_device(device)
+    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.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()
+            self.value_label.set_text(t)
+        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 = libsigrok.sr_package_version_string_get()
-        sr_lib = libsigrok.sr_lib_version_string_get()
+        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__':
-        SigrokMeter()
+        s = SigrokMeter()
+        process = Process(target=init_and_run, args=(s.queue,))
+        process.start()
         Gtk.main()
+        process.terminate()
 
index 710a3e1497bce31dd6af7f34234d9c85b69272d5..ab3e353b18424260b963aef2ad1da3e6bcbc3e06 100644 (file)
           </packing>
         </child>
         <child>
-          <placeholder/>
+          <object class="GtkLabel" id="value_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="justify">center</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
         </child>
         <child>
           <placeholder/>