Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display up to 4 channels and export to CSV #3

Merged
merged 4 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Requirements:

matplotlib
numpy
python-usbtmc (installed with pip)
wxgtk (installed for instance from `sudo apt-get install python-wxgtk3.0`)
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be scope-dependent, I'll look into it, but am merging for now. There is a better way to get the record length directly from the scope and that is how it should be done in an instrument-neutral way.

return time


Expand Down