Skip to content

Commit

Permalink
File output function handles both channels (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadmack committed Feb 4, 2011
1 parent 84fe1d4 commit d019b63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PyUSBtmc is a simple library for interacting with test equipment (primarily Rigo

It was conceived of by Matt Mets in 2010, and is distributed under the MIT License. See LICENSE for a copy of this license.

The PyUSBtmc project is in no way affiliated with Rigol Technologies Inc.

Setup USB permissions for udev
------------------------------
echo 'ACTION=="add", BUS=="usb", SYSFS{idVendor}=="1ab1", SYSFS{idProduct}=="0588", GROUP:="adm"' > tmpfile
Expand Down
9 changes: 9 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
TODO

* File dump mode for one or two traces
* Test with 1102CD scope (older firmware)
* Try firmware upgrade?
* Plotting routines (in wxFrame?, direct to EPS/PNG)

Should the RigolScope object hold the most recently acquired data for use by processing routines? For example the plotting object can be linked to RigolScope object for message passing.

Which RigolScope methods should be part of the public interface and which are private?


38 changes: 21 additions & 17 deletions pyusbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,12 @@ def getTimeOffset(self):
return float(self.query(":TIM:OFFS?", 20))

def getScaledWaveform(self,chan=1):
"""Read scope and rescale data from axis information
return data as a tuple (t,y)
TODO: Multichannel mode
TODO: Return scope parameters in dictionary """
"""Read scope channel vertical axis and rescale data from axis information
Returns a numpy array with voltage scaled scope trace"""
data = self.readData(chan)

voltscale = self.getVoltScale(chan)
voltoffset = self.getVoltOffset(chan)

# Walk through the data, and map it to actual voltages
# First invert the data (ya rly)
data = 255 - data
# Now, we know from experimentation that the scope display range is actually
Expand All @@ -141,7 +137,8 @@ def getScaledWaveform(self,chan=1):
def getTimeAxis(self):
"""Retrieve timescale and offset from the scope and return an array or
time points corresponding to the present scope trace
Units are seconds by default"""
Units are seconds by default
Returns a numpy array of time points"""
timescale = self.getTimeScale()
timeoffset = self.getTimeOffset()
# Now, generate a time axis. The scope display range is 0-600, with 300 being
Expand All @@ -150,26 +147,33 @@ def getTimeAxis(self):
time = numpy.linspace(-timespan,+timespan, 600)
return time

def writeWaveformToFile(self, filename, chan=1):
"""Write scaled scope data to file"""
def writeWaveformToFile(self, filename, chans=1):
"""Write scaled scope data to file
Zeros are generated for any unused channel for consistancy in data file"""
fd = open(filename, 'w')
data = self.getScaledWaveform(chan)
time = self.getTimeAxis()
self._writeChannelDataToFile(fd, data, time)
data1 = numpy.zeros(time.size)
data2 = numpy.zeros(time.size)
if chan==1 or chan=='BOTH':
data1 = self.getScaledWaveform(1)
if chan==2 or chan=='BOTH':
data2 = self.getScaledWaveform(2)

self._writeChannelDataToFile(fd, data1, data2, time)
fd.close()

def _writeChannelDataToFile(self, fd, data, time):
def _writeChannelDataToFile(self, fd, data1, data2, time):
"""Write data and time arrays to file descriptor"""
fd.write("# Time\tVoltage\n")
fd.write("# Time\tChannel 1\tChannel 2\n")
for i in range(data.size):
fd.write("%f\t%f\n"%(time[i],data[i]))
fd.write("%f\t%f\t%f\n"%(time[i],data1[i],data2[i]))

def main():
print "# RigolScope Test #"
scope = RigolScope("/dev/usbtmc0")
scope.stop()
print scope.readRawData(1)
scope.run()

scope.writeWaveformToFile("testdata.txt", 1)

scope.close()

if __name__ == "__main__":
Expand Down

0 comments on commit d019b63

Please sign in to comment.