Skip to content
Snippets Groups Projects
Commit f94d9d6b authored by Michael DM Dryden's avatar Michael DM Dryden
Browse files

CA data acquisition and plotting works.

parent 6bcaead1
Branches
Tags
No related merge requests found
......@@ -38,6 +38,7 @@
buildPhases = (
);
buildToolPath = /usr/local/bin/python;
buildWorkingDirectory = "/Users/mdryden/src/dstat-interface2/dstatInterface";
dependencies = (
);
name = dstatInterface;
......
......@@ -4,11 +4,11 @@ import serial, io
from serial.tools import list_ports
# class that holds analog data for N samples
class AnalogData:
class linearData:
# constr
def __init__(self):
self.ax = []
self.ay = []
self.xdata = []
self.ydata = []
self.first = 1
# add data
......@@ -17,8 +17,8 @@ class AnalogData:
self.first = 0
return
assert(len(data) == 2)
self.ax.append(data[0])
self.ay.append(data[1])
self.x.append(data[0])
self.y.append(data[1])
# clear data
def clear(self):
......@@ -27,33 +27,6 @@ class AnalogData:
self.ay = []
# plot class
class AnalogPlot:
# constr
def __init__(self, analogData):
self.i = 0
# set plot to animated
plt.ion() #interactive mode on
plt.autoscale(True,True,True)
self.line = plt.plot(analogData.ax,analogData.ay)
# update plot
def update(self, analogData):
if self.i < 5:
self.i += 1
return
plt.setp(self.line,xdata=analogData.ax, ydata=analogData.ay)
ax = plt.gca()
# recompute the ax.dataLim
ax.relim()
# update ax.viewLim using the new dataLim
ax.autoscale_view()
plt.draw()
self.i=0
class SerialDevices:
def __init__(self):
self.ports, _, _ = zip(*list_ports.comports())
......@@ -61,25 +34,124 @@ class SerialDevices:
def refresh(self):
self.ports, _, _ = zip(*list_ports.comports())
def chronoamp(adc_buffer, adc_rate, adc_pga, gain, potential, time):
s = "A "
s += (adc_buffer)
s += " "
s += (adc_rate)
s += " "
s += (adc_pga)
s += " G "
s += (gain)
s += " R "
s += str(len(potential))
s += " "
for i in potential:
s += str(i)
s += " "
for i in time:
s += str (i)
s += " "
print s
class Experiment:
def __init__(self):
pass
def init(self, adc_buffer, adc_rate, adc_pga, gain):
self.datatype = ""
self.datalength = 2
self.data = []
self._gaintable = [1e2, 3e2, 3e3, 3e4, 3e5, 3e6, 3e7, 5e8]
self.gain = self._gaintable[int(gain)]
self.commands = []
self.xlabel = ""
self.ylabel = ""
self.commands += "A "
self.commands[0] += (adc_buffer)
self.commands[0] += " "
self.commands[0] += (adc_rate)
self.commands[0] += " "
self.commands[0] += (adc_pga)
self.commands[1] = "G"
self.commands[1] += (gain)
def run(self, strPort, plotbox_instance):
self.ser = serial.Serial(strPort, 1024000,timeout=2)
self.sio = io.TextIOWrapper(io.BufferedRWPair(self.ser,self.ser,buffer_size=1), newline = '\n', line_buffering = True)
self.ser.write("ck")
plotbox_instance.changetype(self)
self.ser.flushInput()
self.updatecounter = 0
while True:
for c in self.commands:
self.ser.write(c)
print c
for line in self.ser:
if not line.isspace():
print line
if line.lstrip().startswith("no"):
self.ser.flushInput()
break
if not (line.isspace() or line.lstrip().startswith('#')):
# print line
self.inputdata = [float(val) for val in line.split()]
if(len(self.inputdata) == self.datalength):
# print self.inputdata
for i in range(self.datalength):
self.data[i].append(self.inputdata[i])
plotbox_instance.update(self)
if self.updatecounter == 5:
plotbox_instance.redraw()
self.updatecounter = 0
else:
self.updatecounter +=1
for i in self.data:
i.pop(0)
i.pop(0)
plotbox_instance.update(self)
plotbox_instance.redraw()
break
self.ser.close()
class chronoamp(Experiment):
def __init__(self, adc_buffer, adc_rate, adc_pga, gain, potential, time):
self.init(adc_buffer, adc_rate, adc_pga, gain)
self.datatype = "linearData"
self.xlabel = "Time (s)"
self.ylabel = "Current (ADC Index)"
self.data = [[],[]]
self.datalength = 2
self.xmin = 0
self.xmax = 0
for i in time:
self.xmax += int(i)
self.commands += "R"
self.commands[2] += str(len(potential))
self.commands[2] += " "
for i in potential:
self.commands[2] += str(int(i*(65536./3000)+32768))
self.commands[2] += " "
for i in time:
self.commands[2] += str(i)
self.commands[2] += " "
#def chronoamp(adc_buffer, adc_rate, adc_pga, gain, potential, time):
# s = "A "
# s += (adc_buffer)
# s += " "
# s += (adc_rate)
# s += " "
# s += (adc_pga)
# s += " G "
# s += (gain)
# s += " R "
# s += str(len(potential))
# s += " "
# for i in potential:
# s += str(i)
# s += " "
# for i in time:
# s += str (i)
# s += " "
# print s
def lsv_exp(adc_buffer, adc_rate, adc_pga, gain, start, stop, slope):
s = "A "
......
......@@ -20,6 +20,7 @@ import interface.swv as swv
import interface.acv as acv
import interface.pd as pd
import dstat_comm as comm
from serial import SerialException
import mpltest
......@@ -38,16 +39,6 @@ class InputError(Error):
self.expr = expr
self.msg = msg
class testData:
def __init__(self):
self.x = [1,2,3,4,5]
self.y = [1,2,3,4,5]
class testLabels:
def __init__(self):
self.x = "Potential (DAC)"
self.y = "Current (ADC)"
class main:
def __init__(self):
......@@ -68,14 +59,9 @@ class main:
self.acv = acv.acv()
self.pd = pd.pd()
self.data = testData()
self.labels = testLabels()
self.error_context_id = self.statusbar.get_context_id("error")
self.plotbox = mpltest.plotbox(self.data)
self.plotbox.changetype(self.labels)
self.plotbox = mpltest.plotbox()
self.plotwindow = self.builder.get_object('plotbox')
self.plotbox.vbox.reparent(self.plotwindow)
......@@ -197,15 +183,27 @@ class main:
adc_rate = self.srate_model.get_value(self.adc_pot.srate_combobox.get_active_iter(), 2) #third column
adc_pga = self.pga_model.get_value(self.adc_pot.pga_combobox.get_active_iter(), 2)
gain = self.gain_model.get_value(self.adc_pot.gain_combobox.get_active_iter(), 2)
try:
potential = [int(r[0]) for r in self.chronoamp.model]
time = [int(r[1]) for r in self.chronoamp.model]
if not potential:
raise InputError(potential,"Step table is empty")
self.current_exp = comm.chronoamp(adc_buffer, adc_rate, adc_pga, gain, potential, time)
self.current_exp.run(self.serial_liststore.get_value(self.serial_combobox.get_active_iter(), 0), self.plotbox)
except ValueError:
self.statusbar.push(self.error_context_id, "Experiment parameters must be integers.")
except InputError as e:
self.statusbar.push(self.error_context_id, e.msg)
except SerialException:
self.statusbar.push(self.error_context_id, "Could not establish serial connection.")
comm.chronoamp(adc_buffer, adc_rate, adc_pga, gain, potential, time)
elif selection == 1: #LSV
......
......@@ -8,19 +8,16 @@ from matplotlib.figure import Figure
from matplotlib import pyplot as plt
from numpy import arange, sin, pi
# uncomment to select /GTK/GTKAgg/GTKCairo
#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
#from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
from matplotlib.backends.backend_gtkcairo import NavigationToolbar2Cairo as NavigationToolbar
class plotbox:
def __init__(self, xyData):
def __init__(self):
self.figure = Figure()
self.figure.subplots_adjust(left=0.07, bottom=0.07, right=0.96, top=0.96)
self.axe1 = self.figure.add_subplot(111)
self.line1, = self.axe1.plot(xyData.x, xyData.y)
self.line1, = self.axe1.plot([0,1], [0,1])
self.canvas = FigureCanvas(self.figure)
self.win = gtk.Window()
......@@ -30,16 +27,20 @@ class plotbox:
self.toolbar = NavigationToolbar(self.canvas, self.win)
self.vbox.pack_start(self.toolbar, False, False)
def update(self, xyData):
self.axe1.set_ydata(xyData.y)
self.axe1.set_xdata(xyData.x)
self.axe1.relim()
ax.autoscale_view()
self.figure.canvas.draw()
def update(self, Experiment):
self.line1.set_ydata(Experiment.data[1])
self.line1.set_xdata(Experiment.data[0])
# self.figure.canvas.draw()
def changetype(self, labels):
self.axe1.set_xlabel(labels.x)
self.axe1.set_ylabel(labels.y)
def changetype(self, Experiment):
self.axe1.set_xlabel(Experiment.xlabel)
self.axe1.set_ylabel(Experiment.ylabel)
self.axe1.set_xlim(Experiment.xmin, Experiment.xmax)
self.figure.canvas.draw()
def redraw(self):
self.axe1.relim()
self.axe1.autoscale_view(False, False, True)
self.figure.canvas.draw()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment