Commit f6bab201 authored by Federico Asara's avatar Federico Asara

Various bugfixes.

parent 4f1aeb02
...@@ -79,6 +79,7 @@ class Agilent33250A(Generator): ...@@ -79,6 +79,7 @@ class Agilent33250A(Generator):
def command(self, what): def command(self, what):
'''Send a (list of) command(s) to the device: a command is a string, and '''Send a (list of) command(s) to the device: a command is a string, and
this function appends automatically a new line.''' this function appends automatically a new line.'''
print what
if len(what) == 0: if len(what) == 0:
return return
...@@ -129,21 +130,29 @@ class Agilent33250A(Generator): ...@@ -129,21 +130,29 @@ class Agilent33250A(Generator):
if type(f) in (tuple, list): if type(f) in (tuple, list):
if len(f) == 2: if len(f) == 2:
f, n = f f, n = f
if n[0] != ':':
n = ":"+n
else: else:
return return
else:
n = ''
if type(f) != str: if type(f) != str:
return return
f = f.upper() f = f.upper()
if ' ' in f: if ' ' in f:
f, n = f.split(' ') f, n = f.split(' ')
else: if n[0] != ':':
n = ":"+n
elif ':' not in n:
n = '' n = ''
if f not in self.functionList: if f not in self.functionList:
return return
self.command("FUNC %s %s" % (f, n)) self.command("FUNC %s%s" % (f, n))
return locals() return locals()
......
...@@ -15,7 +15,9 @@ class Generator(Item): ...@@ -15,7 +15,9 @@ class Generator(Item):
# this dictionary is used to map data types into function which can # this dictionary is used to map data types into function which can
# translate such type of data into something the generator can understand. # translate such type of data into something the generator can understand.
adaptDict = {} adaptDict = {}
def play(self, wave):
return
def adaptKeys(self): def adaptKeys(self):
"""Returns all data types supported.""" """Returns all data types supported."""
return self.adaptDict.keys() return self.adaptDict.keys()
......
...@@ -31,6 +31,19 @@ class SineWaveform(Waveform.Waveform): ...@@ -31,6 +31,19 @@ class SineWaveform(Waveform.Waveform):
return (s/lsb).astype(int) return (s/lsb).astype(int)
def generatePeriod(self, nbits, samples, fsr):
f = self.frequency
A = self.amplitude
C = self.dc
t = arange(samples, dtype=float)/samples
s = A*sin(2*pi*t) +C
lsb = fsr/(2**nbits)
return (s/lsb).astype(int), f
def scale(self, factor): def scale(self, factor):
"""Multiply the frequency by factor.""" """Multiply the frequency by factor."""
self.frequency *= factor self.frequency *= factor
......
...@@ -6,7 +6,32 @@ import Pyro4 ...@@ -6,7 +6,32 @@ import Pyro4
import Pyro4.util import Pyro4.util
import sys import sys
import commands import commands
def gcd(a, b):
"""Return greatest common divisor using Euclid's Algorithm."""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""Return lowest common multiple."""
return a * b // gcd(a, b)
def frac(x, n):
AA = 0
BB = 1
A = 1
B = 0
for i in range(n):
a = int(math.floor(x))
try:
x = 1/(x-a)
AA, A = A, AA + a * A
BB, B = B, BB + a * B
except:
return
yield (x, a, A, B,)
class TTWaveform(Waveform.Waveform): class TTWaveform(Waveform.Waveform):
def get(self, what): def get(self, what):
return self.__getattribute__(what) return self.__getattribute__(what)
...@@ -34,6 +59,23 @@ class TTWaveform(Waveform.Waveform): ...@@ -34,6 +59,23 @@ class TTWaveform(Waveform.Waveform):
return (s/lsb).astype(int) return (s/lsb).astype(int)
def generatePeriod(self, nbits, samples, fsr):
A = self.amplitude
C = self.dc
# r1, r2 = list(frac(self.ratio, 7))[-1][2:]
# print r1, r2
#print 'Samples:', samples*self.ratio*r2
freq = 2./(self.ratio -1.)
t = arange(samples*freq, dtype=float)/samples
s = A*sin(2*pi*t) +A*sin(2*pi*self.ratio*t) +C
lsb = fsr/(2**nbits)
return (s/lsb).astype(int), self.frequency/freq
def scale(self, factor): def scale(self, factor):
"""Multiply the frequency by factor""" """Multiply the frequency by factor"""
self.frequency *= factor self.frequency *= factor
......
...@@ -11,9 +11,14 @@ class Waveform(Item): ...@@ -11,9 +11,14 @@ class Waveform(Item):
"""Set an attribute value. Supports Pyro4.""" """Set an attribute value. Supports Pyro4."""
self.__setattr__(what, how) self.__setattr__(what, how)
"""A waveform must provide this method.
Create a numeric array which represents the wave."""
def generate(self, nbits, frequency, samples, fsr): def generate(self, nbits, frequency, samples, fsr):
"""A waveform must provide this method.
Create a numeric array which represents the wave."""
return array([])
def generatePeriod(self, nbits, samples, fsr):
"""A waveform must provide this method.
Create a numeric array which represents a period of the wave."""
return array([]) return array([])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment