1
0
Fork 0

add communication log

This commit is contained in:
Peter McGoron 2021-05-27 22:42:48 -04:00
parent 57c0b7fdd8
commit 0a49a3fd2e
2 changed files with 389 additions and 334 deletions

View File

@ -23,14 +23,25 @@ class SerComm:
def error_popup(self, x):
error_popup(self.getobj("win"), x)
def append(self, s):
o = self.getobj("debug_buf")
o.insert_markup(o.get_end_iter(), s, -1)
self.getobj("debug_win").scroll_to_mark(
o.get_insert(), 0.1, False, 0, 1)
def get_or_to(self):
s = self.ser.read_until().decode()
if not s:
raise Exception(f"DAC timeout: '{s}'")
s = s.rstrip("\r\n")
self.getobj("dac_resp").set_text(s)
self.append(f'{s}\n')
return s
def send(self, s):
b = bytes(s, "UTF-8")
self.ser.write(b + b"\r")
self.append(f'<span color="blue">{s}</span>\n')
def make_dac_conn(self, f):
for x in CHANGE_BUTTONS:
self.getobj(x).set_sensitive(False)
@ -51,8 +62,10 @@ class SerComm:
if s == None:
self.getobj("dac_idn").set_label("(disconnected)")
self.append('<span color="red">Disconnecting</span>\n')
return None
self.append(f'<span color="red">Connecting to "{s}"</span>\n')
self.ser.port = s
self.ser.open()
@ -66,7 +79,7 @@ class SerComm:
raise Exception(f"Unknown message from DAC: '{s}'")
self.getobj(f"Ch{int(loc.group(0)) + 1}").set_label('<span color="red">ERR</span>')
self.ser.write(b"*IDN?\r\n")
self.send("*IDN?")
self.getobj("dac_idn").set_label(self.get_or_to())
def on_connect(self, _):
@ -79,7 +92,7 @@ class SerComm:
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"))
self.send(f"SET,{ch},{vol}")
s = self.get_or_to()
if not s.startswith("DAC"):

704
gui.glade
View File

@ -2,6 +2,10 @@
<!-- Generated with glade 3.38.1 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkTextBuffer" id="debug_buf">
<property name="text" translatable="yes">
</property>
</object>
<object class="GtkWindow" id="win">
<property name="can-focus">False</property>
<child>
@ -127,94 +131,15 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">32</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Set channel</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="SET_ch">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item id="1" translatable="yes">1</item>
<item id="2" translatable="yes">2</item>
<item id="3" translatable="yes">3</item>
<item id="4" translatable="yes">4</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">to voltage</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="SET_v">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="SET_do">
<property name="label" translatable="yes">Execute</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<property name="hexpand">True</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="orientation">vertical</property>
<property name="spacing">32</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -224,16 +149,16 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Ramp channel</property>
<property name="label" translatable="yes">Set channel</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="RAMP_ch1">
<object class="GtkComboBoxText" id="SET_ch">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
@ -247,33 +172,14 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">and</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="RAMP_ch2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active-id">default</property>
<items>
<item id="1" translatable="yes">1</item>
<item id="2" translatable="yes">2</item>
<item id="3" translatable="yes">3</item>
<item id="4" translatable="yes">4</item>
<item id="none" translatable="yes">N/A</item>
</items>
<property name="label" translatable="yes">to voltage</property>
</object>
<packing>
<property name="expand">False</property>
@ -281,32 +187,8 @@
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">from</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_st">
<object class="GtkEntry" id="SET_v">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
@ -316,142 +198,278 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">to</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_ed">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">in a total of</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_step">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">9</property>
<property name="placeholder-text" translatable="yes">steps</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">steps</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">with</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_t">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">4</property>
<property name="placeholder-text" translatable="yes">time</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">milliseconds between each</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="RAMP_do">
<object class="GtkButton" id="SET_do">
<property name="label" translatable="yes">Execute</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Ramp channel</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="RAMP_ch1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item id="1" translatable="yes">1</item>
<item id="2" translatable="yes">2</item>
<item id="3" translatable="yes">3</item>
<item id="4" translatable="yes">4</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">and</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="RAMP_ch2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active-id">default</property>
<items>
<item id="1" translatable="yes">1</item>
<item id="2" translatable="yes">2</item>
<item id="3" translatable="yes">3</item>
<item id="4" translatable="yes">4</item>
<item id="none" translatable="yes">N/A</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">from</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_st">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">to</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_ed">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">6</property>
<property name="placeholder-text" translatable="yes">±10</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">in a total of</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_step">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">9</property>
<property name="placeholder-text" translatable="yes">steps</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">steps</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">with</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="RAMP_t">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">4</property>
<property name="placeholder-text" translatable="yes">time</property>
<property name="input-purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">milliseconds between each</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="RAMP_do">
<property name="label" translatable="yes">Execute</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
@ -462,10 +480,95 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Communication Log</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="width-request">206</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTextView" id="debug_win">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="buffer">debug_buf</property>
<property name="accepts-tab">False</property>
<property name="input-purpose">terminal</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel" id="dac_idn">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">(disconnected)</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="sel_ref">
<property name="label" translatable="yes">Refresh</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
@ -473,84 +576,23 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkComboBoxText" id="sel_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkButton" id="sel_ref">
<property name="label" translatable="yes">Refresh</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="sel_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="sel_do">
<property name="label" translatable="yes">Connect</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<property name="active">0</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkButton" id="sel_do">
<property name="label" translatable="yes">Connect</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="dac_idn">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">(disconnected)</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="dac_resp">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">(previous response)</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
@ -561,8 +603,8 @@
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>