more work on HP3562A data block dumper/displayer application.

Mon, 11 Feb 2008 23:35:41 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 11 Feb 2008 23:35:41 +0100
changeset 43
a250bd7a2022
parent 42
a947d80b1afd
child 44
c4bdd390918c

more work on HP3562A data block dumper/displayer application.

bin/q3562 file | annotate | diff | comparison | revisions
examples/coord.bin file | annotate | diff | comparison | revisions
examples/datablocks/coord.bin file | annotate | diff | comparison | revisions
examples/datablocks/dump.bin file | annotate | diff | comparison | revisions
examples/datablocks/dump_1_21.bin file | annotate | diff | comparison | revisions
examples/datablocks/dump_1_21_ftop.bin file | annotate | diff | comparison | revisions
examples/datablocks/state.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace2.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace3.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace4.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace5.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace_10.bin file | annotate | diff | comparison | revisions
examples/datablocks/trace_11.bin file | annotate | diff | comparison | revisions
examples/dump.bin file | annotate | diff | comparison | revisions
examples/dump_1_21.bin file | annotate | diff | comparison | revisions
examples/dump_1_21_ftop.bin file | annotate | diff | comparison | revisions
examples/state.bin file | annotate | diff | comparison | revisions
examples/trace.bin file | annotate | diff | comparison | revisions
pygpibtoolkit/HP3562A/q3562A.py file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/q3562	Mon Feb 11 23:35:41 2008 +0100
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+
+import sys, os
+try:
+    from pygpibtoolkit.HP3562A.q3562A import main
+except ImportError:
+    sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+    from pygpibtoolkit.HP3562A.q3562A import main
+main()
Binary file examples/coord.bin has changed
Binary file examples/datablocks/coord.bin has changed
Binary file examples/datablocks/dump.bin has changed
Binary file examples/datablocks/dump_1_21.bin has changed
Binary file examples/datablocks/dump_1_21_ftop.bin has changed
Binary file examples/datablocks/state.bin has changed
Binary file examples/datablocks/trace.bin has changed
Binary file examples/datablocks/trace2.bin has changed
Binary file examples/datablocks/trace3.bin has changed
Binary file examples/datablocks/trace4.bin has changed
Binary file examples/datablocks/trace5.bin has changed
Binary file examples/datablocks/trace_10.bin has changed
Binary file examples/datablocks/trace_11.bin has changed
Binary file examples/dump.bin has changed
Binary file examples/dump_1_21.bin has changed
Binary file examples/dump_1_21_ftop.bin has changed
Binary file examples/state.bin has changed
Binary file examples/trace.bin has changed
--- a/pygpibtoolkit/HP3562A/q3562A.py	Fri Feb 08 20:01:47 2008 +0100
+++ b/pygpibtoolkit/HP3562A/q3562A.py	Mon Feb 11 23:35:41 2008 +0100
@@ -9,7 +9,7 @@
 
 if "-m" in sys.argv:
     from dump_datablock_mockup import HP3562dumper
-else:
+else: 
     from dump_datablock import HP3562dumper
 
 from pygpibtoolkit.qt4.qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem
@@ -42,30 +42,6 @@
     background = ColorItem(default=QtGui.QColor("white"),
                            name="Plots background",
                            group="Colors")
-    color0 = ColorItem(default=QtGui.QColor("black"),
-                       name="Pen #0",
-                       group="Colors")
-    color1 = ColorItem(default=QtGui.QColor("green"),
-                       name="Pen #1",
-                       group="Colors")
-    color2 = ColorItem(default=QtGui.QColor("red"),
-                       name="Pen #2",
-                       group="Colors")
-    color3 = ColorItem(default=QtGui.QColor("blue"),
-                       name="Pen #3",
-                       group="Colors")
-    color4 = ColorItem(default=QtGui.QColor("yellow"),
-                       name="Pen #4",
-                       group="Colors")
-    color5 = ColorItem(default=QtGui.QColor("cyan"),
-                       name="Pen #5",
-                       group="Colors")
-    color6 = ColorItem(default=QtGui.QColor("magenta"),
-                       name="Pen #6",
-                       group="Colors")
-    color7 = ColorItem(default=QtGui.QColor("darkred"),
-                       name="Pen #7",
-                       group="Colors")
     
 class Qt3562(QtGui.QMainWindow):
     def __init__(self, parent=None):
@@ -96,13 +72,9 @@
 
     def readPreferences(self):
         bg = self._prefs.background
-        pen_colors = [self._prefs["color%d"%i] for i in range(8)]
+        #pen_colors = [self._prefs["color%d"%i] for i in range(8)]
         #self.plotterWidget.pen_colors = pen_colors
-        
-    def replotCurrent(self):
-        pass
-        #self.currentPlotChanged(self.plotsView.currentIndex())
-        
+                
     def createActions(self):
         self.openAct = QtGui.QAction(QtGui.QIcon(":/icons/open.png"),
                         self.tr("&Open..."), self)
@@ -171,6 +143,19 @@
                      QtGui.qApp, QtCore.SLOT("aboutQt()"))
 
 
+        self.getStateAct = QtGui.QAction(self.tr("Get state"), self)
+        self.getStateAct.setStatusTip(self.tr("Retrieve State from GPIB device"))
+        self.connect(self.getStateAct, QtCore.SIGNAL("triggered()"),
+                     self.getState)
+        self.getTraceAct = QtGui.QAction(self.tr("Get trace"), self)
+        self.getTraceAct.setStatusTip(self.tr("Retrieve Trace from GPIB device"))
+        self.connect(self.getTraceAct, QtCore.SIGNAL("triggered()"),
+                     self.getTrace)
+        self.getCoordAct = QtGui.QAction(self.tr("Get coord"), self)
+        self.getCoordAct.setStatusTip(self.tr("Retrieve Coord from GPIB device"))
+        self.connect(self.getCoordAct, QtCore.SIGNAL("triggered()"),
+                     self.getCoord)
+        
     def setupUi(self):
         self.connect(self.actionPreferences, SIGNAL('triggered(bool)'),
                      self.preferencesTriggered)
@@ -244,29 +229,30 @@
         self.connect(self.windowMenu, QtCore.SIGNAL("aboutToShow()"), 
                      self.updateWindowMenu)
 
+
+
+        self.deviceMenu = self.menuBar().addMenu(self.tr("&Device"))
+        self.deviceMenu.addAction(self.getStateAct)
+        self.deviceMenu.addAction(self.getTraceAct)
+        self.deviceMenu.addAction(self.getCoordAct)
+
         self.menuBar().addSeparator()
-
         self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
         self.helpMenu.addAction(self.aboutAct)
         self.helpMenu.addAction(self.aboutQtAct)
-
+        
     def createToolBars(self):
         self.fileToolBar = self.addToolBar(self.tr("File"))
         self.fileToolBar.addAction(self.openAct)
         self.fileToolBar.addAction(self.saveAsAct)
+        self.fileToolBar.addSeparator()
+        self.fileToolBar.addAction(self.getStateAct)
+        self.fileToolBar.addAction(self.getTraceAct)
+        self.fileToolBar.addAction(self.getCoordAct)
                 
     def createStatusBar(self):
         self.statusBar().showMessage(self.tr("Ready"))
-        
-
-    def currentPlotChanged(self, index, old_index=None):
-        if index.isValid():
-            pass
-#             value = unicode(self.plotsView.model().data(index, Qt.DisplayRole).toString())
-            
-#             self.plotterWidget.clear()
-#             self.plotterWidget.parse(self._plots[value])
-            
+                    
     def preferencesTriggered(self, checked=False):
         PreferencesEditor(self._prefs, self).exec_()
         self.readPreferences()
@@ -285,13 +271,7 @@
     def open(self, checked=False):
         filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open a dumped data block file", '.', 'bin files (*.bin)\nAll files (*)')
         self.openFiles(filenames)
-        self.displayFirst()
-        
-    def displayFirst(self):
-        pass
-#         if not self.plotsView.currentIndex().isValid():
-#             self.plotsView.setCurrentIndex(self.plotsView.model().index(0, 0))
-        
+                
     def openFiles(self, filenames):
         ok = False
         for filename in filenames:
@@ -299,7 +279,7 @@
             if os.path.exists(filename):
                 data = open(filename).read()
                 name = os.path.basename(filename)
-                name = os.path.splitext(name)[0]
+                #name = os.path.splitext(name)[0]
                 child_cls = getChild(data)
                 assert child_cls
                 child = child_cls(data, name=name)
@@ -322,22 +302,87 @@
         return self.workspace.activeWindow()
         
     def initializeGPIB(self):
-        self._online = False
         try:
-            self.gpib_plotter = QGPIBplotter(device=self._prefs.device,
+            self.gpib_dumper = HP3562dumper(device=self._prefs.device,
                                             address=self._prefs.address,
                                             )
-            self.captureThread = GPIBReceiver(self.gpib_plotter)
-            self.connect(self.captureThread, SIGNAL('plotReceived(int)'),
-                         self.plotReceived)
-            self.connect(self.captureThread, SIGNAL('plotStarted()'),
-                         self.plotStarted)
+            self.captureThread = GPIBReceiver(self.gpib_dumper)
+            self.connect(self.captureThread, SIGNAL('datablockDumped(const QByteArray)'),
+                         self.datablockReceived)
             self.captureThread.start()
         except Exception, e:
-            #print e
+            print e
             self.gpib_plotter = None
 
+    def datablockReceived(self, datablock):
+        datablock = datablock.data()
+        child_cls = getChild(datablock)
+        assert child_cls
+        child = child_cls(datablock)
+        self.workspace.addWindow(child)
+        child.show()
 
+    def getState(self):
+        self.captureThread.startCapture(mode="state")
+        
+    def getTrace(self):
+        self.captureThread.startCapture(mode="trace")
+
+    def getCoord(self):
+        self.captureThread.startCapture(mode="coord")
+
+class GPIBReceiver(QtCore.QThread):
+    def __init__(self, cnx):
+        QtCore.QThread.__init__(self)
+        self.gpibdumper = cnx
+        
+        self._cancelmutex = QtCore.QMutex()
+        self._cancel = False
+        self._modemutex = QtCore.QMutex()
+        self._mode = None
+        #self._nreceived = 0
+        self._startstopmutex = QtCore.QMutex()
+        self._startstop = QtCore.QWaitCondition()
+        self._capturing = False
+        
+    def cancel(self):
+        self._cancelmutex.lock()
+        self._cancel = True
+        self._cancelmutex.unlock()
+
+    def startCapture(self, mode):
+        self._modemutex.lock()
+        self._mode = mode
+        self._modemutex.unlock()        
+        self._startstop.wakeOne()
+
+    def stopCapture(self):
+        self._startstopmutex.lock()
+        self._capturing = False
+        self._startstopmutex.unlock()
+
+    def run(self):
+        while 1:
+            self._cancelmutex.lock()
+            if self._cancel:
+                return
+            self._cancelmutex.unlock()
+            self._startstopmutex.lock()
+            if not self._capturing:
+                self._startstop.wait(self._startstopmutex)
+                self._capturing = True
+            self._startstopmutex.unlock()
+            self._modemutex.lock()
+            mode = self._mode
+            self._modemutex.unlock()
+            datablock = self.gpibdumper.dump(mode=mode)
+            self._capturing = False
+            timestamp = time.time()
+            if datablock:
+                self.emit(SIGNAL('datablockDumped(const QByteArray)'),
+                          QtCore.QByteArray(datablock))
+            self.msleep(10)
+    
 def main():
     import optparse
     opt = optparse.OptionParser('A simple PyQt4 HP7470A GPIB plotter emulator for USB-GPIB bundle (ProLogix)')
@@ -357,8 +402,7 @@
     w = Qt3562()
     files = [f for f in argv[1:] if os.path.isfile(f)]
     files.sort(cmp=str_num_cmp)
-    if w.openFiles(files):    
-        w.displayFirst()
+    w.openFiles(files)    
 
     w.show()
     a.exec_()

mercurial