Commit c54e6c48 authored by Federico Asara's avatar Federico Asara

Generic module describes generic waves and generator .

parent eaec8eef
import serial
import time
def Property(func):
return property(**func())
"""This class should manage a generic 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 = "Output status of the generator"
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)
def Property(func):
return property(**func())
class Waveform(object):
def apply(self):
return ""
__author__="Federico"
__date__ ="$Aug 17, 2011 4:43:08 PM$"
# PAIn: Python ADC Interface
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