r4946 - in developers/werner/ahrt/host/tmc: . lib

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Mar 3 15:37:21 CET 2009


Author: werner
Date: 2009-03-03 15:37:21 +0100 (Tue, 03 Mar 2009)
New Revision: 4946

Modified:
   developers/werner/ahrt/host/tmc/lib/scope.py
   developers/werner/ahrt/host/tmc/lib/wave.py
   developers/werner/ahrt/host/tmc/python.c
Log:
- python.c: increase buffer size from 1 MB to > 20 MB
- lib/scope.py: added basic support for Tektronix MSO4000 series
- lib/wave.py: label assignment logic in "binary" incorrectly assumed that we
  only use waves, no scalars



Modified: developers/werner/ahrt/host/tmc/lib/scope.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/scope.py	2009-03-03 14:07:29 UTC (rev 4945)
+++ developers/werner/ahrt/host/tmc/lib/scope.py	2009-03-03 14:37:21 UTC (rev 4946)
@@ -451,3 +451,76 @@
 		t0 = t1-self.samples/real_rate
 	    center = (t0+t1)/2.0
 	    self.hor.pos = center-trigger
+
+
+class tektronix_mso4000(scope):
+    channels = 4
+    div_hor = 10
+    div_vert = 10
+    samples_per_div = 50	# ???
+
+    def __init__(self):
+	scope.__init__(self, "usbtmc", "timeout=10", "retry",
+          "vendor=0x0699", "product=0x0401")
+	self.ch = []
+	self.d = map(lambda x: x, range(0, 16))
+	for n in range(1, self.channels+1):
+	    self.ch.append(channel(self, n))
+	self.trigger = None
+	self.hor = horizontal(self)
+	self.lock_attr()
+
+# for now, we treat it almost like a Rigol
+
+    def forget(self):
+	for ch in self.ch:
+	    ch.forget()
+	self.hor.forget()
+
+    def download_wave(self, channel, start, end, step):
+	self.send(":DATA:SOU CH"+str(channel.number))
+	self.send(":DATA:ENC RPB")
+	self.send(":WFMO:BYT_NR 1")
+	self.send(":CURVE B")
+	s = self.query(":WFMO?")
+	info = s.split(";")
+	pts = info[6]
+	hincr = float(info[9])
+	hzero = float(info[10])
+	vincr = float(info[13])
+	vzero = float(info[14])
+	start = 400000
+	self.send(":DATA:START "+str(start))
+	self.send(":DATA:STOP 700000")
+	d = self.query(":CURVE?")
+	digits = int(d[1])
+	d = d[2+digits:-1]
+	wave = analog()
+	t = hzero+hincr*start
+	for c in d:
+	    wave.append(t, (ord(c)-vzero)*vincr)
+	    t += hincr
+	return wave
+
+    def sampling_rate(self):
+	return float(self.query(":ACQ:SAMP? CH1"))
+
+    def screendump(self):
+	self.send(":SAV:IMAG:FILEF PNG");
+	return self.query(":HARDCOPY START")
+
+    def wave(self, channels, start = None, end = None, step = None):
+	if not hasattr(channels, "__iter__"):
+	    return self.wave([channels], start, end, step)[0]
+	la = None
+	res = waves()
+	for ch in channels:
+	    if isinstance(ch, channel):
+		res.append(self.download_wave(ch, start, end, step))
+		res[-1].label = ch.name
+	    else:
+		if la is None:
+		    la = self.download_la(start, end, step)
+		res.append(la[ch])
+		res[-1].label = "D"+str(ch)
+	return res

Modified: developers/werner/ahrt/host/tmc/lib/wave.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/wave.py	2009-03-03 14:07:29 UTC (rev 4945)
+++ developers/werner/ahrt/host/tmc/lib/wave.py	2009-03-03 14:37:21 UTC (rev 4946)
@@ -1,7 +1,7 @@
 #
 # wave.py - Analog and digital waveforms
 #
-# Copyright (C) 2008 by OpenMoko, Inc.
+# Copyright (C) 2008, 2009 by OpenMoko, Inc.
 # Written by Werner Almesberger <werner at openmoko.org>
 # All Rights Reserved
 #  
@@ -114,23 +114,25 @@
 
     def binary(self, other, op):
 	res = analog()
-	s = self.label
-	if not s:
-	    s = ""
-	if other.label:
-	    if s:
-		s += "_"
-	    s += other.label
 	if isinstance(self, wave):
+	    s = self.label
+	    if not s:
+		s = ""
 	    if isinstance(other, wave):
+		if False: # other.label:
+		    if s:
+			s += "_"
+		    s += other.label
 		for v in waves(self, other).iterate():
 		    res.append(v[0], op(float(v[1]), float(v[2])))
 	    else:
 		for p in self:
 		    res.append(p[0], op(float(p[1]), float(other)))
 	else:
+	    s = other.label
 	    for p in other:
 		res.append(p[0], op(float(self), float(p[1])))
+	res.label = s
 	return res
 
     def __add__(self, other):

Modified: developers/werner/ahrt/host/tmc/python.c
===================================================================
--- developers/werner/ahrt/host/tmc/python.c	2009-03-03 14:07:29 UTC (rev 4945)
+++ developers/werner/ahrt/host/tmc/python.c	2009-03-03 14:37:21 UTC (rev 4946)
@@ -1,7 +1,7 @@
 /*
  * python.c - Python binding for TMC functions
  *
- * Copyright (C) 2008 by OpenMoko, Inc.
+ * Copyright (C) 2008, 2009 by OpenMoko, Inc.
  * Written by Werner Almesberger <werner at openmoko.org>
  * All Rights Reserved
  *
@@ -17,7 +17,7 @@
 #include "tmc.h"
 
 
-#define BUF_SIZE (1024*1024)
+#define BUF_SIZE (21*1024*1024)	/* Tek MSO4000 can return about 20 MB */
 #define ERROR fprintf(stderr, "ERROR %d\n", __LINE__)
 	/* @@@FIXME: raise exceptions */
 
@@ -27,6 +27,9 @@
 };
 
 
+static char *buf;
+
+
 /*
  * @@@FIXME: how to _properly_ deallocate these strings ?
  */
@@ -139,7 +142,6 @@
 static PyObject *tmc_py_read(PyObject *self, PyObject *noarg)
 {
 	struct py_instr *s = (struct py_instr *) self;
-	static char buf[BUF_SIZE];
 	int len;
 
 //fprintf(stderr, "tmc_py_read\n");
@@ -248,7 +250,12 @@
 	tmc_instr_type.tp_new = PyType_GenericNew;
 	if (PyType_Ready(&tmc_instr_type) < 0)
 		return;
-	m = Py_InitModule3("_tmc", tmc_methods, "Test & Mesurement Control");
+	m = Py_InitModule3("_tmc", tmc_methods, "Test & Measurement Control");
 	Py_INCREF(&tmc_instr_type);
 	PyModule_AddObject(m, "Instr", (PyObject *) &tmc_instr_type);
+	buf = malloc(BUF_SIZE);
+	if (!buf) {
+		perror("malloc");
+		exit(1);
+	}
 }




More information about the commitlog mailing list