forked from cibomahto/pyusbtmc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbnc645.py~
More file actions
executable file
·94 lines (75 loc) · 2.83 KB
/
bnc645.py~
File metadata and controls
executable file
·94 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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()