Skip to content

Commit

Permalink
Merge pull request #3 from Padoup-Padoup/master
Browse files Browse the repository at this point in the history
Display up to 4 channels and export to CSV
  • Loading branch information
amcdawes authored Jun 21, 2017
2 parents 0b79484 + ff91b3d commit 65b1331
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Python code for interacting with our lab instruments via USBTMC
- RigolDG - Rigol DG4102 Arb Gen.

Requirements:
- matplotlib
- numpy
- python-usbtmc (installed with pip) pypi.python.org/pypi/python-usbtmc
- wxgtk

matplotlib
numpy
wxgtk (i.e. via `sudo apt-get install python-wxgtk3.0` in Ubuntu/Debian linux or `conda install wxpython` for Anaconda python mac)
python-usbtmc (installed with `pip`) pypi.python.org/pypi/python-usbtmc



57 changes: 52 additions & 5 deletions TekScopeGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self):
wx.Frame.__init__(self, None, -1, self.title)

self.data = [0, 0, 0, 0, 0]

self.xdata = range(len(self.data))

self.create_menu()
self.create_status_bar()
self.create_main_panel()
Expand All @@ -45,8 +46,10 @@ def create_menu(self):
self.menubar = wx.MenuBar()

menu_file = wx.Menu()
m_expt = menu_file.Append(-1, "&Save data\tCtrl-S", "Save data to file")
m_expt = menu_file.Append(-1, "&Save data to Numpy\tCtrl-S", "Save data to Numpy file")
self.Bind(wx.EVT_MENU, self.on_save_data, m_expt)
m_expt = menu_file.Append(-1, "&Save data to CSV\tCtrl-Shift-S", "Save data to CSVfile")
self.Bind(wx.EVT_MENU, self.on_save_data_csv, m_expt)
menu_file.AppendSeparator()
m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit")
self.Bind(wx.EVT_MENU, self.on_exit, m_exit)
Expand Down Expand Up @@ -87,6 +90,13 @@ def create_main_panel(self):
self.ch2button = wx.Button(self.panel, -1, "CH2")
self.Bind(wx.EVT_BUTTON, self.on_ch2_button, self.ch2button)

self.ch3button = wx.Button(self.panel, -1, "CH3")
self.Bind(wx.EVT_BUTTON, self.on_ch3_button, self.ch3button)

self.ch4button = wx.Button(self.panel, -1, "CH4")
self.Bind(wx.EVT_BUTTON, self.on_ch4_button, self.ch4button)


self.refabutton = wx.Button(self.panel, -1, "RefA")
self.Bind(wx.EVT_BUTTON, self.on_refa_button, self.refabutton)

Expand Down Expand Up @@ -115,6 +125,8 @@ def create_main_panel(self):
flags = wx.ALIGN_LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL
self.hbox.Add(self.ch1button, 0, border=3, flag=flags)
self.hbox.Add(self.ch2button, 0, border=3, flag=flags)
self.hbox.Add(self.ch3button, 0, border=3, flag=flags)
self.hbox.Add(self.ch4button, 0, border=3, flag=flags)
self.hbox.Add(self.refabutton, 0, border=3, flag=flags)
self.hbox.Add(self.refbbutton, 0, border=3, flag=flags)
self.hbox.Add(self.cb_grid, 0, border=3, flag=flags)
Expand All @@ -131,31 +143,45 @@ def create_status_bar(self):
def draw_figure(self):
""" Redraws the figure
"""

# clear the axes and redraw the plot anew
self.axes.clear()
self.axes.grid(self.cb_grid.IsChecked())

self.axes.plot(self.data)
self.axes.plot([i*1000 for i in self.xdata], self.data)
self.canvas.draw()

def on_cb_grid(self, event):
self.draw_figure()

def on_ch1_button(self, event):
self.data = inst.get_data("CH1")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_ch2_button(self, event):
self.data = inst.get_data("CH2")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_ch3_button(self, event):
self.data = inst.get_data("CH3")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_ch4_button(self, event):
self.data = inst.get_data("CH4")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_refa_button(self, event):
self.data = inst.get_data("REFA")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_refb_button(self, event):
self.data = inst.get_data("REFB")
self.xdata = inst.get_xdata()
self.draw_figure()

def on_save_data(self, event):
Expand All @@ -172,9 +198,30 @@ def on_save_data(self, event):
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
#self.canvas.print_figure(path, dpi=self.dpi)
numpy.save(path, self.data)
numpy.save(path, (self.xdata, self.data))
self.flash_status_message("Data saved to %s" % path)

def on_save_data_csv(self, event):
file_choices = "CSV (*.csv)|*.csv"

dlg = wx.FileDialog(
self,
message="Save data as...",
defaultDir=os.getcwd(),
defaultFile="data",
wildcard=file_choices,
style=wx.SAVE)

if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
#self.canvas.print_figure(path, dpi=self.dpi)
out = numpy.zeros((len(self.data), 2))
for (i,l) in enumerate(zip(self.xdata, self.data)):
out[i,:] = l
numpy.savetxt(path, out)
self.flash_status_message("Data saved to %s" % path)


def on_exit(self, event):
self.Destroy()

Expand Down
2 changes: 1 addition & 1 deletion instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_xdata(self):
self.write("HORIZONTAL:RECORDLENGTH?")
time_size = int(self.read(30))

time = numpy.arange(0,timescale*10,timescale*10/time_size)
time = numpy.arange(0,timescale*10,timescale*10/time_size*2) # For some reason the output was too short compared to the data buffer
return time


Expand Down

0 comments on commit 65b1331

Please sign in to comment.