Skip to content

Commit c163897

Browse files
authored
Merge pull request #124 from fietser28/master
Additional check in CapReform script
2 parents 291a949 + b9c10db commit c163897

File tree

1 file changed

+54
-46
lines changed

1 file changed

+54
-46
lines changed

scripts/CapReform/CapReform.py

+54-46
Original file line numberDiff line numberDiff line change
@@ -182,57 +182,65 @@ def show_main_dialog():
182182

183183
# Start of main (loop) script
184184
#############################
185-
# Save state
186-
scpi("*SAV 10")
187-
scpi("MEM:STATE:FREEZE ON")
188-
189-
# From now on we always restore the state in case of an error.
190-
try:
191-
# Digital output for timing/jitter measurements
192-
scpi('SYSTEM:DIGITAL:PIN4:FUNCTION DOUTPUT')
193-
scpi('SYST:DIGITAL:PIN4:POLARITY POS')
194-
scpi('SYST:DIG:OUTP:DATA 4,0')
185+
def main():
186+
# Save state
187+
scpi("*SAV 10")
188+
scpi("MEM:STATE:FREEZE ON")
189+
190+
# From now on we always restore the state in case of an error.
191+
try:
192+
# Script requires firmware > 1.6, check for it.
193+
firmwareversion = scpi("SYSTem:CPU:FIRMware?")
194+
if float(firmwareversion) < 1.6:
195+
scpi('DISP:ERR "Script requires firmware >= 1.6"')
196+
return
195197

196-
# TODO: check & setup stuff
197-
# set maximum values, check channel/module types/configure serial if possible....
198-
ch1Model = scpi("SYSTem:CHANnel:MODel? ch1")
199-
ch2Model = scpi("SYSTem:CHANnel:MODel? ch2")
200-
if ch1Model.startswith("DCP405") and ch2Model.startswith("DCP405"):
201-
scpi("INST:COUP:TRAC SER")
202-
else:
203-
scpi("INST:COUP:TRAC NONE")
198+
# Digital output for timing/jitter measurements
199+
scpi('SYSTEM:DIGITAL:PIN4:FUNCTION DOUTPUT')
200+
scpi('SYST:DIGITAL:PIN4:POLARITY POS')
201+
scpi('SYST:DIG:OUTP:DATA 4,0')
204202

205-
scpi("INST ch1")
206-
module_max_volt = float(scpi("VOLT? MAX"))
207-
scpi("OUTP 0")
208-
show_main_dialog()
209-
210-
while True:
211-
action = scpi("DISP:DIALOG:ACTION?")
212-
if action == "input_cap_max_volt":
213-
input_cap_max_volt()
214-
elif action == "input_charge_current":
215-
input_charge_current()
216-
elif action == "input_reform_time":
217-
input_reform_time()
218-
elif action == "input_reform_time":
219-
input_reform_time()
220-
elif action == "view_dlog":
221-
scpi("DISP:WINDOW:DLOG \"/Recordings/ReformCap.dlog\"")
222-
elif action == "start_reform":
223-
discharge_cap()
224-
scpi('DISP:DIALog:DATA "run_state", INT, 1')
225-
scpi('DISP:DIALog:DATA "data_viewable", INT, 1')
226-
start_reform()
227-
scpi("DISP:DIAL:DATA \"reform_progress\", INT, 0")
228-
scpi('DISP:DIALog:DATA "run_state", INT, 0')
229-
elif action == "close_script" or action == 0:
230-
break
231-
finally:
232-
close_script()
203+
if scpi("SYSTem:CHANnel:COUNt?") >= 2:
204+
ch1Model = scpi("SYSTem:CHANnel:MODel? ch1")
205+
ch2Model = scpi("SYSTem:CHANnel:MODel? ch2")
206+
if ch1Model.startswith("DCP405") and ch2Model.startswith("DCP405"):
207+
scpi("INST:COUP:TRAC SER")
208+
else:
209+
scpi("INST:COUP:TRAC NONE")
210+
else:
211+
scpi("INST:COUP:TRAC NONE")
212+
213+
scpi("INST ch1")
214+
module_max_volt = float(scpi("VOLT? MAX"))
215+
scpi("OUTP 0")
216+
show_main_dialog()
233217

218+
while True:
219+
action = scpi("DISP:DIALOG:ACTION?")
220+
if action == "input_cap_max_volt":
221+
input_cap_max_volt()
222+
elif action == "input_charge_current":
223+
input_charge_current()
224+
elif action == "input_reform_time":
225+
input_reform_time()
226+
elif action == "input_reform_time":
227+
input_reform_time()
228+
elif action == "view_dlog":
229+
scpi("DISP:WINDOW:DLOG \"/Recordings/ReformCap.dlog\"")
230+
elif action == "start_reform":
231+
discharge_cap()
232+
scpi('DISP:DIALog:DATA "run_state", INT, 1')
233+
scpi('DISP:DIALog:DATA "data_viewable", INT, 1')
234+
start_reform()
235+
scpi("DISP:DIAL:DATA \"reform_progress\", INT, 0")
236+
scpi('DISP:DIALog:DATA "run_state", INT, 0')
237+
elif action == "close_script" or action == 0:
238+
break
239+
finally:
240+
close_script()
234241

235242

243+
main()
236244

237245

238246

0 commit comments

Comments
 (0)