Changeset 4608


Ignore:
Timestamp:
08/25/08 20:51:26 (5 years ago)
Author:
werner
Message:

This mainly adds the long-awaited screendump functionality. Also fixes
two serious bugs, namely an off-by-twelve error in Rigol USB TMC read
function and caching converted instead of unconverted values in
settings, which broke larger scripts.

  • lib/wave.py: added "extend" method for all waves
  • lib/scope.py: started support for piecewise wave retrieval (doesn't work yet)
  • lib/instrument.py (setting.set): store the value being set, not the one converted for the instrument
  • usbtmc.c, python.c: increased SIZE_IOBUFFER from 4kB to 1MB and BUF_SIZE from 8kB to 1MB, to accommodate Rigol screen dumps
  • usbtmc.c: added pointer to rew's Rigol driver
  • lib/scope.py: new method "screendump"
  • usbtmc.c (usbtmc_read): Rigol buffer reads were off by 12 bytes
  • lib/scope.py (rigol_channel_data, rigol_la_data): added 12 to offsets and corrected off-by-two error in analog wave offset
Location:
developers/werner/ahrt/host/tmc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • developers/werner/ahrt/host/tmc/lib/instrument.py

    r4601 r4608  
    3939            self.value = None 
    4040        elif value != self.value: 
     41            self.value = value 
    4142            if self.out_convert: 
    4243                value = self.out_convert(value) 
     
    4546            self.instr.send((self.set_cmd, self.path)[self.set_cmd is None]+ 
    4647              " "+self.args+str(value)) 
    47             self.value = value 
    4848 
    4949 
  • developers/werner/ahrt/host/tmc/lib/scope.py

    r4601 r4608  
    33# scope.py - Oscilloscope control 
    44#  
     5 
     6# Found screen dump algorithm here: 
     7# http://www.circuitsonline.net/forum/view/message/652573#652573 
    58 
    69# 
     
    2023# TODO: make range configurable 
    2124 
    22 def scale_125(n, fuzz): 
     25def scale_125(n = None, fuzz = None, min = None, max = None): 
     26    res = None 
    2327    for e in range(-9, 1+1): 
    2428        for m in [1, 2, 5]: 
     
    2832                s = str(m)+"0"*e 
    2933            r = float(s) 
    30             if r >= n*(1-fuzz) and r <= n*(1+fuzz): 
     34            if n is not None and r >= n*(1-fuzz) and r <= n*(1+fuzz): 
    3135                return s 
     36            if min is not None and r >= min: 
     37                return s 
     38            if max is not None and r <= max: 
     39                res = s 
     40    if res is not None: 
     41        return res 
     42    raise hell 
    3243 
    3344 
     
    97108 
    98109    def wave(self, start = None, end = None, step = None): 
    99         return self.scope.download_wave(self, start, end, step) 
     110        width = self.scope.div_hor*self.scope.hor.scale 
     111        if start is None and end is None: 
     112            start = self.scope.hor.pos 
     113        if start is not None and end is None: 
     114            end = start+width 
     115        elif start is None and end is not None: 
     116            start = end-width 
     117        if step is None: 
     118            return self.scope.download_wave(self, start, end, None) 
     119        else: 
     120            # @@@ put setting the horizontal system into download_wave 
     121            if step*self.scope.sampling_rate() < 1: 
     122                raise hell 
     123            span = step*self.scope.samples_per_div*self.scope.div_hor 
     124            if False and span >= start-end: 
     125                return self.scope.download_wave(self, start, end, None) 
     126            else: 
     127                scale = float(scale_125(max = step*self.scope.samples_per_div)) 
     128                orig_pos = self.scope.hor.pos 
     129                orig_scale = self.scope.hor.scale 
     130                self.scope.hor.scale = scale 
     131                span = self.scope.div_hor*self.scope.hor.scale 
     132                wave = analog_wave() 
     133                pos = start 
     134                while pos < end: 
     135                    self.scope.hor.pos = pos 
     136                    wave.extend(self.scope.download_wave(self, pos, pos+span, 
     137                      None)) 
     138                    pos += span 
     139                self.scope.hor.pos = orig_pos 
     140                self.scope.hor.scale = orig_scale 
     141                return wave 
    100142 
    101143 
     
    197239def rigol_channel_data(s, t0, td, v0, vd): 
    198240    res = analog_wave() 
    199     i = 202 
    200     while i != 800: 
    201         div = (i-502)/50.0 
     241    i = 212 
     242    while i != 812: 
     243        div = (i-512)/50.0 
    202244        t = t0+div*td 
    203245        div = (125-ord(s[i]))/25.0 
     
    212254    for b in range(0, 16): 
    213255        res.append(digital_wave()) 
    214     i = 412  
    215     while i != 1612: 
    216         div = (i-1012)/100.0 
     256    i = 424 
     257    while i != 1624: 
     258        div = (i-1024)/100.0 
    217259        t = t0+div*td 
    218260        for b in range(0, 8): 
     
    223265 
    224266 
     267def rigol_to_ppm(s): 
     268    lut = [] 
     269    i = 0 
     270    while i != 256: 
     271        lut.append(chr(i & 0xc0)+chr((i & 0x38) << 2)+chr((i & 3) << 5)) 
     272        i += 1 
     273    res = "P6 320 234 255\n" 
     274    i = 0 
     275    while i != 320*234: 
     276        res += lut[ord(s[i])] 
     277        i += 1 
     278    return res 
     279 
     280 
    225281class rigol_ds1000c(scope): 
    226282    channels = 2 
    227283    div_hor = 12 
    228284    div_vert = 10 
     285    samples_per_div = 600       #@@@ not exactly true. needs more investigation 
    229286 
    230287    def __init__(self): 
     
    274331        data = self.query(":WAV:DATA? DIG") 
    275332        return rigol_la_data(data, self.hor.pos, self.hor.scale) 
     333 
     334    def sampling_rate(self): 
     335        return float(self.query(":ACQ:SAMP? CH1")) 
     336 
     337    def screendump(self): 
     338        self.send(":HARDCOPY") 
     339        return rigol_to_ppm(self.query(":LCD:DATA?")) 
  • developers/werner/ahrt/host/tmc/lib/wave.py

    r4601 r4608  
    111111            raise hell 
    112112        self.data.append((t, y)) 
     113 
     114    def extend(self, wave): 
     115        if len(self.data) and len(wave.data) and \ 
     116          wave.data[0][0] < self.data[-1][0]: 
     117            raise hell 
     118        self.data.extend(wave.data) 
    113119 
    114120    def get_one(self, t): 
     
    154160        self.initial = None 
    155161        self.data = [] 
    156         self.cursor = None 
    157162        self.t_end = None 
    158163 
     
    173178            self.data.append(t) 
    174179        self.t_end = t 
     180 
     181    def extend(self, wave): 
     182        if wave.t_end is None: 
     183            return 
     184        if self.t_end is None: 
     185            self.t_end = wave.t_end 
     186            self.data = wave.data 
     187            self.initial = wave.initial 
     188            return 
     189        if wave.data[0] < self.t_end: 
     190            raise hell 
     191        if self.initial ^ (len(self.data) & 1) == wave.initial: 
     192            self.data.extend(wave.data) 
     193        else: 
     194            self.data.extend(wave.data[1:]) 
     195        self.t_end = wave.t_end 
    175196 
    176197    def get_one(self, t): 
  • developers/werner/ahrt/host/tmc/python.c

    r4526 r4608  
    1818 
    1919 
    20 #define BUF_SIZE 8192 
     20#define BUF_SIZE (1024*1024) 
    2121#define ERROR fprintf(stderr, "ERROR %d\n", __LINE__) 
    2222        /* @@@FIXME: raise exceptions */ 
  • developers/werner/ahrt/host/tmc/usbtmc.c

    r4601 r4608  
    1515 * http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.html 
    1616 * http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.tar 
     17 * 
     18 * The Rigol protocol variant is based on this driver: 
     19 * http://www.circuitsonline.net/forum/view/message/652371#652371 
    1720 */ 
    1821 
     
    4346#endif 
    4447 
    45 #define SIZE_IOBUFFER 4096 
     48#define SIZE_IOBUFFER (1024*1024)       /* memory is cheap ;-) */ 
    4649 
    4750#define DEV_DEP_MSG_OUT                 1 
     
    669672                if (d->rigol && payload > 64-12) { 
    670673                        got = usb_bulk_read(d->handle, d->ep_bulk_in, 
    671                             (void *) tmp+64-12, payload-12, d->timeout); 
    672                         dump("RECV", tmp+64-12, got); 
     674                            (void *) tmp+64, payload-(64-12), d->timeout); 
     675                        dump("RECV", tmp+64, got); 
    673676                } 
    674677 
Note: See TracChangeset for help on using the changeset viewer.