finish some previous unfinished (!) refactoring

Tue, 19 Aug 2008 19:09:28 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 19 Aug 2008 19:09:28 +0200
changeset 62
486a480d196b
parent 61
6ecb0fd8c129
child 63
1c0d92f95115

finish some previous unfinished (!) refactoring

pygpibtoolkit/HP3562A/HP356X.py file | annotate | diff | comparison | revisions
pygpibtoolkit/HP3562A/coord_decoder.py file | annotate | diff | comparison | revisions
pygpibtoolkit/HP3562A/state_decoder.py file | annotate | diff | comparison | revisions
pygpibtoolkit/HP3562A/trace_decoder.py file | annotate | diff | comparison | revisions
pygpibtoolkit/gpib_utils.py file | annotate | diff | comparison | revisions
pygpibtoolkit/gpibcontroller.py file | annotate | diff | comparison | revisions
pygpibtoolkit/plotter/qgpib_plotter.py file | annotate | diff | comparison | revisions
pygpibtoolkit/pygpib.py file | annotate | diff | comparison | revisions
--- a/pygpibtoolkit/HP3562A/HP356X.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/HP3562A/HP356X.py	Tue Aug 19 19:09:28 2008 +0200
@@ -12,6 +12,19 @@
 # HP3562A constants and command set
 # **VERY INCOMPLETE**
 
+class LinRes(Condition):
+    def __call__(self, device):
+        return device.MeasMode == "LINEAR RES"
+class LogRes(Condition):
+    def __call__(self, device):
+        return device.MeasMode == "LOG RES"
+class SweptSine(Condition):
+    def __call__(self, device):
+        return device.MeasMode == "SWEPT SINE"
+class TimeCaptur(Condition):
+    def __call__(self, device):
+        return device.MeasMode == "TIME CAPTUR"
+
 # GPIB buffer size is 3x80 characters lines
 class STATUS_BYTE(Constants):
     # HP3562A Status Byte, as returned by a serial poll
@@ -103,6 +116,12 @@
     "Trace Display"
     A = ModeCommand("A trace", "A")
     B = ModeCommand("B trace", "B")
+    AB = ModeCommand("A & B traces", "A&B")
+
+    def get_mode(self, device):
+        # XXX Can I get this from the device?
+        #mode = device.DSBN. # HERE
+        return None
     
 class ARM(Command):
     "ARM - Arm"
@@ -111,20 +130,23 @@
 
 class AverageMode(Mode):
     "Average mode"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','LOG RES', 'TIME CAPTUR']
-    AVOF = ModeCommand("Average off", "AVG OFF")
-    STBL = ModeCommand("Stable (means)", "STABLE (MEAN)")
-    EXP  = ModeCommand("Exponential", "EXPON")
-    PHLD = ModeCommand("Peak hold", "PEAK HOLD")
-    CNPK = ModeCommand("Cont. peak", "CONT PEAK")
+    _condition = LinRes | LogRes | TimeCaptur
+    _key = "EAVGTYP"
+    _DATA_BLOCK = "DSBN"
+    
+    STBL = ModeCommand(6, "STABLE (MEAN)")
+    EXP  = ModeCommand(7, "EXPON")
+    PHLD = ModeCommand(8, "PEAK HOLD")
+    CNPK = ModeCommand(9, "CONT PEAK")
+    AVOF = ModeCommand(10, "AVG OFF")
 
 class TIAV(BoolValue):
     "TIM AV ON OFF - Time average"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
 
 class OVLP(PercentageValue):
     "OVRLP% - Overlap (%)"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
     
 class AUTO(BoolValue):
     "AUTO ON OFF - Auto calibration"
@@ -134,43 +156,55 @@
 
 class CoordMode(Mode):
     "Coord mode"
-    MGDB = ModeCommand("Mag. (dB)", "MAG (dB)")
-    MDBM = ModeCommand("Mag. (dBm)", "MAG (dBm)")
-    MGLG = ModeCommand("Mag. (log)", "MAG (LOG)")
-    MAG  = ModeCommand("Mag. (lin)", "MAG (LIN)")
-    PHSE = ModeCommand("Phase", "PHASE")
-    REAL = ModeCommand("Real", "REAL")
-    IMAG = ModeCommand("Imag.", "IMAG")
-    NYQT = ModeCommand("Nyquist", "NYQUIST")
-    NICL = ModeCommand("Nichol", "NICHOL")
+    _key = "EYCOORD"
+    _DATA_BLOCK = "DCBN"
+
+    MGDB = ModeCommand(5, "MAG (dB)")
+    MDBM = ModeCommand(10, "MAG (dBm)")
+    MGLG = ModeCommand(4, "MAG (LOG)")
+    MAG  = ModeCommand(3, "MAG (LIN)")
+    PHSE = ModeCommand(8, "PHASE")
+    REAL = ModeCommand(1, "REAL")
+    IMAG = ModeCommand(2, "IMAG")
+    NYQT = ModeCommand(6, "NYQUIST")
+    NICL = ModeCommand(9, "NICHOL")
 
 # FREQ menu
 class FRS(FrequencyValue):
     "FREQ SPAN - Freq. span"
+
 class SF(FrequencyValue):
     "START FREQ - Start freq."
+
 class CF(FrequencyValue):
     "CENTER FREQ - Center freq."
     _units = "hz","khz","mhz","ord","rmp"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class ZST(Command):
     "ZERO START - Zero start"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class MAXS(FrequencyValue):
     "MAX SPAN - Max span"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class TLN(DurationValue):
     "TIME LENGTH - Time len."
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class ESMP(BoolValue):
     "E SMPL ON OFF - E sample"
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class SMPF(FrequencyValue):
     "SAMPLE FREQ - Sample freq."
-    _condition = lambda device: device.MeasMode in ['LINEAR RES','TIME CAPTUR','SWEPT SINE']
+    _condition = LinRes | TimeCaptur | SweptSine
+    
 class SPF(FrequencyValue):
     "STOP FREQ - Stop freq."
-    _condition = lambda device: device.MeasMode in ['SWEPT SINE']
+    _condition = SweptSine
+    
 class SWRT(FrequencyValue):
     "SWEEP RATE - Sweep rate"
 
@@ -184,8 +218,10 @@
     
 class Chan1Coupling(Mode):
     "Channel 1 coupling"
-    FLT1 = ModeCommand("Float", "FLOAT CHAN1")
-    GND1 = ModeCommand("Ground", "GROUND CHAN1")
+    _key = "FLT1"
+    _DATA_BLOCK = "DSBN"
+    FLT1 = ModeCommand(1, "FLOAT CHAN1")
+    GND1 = ModeCommand(0, "GROUND CHAN1")
 
 class C2AC(EnumValue):
     "CHAN2 AC DC - Channel 2 AC/DC"
@@ -193,6 +229,8 @@
     
 class Chan2Coupling(Mode):
     "Channel 2 coupling"
+    _key = "FLT1"
+    _DATA_BLOCK = "DSBN"
     FLT2 = ModeCommand("Float", "FLOAT CHAN2")
     GND2 = ModeCommand("Ground", "GROUND CHAN2")
 
@@ -210,27 +248,75 @@
 # MEAS MODE
 class MeasMode(Mode):
     "Measurement mode"
-    LNRS = ModeCommand("Linear resolution", "LINEAR RES")
-    LGRS = ModeCommand("Log resolution", "LOG RES")
-    SSIN = ModeCommand("Swept sinus", "SWEPT SINE")
-    CPTR = ModeCommand("Time Capture", "TIME CAPTUR")
+    _key = "EMEAS"
+    _DATA_BLOCK = "DSBN"
+    LNRS = ModeCommand(0, "LINEAR RES")
+    LGRS = ModeCommand(1, "LOG RES")
+    SSIN = ModeCommand(2, "SWEPT SINE")
+    CPTR = ModeCommand(3, "TIME CAPTUR")
     
 # MEAS DISP
 class MeasDisp(Mode):
     # TODO
-    pass
+    FRQR = ModeCommand(0, "FREQ RESP", condition=(LinRes | LogRes) & FreqResp | SweptSine)
+    COHR = ModeCommand(0, "COHER", condition=(LinRes | LogRes) & FreqResp | SweptSine)
+    PSP1 = ModeCommand(0, "POWER SPEC1", condition=(LinRes | LogRes) & FreqResp | SweptSine)
+    PSP2 = ModeCommand(0, "POWER SPEC2", condition=(LinRes | LogRes) & FreqResp | SweptSine)
+    CSPS = ModeCommand(0, "CROSS SPEC", condition=(LinRes | LogRes) & FreqResp | SweptSine)
+    IRSP = ModeCommand(0, "IMPLS RESP", condition=LinRes & FreqResp)
+    AUMT = ModeCommand(0, "AUTO MATH", )
+    FILT = ModeCommand(0, "FILTRD INPUT")
+
+    TMR1 = ModeCommand(0, "TIME REC1", condition=TimeCaptur)
+    TMR2 = ModeCommand(0, "TIME REC2", condition=TimeCaptur)
+    LSP1 = ModeCommand(0, "LINEAR SPEC1", condition=TimeCaptur)
+    LSP2 = ModeCommand(0, "LINEAR SPEC2", condition=TimeCaptur)
+    
+class FreqResp(Condition):
+    def __call__(self, device):
+        return device.SelectMeas == "FREQ RESP"
+
+class PowerSpec(Condition):
+    def __call__(self, device):
+        return device.SelectMeas == "POWER SPEC"
+
+class AutoCorr(Condition):
+    def __call__(self, device):
+        return device.SelectMeas == "AUTO CORR"
+
+class CrossCorr(Condition):
+    def __call__(self, device):
+        return device.SelectMeas == "CROSS CORR"
+
+class Hist(Condition):
+    def __call__(self, device):
+        return device.SelectMeas == "HIST"
+
+
 
 # SELECT MEAS
 class SelectMeas(Mode):
     "Select measurement"
-    FRSP = ModeCommand("Frequency response", "FREQ RESP", condition=lambda device: device.MeasMode in ["LINEAR RES", "LOG RES", "SWEPT SINE"])
-    PSPC = ModeCommand("Power spectrum", "POWER SPEC", condition=lambda device: device.MeasMode in ["LINEAR RES","LOG RES","TIME CAPTUR"])
-    AUCR = ModeCommand("Auto correlation", "AUTO CORR", condition=lambda device: device.MeasMode in ["LINEAR RES","TIME CAPTUR"])
-    CCOR = ModeCommand("Cross correlation", "CROSS CORR", condition=lambda device: device.MeasMode == "LINEAR RES")
-    HIST = ModeCommand("Histogramm", "HIST", condition=lambda device: device.MeasMode in ["LINEAR RES", "TIME CAPTUR"])
-    CH12 = ModeCommand("Channel 1&2 active", "CH 1&2 ACTIVE", condition=lambda device: device.MeasMode in ["LINEAR RES", "LOG RES"])
-    CH1 = ModeCommand("Channel 1 active", "CH 1 ACTIVE", condition=lambda device: device.MeasMode in ["LINEAR RES", "LOG RES", "TIME CAPTUR"])
-    CH2 = ModeCommand("Channel 2 active", "CH 2 ACTIVE", condition=lambda device: device.MeasMode in ["LINEAR RES", "LOG RES", "TIME CAPTUR"])
+    _key = "EMTYP"
+    _DATA_BLOCK = "DSBN"
+        _condition = LinRes | TimeCaptur | SweptSine
+
+    FRSP = ModeCommand(0, "FREQ RESP", condition=LinRes | LogRes | SweptSine)
+    PSPC = ModeCommand(2, "POWER SPEC", condition=LinRes | LogRes | TimeCaptur)
+    AUCR = ModeCommand(3, "AUTO CORR", condition=LinRes | TimeCaptur)
+    CCOR = ModeCommand(1, "CROSS CORR", condition=LinRes)
+    HIST = ModeCommand(4, "HIST", condition=LinRes | TimeCaptur)
+
+class Channel(Mode):
+    ""
+    _key = "ECH"
+    _DATA_BLOCK = "DDBN" # XXX sure?
+    CH12 = ModeCommand("Channel 1&2 active", "CH 1&2 ACTIVE",
+                       condition=LinRes | LogRes)
+    CH1 = ModeCommand("Channel 1 active", "CH 1 ACTIVE",
+                      condition=LinRes | LogRes | TimeCaptur)
+    CH2 = ModeCommand("Channel 2 active", "CH 2 ACTIVE",
+                      condition=LinRes | LogRes | TimeCaptur)
 
 class REV(StringValue):
     _readonly = True
--- a/pygpibtoolkit/HP3562A/coord_decoder.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/HP3562A/coord_decoder.py	Tue Aug 19 19:09:28 2008 +0200
@@ -9,39 +9,39 @@
 This file can be exectued as a python script. Use '-h' for more informations. 
 """
 
-from pygpibtoolkit.gpi_utils import format_datablock_header, decode_datablock_header, read_datablock_trace
-from pygpibtoolkit.gpi_utils import decode_float, decode_string
+from pygpibtoolkit.gpib_utils import format_datablock_header, decode_datablock_header, read_datablock_trace
+from pygpibtoolkit.gpib_utils import decode_float, decode_string
 from pygpibtoolkit.HP3562A.trace_decoder import decode_trace, HEADER as TRACE_HEADER
 from pygpibtoolkit.HP3562A.enum_types import *
 
-HEADER = [("Y coordinates", EYCOORD, 'h', 2),
-          ("# of disp elements", int, "h", 2),
-          ("First element", int, "h", 2),
-          ("Total elements", int, 'h', 2),
-          ("Display sampling", EDISPSMP, 'h', 2),
-          ("Scaling", ESCAL, 'h', 2),
-          ("Data pointer", long, 'l', 4),
-          ("In data", long, 'l', 4),
-          ("Log/linear x-axis", bool, 'h', 2),
-          ("Sampled display data", bool, 'h', 2),
-          ("Plot/Graph mode", bool, 'h', 2),
-          ("Phase wrap", bool, 'h', 2),
-          ("Not used", None, None, 36),
-          ("X scale factor", decode_float, None, 4),
-          ("Grid min Y scale", decode_float, None, 4),
-          ("Grid max Y scale", decode_float, None, 4),
-          ("/div", decode_float, None, 4),
-          ("Min value of data", decode_float, None, 4),
-          ("Max value of data", decode_float, None, 4),
-          ("Y cumulative min", decode_float, None, 4),
-          ("Y cumulative max", decode_float, None, 4),
-          ("Y scale factor", decode_float, None, 4),
-          ("Not used", None, None, 16),
-          ("Stop value", decode_float, None, 8),
-          ("Left grid", decode_float, None, 8),
-          ("Right grid", decode_float, None, 8),
-          ("Left data", decode_float, None, 8),
-          ("Right data", decode_float, None, 8),          
+HEADER = [("EYCOORD", "Y coordinates", EYCOORD, 'h', 2),
+          ("", "# of disp elements", int, "h", 2),
+          ("", "First element", int, "h", 2),
+          ("", "Total elements", int, 'h', 2),
+          ("", "Display sampling", EDISPSMP, 'h', 2),
+          ("", "Scaling", ESCAL, 'h', 2),
+          ("", "Data pointer", long, 'l', 4),
+          ("", "In data", long, 'l', 4),
+          ("", "Log/linear x-axis", bool, 'h', 2),
+          ("", "Sampled display data", bool, 'h', 2),
+          ("", "Plot/Graph mode", bool, 'h', 2),
+          ("", "Phase wrap", bool, 'h', 2),
+          ("", "Not used", None, None, 36),
+          ("", "X scale factor", decode_float, None, 4),
+          ("", "Grid min Y scale", decode_float, None, 4),
+          ("", "Grid max Y scale", decode_float, None, 4),
+          ("", "/div", decode_float, None, 4),
+          ("", "Min value of data", decode_float, None, 4),
+          ("", "Max value of data", decode_float, None, 4),
+          ("", "Y cumulative min", decode_float, None, 4),
+          ("", "Y cumulative max", decode_float, None, 4),
+          ("", "Y scale factor", decode_float, None, 4),
+          ("", "Not used", None, None, 16),
+          ("", "Stop value", decode_float, None, 8),
+          ("", "Left grid", decode_float, None, 8),
+          ("", "Right grid", decode_float, None, 8),
+          ("", "Left data", decode_float, None, 8),
+          ("", "Right data", decode_float, None, 8),          
     ]
 
 def decode_coord(data):
--- a/pygpibtoolkit/HP3562A/state_decoder.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/HP3562A/state_decoder.py	Tue Aug 19 19:09:28 2008 +0200
@@ -8,103 +8,103 @@
 
 This file can be exectued as a python script. Use '-h' for more informations. 
 """
-from pygpibtoolkit.gpi_utils import format_datablock_header, decode_datablock_header
-from pygpibtoolkit.gpi_utils import decode_float, decode_string
+from pygpibtoolkit.gpib_utils import format_datablock_header, decode_datablock_header
+from pygpibtoolkit.gpib_utils import decode_float, decode_string
 
 from pygpibtoolkit.HP3562A.enum_types import *
 
-HEADER = [("Measurement mode", EMEAS, 'h', 2),
-          ("Measurement 1", EMTYP, 'h', 2),
-          ("Measurement 2", EMTYP, 'h', 2),
-          ("Window type", EWINTYP, 'h', 2),
-          ("Force/Expon window 1", EFEXPW, 'h', 2),
-          ("Force/Expon window 2", EFEXPW, 'h', 2),
-          ("Average type", EAVGTYP, 'h', 2),
-          ("Overlap percentage", int, 'h', 2),
-          ("Number of averages", int, 'h', 2),
-          ("Sweep # of averages", int, 'h', 2),
-          ("Trigger type", ETRGTYP, 'h', 2),
-          ("Trigger slope", ETRGSLP, 'h', 2),
-          ("Preview type", EPRVTYP, 'h', 2),
-          ("Sample type", ESMPTYP, 'h', 2),
-          ("Range units chan 1", ERNGUNT, 'h', 2),
-          ("Range units chan 2", ERNGUNT, 'h', 2),
-          ("Range type 1", ERNGTYP, 'h', 2),
-          ("Range type 2", ERNGTYP, 'h', 2),
-          ("Input coupling 1", EINCPL, 'h', 2),
-          ("Input coupling 2", EINCPL, 'h', 2),
-          ("Source type", ESRCTYP, 'h', 2),
-          ("Chirp percent", int, 'h', 2),
-          ("Burst percent", int, 'h', 2),
-          ("Sweep direction", ESWPDIR, 'h', 2),
-          ("Sweep mode", ESWPMOD, 'h', 2),
-          ("Ext sample freq untis", EXAXIS, 'h', 2),
-          ("Bandwidth units", EXAXIS, 'h', 2),
-          ("Log span index", int, 'h', 2),
-          ("Log start index", int, 'h', 2),
-          ("Sweep rate units", EXAXIS, 'h', 2),
-          ("Auto gain ref chan", EDEMODCH, 'h', 2),
-          ("Demod channels", EDEMODCH, 'h', 2),
-          ("Demod type chan 1", EDEMOD, 'h', 2),
-          ("Demod type chan 2", EDEMOD, 'h', 2),
-          ("Source level units", EXAXIS, 'h', 2),
-          ("Source offset units", EXAXIS, 'h', 2),
-          ("Trigger level units", EXAXIS, 'h', 2),
-          ("Capt/thru length units", EXAXIS, 'h', 2),
-          ("EU label 1", str, 's', 6),
-          ("EU label 2", str, 's', 6),
-          ("Auto carrier on/off", bool, 'h', 2),
-          ("Time average on/off", bool, 'h', 2),
-          ("Auto/fixed resolution", bool, 'h', 2),
-          ("Auto gain on/off", bool, 'h', 2),
-          ("Auto/fixed integrate",bool, 'h', 2),
-          ("Fast average on/off", bool, 'h', 2),
-          ("Overload reject on/off", bool, 'h', 2),
-          ("Chan 1 float/ground", bool, 'h', 2),
-          ("Chan 2 float/ground", bool, 'h', 2),
-          ("Time throughput on/off", bool, 'h', 2),
-          ("Demodulation on/off", bool, 'h', 2),
-          ("EU/volts chan 1", bool, 'h', 2),
-          ("EU/volts chan 2", bool, 'h', 2),
-          ("Manual/auto arm", bool, 'h', 2),
-          ("Demod preview on/off", bool, 'h', 2),
-          ("Delete freq on/off", bool, 'h', 2),
-          ("Lin res Fstart pegged", bool, 'h', 2),
-          ("Swept Fstart pegged", bool, 'h', 2),
-          ("Force length chan 1", decode_float, None, 4),
-          ("Force length chan 2", decode_float, None, 4),
-          ("Expon time constant 1", decode_float, None, 4),
-          ("Expon time constant 2", decode_float, None, 4),
-          ("Sweep time", decode_float, None, 4),
-          ("Sweep rate", decode_float, None, 4),
-          ("Sweep resolution", decode_float, None, 4),
-          ("Sweep integrate time", decode_float, None, 4),
-          ("Auto gain level", decode_float, None, 4),
-          ("Auto gain limit", decode_float, None, 4),
-          ("Source level", decode_float, None, 4),
-          ("EU value chan 1", decode_float, None, 4),
-          ("EU value chan 2", decode_float, None, 4),
-          ("Trigger delay chan 1", decode_float, None, 4),
-          ("Trigger delay chan 2", decode_float, None, 4),
-          ("Integrate var thresh", decode_float, None, 4),
-          ("Capt/thru length", decode_float, None, 4),
-          ("Frequency span", decode_float, None, 4),
-          ("Time record length", decode_float, None, 4),
-          ("Frequency resolution", decode_float, None, 4),
-          ("Time resolution", decode_float, None, 4),
-          ("External sample rate", decode_float, None, 4),
-          ("Sample rate (actual)", decode_float, None, 4),
-          ("Range channel 1", decode_float, None, 4),
-          ("Range channel 2", decode_float, None, 4),
-          ("Preview time", decode_float, None, 4),
-          ("Trigger level", decode_float, None, 4),
-          ("Source dc offset", decode_float, None, 4),
-          ("Fixed sine frequency", decode_float, None, 8),
-          ("Start frequency", decode_float, None, 8),
-          ("Center frequency", decode_float, None, 8),
-          ("Sweep start", decode_float, None, 8),
-          ("Sweep end", decode_float, None, 8),
-          ("Carrier frequency", decode_float, None, 8),
+HEADER = [("EMEAS", "Measurement mode", EMEAS, 'h', 2),
+          ("MTYP1", "Measurement 1", EMTYP, 'h', 2),
+          ("MTYP2", "Measurement 2", EMTYP, 'h', 2),
+          ("WNDO", "Window type", EWINTYP, 'h', 2),
+          ("FOXP1", "Force/Expon window 1", EFEXPW, 'h', 2),
+          ("FOXP2", "Force/Expon window 2", EFEXPW, 'h', 2),
+          ("EAVGTYP", "Average type", EAVGTYP, 'h', 2),
+          ("OVLP", "Overlap percentage", int, 'h', 2),
+          ("NAVG", "Number of averages", int, 'h', 2),
+          ("SWAVG", "Sweep # of averages", int, 'h', 2),
+          ("TRGTYP", "Trigger type", ETRGTYP, 'h', 2),
+          ("TRGSLP", "Trigger slope", ETRGSLP, 'h', 2),
+          ("PRVTYP", "Preview type", EPRVTYP, 'h', 2),
+          ("SMPF", "Sample type", ESMPTYP, 'h', 2),
+          ("RNG1", "Range units chan 1", ERNGUNT, 'h', 2),
+          ("RNG2", "Range units chan 2", ERNGUNT, 'h', 2),
+          ("RNGTYP1", "Range type 1", ERNGTYP, 'h', 2),
+          ("RNGTYP2", "Range type 2", ERNGTYP, 'h', 2),
+          ("CPL1", "Input coupling 1", EINCPL, 'h', 2),
+          ("CPL2", "Input coupling 2", EINCPL, 'h', 2),
+          ("SRCTYP", "Source type", ESRCTYP, 'h', 2),
+          ("CHRP", "Chirp percent", int, 'h', 2),
+          ("BRST", "Burst percent", int, 'h', 2),
+          ("SWPDIR", "Sweep direction", ESWPDIR, 'h', 2),
+          ("SWPMOD", "Sweep mode", ESWPMOD, 'h', 2),
+          ("EFRQUNT", "Ext sample freq units", EXAXIS, 'h', 2),
+          ("BWUNT", "Bandwidth units", EXAXIS, 'h', 2),
+          ("LGSP", "Log span index", int, 'h', 2),
+          ("LGID", "Log start index", int, 'h', 2),
+          ("SWUNT", "Sweep rate units", EXAXIS, 'h', 2),
+          ("AGREFCH", "Auto gain ref chan", EDEMODCH, 'h', 2),
+          ("DMDCH", "Demod channels", EDEMODCH, 'h', 2),
+          ("DMDTYP1", "Demod type chan 1", EDEMOD, 'h', 2),
+          ("DMDTYP2", "Demod type chan 2", EDEMOD, 'h', 2),
+          ("SRLVUNT", "Source level units", EXAXIS, 'h', 2),
+          ("SROFUNT", "Source offset units", EXAXIS, 'h', 2),
+          ("TRLVUNT", "Trigger level units", EXAXIS, 'h', 2),
+          ("", "Capt/thru length units", EXAXIS, 'h', 2),
+          ("EULB1", "EU label 1", str, 's', 6),
+          ("EULB2", "EU label 2", str, 's', 6),
+          ("", "Auto carrier on/off", bool, 'h', 2),
+          ("", "Time average on/off", bool, 'h', 2),
+          ("", "Auto/fixed resolution", bool, 'h', 2),
+          ("", "Auto gain on/off", bool, 'h', 2),
+          ("", "Auto/fixed integrate",bool, 'h', 2),
+          ("", "Fast average on/off", bool, 'h', 2),
+          ("", "Overload reject on/off", bool, 'h', 2),
+          ("FLT1", "Chan 1 float/ground", bool, 'h', 2),
+          ("FLT2", "Chan 2 float/ground", bool, 'h', 2),
+          ("", "Time throughput on/off", bool, 'h', 2),
+          ("", "Demodulation on/off", bool, 'h', 2),
+          ("", "EU/volts chan 1", bool, 'h', 2),
+          ("", "EU/volts chan 2", bool, 'h', 2),
+          ("", "Manual/auto arm", bool, 'h', 2),
+          ("", "Demod preview on/off", bool, 'h', 2),
+          ("", "Delete freq on/off", bool, 'h', 2),
+          ("", "Lin res Fstart pegged", bool, 'h', 2),
+          ("", "Swept Fstart pegged", bool, 'h', 2),
+          ("", "Force length chan 1", decode_float, None, 4),
+          ("", "Force length chan 2", decode_float, None, 4),
+          ("", "Expon time constant 1", decode_float, None, 4),
+          ("", "Expon time constant 2", decode_float, None, 4),
+          ("", "Sweep time", decode_float, None, 4),
+          ("", "Sweep rate", decode_float, None, 4),
+          ("", "Sweep resolution", decode_float, None, 4),
+          ("", "Sweep integrate time", decode_float, None, 4),
+          ("", "Auto gain level", decode_float, None, 4),
+          ("", "Auto gain limit", decode_float, None, 4),
+          ("", "Source level", decode_float, None, 4),
+          ("", "EU value chan 1", decode_float, None, 4),
+          ("", "EU value chan 2", decode_float, None, 4),
+          ("", "Trigger delay chan 1", decode_float, None, 4),
+          ("", "Trigger delay chan 2", decode_float, None, 4),
+          ("", "Integrate var thresh", decode_float, None, 4),
+          ("", "Capt/thru length", decode_float, None, 4),
+          ("", "Frequency span", decode_float, None, 4),
+          ("", "Time record length", decode_float, None, 4),
+          ("", "Frequency resolution", decode_float, None, 4),
+          ("", "Time resolution", decode_float, None, 4),
+          ("", "External sample rate", decode_float, None, 4),
+          ("", "Sample rate (actual)", decode_float, None, 4),
+          ("", "Range channel 1", decode_float, None, 4),
+          ("", "Range channel 2", decode_float, None, 4),
+          ("", "Preview time", decode_float, None, 4),
+          ("", "Trigger level", decode_float, None, 4),
+          ("", "Source dc offset", decode_float, None, 4),
+          ("", "Fixed sine frequency", decode_float, None, 8),
+          ("", "Start frequency", decode_float, None, 8),
+          ("", "Center frequency", decode_float, None, 8),
+          ("", "Sweep start", decode_float, None, 8),
+          ("", "Sweep end", decode_float, None, 8),
+          ("", "Carrier frequency", decode_float, None, 8),
           ]
           
 def decode_state(data):
@@ -136,11 +136,9 @@
     if options.filename is None:
         print "Can't deal stdin for now..."
         sys.exit(1)
-    #try:
-    if 1:
-        header = decode_datablock_state(open(options.filename, 'rb').read())
-    else:
-    #except Exception, e:
+    try:
+        header = decode_state(open(options.filename, 'rb').read())
+    except Exception, e:
         print "ERROR: can't read %s an interpret it as a HP3562 trace"%options.filename
         print e
         sys.exit(1)
--- a/pygpibtoolkit/HP3562A/trace_decoder.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/HP3562A/trace_decoder.py	Tue Aug 19 19:09:28 2008 +0200
@@ -10,57 +10,57 @@
 """
 import struct
 import numpy
-from pygpibtoolkit.gpi_utils import format_datablock_header, decode_datablock_header, read_datablock_trace
-from pygpibtoolkit.gpi_utils import decode_float, decode_string
+from pygpibtoolkit.gpib_utils import format_datablock_header, decode_datablock_header, read_datablock_trace
+from pygpibtoolkit.gpib_utils import decode_float, decode_string
 
 from pygpibtoolkit.HP3562A.enum_types import *
 
 
-HEADER = [ ("Display function", EDSP, 'h', 2),
-           ('Number of elements', int, 'h', 2),
-           ('Displayed elements', int, 'h', 2),
-           ('Number of averages', int, 'h', 2),
-           ('Channel selection', ECH, 'h', 2),
-           ('Overflow status', EOVR, 'h', 2),
-           ('Overlap percentage', int, 'h', 2),
-           ('Domain', EDOM, 'h', 2),
-           ('Volts peak/rms', EVLT, 'h', 2),
-           ('Amplitude units', EAMP, 'h', 2),
-           ('X axis units', EXAXIS, 'h', 2),
-           ('Auto math label', str, 's', 14),
-           ('Trace label', str, 's', 22),
-           ('EU label 1', str, 's', 6),
-           ('EU label 2', str, 's', 6),
-           ('Float/Interger', bool, 'h', 2),
-           ('Complex/Real', bool, 'h', 2),
-           ('Live/Recalled', bool, 'h', 2),
-           ('Math result', bool, 'h', 2),
-           ('Real/Complex input', bool, 'h', 2),
-           ('Log/Linear data', bool, 'h', 2),
-           ('Auto math', bool, 'h', 2),
-           ('Real time status', bool, 'h', 2),
-           ('Measurement mode', EMEAS, 'h', 2),
-           ('Window', EWIN, 'h', 2),
-           ('Demod type channel 1', EDEMOD, 'h', 2),
-           ('Demod type channel 2', EDEMOD, 'h', 2),
-           ('Demod active channel 1', bool, 'h', 2),
-           ('Demod active channel 2', bool, 'h', 2),
-           ('Average status', EAVG, 'h', 2),
-           ('Not used', int, 'hh', 4),
-           ('Samp freq/2 (real)', decode_float, None, 4),
-           ('Samp freq/2 (imag)', decode_float, None, 4),
-           ('Not used', decode_float, None, 4),
-           ('Delta X-axis', decode_float, None, 4),
-           ('Max range', decode_float, None, 4),
-           ('Start time value', decode_float, None, 4),
-           ('Expon wind const 1', decode_float, None, 4),
-           ('Expon wind const 2', decode_float, None, 4),
-           ('EU value chan 1', decode_float, None, 4),
-           ('EU value chan 2', decode_float, None, 4),
-           ('Trig delay chan 1', decode_float, None, 4),
-           ('Trig delay chan 2', decode_float, None, 4),
-           ('Start freq value', decode_float, None, 8),
-           ('Start data value', decode_float, None, 8),
+HEADER = [ ("DSPFCT", "Display function", EDSP, 'h', 2),
+           ("NELTS", 'Number of elements', int, 'h', 2),
+           ("DSPELTS", 'Displayed elements', int, 'h', 2),
+           ("NAVG", 'Number of averages', int, 'h', 2),
+           ("CHSEL", 'Channel selection', ECH, 'h', 2),
+           ("OVST", 'Overflow status', EOVR, 'h', 2),
+           ("OVLP", 'Overlap percentage', int, 'h', 2),
+           ("DOM", 'Domain', EDOM, 'h', 2),
+           ("VOLTMEAS", 'Volts peak/rms', EVLT, 'h', 2),
+           ("AMPLUNT", 'Amplitude units', EAMP, 'h', 2),
+           ("XUNT", 'X axis units', EXAXIS, 'h', 2),
+           ("AMTHLBL", 'Auto math label', str, 's', 14),
+           ("TRLBL", 'Trace label', str, 's', 22),
+           ("EULB1", 'EU label 1', str, 's', 6),
+           ("EULB2", 'EU label 2', str, 's', 6),
+           ("VALTYPE", 'Float/Interger', bool, 'h', 2),
+           ("RVALTYPE", 'Complex/Real', bool, 'h', 2),
+           ("LIVE", 'Live/Recalled', bool, 'h', 2),
+           ("MATHRESU", 'Math result', bool, 'h', 2),
+           ("RVALINPUTTYPE", 'Real/Complex input', bool, 'h', 2),
+           ("LOGDATA", 'Log/Linear data', bool, 'h', 2),
+           ("AMTH", 'Auto math', bool, 'h', 2),
+           ("RTST", 'Real time status', bool, 'h', 2),
+           ("EMEAS", 'Measurement mode', EMEAS, 'h', 2),
+           ("", 'Window', EWIN, 'h', 2),
+           ("", 'Demod type channel 1', EDEMOD, 'h', 2),
+           ("", 'Demod type channel 2', EDEMOD, 'h', 2),
+           ("", 'Demod active channel 1', bool, 'h', 2),
+           ("", 'Demod active channel 2', bool, 'h', 2),
+           ("", 'Average status', EAVG, 'h', 2),
+           ("", 'Not used', int, 'hh', 4),
+           ("", 'Samp freq/2 (real)', decode_float, None, 4),
+           ("", 'Samp freq/2 (imag)', decode_float, None, 4),
+           ("", 'Not used', decode_float, None, 4),
+           ("", 'Delta X-axis', decode_float, None, 4),
+           ("", 'Max range', decode_float, None, 4),
+           ("", 'Start time value', decode_float, None, 4),
+           ("", 'Expon wind const 1', decode_float, None, 4),
+           ("", 'Expon wind const 2', decode_float, None, 4),
+           ("", 'EU value chan 1', decode_float, None, 4),
+           ("", 'EU value chan 2', decode_float, None, 4),
+           ("", 'Trig delay chan 1', decode_float, None, 4),
+           ("", 'Trig delay chan 2', decode_float, None, 4),
+           ("", 'Start freq value', decode_float, None, 8),
+           ("", 'Start data value', decode_float, None, 8),
            ]
 
 def decode_trace(data, idx=0):
--- a/pygpibtoolkit/gpib_utils.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/gpib_utils.py	Tue Aug 19 19:09:28 2008 +0200
@@ -52,8 +52,9 @@
     
     todisp = []
     for row in head_struct:
-        key = row[0]
-        typ = row[1]
+        pname = row[0]
+        key = row[1]
+        typ = row[2]
         if typ is None:
             continue
         val = header.get(key, "N/A")
@@ -84,6 +85,7 @@
         nrows = len(todisp)/ncols
     else:
         nrows = len(todisp)
+        ncols = 1
     res = ""
     for i in range(nrows):
         res += "| ".join([fmt%todisp[j*nrows+i] for j in range(ncols)]) + "\n"
@@ -100,7 +102,7 @@
         idx += 2
     tt=0
     header = {}
-    for i, (nam, dtype, fmt, nbytes) in enumerate(header_struct):
+    for i, (cmd, nam, dtype, fmt, nbytes) in enumerate(header_struct):
         if dtype is None:
             idx += nbytes
             continue
--- a/pygpibtoolkit/gpibcontroller.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/gpibcontroller.py	Tue Aug 19 19:09:28 2008 +0200
@@ -52,21 +52,19 @@
         self._use_cache = bool(use)
         
     def _get(self, name):
-        if self._use_cache and name in self._cache and self._cache[name] is not None:
+        if self._use_cache and name in self._cache and \
+                self._cache[name] is not None:
             return self._cache[name]
         
         param = getattr(self.__class__, name) 
-        cmd = param.build_get_cmd()
-        value = self._controller.send_command(self._address, cmd)
-        value = param.convert_from(value)
+        value = param.get_value_from_device(self)
         if name in self._cache:
             self._cache[name] = value
         return value
             
     def _set(self, name, value):
         param = getattr(self.__class__, name) 
-        cmd = param.build_set_cmd(value)
-        res = self._controller.send_command(self._address, cmd)
+        res, value = param.send_value_to_device(self, value)
         if name in self._cache:
             self._cache[name] = value
         return res
--- a/pygpibtoolkit/plotter/qgpib_plotter.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/plotter/qgpib_plotter.py	Tue Aug 19 19:09:28 2008 +0200
@@ -14,7 +14,8 @@
 from hpgl_qt import QHPGLPlotterWidget
 
 ldir = os.path.abspath(os.path.dirname(__file__))
-sys.path.append(ldir)
+sys.path.append(os.path.join(ldir, "..", "qt4"))
+print "ldir=",ldir
 form_class, base_class = uic.loadUiType(os.path.join(ldir, "qhpgl_plotter.ui"))
 
 from pygpibtoolkit.qt4.qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem
--- a/pygpibtoolkit/pygpib.py	Thu Feb 28 18:35:23 2008 +0100
+++ b/pygpibtoolkit/pygpib.py	Tue Aug 19 19:09:28 2008 +0200
@@ -10,6 +10,28 @@
 class ConnectionError(Exception):
     pass
 
+class Condition(object):
+    def __call__(self, device):
+        return True
+    def __and__(self, cond):
+        assert isinstance(cond, Condition)
+        return _ComposedCondition(operator.__and__, self, cond)
+    def __or__(self, cond):
+        assert isinstance(cond, Condition)
+        return _ComposedCondition(operator.__or__, self, cond)
+    
+class _ComposedCondition(Condition):
+    def __init__(self, op, *args):
+        self._conditions = args[:]
+        self._reduc_op = op 
+        for cond in args:
+            assert isinstance(cond, Condition)
+            if isinstance(cond, _ComposedCondition) and cond._reduc_op == op:
+                i = self._conditions.index(cond)
+                self._conditions[i:i+1] = cond._conditions
+    def __call__(self, device):
+        return reduce(self._reduc_op, [f(device) for f in self._conditions])
+    
 class Constants(object):
     def __init__(self):
         self.constants = {}
@@ -57,30 +79,50 @@
         if instance is None:
             return self
         return instance._get(self.__class__.__name__)
+
     def __set__(self, instance, value):
         if instance is None:
             return self
         return instance._set(self.__class__.__name__, value)
+    
+    def get_value_from_device(self, device):
+        cmd = self.build_get_cmd()
+        value = device.send_command(cmd)
+        value = self.convert_from(value)
+        return value
 
-class Command(AbstractCommand):
+    def send_value_to_device(self, device, value):
+        cmd, value = self.build_set_cmd(value)
+        res = device.send_command(cmd)
+        return res, self.convert_to(value)
+    
     def build_get_cmd(self):
         return self.__class__.__name__
 
     def build_set_cmd(self, *value):
         raise ValueError, "Can't set value for command '%s'"%self.__class__.__name__
-
+    
     def convert_from(self, *value):
         return None
+
+    def convert_to(self, *value):
+        return None
+
     
+#XXX TODO: remove this
+class Command(AbstractCommand):
+    pass
+
 class AbstractValue(Command):
     _readonly = False
+
     def build_get_cmd(self):
         return self.__class__.__name__ + "?"
 
     def build_set_cmd(self, *value):
         value = self.convert_to(value)
         cmd = "%s %s"%(self.__class__.__name__, value)
-        return cmd
+        return cmd, value
     
     def convert_to(self, *value):
         if value:
@@ -201,9 +243,34 @@
         return "" # XXX
 
 class Mode(AbstractValue):
-    pass
+    _DATA_BLOCK = None
+    _key = None
+    
+    def __init__(self):
+        self._cmds = []
+        for cmdname, cmd in self.__dict__.items():
+            if isinstance(cmd, ModeCommand):
+                self._cmds.append(cmdname)
 
+    def get_mode(self, device):
+        if self._key and self._DATA_BLOCK:
+            mode = getattr(getattr(device, self._DATA_BLOCK), self._key)
+            return mode
+        return None
+    
+    def get_value_from_device(self, device):
+        value = self.get_mode(device)
+        return value
 
+    def __get__(self, instance, owner):
+        if instance is None:
+            return self
+        return instance._get(self.__class__.__name__)
+
+    def build_set_command(self, value):
+        assert value in self._cmds
+        return value
+        
 # TODO
 # class STATUS_BYTE(Constants):
 #     # IEEE 488.2 Status Byte constants

mercurial