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

Implemented version checking and setting of correct gain options in UI (still...

Implemented version checking and setting of correct gain options in UI (still need to change in experiment to get correct plots)
parent d99a9834
Branches
Tags
No related merge requests found
...@@ -36,6 +36,40 @@ def call_it(instance, name, args=(), kwargs=None): ...@@ -36,6 +36,40 @@ def call_it(instance, name, args=(), kwargs=None):
kwargs = {} kwargs = {}
return getattr(instance, name)(*args, **kwargs) return getattr(instance, name)(*args, **kwargs)
def version_check(ser_port):
"""Tries to contact DStat and get version. Returns a tuple of
(major, minor). If no response, returns empty tuple.
Arguments:
ser_port -- address of serial port to use
"""
ser = delayedSerial(ser_port, 1024000, timeout=1)
ser.write("ck")
ser.flushInput()
ser.write('!')
while not ser.read().startswith("C"):
pass
ser.write('V')
for line in ser:
if line.startswith('V'):
input = line.lstrip('V')
elif line.startswith("#"):
print line
elif line.lstrip().startswith("no"):
print line
ser.flushInput()
break
parted = input.rstrip().split('.')
print parted
ser.close()
return (int(parted[0]), int(parted[1]))
class delayedSerial(serial.Serial): class delayedSerial(serial.Serial):
"""Extends Serial.write so that characters are output individually """Extends Serial.write so that characters are output individually
...@@ -77,7 +111,7 @@ class Experiment(object): ...@@ -77,7 +111,7 @@ class Experiment(object):
self.databytes = 8 self.databytes = 8
self.data_extra = [] # must be defined even when not needed self.data_extra = [] # must be defined even when not needed
self.__gaintable = [1e2, 3e2, 3e3, 3e4, 3e5, 3e6, 3e7, 5e8] self.__gaintable = [1e2, 3e2, 3e3, 3e4, 3e5, 3e6, 3e7, 5e8] #todo version settings
self.gain = self.__gaintable[int(self.parameters['gain'])] self.gain = self.__gaintable[int(self.parameters['gain'])]
self.commands = ["A", "G"] self.commands = ["A", "G"]
......
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
# DStat Interface - An interface for the open hardware DStat potentiostat # DStat Interface - An interface for the open hardware DStat potentiostat
# Copyright (C) 2014 Michael D. M. Dryden - # Copyright (C) 2014 Michael D. M. Dryden -
# Wheeler Microfluidics Laboratory <http://microfluidics.utoronto.ca> # Wheeler Microfluidics Laboratory <http://microfluidics.utoronto.ca>
...@@ -19,6 +20,24 @@ ...@@ -19,6 +20,24 @@
import gtk import gtk
v1_1_gain = [(0, "100 Ω (15 mA FS)", 0),
(1, "300 Ω (5 mA FS)", 1),
(2, "3 kΩ (500 µA FS)", 2),
(3, "30 kΩ (50 µA FS)", 3),
(4, "300 kΩ (5 µA FS)", 4),
(5, "3 MΩ (500 nA FS)", 5),
(6, "30 MΩ (50 nA FS)", 6),
(7, "500 MΩ (3 nA FS)", 7)]
v1_2_gain = [(0, "Bypass", 0),
(1, "100 Ω (15 mA FS)", 1),
(2, "3 kΩ (500 µA FS)", 2),
(3, "30 kΩ (50 µA FS)", 3),
(4, "300 kΩ (5 µA FS)", 4),
(5, "3 MΩ (500 nA FS)", 5),
(6, "30 MΩ (50 nA FS)", 6),
(7, "100 MΩ (15 nA FS)", 7)]
class adc_pot: class adc_pot:
def __init__(self): def __init__(self):
self.builder = gtk.Builder() self.builder = gtk.Builder()
...@@ -40,6 +59,19 @@ class adc_pot: ...@@ -40,6 +59,19 @@ class adc_pot:
self.srate_combobox.set_active(7) self.srate_combobox.set_active(7)
self.gain_combobox = self.builder.get_object('gain_combobox') self.gain_combobox = self.builder.get_object('gain_combobox')
self.gain_liststore = self.builder.get_object('gain_liststore')
self.gain_combobox.pack_start(self.cell, True) self.gain_combobox.pack_start(self.cell, True)
self.gain_combobox.add_attribute(self.cell, 'text', 1) self.gain_combobox.add_attribute(self.cell, 'text', 1)
self.gain_combobox.set_active(2) self.gain_combobox.set_active(2)
\ No newline at end of file
def set_version(self, version):
""" Sets menus for DStat version. """
self.gain_liststore.clear()
if version[0] == 1:
if version[1] == 1:
for i in v1_1_gain:
self.gain_liststore.append(i)
elif version[1] >= 2:
for i in v1_2_gain:
self.gain_liststore.append(i)
\ No newline at end of file
...@@ -1210,6 +1210,21 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property> ...@@ -1210,6 +1210,21 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkButton" id="serial_version">
<property name="label">gtk-connect</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_serial_version_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<object class="GtkStatusbar" id="statusbar"> <object class="GtkStatusbar" id="statusbar">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -1219,7 +1234,7 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property> ...@@ -1219,7 +1234,7 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">3</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
</object> </object>
......
...@@ -167,6 +167,26 @@ class Main(object): ...@@ -167,6 +167,26 @@ class Main(object):
for i in self.serial_devices.ports: for i in self.serial_devices.ports:
self.serial_liststore.append([i]) self.serial_liststore.append([i])
def on_serial_version_clicked(self, data=None):
"""Retrieve DStat version."""
self.version = comm.version_check(self.serial_liststore.get_value(
self.serial_combobox.get_active_iter(), 0))
print self.version
self.statusbar.remove_all(self.error_context_id)
if not len(self.version) == 2:
self.statusbar.push(self.error_context_id, "Communication Error")
return
else:
self.adc_pot.set_version(self.version)
self.statusbar.push(self.error_context_id,
"".join(["DStat version: ", str(self.version[0]), ".",
str(self.version[1])])
)
def on_pot_start_clicked(self, data=None): def on_pot_start_clicked(self, data=None):
"""Run currently visible experiment.""" """Run currently visible experiment."""
......
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