forked from cibomahto/pyusbtmc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
155 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python | ||
# | ||
# PyUSBtmc | ||
# | ||
# Berkely Nucleonics Model 645 Arbitrary Waveform Generator TMC interface | ||
# | ||
# Copyright (c) 2011 Mike Hadmack | ||
# This code is distributed under the MIT license | ||
from pyusbtmc import usbtmc | ||
import numpy | ||
|
||
false = 0; true = 1 | ||
|
||
class WaveformGenerator(usbtmc): | ||
"""Class to control a BNC 645 Arbitrary Waveform Generator""" | ||
def __init__(self, device): | ||
usbtmc.__init__(self, device) | ||
self.name = self.getName() | ||
print "# Connected to: " + self.name | ||
|
||
self.write("*RST;*CLS") # Reset instrument | ||
self.set50OhmOutput(false) # Set output to high impedance | ||
self.write("FORM:BORD SWAP") # Set for little endian byte order | ||
|
||
def outputOn(self): | ||
self.write("OUTPut ON"); | ||
|
||
def outputOff(self): | ||
self.write("OUTPut OFF"); | ||
|
||
def set50OhmOutput(self,on): | ||
if on : self.write("OUTPut:LOAD 50") | ||
else : self.write("OUTPut:LOAD INF") | ||
|
||
def setFunction(self, func): | ||
if func == "SINE" : self.write("FUNCtion SINusoid") | ||
elif func == "SQUARE" : self.write("FUNCtion SQUare") | ||
elif func == "PULSE" : self.write("FUNCtion PULSe") | ||
elif func == "USER" : self.write("FUNCtion USER"); self.write("FUNC:USER VOLATILE") | ||
|
||
def setupExtTrigger(self): | ||
self.write("TRIGger:SOURce EXTernal") | ||
self.write("BURSt:MODE TRIGgered") | ||
self.write("BURSt:STATe ON") | ||
|
||
def setFrequency(self, freq): | ||
self.write("FREQuency %.3f"%freq) | ||
|
||
def setAmplitude(self, volts): | ||
self.write("VOLTage %.3f"%volts) | ||
|
||
def setOffset(self, volts): | ||
self.write("VOLTage:OFFSet %.3f"%volts) | ||
|
||
def setVoltageLow(self,low): | ||
self.write("VOLTage:LOW %.3f"%low) | ||
|
||
def setVoltageHigh(self,high): | ||
self.write("VOLTage:HIGH %.3f"%high) | ||
|
||
def setVoltageRange(self, vMin, vMax): | ||
self.setVoltageLow(vMin); | ||
self.setVoltageHigh(vMax); | ||
|
||
def sendWaveformData(self, data, duration, voltageMin, voltageMax): | ||
'''Loads a data set where values from -1.0 to 1.0 correspond to the voltage range given. | ||
Duration is the time in seconds for the full data set''' | ||
count = len(data) | ||
buf = "DATA VOLATILE" | ||
for x in data: | ||
buf += ", " + str(x) | ||
print buf | ||
self.write(buf) | ||
self.setFrequency(1/duration) | ||
#self.setVoltageRange(voltageMin, voltageMax) | ||
#self.setOffset(5.0) | ||
#self.setAmplitude(3.0) | ||
|
||
def main(): | ||
wg = WaveformGenerator("/dev/usbtmc-bnc645") | ||
wg.outputOff() | ||
#wg.setupExtTrigger() | ||
|
||
# Send data | ||
data = numpy.array([1.0, -1.0, 0.5, -0.5, 0.25, -0.25]) | ||
wg.sendWaveformData(data, 100e-6,-2.0, 3.0) | ||
self.setOffset(0.0) | ||
self.setAmplitude(1.0) | ||
|
||
wg.setFunction("USER") | ||
wg.outputOn() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters