1
0
Fork 0
This commit is contained in:
Peter McGoron 2021-05-27 22:02:05 -04:00
parent 1a2a5d8483
commit 57c0b7fdd8
2 changed files with 33 additions and 12 deletions

View File

@ -31,6 +31,19 @@ class SerComm:
self.getobj("dac_resp").set_text(s)
return s
def make_dac_conn(self, f):
for x in CHANGE_BUTTONS:
self.getobj(x).set_sensitive(False)
try:
f()
except Exception as e:
self.error_popup(str(e))
for x in CHANGE_BUTTONS:
self.getobj(x).set_sensitive(True)
""" make connection (*IDN?) """
def connect(self):
s = self.sel_box.get_active_id()
if self.ser.is_open:
@ -57,16 +70,23 @@ class SerComm:
self.getobj("dac_idn").set_label(self.get_or_to())
def on_connect(self, _):
for x in CHANGE_BUTTONS:
self.getobj(x).set_sensitive(False)
self.make_dac_conn(self.connect)
try:
self.connect()
except Exception as e:
self.error_popup(str(e))
for x in CHANGE_BUTTONS:
self.getobj(x).set_sensitive(True)
""" SET """
def do_SET(self):
if not self.ser.is_open:
return None
ch = int(self.getobj("SET_ch").get_active_id()) - 1
vol = float(self.getobj("SET_v").get_text())
self.ser.write(bytes(f"SET,{ch},{vol}\r", "UTF-8"))
s = self.get_or_to()
if not s.startswith("DAC"):
raise Exception(f"DAC reported an error: {s}")
def on_SET(self, _):
self.make_dac_conn(self.do_SET)
def refresh(self, _):
# Does this cause a memory error? This is a GTK interned string
@ -96,6 +116,7 @@ class SerComm:
getobj("sel_ref").connect("clicked", self.refresh)
self.refresh(None)
getobj("sel_do").connect("clicked", self.on_connect)
getobj("SET_do").connect("clicked", self.on_SET)
if __name__ == "__main__":
builder = Gtk.Builder()

View File

@ -181,7 +181,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">10.000</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
@ -310,7 +310,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">start</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
@ -336,7 +336,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">end</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>