Commit eaec8eef authored by Federico Asara's avatar Federico Asara

Generic module describes generic waves and generator .

parent 9f4558a2
import serial
import time
def Property(func):
return property(**func())
"""This class should manage the Agilent 33250A waveform generator"""
class Generator(serial.Serial):
def __init__(self, device = "/dev/ttyUSB0", bauds = 57600, to = 2, interCharTimeout=1):
serial.Serial.__init__(self, device, bauds, timeout = to, interCharTimeout = 1)
def command(self, what):
return self.write("%s\n" % what)
@Property
def output():
doc = "The person's name"
def fget(self):
self.command("OUTP?")
output = self.read(2)[0]
return output == "1"
def fset(self, status):
if type(status) is not bool:
return
self.command("OUTP %d" % (1 if status else 0))
return locals()
def sine(self, frequency, amplitude, dc = 0, freqm = 'HZ', ampm = 'VPP', dcm = 'V'):
self.command("APPL:SIN %.2f %s, %.2f %s, %.2f %s" % (frequency, freqm, amplitude, ampm, dc, dcm))
def sweep(self, interval, frequencies, amplitude, dc = 0, freqm = 'HZ', ampm = 'VPP', dcm = 'V', callback = None):
for f in frequencies:
self.sine(f, amplitude, dc, freqm, ampm, dcm)
time.sleep(interval)
if callback is not None:
callback(f)
import Waveform
def Property(func):
return property(**func())
def parse(value, s):
if type(value) is str:
value = value.split(" ")
value[0] = float(value[0])
value = tuple(value)
if type(value) is tuple and len(value) == 1:
value = value[0]
if type(value) is not tuple:
return (value, s)
else: return value
class SineWaveform(Waveform.Waveform):
def apply(self):
return ""
_freq = (1, 'KHZ');
_amp = (0.1, 'VPP');
_dc = (0, 'V');
@Property
def frequency():
doc = "Frequency of the sinewave"
def fget(self):
return self._freq
def fset(self, value):
self._freq = parse(value, 'HZ')
def fdel(self):
del self._freq
return locals()
@Property
def amplitude():
doc = "Amplitude of the sinewave"
def fget(self):
return self._amp
def fset(self, value):
self._amp = parse(value, 'HZ')
def fdel(self):
del self._amp
return locals()
@Property
def dc():
doc = "Amplitude of the sinewave"
def fget(self):
return self._dc
def fset(self, value):
self._dc = parse(value, 'HZ')
def fdel(self):
del self._dc
return locals()
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