diff --git a/GreenMonster.py b/GreenMonster.py index 4029995..3409070 100644 --- a/GreenMonster.py +++ b/GreenMonster.py @@ -6,6 +6,7 @@ import tkinter as tk from tkinter import ttk +import distutils.util import os import webbrowser @@ -13,8 +14,10 @@ import tabs.gm_scan as scan_util import tabs.gm_timeboard as tmbd import tabs.gm_vqwk as vqwk -import tabs.gm_adc18 as adc18s -import tabs.gm_vxworks as vxworks +#import tabs.gm_adc18 as adc18s +import tabs.gm_adc18_rtspec as adc18s_rtspec +import tabs.gm_adc18_lftspec as adc18s_lftspec +#import tabs.gm_vxworks as vxworks import utils as u class GreenMonster: @@ -45,12 +48,34 @@ def quit(self): def educate_yourself(self, event): webbrowser.open_new(r"https://en.wikipedia.org/wiki/Green_Monster") + def checkHRSflag(self): + hrsinfile = open("/adaqfs/home/apar/devices/PyGreenMonster/includeHRS.flags",'r') + tmp="False" + for line in hrsinfile: + print("Include HRSs = " + line) + tmp=bool(distutils.util.strtobool(line.strip('\n'))) + print("Include HRSs = " + str(tmp)) + return tmp + def expert_tab(self, expt_tab): tab_control = ttk.Notebook(expt_tab) - tab_titles = [('TimeBoard', tmbd.Timeboard), - ('VQWK ADCs', vqwk.VQWK), - ('ADC18s, CH', adc18s.ADC18), - ('VXWorks Server', vxworks.VXWorks)] + tab_titles = [] + if self.checkHRSflag(): + tab_titles = [('TimeBoard', tmbd.Timeboard), + ('VQWK ADCs', vqwk.VQWK), + #('ADC18s, CH', adc18s.ADC18), + # FIXME No HRSs + ('ADC18s, RtSpec', adc18s_rtspec.ADC18), + ('ADC18s, LftSpec',adc18s_lftspec.ADC18), + #('VXWorks Server', vxworks.VXWorks) + ] + else: + tab_titles = [('TimeBoard', tmbd.Timeboard), + ('VQWK ADCs', vqwk.VQWK), + #('ADC18s, CH', adc18s.ADC18), + # FIXME No HRSs + #('VXWorks Server', vxworks.VXWorks) + ] for title, fn in tab_titles: sub_tab = ttk.Frame(tab_control, width=800, height=600, style="My.TFrame") tab_control.add(sub_tab, text=title) @@ -69,7 +94,10 @@ def create_widgets(self): for title, fn in tab_titles: tab = ttk.Frame(tab_control, width=800, height=600, style="My.TFrame") tab_control.add(tab, text=title) - fn(tab) + if "ScanUtil" in title: + fn(tab,self) + else: + fn(tab) tab_control.grid(row=0, column=0, columnspan=2) fenway = tk.PhotoImage(file='gm.ppm') fenway_pahk = tk.Label(self.win, image=fenway, cursor="hand2", bg=u.green_color) diff --git a/includeHRS.flags b/includeHRS.flags new file mode 100644 index 0000000..bc59c12 --- /dev/null +++ b/includeHRS.flags @@ -0,0 +1 @@ +False diff --git a/tabs/gm_adc16.py b/tabs/gm_adc16.py new file mode 100644 index 0000000..f5cf617 --- /dev/null +++ b/tabs/gm_adc16.py @@ -0,0 +1,224 @@ +''' +Green Monster GUI Revamp +Containing ADC18s Tab +Code Commissioned 2019-01-16 +Code by A.J. Zec +''' + +import tkinter as tk +from tkinter import ttk +import utils as u + +GA_MAXADC =20 +GAINRADIO =100 +DACRADIO =200 +GM_ADC_GET =101 +GM_ADC_SET =201 +DACON =1 +DACOFF =2 +GAINLO =1 +GAINHI =2 +HAPADC_GET_NUMADC =1001 +HAPADC_GET_CSR =1002 +HAPADC_SET_CSR =1003 +HAPADC_GET_LABEL =1004 + +class ADC16(tk.Frame): + def __init__(self, tab): + global numADC + numADC = self.get_num_adc() + ADClabels = [] + + i = 0 + while i < numADC: + ADClabels.append(self.get_label_adc(i)) + i += 1 + + #numADC += 1 + #ADClabels.append(5) + + self.rt_spec_frame = tk.LabelFrame(tab, text='RtSpec', background=u.green_color) + self.adc_ls = [] + self.int_es = [] + self.conv_es = [] + self.dac_settings = [] + self.sample_settings = [] + + i = 0 + while i < numADC: + self.adc_ls.append(tk.Label(self.rt_spec_frame, text='ADC '+str(ADClabels[i]), background=u.green_color)) + self.int_es.append(tk.Entry(self.rt_spec_frame, width=3)) + self.conv_es.append(tk.Entry(self.rt_spec_frame, width=3)) + self.dac_settings.append(tk.StringVar()) + self.sample_settings.append(tk.IntVar()) + i += 1 + + labels = ['Label', 'Int', 'Conv', '-----', 'DAC', 'Settings', '-----', 'Sample by:'] + for i, label in enumerate(labels): + tk.Label(self.rt_spec_frame, text=label, background=u.green_color).grid( + row=0, column=i, padx=8, pady=10, sticky='W') + + self.create_table(numADC) + self.check_values() + + def get_num_adc(self): + packet = [u.COMMAND_HAPADC, HAPADC_GET_NUMADC, 0, 0, 0, "ADC Get Number", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + def get_label_adc(self, index): + packet = [u.COMMAND_HAPADC, HAPADC_GET_LABEL, index, 0, 0, "ADC Get Label", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + + def create_table(self, value): + for i in range(1, value+1): + self.adc_ls[i-1].grid(row=i, column=0, padx=10, pady=10, sticky='W') + u.set_text(self.int_es[i-1], '3').grid(row=i, column=1, padx=10, pady=10) + u.set_text(self.conv_es[i-1], '0').grid(row=i, column=2, padx=10, pady=10) + setting = self.dac_settings[i-1] + settings = ['Tri', 'Saw', 'Const', 'Off'] + setting.set('Tri') + for j,s in enumerate(settings): + tk.Radiobutton(self.rt_spec_frame, text=s, variable=setting, value=s, background=u.green_color).grid( + row=i, column=j+3, padx=5, pady=10, sticky='W') + sample_by = self.sample_settings[i-1] + sample_by.set(1) + tk.OptionMenu(self.rt_spec_frame, sample_by, 1, 2, 4, 8).grid(row=i, column=7) + tk.Button(self.rt_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values).grid( + row=6, column=1, columnspan=2, pady=50, sticky='S') + tk.Button(self.rt_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values).grid( + row=6, column=3, columnspan=2, pady=50, sticky='S') + tk.Button(self.rt_spec_frame, text='Cancel', background=u.green_color, command=self.check_values).grid( + row=6, column=5, pady=50, sticky='S') + self.rt_spec_frame.pack(padx=20, pady=20) + + def check_values(self): + fSample = [] + fGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + packet = [u.COMMAND_HAPADC, HAPADC_GET_CSR, i, 0, 0, "ADC18 Get Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + if reply[3] == -1: + fGain.append(-1) + fDAC.append(-1) + if ((reply[3] & 0x10)==16): + fGain.append(GAINHI) + else: + fGain.apemd(GAINLO) + if ((reply[3] & 0x8)==8): + fDAC.append(DACON) + else: + fDAC.append(DACOFF) + + fSample.append(reply[3]) + self.sample_settings[i].set(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_HAPADC, ADC18_GET_INT, i, 0, 0, "ADC18 Get Int", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + fIntGain.append(reply[3]) + self.int_es[i].delete(0, tk.END) + self.int_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + i += 1 + + def set_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + fIntGain.append(int(self.int_es[i].get())) + + if fIntGain[i] < 0 or fIntGain[i] > 3: + print("ERROR: Int Value is out of range! Try (0-3)...") + else: + packet = [u.COMMAND_HAPADC, ADC18_SET_INT, i, fIntGain[i], 0, "ADC18 Set Int", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fConvGain.append(int(self.conv_es[i].get())) + + if fConvGain[i] < 0 or fConvGain[i] > 15: + print("ERROR: Conv Value is out of range! Try (0-15)...") + else: + packet = [u.COMMAND_HAPADC, ADC18_SET_CONV, i, fConvGain[i], 0, "ADC18 Set Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fDAC.append(self.dac_settings[i].get()) + + if fDAC[i]=='Tri': + dacflag = DACTRI + elif fDAC[i]=='Saw': + dacflag = DACSAW + elif fDAC[i] == 'Const': + dacflag = DACCONST + else: + dacflag = DACOFF18 + + packet = [u.COMMAND_HAPADC, ADC18_SET_DAC, i, dacflag, 0, "ADC18 Set DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fSample.append(int(self.sample_settings[i].get())) + + packet = [u.COMMAND_HAPADC, ADC18_SET_SAMP, i, fSample[i], 0, "ADC18 Set Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + #self.check_values() diff --git a/tabs/gm_adc18.py b/tabs/gm_adc18.py index b2f42fa..65fdf31 100644 --- a/tabs/gm_adc18.py +++ b/tabs/gm_adc18.py @@ -9,31 +9,88 @@ from tkinter import ttk import utils as u +ADC18_GET_NUMADC =1001 +ADC18_GET_LABEL =1002 +ADC18_GET_CSR =1003 +ADC18_SET_CONV =1004 +ADC18_SET_INT =1005 +ADC18_SET_PED =1006 +ADC18_GET_CONV =1007 +ADC18_GET_INT =1008 +ADC18_GET_PED =1009 +ADC18_SET_DAC =1010 +ADC18_GET_DAC =1011 +ADC18_SET_SAMP =1012 +ADC18_GET_SAMP =1013 +GA_MAXADC =20 +DACRADIO18 =100 +GM_ADC_GET =101 +GM_ADC_SET =201 +DACTRI =0 +DACSAW =1 +DACCONST =2 +DACOFF18 =3 + class ADC18(tk.Frame): def __init__(self, tab): + global numADC + numADC = self.get_num_adc() + ADClabels = [] + + i = 0 + while i < numADC: + ADClabels.append(self.get_label_adc(i)) + i += 1 + self.ch_frame = tk.LabelFrame(tab, text='CH', background=u.green_color) - self.adc_ls = [tk.Label(self.ch_frame, text='ADC 8', background=u.green_color), - tk.Label(self.ch_frame, text='ADC 10', background=u.green_color), - tk.Label(self.ch_frame, text='ADC 10', background=u.green_color), - tk.Label(self.ch_frame, text='ADC 11', background=u.green_color)] - self.int_es = [tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3)] - self.conv_es = [tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3), - tk.Entry(self.ch_frame, width=3)] - self.dac_settings = [tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar()] - self.sample_settings = [tk.IntVar(), tk.IntVar(), tk.IntVar(), tk.IntVar()] + self.adc_ls = [] + self.int_es = [] + self.conv_es = [] + self.dac_settings = [] + self.sample_settings = [] + + i = 0 + while i < numADC: + self.adc_ls.append(tk.Label(self.ch_frame, text='ADC '+str(ADClabels[i]), background=u.green_color)) + self.int_es.append(tk.Entry(self.ch_frame, width=3)) + self.conv_es.append(tk.Entry(self.ch_frame, width=3)) + self.dac_settings.append(tk.StringVar()) + self.sample_settings.append(tk.IntVar()) + i += 1 + labels = ['Label', 'Int', 'Conv', '-----', 'DAC', 'Settings', '-----', 'Sample by:'] for i, label in enumerate(labels): tk.Label(self.ch_frame, text=label, background=u.green_color).grid( row=0, column=i, padx=8, pady=10, sticky='W') - self.create_table() - def create_table(self): - for i in range(1, 5): + self.create_table(numADC) + self.check_values() + + def get_num_adc(self): + packet = [u.COMMAND_ADC18, ADC18_GET_NUMADC, 0, 0, 0, "ADC Get Number", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + def get_label_adc(self, index): + packet = [u.COMMAND_ADC18, ADC18_GET_LABEL, index, 0, 0, "ADC Get Label", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + + def create_table(self, value): + for i in range(1, value+1): self.adc_ls[i-1].grid(row=i, column=0, padx=10, pady=10, sticky='W') u.set_text(self.int_es[i-1], '3').grid(row=i, column=1, padx=10, pady=10) u.set_text(self.conv_es[i-1], '0').grid(row=i, column=2, padx=10, pady=10) @@ -46,10 +103,144 @@ def create_table(self): sample_by = self.sample_settings[i-1] sample_by.set(1) tk.OptionMenu(self.ch_frame, sample_by, 1, 2, 4, 8).grid(row=i, column=7) - tk.Button(self.ch_frame, text='Get Settings', background=u.green_color).grid( + tk.Button(self.ch_frame, text='Get Settings', background=u.green_color, command=self.check_values).grid( row=6, column=1, columnspan=2, pady=50, sticky='S') - tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color).grid( + tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color, command=self.set_values).grid( row=6, column=3, columnspan=2, pady=50, sticky='S') - tk.Button(self.ch_frame, text='Cancel', background=u.green_color).grid( + tk.Button(self.ch_frame, text='Cancel', background=u.green_color, command=self.check_values).grid( row=6, column=5, pady=50, sticky='S') self.ch_frame.pack(padx=20, pady=20) + + def check_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + packet = [u.COMMAND_ADC18, ADC18_GET_SAMP, i, 0, 0, "ADC18 Get Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + fSample.append(reply[3]) + self.sample_settings[i].set(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_INT, i, 0, 0, "ADC18 Get Int", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + fIntGain.append(reply[3]) + self.int_es[i].delete(0, tk.END) + self.int_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_CONV, i, 0, 0, "ADC18 Get Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + fConvGain.append(reply[3]) + self.conv_es[i].delete(0, tk.END) + self.conv_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_DAC, i, 0, 0, "ADC18 Get DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + fDAC.append(reply[3]) + if reply[3] == DACSAW: + self.dac_settings[i].set('Saw') + elif reply[3] == DACCONST: + self.dac_settings[i].set('Const') + elif reply[3] == DACTRI: + self.dac_settings[i].set('Tri') + else: + self.dac_settings[i].set('Off') + + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + def set_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + fIntGain.append(int(self.int_es[i].get())) + + if fIntGain[i] < 0 or fIntGain[i] > 3: + print("ERROR: Int Value is out of range! Try (0-3)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_INT, i, fIntGain[i], 0, "ADC18 Set Int", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fConvGain.append(int(self.conv_es[i].get())) + + if fConvGain[i] < 0 or fConvGain[i] > 15: + print("ERROR: Conv Value is out of range! Try (0-15)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_CONV, i, fConvGain[i], 0, "ADC18 Set Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fDAC.append(self.dac_settings[i].get()) + + if fDAC[i]=='Tri': + dacflag = DACTRI + elif fDAC[i]=='Saw': + dacflag = DACSAW + elif fDAC[i] == 'Const': + dacflag = DACCONST + else: + dacflag = DACOFF18 + + packet = [u.COMMAND_ADC18, ADC18_SET_DAC, i, dacflag, 0, "ADC18 Set DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fSample.append(int(self.sample_settings[i].get())) + + packet = [u.COMMAND_ADC18, ADC18_SET_SAMP, i, fSample[i], 0, "ADC18 Set Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_CH, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + self.check_values() diff --git a/tabs/gm_adc18_lftspec.py b/tabs/gm_adc18_lftspec.py new file mode 100644 index 0000000..56d2dde --- /dev/null +++ b/tabs/gm_adc18_lftspec.py @@ -0,0 +1,246 @@ +''' +Green Monster GUI Revamp +Containing ADC18s Tab +Code Commissioned 2019-01-16 +Code by A.J. Zec +''' + +import tkinter as tk +from tkinter import ttk +import utils as u + +ADC18_GET_NUMADC =1001 +ADC18_GET_LABEL =1002 +ADC18_GET_CSR =1003 +ADC18_SET_CONV =1004 +ADC18_SET_INT =1005 +ADC18_SET_PED =1006 +ADC18_GET_CONV =1007 +ADC18_GET_INT =1008 +ADC18_GET_PED =1009 +ADC18_SET_DAC =1010 +ADC18_GET_DAC =1011 +ADC18_SET_SAMP =1012 +ADC18_GET_SAMP =1013 +GA_MAXADC =20 +DACRADIO18 =100 +GM_ADC_GET =101 +GM_ADC_SET =201 +DACTRI =0 +DACSAW =1 +DACCONST =2 +DACOFF18 =3 + +class ADC18(tk.Frame): + def __init__(self, tab): + global numADC + numADC = self.get_num_adc() + ADClabels = [] + + i = 0 + while i < numADC: + ADClabels.append(self.get_label_adc(i)) + i += 1 + + self.lft_spec_frame = tk.LabelFrame(tab, text='LHRS', background=u.green_color) + self.adc_ls = [] + self.int_es = [] + self.conv_es = [] + self.dac_settings = [] + self.sample_settings = [] + + i = 0 + while i < numADC: + self.adc_ls.append(tk.Label(self.lft_spec_frame, text='ADC '+str(ADClabels[i]), background=u.green_color)) + self.int_es.append(tk.Entry(self.lft_spec_frame, width=3)) + self.conv_es.append(tk.Entry(self.lft_spec_frame, width=3)) + self.dac_settings.append(tk.StringVar()) + self.sample_settings.append(tk.IntVar()) + i += 1 + + labels = ['Label', 'Int', 'Conv', '-----', 'DAC', 'Settings', '-----', 'Sample by:'] + for i, label in enumerate(labels): + tk.Label(self.lft_spec_frame, text=label, background=u.green_color).grid( + row=0, column=i, padx=8, pady=10, sticky='W') + + self.create_table(numADC) + self.check_values() + + def get_num_adc(self): + packet = [u.COMMAND_ADC18, ADC18_GET_NUMADC, 0, 0, 0, "ADC Get Number", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + def get_label_adc(self, index): + packet = [u.COMMAND_ADC18, ADC18_GET_LABEL, index, 0, 0, "ADC Get Label", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + + def create_table(self, value): + for i in range(1, value+1): + self.adc_ls[i-1].grid(row=i, column=0, padx=10, pady=10, sticky='W') + u.set_text(self.int_es[i-1], '3').grid(row=i, column=1, padx=10, pady=10) + u.set_text(self.conv_es[i-1], '0').grid(row=i, column=2, padx=10, pady=10) + setting = self.dac_settings[i-1] + settings = ['Tri', 'Saw', 'Const', 'Off'] + setting.set('Tri') + for j,s in enumerate(settings): + tk.Radiobutton(self.lft_spec_frame, text=s, variable=setting, value=s, background=u.green_color).grid( + row=i, column=j+3, padx=5, pady=10, sticky='W') + sample_by = self.sample_settings[i-1] + sample_by.set(1) + tk.OptionMenu(self.lft_spec_frame, sample_by, 1, 2, 4, 8).grid(row=i, column=7) + tk.Button(self.lft_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values).grid( + row=6, column=1, columnspan=2, pady=50, sticky='S') + tk.Button(self.lft_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values).grid( + row=6, column=3, columnspan=2, pady=50, sticky='S') + tk.Button(self.lft_spec_frame, text='Cancel', background=u.green_color, command=self.check_values).grid( + row=6, column=5, pady=50, sticky='S') + self.lft_spec_frame.pack(padx=20, pady=20) + + def check_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + packet = [u.COMMAND_ADC18, ADC18_GET_SAMP, i, 0, 0, "ADC18 Get Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + fSample.append(reply[3]) + self.sample_settings[i].set(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_INT, i, 0, 0, "ADC18 Get Int", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + fIntGain.append(reply[3]) + self.int_es[i].delete(0, tk.END) + self.int_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_CONV, i, 0, 0, "ADC18 Get Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + fConvGain.append(reply[3]) + self.conv_es[i].delete(0, tk.END) + self.conv_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_DAC, i, 0, 0, "ADC18 Get DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + fDAC.append(reply[3]) + if reply[3] == DACSAW: + self.dac_settings[i].set('Saw') + elif reply[3] == DACCONST: + self.dac_settings[i].set('Const') + elif reply[3] == DACTRI: + self.dac_settings[i].set('Tri') + else: + self.dac_settings[i].set('Off') + + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + def set_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + fIntGain.append(int(self.int_es[i].get())) + + if fIntGain[i] < 0 or fIntGain[i] > 3: + print("ERROR: Int Value is out of range! Try (0-3)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_INT, i, fIntGain[i], 0, "ADC18 Set Int", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fConvGain.append(int(self.conv_es[i].get())) + + if fConvGain[i] < 0 or fConvGain[i] > 15: + print("ERROR: Conv Value is out of range! Try (0-15)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_CONV, i, fConvGain[i], 0, "ADC18 Set Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fDAC.append(self.dac_settings[i].get()) + + if fDAC[i]=='Tri': + dacflag = DACTRI + elif fDAC[i]=='Saw': + dacflag = DACSAW + elif fDAC[i] == 'Const': + dacflag = DACCONST + else: + dacflag = DACOFF18 + + packet = [u.COMMAND_ADC18, ADC18_SET_DAC, i, dacflag, 0, "ADC18 Set DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fSample.append(int(self.sample_settings[i].get())) + + packet = [u.COMMAND_ADC18, ADC18_SET_SAMP, i, fSample[i], 0, "ADC18 Set Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_LHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + self.check_values() diff --git a/tabs/gm_adc18_rtspec.py b/tabs/gm_adc18_rtspec.py new file mode 100644 index 0000000..dfc06d2 --- /dev/null +++ b/tabs/gm_adc18_rtspec.py @@ -0,0 +1,246 @@ +''' +Green Monster GUI Revamp +Containing ADC18s Tab +Code Commissioned 2019-01-16 +Code by A.J. Zec +''' + +import tkinter as tk +from tkinter import ttk +import utils as u + +ADC18_GET_NUMADC =1001 +ADC18_GET_LABEL =1002 +ADC18_GET_CSR =1003 +ADC18_SET_CONV =1004 +ADC18_SET_INT =1005 +ADC18_SET_PED =1006 +ADC18_GET_CONV =1007 +ADC18_GET_INT =1008 +ADC18_GET_PED =1009 +ADC18_SET_DAC =1010 +ADC18_GET_DAC =1011 +ADC18_SET_SAMP =1012 +ADC18_GET_SAMP =1013 +GA_MAXADC =20 +DACRADIO18 =100 +GM_ADC_GET =101 +GM_ADC_SET =201 +DACTRI =0 +DACSAW =1 +DACCONST =2 +DACOFF18 =3 + +class ADC18(tk.Frame): + def __init__(self, tab): + global numADC + numADC = self.get_num_adc() + ADClabels = [] + + i = 0 + while i < numADC: + ADClabels.append(self.get_label_adc(i)) + i += 1 + + self.rt_spec_frame = tk.LabelFrame(tab, text='RHRS', background=u.green_color) + self.adc_ls = [] + self.int_es = [] + self.conv_es = [] + self.dac_settings = [] + self.sample_settings = [] + + i = 0 + while i < numADC: + self.adc_ls.append(tk.Label(self.rt_spec_frame, text='ADC '+str(ADClabels[i]), background=u.green_color)) + self.int_es.append(tk.Entry(self.rt_spec_frame, width=3)) + self.conv_es.append(tk.Entry(self.rt_spec_frame, width=3)) + self.dac_settings.append(tk.StringVar()) + self.sample_settings.append(tk.IntVar()) + i += 1 + + labels = ['Label', 'Int', 'Conv', '-----', 'DAC', 'Settings', '-----', 'Sample by:'] + for i, label in enumerate(labels): + tk.Label(self.rt_spec_frame, text=label, background=u.green_color).grid( + row=0, column=i, padx=8, pady=10, sticky='W') + + self.create_table(numADC) + self.check_values() + + def get_num_adc(self): + packet = [u.COMMAND_ADC18, ADC18_GET_NUMADC, 0, 0, 0, "ADC Get Number", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + def get_label_adc(self, index): + packet = [u.COMMAND_ADC18, ADC18_GET_LABEL, index, 0, 0, "ADC Get Label", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + return int(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + + def create_table(self, value): + for i in range(1, value+1): + self.adc_ls[i-1].grid(row=i, column=0, padx=10, pady=10, sticky='W') + u.set_text(self.int_es[i-1], '3').grid(row=i, column=1, padx=10, pady=10) + u.set_text(self.conv_es[i-1], '0').grid(row=i, column=2, padx=10, pady=10) + setting = self.dac_settings[i-1] + settings = ['Tri', 'Saw', 'Const', 'Off'] + setting.set('Tri') + for j,s in enumerate(settings): + tk.Radiobutton(self.rt_spec_frame, text=s, variable=setting, value=s, background=u.green_color).grid( + row=i, column=j+3, padx=5, pady=10, sticky='W') + sample_by = self.sample_settings[i-1] + sample_by.set(1) + tk.OptionMenu(self.rt_spec_frame, sample_by, 1, 2, 4, 8).grid(row=i, column=7) + tk.Button(self.rt_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values).grid( + row=6, column=1, columnspan=2, pady=50, sticky='S') + tk.Button(self.rt_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values).grid( + row=6, column=3, columnspan=2, pady=50, sticky='S') + tk.Button(self.rt_spec_frame, text='Cancel', background=u.green_color, command=self.check_values).grid( + row=6, column=5, pady=50, sticky='S') + self.rt_spec_frame.pack(padx=20, pady=20) + + def check_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + packet = [u.COMMAND_ADC18, ADC18_GET_SAMP, i, 0, 0, "ADC18 Get Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + fSample.append(reply[3]) + self.sample_settings[i].set(reply[3]) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_INT, i, 0, 0, "ADC18 Get Int", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + fIntGain.append(reply[3]) + self.int_es[i].delete(0, tk.END) + self.int_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_CONV, i, 0, 0, "ADC18 Get Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + fConvGain.append(reply[3]) + self.conv_es[i].delete(0, tk.END) + self.conv_es[i].insert(0, str(reply[3])) + + else: + print("ERROR, Could not access socket.") + return -1 + + packet = [u.COMMAND_ADC18, ADC18_GET_DAC, i, 0, 0, "ADC18 Get DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + fDAC.append(reply[3]) + if reply[3] == DACSAW: + self.dac_settings[i].set('Saw') + elif reply[3] == DACCONST: + self.dac_settings[i].set('Const') + elif reply[3] == DACTRI: + self.dac_settings[i].set('Tri') + else: + self.dac_settings[i].set('Off') + + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + def set_values(self): + fSample = [] + fIntGain = [] + fConvGain = [] + fDAC = [] + value = numADC + + i = 0 + while i < value: + fIntGain.append(int(self.int_es[i].get())) + + if fIntGain[i] < 0 or fIntGain[i] > 3: + print("ERROR: Int Value is out of range! Try (0-3)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_INT, i, fIntGain[i], 0, "ADC18 Set Int", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fConvGain.append(int(self.conv_es[i].get())) + + if fConvGain[i] < 0 or fConvGain[i] > 15: + print("ERROR: Conv Value is out of range! Try (0-15)...") + else: + packet = [u.COMMAND_ADC18, ADC18_SET_CONV, i, fConvGain[i], 0, "ADC18 Set Conv", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fDAC.append(self.dac_settings[i].get()) + + if fDAC[i]=='Tri': + dacflag = DACTRI + elif fDAC[i]=='Saw': + dacflag = DACSAW + elif fDAC[i] == 'Const': + dacflag = DACCONST + else: + dacflag = DACOFF18 + + packet = [u.COMMAND_ADC18, ADC18_SET_DAC, i, dacflag, 0, "ADC18 Set DAC", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + + fSample.append(int(self.sample_settings[i].get())) + + packet = [u.COMMAND_ADC18, ADC18_SET_SAMP, i, fSample[i], 0, "ADC18 Set Sample", "Y"] + err_flag, reply = u.send_command(u.Crate_RHRS, packet) + + if err_flag == u.SOCK_OK: + pass + else: + print("ERROR, Could not access socket.") + return -1 + i += 1 + + self.check_values() diff --git a/tabs/gm_bmw.py b/tabs/gm_bmw.py index 8f654d4..a2f59d1 100644 --- a/tabs/gm_bmw.py +++ b/tabs/gm_bmw.py @@ -40,6 +40,7 @@ def __init__(self, tab): self.script_frame_layout() self.test_frame_layout() self.bm_frame.pack(padx=20, pady=20, anchor='w') + self.check_status_button() def script_frame_layout(self): self.ks_bm_l.grid(row=0, column=0, padx=10, pady=10, sticky='W') @@ -100,7 +101,7 @@ def check_status(self): kill_switch = bool(reply[3]) print(tab_title + " check_status: kill_switch = " + str(kill_switch)) - if kill_switch: self.ks.bm_l['text'] = 'Kill Switch is ON' + if kill_switch: self.ks_bm_l['text'] = 'Kill Switch is ON' else: self.ks_bm_l['text'] = 'Kill Switch is OFF' if bmw_running: diff --git a/tabs/gm_scan.py b/tabs/gm_scan.py index a9ce079..c3b9416 100644 --- a/tabs/gm_scan.py +++ b/tabs/gm_scan.py @@ -8,12 +8,27 @@ import tkinter as tk from tkinter import ttk import utils as u +import os +import subprocess +SCAN_GET_DATA =1001 +SCAN_SET_DATA =1002 +SCAN_GET_STATUS =1003 +SCAN_SET_STATUS =1004 +GM_SCN_CHECK =6002 +GM_SCN_SET =6003 +SCN_RADIO_CLN =6101 +SCN_RADIO_NOT =6102 +SCN_RADIO_CLN_BT=0 +SCN_RADIO_NOT_BT=1 +SCN_INT_CLN =1 +SCN_INT_NOT =0 class ScanUtil(tk.Frame): - def __init__(self, tab): + def __init__(self, tab, gm): self.util_frame = tk.LabelFrame(tab, text='SCAN UTILITY', bg=u.green_color) - self.options = ['CLEAN', 'NOT CLEAN'] + self.GM = gm + self.options = ['CLEAN', 'NOT CLEAN', 'GRAB EPICS/NOT CLEAN'] self.clean_setting = tk.StringVar() self.clean_setting.set(self.options[0]) self.inj_frame = tk.LabelFrame(self.util_frame, text='Inj', bg=u.green_color) @@ -25,16 +40,194 @@ def __init__(self, tab): tk.Entry(self.inj_frame), tk.Entry(self.inj_frame), tk.Entry(self.inj_frame)] + self.epics_frame = tk.LabelFrame(self.util_frame, text='EPICS', bg=u.green_color) + self.epics_labels = [tk.Label(self.epics_frame, text='Epics Variable 1', bg=u.green_color), + tk.Label(self.epics_frame, text='Epics Variable 2', bg=u.green_color), + tk.Label(self.epics_frame, text='Epics Variable 3', bg=u.green_color), + tk.Label(self.epics_frame, text='Epics Variable 4', bg=u.green_color)] + self.epics_entries = [tk.Entry(self.epics_frame), + tk.Entry(self.epics_frame), + tk.Entry(self.epics_frame), + tk.Entry(self.epics_frame)] + self.timer_frame = tk.LabelFrame(self.util_frame, text='Timer (seconds)', bg=u.green_color) + self.timer_labels = [tk.Label(self.timer_frame, text='0', fg='#ffffff', bg='#3C5353', padx=10, pady=10)] + self.timer_entries = [tk.Entry(self.timer_frame)] for i, op in enumerate(self.options): tk.Radiobutton(self.util_frame, text=op, variable=self.clean_setting, - value=op, bg=u.green_color).grid(row=0, column=i, padx=10, pady=10, sticky='W') + value=op, bg=u.green_color, command=self.set_status).grid(row=0, column=i, padx=10, pady=10, sticky='W') self.fill_inj_frame() self.inj_frame.grid(row=1, column=0, columnspan=2, padx=10, pady=10, sticky='W') - tk.Button(self.util_frame, text='Check Status', bg=u.green_color).grid(row=2, column=0, padx=10, pady=10) - tk.Button(self.util_frame, text='Set Values', bg=u.green_color).grid(row=2, column=1, padx=10, pady=10) + self.fill_epics_frame() + self.epics_frame.grid(row=1, column=2, columnspan=1, padx=10, pady=10, sticky='W') + self.fill_timer_frame() + self.timer_frame.grid(row=3, column=0, columnspan=5, padx=10, pady=10, sticky='W') + tk.Button(self.util_frame, text='Check Values', bg=u.green_color, command=self.check_values).grid(row=2, column=0, padx=10, pady=10) + tk.Button(self.util_frame, text='Set Values', bg=u.green_color, command=self.set_values).grid(row=2, column=1, padx=10, pady=10) + tk.Button(self.util_frame, text='Grab EPICS', bg=u.green_color, command=self.check_EPICS).grid(row=2, column=2, padx=10, pady=10) + tk.Button(self.timer_frame, text='Start', bg=u.green_color, command=lambda: self.start_timer()).grid(row=0, column=2, padx=5, pady=5) + tk.Button(self.timer_frame, text='Pause', bg=u.green_color, command=lambda: self.pause_timer()).grid(row=0, column=3, padx=5, pady=5) + tk.Button(self.timer_frame, text='Clear', bg=u.green_color, command=lambda: self.clear_timer()).grid(row=0, column=4, padx=5, pady=5) self.util_frame.pack(padx=20, pady=20, anchor='w') + self.check_values() + self.startTimer = False + self.timer_loop() def fill_inj_frame(self): for r in range(0, 4): self.inj_labels[r].grid(row=r, column=0, padx=15, pady=10, sticky='E') u.set_text(self.inj_entries[r], '0').grid(row=r, column=1, padx=10, pady=10, sticky='W') + + def fill_epics_frame(self): + for r in range(0, 4): + self.epics_labels[r].grid(row=r, column=0, padx=15, pady=10, sticky='E') + u.set_text(self.epics_entries[r], 'None').grid(row=r, column=1, padx=10, pady=10, sticky='W') + + def fill_timer_frame(self): + self.timer_labels[0].grid(row=0, column=0, padx=15, pady=10, sticky='E') + u.set_text(self.timer_entries[0], '0').grid(row=0, column=1, padx=10, pady=10, sticky='W') + + def start_timer(self): + self.startTimer = True + self.timer_labels[0].config(text=self.timer_entries[0].get()) + self.timer_frame.config(bg=u.green_color) + self.timer_labels[0].config(bg='#3C5353') + + def timer_loop(self): + # Make a timing thing: + if self.startTimer is True: + try: + localTime = int(float(self.timer_labels[0].cget("text"))) + except ValueError: + localTime = 0 + if localTime<=0: + localTime = 0 + self.startTimer = False + self.timer_frame.config(bg='#9E1A1A') + self.timer_labels[0].config(bg='#3E1515') + else: + localTime = localTime - 1 + self.timer_labels[0].config(text=str(localTime)) + #self.timer_entries[0].delete(0, tk.END) + #self.timer_entries[0].insert(0, str(localTime)) + self.GM.win.after(1000,self.timer_loop) # Recursion loop here - splits off a new instance of this function and finishes the one currently running (be careful) + #else: + # gm.win.after(1000,self.timer_loop(gm),gm) # Recursion loop here - splits off a new instance of this function and finishes the one currently running (be careful) + + def pause_timer(self): + self.startTimer = False + self.timer_frame.config(bg=u.green_color) + self.timer_labels[0].config(bg='#3C5353') + + def clear_timer(self): + self.startTimer = False + self.timer_labels[0].config(text='0') + #self.timer_entries[0].delete(0, tk.END) + #self.timer_entries[0].insert(0, '0') + self.timer_frame.config(bg=u.green_color) + self.timer_labels[0].config(bg='#3C5353') + + def check_status(self): + packet = [u.COMMAND_SCAN, SCAN_GET_STATUS, 0, 0, 0, "SCN status check", "Y"] + err_flag, reply = u.send_command(u.Crate_INJ, packet) + + if err_flag == u.SOCK_OK: + iclean = bool(reply[2]) + if (iclean == SCN_INT_NOT): + self.clean_setting.set(self.options[1]) + elif (iclean == SCN_INT_CLN): + self.clean_setting.set(self.options[0]) + else: + print("UNKNOWN REPLY FOR SCN STATUS: " + str(iclean)) + self.clean_setting.set(self.options[1]) + + else: + print(" check_status: ERROR, Could not access socket.") + return + + def check_values(self): + i = 0 + while i < 4: + packet = [u.COMMAND_SCAN, SCAN_GET_DATA, i+1, 0, 0, "Check SCN Data Value", "Y"] + err_flag, reply = u.send_command(u.Crate_INJ, packet) + + if err_flag == u.SOCK_OK: + value = int(reply[3]) + self.inj_entries[i].delete(0, tk.END) + self.inj_entries[i].insert(0, str(value)) + print("Value is " + str(value)) + + else: + print(" check_status: ERROR, Could not access socket.") + return + + i += 1 + + self.check_status() + + def check_EPICS(self): + i = 0 + while i < 4: + # if inj_ + cmds = ['caget', '-t', '-w 1', self.epics_entries[i].get()] + value = "NULL" + if "None" not in self.epics_entries[i].get(): + value = subprocess.Popen(cmds, stdout=subprocess.PIPE).stdout.read().strip().decode('ascii') # Needs to be decoded... be careful + if value != "NULL" and "Invalid" not in value: + #self.inj_entries[i] = str(value) + value = int(round(float(value))) + self.inj_entries[i].delete(0, tk.END) + self.inj_entries[i].insert(0, str(value)) + i += 1 + self.check_status() + + def set_status(self): + if self.clean_setting.get() == 'CLEAN': + status = 1 + else: + status = 0 + + if self.clean_setting.get() == 'GRAB EPICS/NOT CLEAN': + i = 0 + while i < 4: + # if inj_ + cmds = ['caget', '-t', '-w 1', self.epics_entries[i].get()] + value = "NULL" + if "None" not in self.epics_entries[i].get(): + value = subprocess.Popen(cmds, stdout=subprocess.PIPE).stdout.read().strip().decode('ascii') # Needs to be decoded... be careful + if value != "NULL" and "Invalid" not in value: + #self.inj_entries[i] = str(value) + self.inj_entries[i].delete(0, tk.END) + self.inj_entries[i].insert(0, str(value)) + i += 1 + + self.set_values() + + packet = [u.COMMAND_SCAN, SCAN_SET_STATUS, status, 0, 0, "SCN Status Change", "Y"] + err_flag, reply = u.send_command(u.Crate_INJ, packet) + + print("Setting SCN status: " + str(status)) + if err_flag == u.SOCK_OK: + print("SCAN status change call is complete"); + else: + print(" check_status: ERROR, Could not access socket.") + + self.check_values() + + def set_values(self): + i = 0 + while i < 4: + value = int(round(float(self.inj_entries[i].get()))) + packet = [u.COMMAND_SCAN, SCAN_SET_DATA, i+1, value, 0, "Set SCN Data Value", "Y"] + err_flag, reply = u.send_command(u.Crate_INJ, packet) + + if err_flag == u.SOCK_OK: + print("Writing new SCAN set point " + str(value) + " to data " + str(i)) + + else: + print(" check_status: ERROR, Could not access socket.") + return + + i += 1 + + self.check_values() + diff --git a/tabs/gm_timeboard.py b/tabs/gm_timeboard.py index 558d07f..6455d30 100644 --- a/tabs/gm_timeboard.py +++ b/tabs/gm_timeboard.py @@ -8,68 +8,724 @@ import tkinter as tk from tkinter import ttk import utils as u +import distutils.util from ctypes import cdll +GM_HAPTB =1000 +GM_TB_GET =1001 +GM_TB_SET =1002 +HAPTB_GET_DATA =1001 +HAPTB_SET_DATA =1002 +HAPTB_RD =201 +HAPTB_IT =202 +HAPTB_OS =221 +PATH ="/adaqfs/home/apar/devices/crl/vqwkTiming.flags" +HRSFLAG ="/adaqfs/home/apar/devices/PyGreenMonster/includeHRS.flags" + class Timeboard(tk.Frame): def __init__(self, tab): - self.ch_frame = tk.LabelFrame(tab, text='CH', background=u.green_color, width=500) + self.ch_frame = tk.LabelFrame(tab, text='Counting House', background=u.green_color, width=500) + self.inj_frame = tk.LabelFrame(tab, text='Injector', background=u.green_color, width=500) + self.lft_spec_frame = tk.LabelFrame(tab, text='Left Spectrometer', background=u.green_color, width=500) + self.rt_spec_frame = tk.LabelFrame(tab, text='Right Spectrometer', background=u.green_color, width=500) + self.defaults_frame = tk.LabelFrame(tab, text='Default Controls', background=u.green_color, width=1000) + self.ramp_delay_l = tk.Label(self.ch_frame, text='Ramp Delay', background=u.green_color) self.int_time_l = tk.Label(self.ch_frame, text='Integrate Time', background=u.green_color) self.oversamp_l = tk.Label(self.ch_frame, text='Oversampling', background=u.green_color) self.ramp_delay_e = tk.Entry(self.ch_frame) self.int_time_e = tk.Entry(self.ch_frame) self.oversamp_e = tk.Entry(self.ch_frame) + self.includeHRSs = self.checkHRSflag(); self.ramp_delay_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') self.int_time_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') self.oversamp_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') - u.set_text(self.ramp_delay_e, '40').grid(row=0, column=1) - u.set_text(self.int_time_e, '13200').grid(row=1, column=1) - u.set_text(self.oversamp_e, '0').grid(row=2, column=1) - tk.Button(self.ch_frame, text='Get Settings', background=u.green_color).grid( + u.set_text(self.ramp_delay_e, '0').grid(row=0, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.int_time_e, '0').grid(row=1, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.oversamp_e, '0').grid(row=2, column=1, padx=10, pady=5, sticky='W') + tk.Button(self.ch_frame, text='Get Settings', background=u.green_color, command=self.check_values_ch).grid( + row=3, column=0, pady=10) + tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color, command=self.set_values_ch).grid( + row=3, column=1, pady=10) + self.ch_frame.grid(row=0, column=0, padx=20, pady=10) + + self.inj_ramp_delay_l = tk.Label(self.inj_frame, text='Ramp Delay', background=u.green_color) + self.inj_int_time_l = tk.Label(self.inj_frame, text='Integrate Time', background=u.green_color) + self.inj_oversamp_l = tk.Label(self.inj_frame, text='Oversampling', background=u.green_color) + self.inj_ramp_delay_e = tk.Entry(self.inj_frame) + self.inj_int_time_e = tk.Entry(self.inj_frame) + self.inj_oversamp_e = tk.Entry(self.inj_frame) + + self.inj_ramp_delay_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') + self.inj_int_time_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') + self.inj_oversamp_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') + u.set_text(self.inj_ramp_delay_e, '0').grid(row=0, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.inj_int_time_e, '0').grid(row=1, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.inj_oversamp_e, '0').grid(row=2, column=1, padx=10, pady=5, sticky='W') + tk.Button(self.inj_frame, text='Get Settings', background=u.green_color, command=self.check_values_inj).grid( row=3, column=0, pady=10) - tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color).grid( + tk.Button(self.inj_frame, text='Apply Settings', background=u.green_color, command=self.set_values_inj).grid( row=3, column=1, pady=10) - self.ch_frame.pack(padx=20, pady=10, anchor='w') - - ''' - def get_RD_value(self): - new_rd = self.lib.getRDvalue(self.obj) - self.ramp_delay_e = u.set_text(self.ramp_delay_e, str(new_rd)) + self.inj_frame.grid(row=0, column=1, padx=20, pady=10) + + self.lft_spec_ramp_delay_l = tk.Label(self.lft_spec_frame, text='Ramp Delay', background=u.green_color) + self.lft_spec_int_time_l = tk.Label(self.lft_spec_frame, text='Integrate Time', background=u.green_color) + self.lft_spec_oversamp_l = tk.Label(self.lft_spec_frame, text='Oversampling', background=u.green_color) + self.lft_spec_ramp_delay_e = tk.Entry(self.lft_spec_frame) + self.lft_spec_int_time_e = tk.Entry(self.lft_spec_frame) + self.lft_spec_oversamp_e = tk.Entry(self.lft_spec_frame) + + self.lft_spec_ramp_delay_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') + self.lft_spec_int_time_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') + self.lft_spec_oversamp_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') + u.set_text(self.lft_spec_ramp_delay_e, '0').grid(row=0, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.lft_spec_int_time_e, '0').grid(row=1, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.lft_spec_oversamp_e, '0').grid(row=2, column=1, padx=10, pady=5, sticky='W') + tk.Button(self.lft_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values_lft_spec).grid( + row=3, column=0, pady=10) + tk.Button(self.lft_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values_lft_spec).grid( + row=3, column=1, pady=10) + self.lft_spec_frame.grid(row=1, column=0, padx=20, pady=10) + + self.rt_spec_ramp_delay_l = tk.Label(self.rt_spec_frame, text='Ramp Delay', background=u.green_color) + self.rt_spec_int_time_l = tk.Label(self.rt_spec_frame, text='Integrate Time', background=u.green_color) + self.rt_spec_oversamp_l = tk.Label(self.rt_spec_frame, text='Oversampling', background=u.green_color) + self.rt_spec_ramp_delay_e = tk.Entry(self.rt_spec_frame) + self.rt_spec_int_time_e = tk.Entry(self.rt_spec_frame) + self.rt_spec_oversamp_e = tk.Entry(self.rt_spec_frame) + + self.rt_spec_ramp_delay_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') + self.rt_spec_int_time_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') + self.rt_spec_oversamp_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') + u.set_text(self.rt_spec_ramp_delay_e, '0').grid(row=0, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.rt_spec_int_time_e, '0').grid(row=1, column=1, padx=10, pady=5, sticky='W') + u.set_text(self.rt_spec_oversamp_e, '0').grid(row=2, column=1, padx=10, pady=5, sticky='W') + tk.Button(self.rt_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values_rt_spec).grid( + row=3, column=0, pady=10) + tk.Button(self.rt_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values_rt_spec).grid( + row=3, column=1, pady=10) + self.rt_spec_frame.grid(row=1, column=1, padx=20, pady=10) + + tk.Button(self.defaults_frame, text='Get All Values From Boards', background=u.green_color, command=self.check_all).grid( + row=0, column=0, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Set All Values to Boards', background=u.green_color, command=self.set_all).grid( + row=0, column=1, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Get Default Values From File', background=u.green_color, command=self.read_defaults).grid( + row=1, column=0, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Write Values to Defaults File', background=u.green_color, command=self.set_defaults).grid( + row=1, column=1, padx=10, pady=10) + + + self.defaults_frame.grid(row=2, column=0, padx=20, pady=10, columnspan=2) + + #self.read_defaults() + #self.set_all() + self.check_all() + + def checkHRSflag(self): + hrsinfile = open(HRSFLAG,'r') + tmp="False" + for line in hrsinfile: + print("Include HRSs = " + line) + tmp=bool(distutils.util.strtobool(line.strip('\n'))) + print("Include HRSs = " + str(tmp)) + return tmp + + + def read_defaults(self): + global delayCH + global inttimeCH + global delayINJ + global inttimeINJ + global delayRHRS + global inttimeRHRS + global delayLHRS + global inttimeLHRS + + infile = open(PATH,'r') + for line in infile: + if (line[0] == ';'): + continue + else: + delayCH = int(line[(line.index("HAPTB_delay_CH=") + 15):line.index(",HAPTB_int_time_CH=")]) + inttimeCH = int(line[(line.index("HAPTB_int_time_CH=") + 18):line.index(",HAPTB_delay_INJ=")]) + + delayINJ = int(line[(line.index("HAPTB_delay_INJ=") + 16):line.index(",HAPTB_int_time_INJ=")]) + inttimeINJ = int(line[(line.index("HAPTB_int_time_INJ=") + 19):line.index(",HAPTB_delay_RHRS=")]) + + delayRHRS = int(line[(line.index("HAPTB_delay_RHRS=") + 17):line.index(",HAPTB_int_time_RHRS=")]) + inttimeRHRS = int(line[(line.index("HAPTB_int_time_RHRS=") + 20):line.index(",HAPTB_delay_LHRS=")]) + + delayLHRS = int(line[(line.index("HAPTB_delay_LHRS=") + 17):line.index(",HAPTB_int_time_LHRS=")]) + inttimeLHRS = int(line[(line.index("HAPTB_int_time_LHRS=") + 20):line.index("\n")]) + infile.close() + + self.ramp_delay_e.delete(0, tk.END) + self.ramp_delay_e.insert(0, str(delayCH)) + + self.int_time_e.delete(0, tk.END) + self.int_time_e.insert(0, str(inttimeCH)) + + self.inj_ramp_delay_e.delete(0, tk.END) + self.inj_ramp_delay_e.insert(0, str(delayINJ)) + + self.inj_int_time_e.delete(0, tk.END) + self.inj_int_time_e.insert(0, str(inttimeINJ)) + + self.lft_spec_ramp_delay_e.delete(0, tk.END) + self.lft_spec_ramp_delay_e.insert(0, str(delayLHRS)) + + self.lft_spec_int_time_e.delete(0, tk.END) + self.lft_spec_int_time_e.insert(0, str(inttimeLHRS)) + + self.rt_spec_ramp_delay_e.delete(0, tk.END) + self.rt_spec_ramp_delay_e.insert(0, str(delayRHRS)) + + self.rt_spec_int_time_e.delete(0, tk.END) + self.rt_spec_int_time_e.insert(0, str(inttimeRHRS)) + + def set_defaults(self): + delayCH = int(self.ramp_delay_e.get()) + inttimeCH = int(self.int_time_e.get()) + value3 = int(self.oversamp_e.get()) + + delayINJ = int(self.inj_ramp_delay_e.get()) + inttimeINJ = int(self.inj_int_time_e.get()) + value3 = int(self.inj_oversamp_e.get()) + + delayRHRS = int(self.rt_spec_ramp_delay_e.get()) + inttimeRHRS = int(self.rt_spec_int_time_e.get()) + value3 = int(self.rt_spec_oversamp_e.get()) + + delayLHRS = int(self.lft_spec_ramp_delay_e.get()) + inttimeLHRS = int(self.lft_spec_int_time_e.get()) + value3 = int(self.lft_spec_oversamp_e.get()) + + newdefaultstring = "AUTO_GENERATED_CONTENT=1,HAPTB_delay_CH="+str(delayCH)+",HAPTB_int_time_CH="+str(inttimeCH)+",HAPTB_delay_INJ="+str(delayINJ)+",HAPTB_int_time_INJ="+str(inttimeINJ)+",HAPTB_delay_RHRS="+str(delayRHRS)+",HAPTB_int_time_RHRS="+str(inttimeRHRS)+",HAPTB_delay_LHRS="+str(delayLHRS)+",HAPTB_int_time_LHRS="+str(inttimeLHRS)+"\n" + + buff = [] + i = 0 + autogen = 0 + infile = open(PATH,'r') + for line in infile: + if (line == ";;;;;;;LINES BELOW ARE AUTOGENERATED;;;;;;;\n"): + autogen = 1 + buff.append(line) + i+=1 + continue + if (autogen == 0): + buff.append(line) + i+=1 + if (line[0] != ';' and autogen == 0): + buff[i-1] = (";" + line) + infile.close() + + buff.append(newdefaultstring) + + outfile = open(PATH,'w') + for i in range(len(buff)): + outfile.write(buff[i]) + outfile.close() + + + def check_all(self): + self.check_values_ch() + self.check_values_inj() + # no HRS + if self.includeHRSs: + self.check_values_lft_spec() + self.check_values_rt_spec() + + def set_all(self): + self.set_values_ch() + self.set_values_inj() + #no HRS + if self.includeHRSs: + self.set_values_lft_spec() + self.set_values_rt_spec() + + def check_values_ch(self): + packet1 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_RD, 0, 0, "TB Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_CH, packet1) + + print("I am here where you thought I was") + print("COMMAND_HAPTB is " + str(u.COMMAND_HAPTB)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentRD = int(reply1[3]) + self.ramp_delay_e.delete(0, tk.END) + self.ramp_delay_e.insert(0, str(CurrentRD)) + print("Ramp delay is " + str(CurrentRD)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_IT, 0, 0, "TB Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_CH, packet2) + + if err_flag == u.SOCK_OK: + CurrentIT = int(reply2[3]) + self.int_time_e.delete(0, tk.END) + self.int_time_e.insert(0, str(CurrentIT)) + print("Integration time is " + str(CurrentIT)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_OS, 0, 0, "TB Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_CH, packet3) + + if err_flag == u.SOCK_OK: + CurrentOS = int(reply3[3]) + self.oversamp_e.delete(0, tk.END) + self.oversamp_e.insert(0, str(CurrentOS)) + print("Oversampling is " + str(CurrentOS)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_rt_spec(self): + packet1 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_RD, 0, 0, "TB Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_RHRS, packet1) + + print("I am here where you thought I was") + print("COMMAND_HAPTB is " + str(u.COMMAND_HAPTB)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentRD = int(reply1[3]) + self.rt_spec_ramp_delay_e.delete(0, tk.END) + self.rt_spec_ramp_delay_e.insert(0, str(CurrentRD)) + print("Ramp delay is " + str(CurrentRD)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_IT, 0, 0, "TB Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_RHRS, packet2) + + if err_flag == u.SOCK_OK: + CurrentIT = int(reply2[3]) + self.rt_spec_int_time_e.delete(0, tk.END) + self.rt_spec_int_time_e.insert(0, str(CurrentIT)) + print("Integration time is " + str(CurrentIT)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_OS, 0, 0, "TB Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_RHRS, packet3) + + if err_flag == u.SOCK_OK: + CurrentOS = int(reply3[3]) + self.rt_spec_oversamp_e.delete(0, tk.END) + self.rt_spec_oversamp_e.insert(0, str(CurrentOS)) + print("Oversampling is " + str(CurrentOS)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_lft_spec(self): + packet1 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_RD, 0, 0, "TB Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_LHRS, packet1) + + print("I am here where you thought I was") + print("COMMAND_HAPTB is " + str(u.COMMAND_HAPTB)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentRD = int(reply1[3]) + self.lft_spec_ramp_delay_e.delete(0, tk.END) + self.lft_spec_ramp_delay_e.insert(0, str(CurrentRD)) + print("Ramp delay is " + str(CurrentRD)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_IT, 0, 0, "TB Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_LHRS, packet2) + + if err_flag == u.SOCK_OK: + CurrentIT = int(reply2[3]) + self.lft_spec_int_time_e.delete(0, tk.END) + self.lft_spec_int_time_e.insert(0, str(CurrentIT)) + print("Integration time is " + str(CurrentIT)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_OS, 0, 0, "TB Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_LHRS, packet3) + + if err_flag == u.SOCK_OK: + CurrentOS = int(reply3[3]) + self.lft_spec_oversamp_e.delete(0, tk.END) + self.lft_spec_oversamp_e.insert(0, str(CurrentOS)) + print("Oversampling is " + str(CurrentOS)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_inj(self): + packet1 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_RD, 0, 0, "TB Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_INJ, packet1) + + print("I am here where you thought I was") + print("COMMAND_HAPTB is " + str(u.COMMAND_HAPTB)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentRD = int(reply1[3]) + self.inj_ramp_delay_e.delete(0, tk.END) + self.inj_ramp_delay_e.insert(0, str(CurrentRD)) + print("Ramp delay is " + str(CurrentRD)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_IT, 0, 0, "TB Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_INJ, packet2) + + if err_flag == u.SOCK_OK: + CurrentIT = int(reply2[3]) + self.inj_int_time_e.delete(0, tk.END) + self.inj_int_time_e.insert(0, str(CurrentIT)) + print("Integration time is " + str(CurrentIT)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_HAPTB, HAPTB_GET_DATA, HAPTB_OS, 0, 0, "TB Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_INJ, packet3) + + if err_flag == u.SOCK_OK: + CurrentOS = int(reply3[3]) + self.inj_oversamp_e.delete(0, tk.END) + self.inj_oversamp_e.insert(0, str(CurrentOS)) + print("Oversampling is " + str(CurrentOS)) + + else: + print("ERROR, Could not access socket.") + return + + def set_values_ch(self): + + value1 = int(self.ramp_delay_e.get()) + value2 = int(self.int_time_e.get()) + value3 = int(self.oversamp_e.get()) + + packet1 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_RD, value1, 0, "TB Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_CH, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != HAPTB_RD: + print("Server replied with wrong TB number: " +str(reply1[2])+ " instead of " +str(HAPTB_RD)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong TB set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + packet2 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_IT, value2, 0, "TB Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_CH, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != HAPTB_IT: + print("Server replied with wrong TB number: " +str(reply2[2])+ " instead of " +str(HAPTB_IT)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong TB set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + packet3 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_OS, value3, 0, "TB Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_CH, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != HAPTB_OS: + print("Server replied with wrong TB number: " +str(reply3[2])+ " instead of " +str(HAPTB_OS)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong TB set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + self.check_values_ch() + + def set_values_rt_spec(self): + + value1 = int(self.rt_spec_ramp_delay_e.get()) + value2 = int(self.rt_spec_int_time_e.get()) + value3 = int(self.rt_spec_oversamp_e.get()) + + packet1 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_RD, value1, 0, "TB Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_RHRS, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != HAPTB_RD: + print("Server replied with wrong TB number: " +str(reply1[2])+ " instead of " +str(HAPTB_RD)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong TB set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + packet2 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_IT, value2, 0, "TB Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_RHRS, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != HAPTB_IT: + print("Server replied with wrong TB number: " +str(reply2[2])+ " instead of " +str(HAPTB_IT)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong TB set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + packet3 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_OS, value3, 0, "TB Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_RHRS, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != HAPTB_OS: + print("Server replied with wrong TB number: " +str(reply3[2])+ " instead of " +str(HAPTB_OS)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong TB set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") + + self.check_values_rt_spec() + + def set_values_lft_spec(self): + + value1 = int(self.lft_spec_ramp_delay_e.get()) + value2 = int(self.lft_spec_int_time_e.get()) + value3 = int(self.lft_spec_oversamp_e.get()) + + packet1 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_RD, value1, 0, "TB Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_LHRS, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != HAPTB_RD: + print("Server replied with wrong TB number: " +str(reply1[2])+ " instead of " +str(HAPTB_RD)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong TB set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def set_RD_value(self): - self.lib.setRDvalue(self.obj, int(self.ramp_delay_e.get())) + packet2 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_IT, value2, 0, "TB Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_LHRS, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != HAPTB_IT: + print("Server replied with wrong TB number: " +str(reply2[2])+ " instead of " +str(HAPTB_IT)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong TB set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def get_IS_value(self): - new_is = self.lib.getISvalue(self.obj) - self.int_time_e = u.set_text(self.int_time_e, str(new_is)) + packet3 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_OS, value3, 0, "TB Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_LHRS, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != HAPTB_OS: + print("Server replied with wrong TB number: " +str(reply3[2])+ " instead of " +str(HAPTB_OS)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong TB set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def set_IS_value(self): - self.lib.setISvalue(self.obj, int(self.int_time_e.get())) + self.check_values_lft_spec() - def get_OS_value(self): - new_os = self.lib.getOSvalue(self.obj) - self.oversamp_e = u.set_text(self.oversamp_e, str(new_os)) + def set_values_inj(self): - def set_OS_value(self): - self.lib.setOSvalue(self.obj, int(self.oversamp_e.get())) + value1 = int(self.inj_ramp_delay_e.get()) + value2 = int(self.inj_int_time_e.get()) + value3 = int(self.inj_oversamp_e.get()) - def pull_from_board(self): - self.lib.getValsTB(self.obj) + packet1 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_RD, value1, 0, "TB Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_INJ, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != HAPTB_RD: + print("Server replied with wrong TB number: " +str(reply1[2])+ " instead of " +str(HAPTB_RD)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong TB set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def push_to_board(self): - self.lib.setValsTB(self.obj) + packet2 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_IT, value2, 0, "TB Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_INJ, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != HAPTB_IT: + print("Server replied with wrong TB number: " +str(reply2[2])+ " instead of " +str(HAPTB_IT)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong TB set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def get_all_values(self): - self.pull_from_board() - self.get_RD_value() - self.get_IS_value() - self.get_OS_value() + packet3 = [u.COMMAND_HAPTB, HAPTB_SET_DATA, HAPTB_OS, value3, 0, "TB Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_INJ, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with TB error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != HAPTB_OS: + print("Server replied with wrong TB number: " +str(reply3[2])+ " instead of " +str(HAPTB_OS)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong TB set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set TB parameter") - def set_all_values(self): - self.set_RD_value() - self.set_IS_value() - self.set_OS_value() - self.push_to_board() + self.check_values_inj() - ''' diff --git a/tabs/gm_vqwk.py b/tabs/gm_vqwk.py index 9931f7a..ca198be 100644 --- a/tabs/gm_vqwk.py +++ b/tabs/gm_vqwk.py @@ -8,18 +8,35 @@ import tkinter as tk from tkinter import ttk import utils as u +import distutils.util from ctypes import cdll +GM_VQWK =7000 +GM_VQWK_GET =7001 +GM_VQWK_SET =7002 +VQWK_GET_DATA =7001 +VQWK_SET_DATA =7002 +VQWK_SPB =701 +VQWK_GD =702 +VQWK_NB =703 +PATH ="/adaqfs/home/apar/devices/crl/injector/g0inj.flags" +HRSFLAG ="/adaqfs/home/apar/devices/PyGreenMonster/includeHRS.flags" + class VQWK(tk.Frame): def __init__(self, tab): - self.ch_frame = tk.LabelFrame(tab, text='CH', background=u.green_color, width=500) - self.inj_frame = tk.LabelFrame(tab, text='Inj', background=u.green_color, width=500) + self.ch_frame = tk.LabelFrame(tab, text='Counting House', background=u.green_color, width=500) + self.inj_frame = tk.LabelFrame(tab, text='Injector', background=u.green_color, width=500) + self.lft_spec_frame = tk.LabelFrame(tab, text='Left Spectrometer', background=u.green_color, width=500) + self.rt_spec_frame = tk.LabelFrame(tab, text='Right Spectrometer', background=u.green_color, width=500) + self.defaults_frame = tk.LabelFrame(tab, text='Default Controls', background=u.green_color, width=1000) + self.samples_ch_l = tk.Label(self.ch_frame, text='Samples Per Block', background=u.green_color) self.gate_ch_l = tk.Label(self.ch_frame, text='Gate Delay', background=u.green_color) self.blocks_ch_l = tk.Label(self.ch_frame, text='Number of Blocks', background=u.green_color) self.samples_ch_e = tk.Entry(self.ch_frame) self.gate_ch_e = tk.Entry(self.ch_frame) self.blocks_ch_e = tk.Entry(self.ch_frame) + self.includeHRSs = self.checkHRSflag(); self.fill_ch_frame() self.ch_frame.grid(row=0, column=0, padx=20, pady=10) @@ -32,90 +49,750 @@ def __init__(self, tab): self.fill_inj_frame() self.inj_frame.grid(row=0, column=1, padx=20, pady=10) + self.samples_lft_spec_l = tk.Label(self.lft_spec_frame, text='Samples Per Block', background=u.green_color) + self.gate_lft_spec_l = tk.Label(self.lft_spec_frame, text='Gate Delay', background=u.green_color) + self.blocks_lft_spec_l = tk.Label(self.lft_spec_frame, text='Number of Blocks', background=u.green_color) + self.samples_lft_spec_e = tk.Entry(self.lft_spec_frame) + self.gate_lft_spec_e = tk.Entry(self.lft_spec_frame) + self.blocks_lft_spec_e = tk.Entry(self.lft_spec_frame) + self.fill_lft_spec_frame() + self.lft_spec_frame.grid(row=1, column=0, padx=20, pady=10) + + self.samples_rt_spec_l = tk.Label(self.rt_spec_frame, text='Samples Per Block', background=u.green_color) + self.gate_rt_spec_l = tk.Label(self.rt_spec_frame, text='Gate Delay', background=u.green_color) + self.blocks_rt_spec_l = tk.Label(self.rt_spec_frame, text='Number of Blocks', background=u.green_color) + self.samples_rt_spec_e = tk.Entry(self.rt_spec_frame) + self.gate_rt_spec_e = tk.Entry(self.rt_spec_frame) + self.blocks_rt_spec_e = tk.Entry(self.rt_spec_frame) + self.fill_rt_spec_frame() + self.rt_spec_frame.grid(row=1, column=1, padx=20, pady=10) + + tk.Button(self.defaults_frame, text='Get All Values From Boards', background=u.green_color, command=self.check_all).grid( + row=0, column=0, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Set All Values to Boards', background=u.green_color, command=self.set_all).grid( + row=0, column=1, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Get All Default Values From Inj File', background=u.green_color, command=self.read_defaults).grid( + row=1, column=0, padx=10, pady=10) + tk.Button(self.defaults_frame, text='Write Inj Values to Defaults File', background=u.green_color, command=self.set_defaults).grid( + row=1, column=1, padx=10, pady=10) + + self.defaults_frame.grid(row=2, column=0, padx=20, pady=10, columnspan=2) + + #self.read_defaults() + #self.set_all() + self.check_all() + + def checkHRSflag(self): + hrsinfile = open(HRSFLAG,'r') + tmp="False" + for line in hrsinfile: + print("Include HRSs = " + line) + tmp=bool(distutils.util.strtobool(line.strip('\n'))) + print("Include HRSs = " + str(tmp)) + return tmp + + def read_defaults(self): + global samplesCH + global gateCH + global blocksCH + global samplesINJ + global gateINJ + global blocksINJ + global samplesRHRS + global gateRHRS + global blocksRHRS + global samplesLHRS + global gateLHRS + global blocksLHRS + + infile = open(PATH,'r') + for line in infile: + if (line[0] == ';'): + continue + else: + samplesINJ = int(line[(line.index("vqwksamples=") + 12):line.index(",vqwkdelay=")]) + gateINJ = int(line[(line.index("vqwkdelay=") + 10):line.index(",vqwkblocks=")]) + blocksINJ = int(line[(line.index("vqwkblocks=") + 11):line.index(",vqwkperiod=")]) + + samplesCH = samplesINJ + samplesRHRS = samplesINJ + samplesLHRS = samplesINJ + + gateCH = gateINJ + gateRHRS = gateINJ + gateLHRS = gateINJ + + blocksCH = blocksINJ + blocksRHRS = blocksINJ + blocksLHRS = blocksINJ + + #samplesCH = int(line[(line.index("CHvqwksamples=") + 14):line.index(", CHvqwkdelay=")]) + #gateCH = int(line[(line.index("CHvqwkdelay=") + 12):line.index(", CHvqwkblocks=")]) + #blocksCH = int(line[(line.index("CHvqwkblocks=") + 13):line.index(", CHvqwkperiod=")]) + + #samplesINJ = int(line[(line.index("INJvqwksamples=") + 15):line.index(", INJvqwkdelay=")]) + #gateINJ = int(line[(line.index("INJvqwkdelay=") + 13):line.index(", INJvqwkblocks=")]) + #blocksINJ = int(line[(line.index("INJvqwkblocks=") + 14):line.index(", INJvqwkperiod=")]) + + #samplesRHRS = int(line[(line.index("RHRSvqwksamples=") + 16):line.index(", RHRSvqwkdelay=")]) + #gateRHRS = int(line[(line.index("RHRSvqwkdelay=") + 14):line.index(", RHRSvqwkblocks=")]) + #blocksRHRS = int(line[(line.index("RHRSvqwkblocks=") + 15):line.index(", RHRSvqwkperiod=")]) + + #samplesLHRS = int(line[(line.index("LHRSvqwksamples=") + 16):line.index(", LHRSvqwkdelay=")]) + #gateLHRS = int(line[(line.index("LHRSvqwkdelay=") + 14):line.index(", LHRSvqwkblocks=")]) + #blocksLHRS = int(line[(line.index("LHRSvqwkblocks=") + 15):line.index(", LHRSvqwkperiod=")]) + infile.close() + + self.samples_ch_e.delete(0, tk.END) + self.samples_ch_e.insert(0, str(samplesCH)) + + self.gate_ch_e.delete(0, tk.END) + self.gate_ch_e.insert(0, str(gateCH)) + + self.blocks_ch_e.delete(0, tk.END) + self.blocks_ch_e.insert(0, str(blocksCH)) + + self.samples_inj_e.delete(0, tk.END) + self.samples_inj_e.insert(0, str(samplesINJ)) + + self.gate_inj_e.delete(0, tk.END) + self.gate_inj_e.insert(0, str(gateINJ)) + + self.blocks_inj_e.delete(0, tk.END) + self.blocks_inj_e.insert(0, str(blocksINJ)) + + self.samples_rt_spec_e.delete(0, tk.END) + self.samples_rt_spec_e.insert(0, str(samplesRHRS)) + + self.gate_rt_spec_e.delete(0, tk.END) + self.gate_rt_spec_e.insert(0, str(gateRHRS)) + + self.blocks_rt_spec_e.delete(0, tk.END) + self.blocks_rt_spec_e.insert(0, str(blocksRHRS)) + + self.samples_lft_spec_e.delete(0, tk.END) + self.samples_lft_spec_e.insert(0, str(samplesLHRS)) + + self.gate_lft_spec_e.delete(0, tk.END) + self.gate_lft_spec_e.insert(0, str(gateLHRS)) + + self.blocks_lft_spec_e.delete(0, tk.END) + self.blocks_lft_spec_e.insert(0, str(blocksLHRS)) + + def set_defaults(self): + samplesCH = int(self.samples_ch_e.get()) + gateCH = int(self.gate_ch_e.get()) + blocksCH = int(self.blocks_ch_e.get()) + + samplesINJ = int(self.samples_inj_e.get()) + gateINJ = int(self.gate_inj_e.get()) + blocksINJ = int(self.blocks_inj_e.get()) + + samplesRHRS = int(self.samples_rt_spec_e.get()) + gateRHRS = int(self.gate_rt_spec_e.get()) + blocksRHRS = int(self.blocks_rt_spec_e.get()) + + samplesLHRS = int(self.samples_lft_spec_e.get()) + gateLHRS = int(self.gate_lft_spec_e.get()) + blocksLHRS = int(self.blocks_lft_spec_e.get()) + + newdefaultstring = "crateheader=3,badc=0x80,nadc=10,vqwksamples="+str(samplesCH)+",vqwkdelay="+str(gateCH)+",vqwkblocks="+str(blocksCH)+",vqwkperiod=0,vqwkinternal=2,nscaler=1\n" + + #newdefaultstringCH = "CHcrateheader=3, CHbadc=0x80, CHnadc=10, CHvqwksamples="+str(samplesCH)+", CHvqwkdelay="+str(gateCH)+", CHvqwkblocks="+str(blocksCH)+", CHvqwkperiod=0, CHvqwkinternal=2, CHnscaler=1, " + #newdefaultstringINJ = "INJcrateheader=3, INJbadc=0x80, INJnadc=10, INJvqwksamples="+str(samplesINJ)+", INJvqwkdelay="+str(gateINJ)+", INJvqwkblocks="+str(blocksINJ)+", INJvqwkperiod=0, INJvqwkinternal=2, INJnscaler=1, " + #newdefaultstringRHRS = "RHRScrateheader=3, RHRSbadc=0x80, RHRSnadc=10, RHRSvqwksamples="+str(samplesRHRS)+", RHRSvqwkdelay="+str(gateRHRS)+", RHRSvqwkblocks="+str(blocksRHRS)+", RHRSvqwkperiod=0, RHRSvqwkinternal=2, RHRSnscaler=1, " + #newdefaultstringLHRS = "LHRScrateheader=3, LHRSbadc=0x80, LHRSnadc=10, LHRSvqwksamples="+str(samplesLHRS)+", LHRSvqwkdelay="+str(gateLHRS)+", LHRSvqwkblocks="+str(blocksLHRS)+", LHRSvqwkperiod=0, LHRSvqwkinternal=2, LHRSnscaler=1\n" + + buff = [] + i = 0 + autogen = 0 + infile = open(PATH,'r') + for line in infile: + if (line == ";;;;;;;LINES BELOW ARE AUTOGENERATED;;;;;;;\n"): + autogen = 1 + buff.append(line) + i+=1 + continue + if (autogen == 0): + buff.append(line) + i+=1 + if (line[0] != ';' and autogen == 0): + buff[i-1] = (";" + line) + infile.close() + + buff.append(newdefaultstring) + #buff.append(newdefaultstringCH + newdefaultstringINJ + newdefaultstringRHRS + newdefaultstringLHRS) + + outfile = open(PATH,'w') + for i in range(len(buff)): + outfile.write(buff[i]) + outfile.close() + + + def check_all(self): + self.check_values_ch() + self.check_values_inj() + # no HRS + if self.includeHRSs: + self.check_values_lft_spec() + self.check_values_rt_spec() + + def set_all(self): + self.set_values_ch() + self.set_values_inj() + # no HRS + if self.includeHRSs: + self.set_values_lft_spec() + self.set_values_rt_spec() + def fill_ch_frame(self): self.samples_ch_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') self.gate_ch_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') self.blocks_ch_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') - u.set_text(self.samples_ch_e, '4141').grid(row=0, column=1) - u.set_text(self.gate_ch_e, '10').grid(row=1, column=1) - u.set_text(self.blocks_ch_e, '4').grid(row=2, column=1) - tk.Button(self.ch_frame, text='Get Settings', background=u.green_color).grid( + u.set_text(self.samples_ch_e, '0').grid(row=0, column=1) + u.set_text(self.gate_ch_e, '0').grid(row=1, column=1) + u.set_text(self.blocks_ch_e, '0').grid(row=2, column=1) + tk.Button(self.ch_frame, text='Get Settings', background=u.green_color, command=self.check_values_ch).grid( row=3, column=0, pady=10) - tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color).grid( + tk.Button(self.ch_frame, text='Apply Settings', background=u.green_color, command=self.set_values_ch).grid( row=3, column=1, pady=10) def fill_inj_frame(self): self.samples_inj_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') self.gate_inj_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') self.blocks_inj_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') - u.set_text(self.samples_inj_e, '496').grid(row=0, column=1) - u.set_text(self.gate_inj_e, '10').grid(row=1, column=1) - u.set_text(self.blocks_inj_e, '4').grid(row=2, column=1) - tk.Button(self.inj_frame, text='Get Settings', background=u.green_color).grid( + u.set_text(self.samples_inj_e, '0').grid(row=0, column=1) + u.set_text(self.gate_inj_e, '0').grid(row=1, column=1) + u.set_text(self.blocks_inj_e, '0').grid(row=2, column=1) + tk.Button(self.inj_frame, text='Get Settings', background=u.green_color, command=self.check_values_inj).grid( + row=3, column=0, pady=10) + tk.Button(self.inj_frame, text='Apply Settings', background=u.green_color, command=self.set_values_inj).grid( + row=3, column=1, pady=10) + + def fill_lft_spec_frame(self): + self.samples_lft_spec_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') + self.gate_lft_spec_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') + self.blocks_lft_spec_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') + u.set_text(self.samples_lft_spec_e, '0').grid(row=0, column=1) + u.set_text(self.gate_lft_spec_e, '0').grid(row=1, column=1) + u.set_text(self.blocks_lft_spec_e, '0').grid(row=2, column=1) + tk.Button(self.lft_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values_lft_spec).grid( row=3, column=0, pady=10) - tk.Button(self.inj_frame, text='Apply Settings', background=u.green_color).grid( + tk.Button(self.lft_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values_lft_spec).grid( row=3, column=1, pady=10) - ''' - def get_samp_ch(self): - new_samp = self.lib.getSampVal1(self.obj) - self.samples_ch_e = u.set_text(self.samples_ch_e, new_samp) + def fill_rt_spec_frame(self): + self.samples_rt_spec_l.grid(row=0, column=0, padx=10, pady=5, sticky='W') + self.gate_rt_spec_l.grid(row=1, column=0, padx=10, pady=5, sticky='W') + self.blocks_rt_spec_l.grid(row=2, column=0, padx=10, pady=5, sticky='W') + u.set_text(self.samples_rt_spec_e, '0').grid(row=0, column=1) + u.set_text(self.gate_rt_spec_e, '0').grid(row=1, column=1) + u.set_text(self.blocks_rt_spec_e, '0').grid(row=2, column=1) + tk.Button(self.rt_spec_frame, text='Get Settings', background=u.green_color, command=self.check_values_rt_spec).grid( + row=3, column=0, pady=10) + tk.Button(self.rt_spec_frame, text='Apply Settings', background=u.green_color, command=self.set_values_rt_spec).grid( + row=3, column=1, pady=10) + + def check_values_ch(self): + packet1 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_SPB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_CH, packet1) + + print("COMMAND_VQWK is " + str(u.COMMAND_VQWK)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentSPB = int(reply1[3]) + self.samples_ch_e.delete(0, tk.END) + self.samples_ch_e.insert(0, str(CurrentSPB)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_GD, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_CH, packet2) + + if err_flag == u.SOCK_OK: + CurrentGD = int(reply2[3]) + self.gate_ch_e.delete(0, tk.END) + self.gate_ch_e.insert(0, str(CurrentGD)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_NB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_CH, packet3) + + if err_flag == u.SOCK_OK: + CurrentNB = int(reply3[3]) + self.blocks_ch_e.delete(0, tk.END) + self.blocks_ch_e.insert(0, str(CurrentNB)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_inj(self): + packet1 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_SPB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_INJ, packet1) + + print("COMMAND_VQWK is " + str(u.COMMAND_VQWK)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentSPB = int(reply1[3]) + self.samples_inj_e.delete(0, tk.END) + self.samples_inj_e.insert(0, str(CurrentSPB)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_GD, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_INJ, packet2) + + if err_flag == u.SOCK_OK: + CurrentGD = int(reply2[3]) + self.gate_inj_e.delete(0, tk.END) + self.gate_inj_e.insert(0, str(CurrentGD)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_NB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_INJ, packet3) + + if err_flag == u.SOCK_OK: + CurrentNB = int(reply3[3]) + self.blocks_inj_e.delete(0, tk.END) + self.blocks_inj_e.insert(0, str(CurrentNB)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_lft_spec(self): + packet1 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_SPB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_LHRS, packet1) + + print("COMMAND_VQWK is " + str(u.COMMAND_VQWK)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentSPB = int(reply1[3]) + self.samples_lft_spec_e.delete(0, tk.END) + self.samples_lft_spec_e.insert(0, str(CurrentSPB)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_GD, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_LHRS, packet2) + + if err_flag == u.SOCK_OK: + CurrentGD = int(reply2[3]) + self.gate_lft_spec_e.delete(0, tk.END) + self.gate_lft_spec_e.insert(0, str(CurrentGD)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_NB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_LHRS, packet3) + + if err_flag == u.SOCK_OK: + CurrentNB = int(reply3[3]) + self.blocks_lft_spec_e.delete(0, tk.END) + self.blocks_lft_spec_e.insert(0, str(CurrentNB)) + + else: + print("ERROR, Could not access socket.") + return + + def check_values_rt_spec(self): + packet1 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_SPB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_RHRS, packet1) + + print("COMMAND_VQWK is " + str(u.COMMAND_VQWK)) + print("cfSockCommand returned : " + str(err_flag)) + + if err_flag == u.SOCK_OK: + CurrentSPB = int(reply1[3]) + self.samples_rt_spec_e.delete(0, tk.END) + self.samples_rt_spec_e.insert(0, str(CurrentSPB)) + + else: + print("ERROR, Could not access socket.") + return + + packet2 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_GD, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_RHRS, packet2) + + if err_flag == u.SOCK_OK: + CurrentGD = int(reply2[3]) + self.gate_rt_spec_e.delete(0, tk.END) + self.gate_rt_spec_e.insert(0, str(CurrentGD)) + + else: + print("ERROR, Could not access socket.") + return + + packet3 = [u.COMMAND_VQWK, VQWK_GET_DATA, VQWK_NB, 0, 0, "VQWK Get Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_RHRS, packet3) + + if err_flag == u.SOCK_OK: + CurrentNB = int(reply3[3]) + self.blocks_rt_spec_e.delete(0, tk.END) + self.blocks_rt_spec_e.insert(0, str(CurrentNB)) + + else: + print("ERROR, Could not access socket.") + return + + def set_values_ch(self): - def set_samp_ch(self): - self.lib.setSampVal1(self.obj, int(self.samples_ch_e.get())) + value1 = int(self.samples_ch_e.get()) + value2 = int(self.gate_ch_e.get()) + value3 = int(self.blocks_ch_e.get()) - def get_gate_ch(self): - new_gate = self.lib.getGateVal1(self.obj) - self.gate_ch_e = u.set_text(self.gate_ch_e, new_gate) + i = 0 + while (i <= 10): + packet1 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_SPB, value1, i, "VQWK Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_CH, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != VQWK_SPB: + print("Server replied with wrong VQWK number: " +str(reply1[2])+ " instead of " +str(VQWK_SPB)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong VQWK set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 - def set_gate_ch(self): - self.lib.setGateVal1(self.obj, int(self.gate_ch_e.get())) + i = 0 + while (i <= 10): + packet2 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_GD, value2, i, "VQWK Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_CH, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != VQWK_GD: + print("Server replied with wrong VQWK number: " +str(reply2[2])+ " instead of " +str(VQWK_GD)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong VQWK set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + i = 0 + while (i <= 10): + packet3 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_NB, value3, 0, "VQWK Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_CH, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != VQWK_NB: + print("Server replied with wrong VQWK number: " +str(reply3[2])+ " instead of " +str(VQWK_NB)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong VQWK set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + self.check_values_ch() - def get_blocks_ch(self): - new_blok = self.lib.getBlokVal1(self.obj) - self.blocks_ch_e = u.set_text(self.blocks_ch_e, new_blok) + def set_values_inj(self): - def set_blocks_ch(self): - self.lib.setBlokVal1(self.obj, int(self.blocks_ch_e.get())) + value1 = int(self.samples_inj_e.get()) + value2 = int(self.gate_inj_e.get()) + value3 = int(self.blocks_inj_e.get()) - def get_samp_inj(self): - new_samp = self.lib.getSampVal2(self.obj) - self.samples_inj_e = u.set_text(self.samples_inj_e, new_samp) + i = 0 + while (i <= 10): + packet1 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_SPB, value1, i, "VQWK Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_INJ, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != VQWK_SPB: + print("Server replied with wrong VQWK number: " +str(reply1[2])+ " instead of " +str(VQWK_SPB)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong VQWK set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 - def set_samp_inj(self): - self.lib.setSampVal2(self.obj, int(self.samples_inj_e.get())) + i = 0 + while (i <= 10): + packet2 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_GD, value2, i, "VQWK Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_INJ, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != VQWK_GD: + print("Server replied with wrong VQWK number: " +str(reply2[2])+ " instead of " +str(VQWK_GD)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong VQWK set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + i = 0 + while (i <= 10): + packet3 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_NB, value3, 0, "VQWK Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_INJ, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != VQWK_NB: + print("Server replied with wrong VQWK number: " +str(reply3[2])+ " instead of " +str(VQWK_NB)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong VQWK set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + self.check_values_inj() - def get_gate_inj(self): - new_gate = self.lib.getGateVal2(self.obj) - self.gate_inj_e = u.set_text(self.gate_inj_e, new_gate) + def set_values_lft_spec(self): - def set_gate_inj(self): - self.lib.setGateVal2(self.obj, int(self.gate_inj_e.get())) + value1 = int(self.samples_lft_spec_e.get()) + value2 = int(self.gate_lft_spec_e.get()) + value3 = int(self.blocks_lft_spec_e.get()) - def get_blocks_inj(self): - new_blok = self.lib.getBlokVal2(self.obj) - self.blocks_inj_e = u.set_text(self.blocks_inj_e, new_blok) + i = 0 + while (i <= 10): + packet1 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_SPB, value1, i, "VQWK Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_LHRS, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != VQWK_SPB: + print("Server replied with wrong VQWK number: " +str(reply1[2])+ " instead of " +str(VQWK_SPB)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong VQWK set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 - def set_blocks_inj(self): - self.lib.setBlokVal2(self.obj, int(self.blocks_inj_e.get())) + i = 0 + while (i <= 10): + packet2 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_GD, value2, i, "VQWK Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_LHRS, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != VQWK_GD: + print("Server replied with wrong VQWK number: " +str(reply2[2])+ " instead of " +str(VQWK_GD)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong VQWK set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + i = 0 + while (i <= 10): + packet3 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_NB, value3, 0, "VQWK Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_LHRS, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != VQWK_NB: + print("Server replied with wrong VQWK number: " +str(reply3[2])+ " instead of " +str(VQWK_NB)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong VQWK set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + self.check_values_lft_spec() - def get_settings_ch(self): - self.get_samp_ch() - self.get_gate_ch() - self.get_blocks_ch() + def set_values_rt_spec(self): - def set_settings_ch(self): - self.set_samp_ch() - self.set_gate_ch() - self.set_blocks_ch() + value1 = int(self.samples_rt_spec_e.get()) + value2 = int(self.gate_rt_spec_e.get()) + value3 = int(self.blocks_rt_spec_e.get()) - def get_settings_inj(self): - self.get_samp_inj() - self.get_gate_inj() - self.get_blocks_inj() + i = 0 + while (i <= 10): + packet1 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_SPB, value1, i, "VQWK Set Data", "Y"] + err_flag, reply1 = u.send_command(u.Crate_RHRS, packet1) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply1[1] != 1: + if reply1[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply1[1])) + othererror = 1 + else: + if reply1[2] != VQWK_SPB: + print("Server replied with wrong VQWK number: " +str(reply1[2])+ " instead of " +str(VQWK_SPB)) + othererror = 1 + if reply1[3] != value1: + print("Server replied with wrong VQWK set value: " +str(reply1[3])+ " instead of " +str(value1)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 - def set_settings_inj(self): - self.set_samp_inj() - self.set_gate_inj() - self.set_blocks_inj() - ''' + i = 0 + while (i <= 10): + packet2 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_GD, value2, i, "VQWK Set Data", "Y"] + err_flag, reply2 = u.send_command(u.Crate_RHRS, packet2) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply2[1] != 1: + if reply2[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply2[1])) + othererror = 1 + else: + if reply2[2] != VQWK_GD: + print("Server replied with wrong VQWK number: " +str(reply2[2])+ " instead of " +str(VQWK_GD)) + othererror = 1 + if reply2[3] != value2: + print("Server replied with wrong VQWK set value: " +str(reply2[3])+ " instead of " +str(value2)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + i = 0 + while (i <= 10): + packet3 = [u.COMMAND_VQWK, VQWK_SET_DATA, VQWK_NB, value3, 0, "VQWK Set Data", "Y"] + err_flag, reply3 = u.send_command(u.Crate_RHRS, packet3) + + othererror = 0 + if err_flag == u.SOCK_OK: + if reply3[1] != 1: + if reply3[1] == -2: + print("Cannot set parameter, CODA run in progress!") + else: + print("Error:Server replied with VQWK error code: " + str(reply3[1])) + othererror = 1 + else: + if reply3[2] != VQWK_NB: + print("Server replied with wrong VQWK number: " +str(reply3[2])+ " instead of " +str(VQWK_NB)) + othererror = 1 + if reply3[3] != value3: + print("Server replied with wrong VQWK set value: " +str(reply3[3])+ " instead of " +str(value3)) + othererror = 1 + else: + print(" check_status: ERROR, Could not access socket.") + if othererror == 1: + print("Unknown error, cannot set VQWK parameter") + i += 1 + + self.check_values_rt_spec() diff --git a/tabs/gm_vxworks.py b/tabs/gm_vxworks.py index e5fa886..f9d4ff9 100644 --- a/tabs/gm_vxworks.py +++ b/tabs/gm_vxworks.py @@ -9,12 +9,40 @@ from tkinter import ttk import utils as u +KILL_SERVER_1 =5001 +KILL_SERVER_2 =5002 +KILL_SERVER_3 =5003 +KILL_SERVER_4 =5004 +KILL_SERVER_5 =5005 class VXWorks(tk.Frame): def __init__(self, tab): self.vx_frame = tk.Frame(tab, bg=u.green_color) - tk.Button(self.vx_frame, text='Kill VXWorks Server, CH', bg=u.green_color, width=30).grid( - row=0, column=0, padx=2, pady=2) - tk.Button(self.vx_frame, text='Kill VXWorks Server, Inj', bg=u.green_color, width=30).grid( - row=1, column=0, padx=2, pady=2) + self.crateStrings = ["Kill VXWorks Server, CH","Kill VXWorks Server, INJ","Kill VXWorks Server, LftSpec","Kill VXWorks Server, RtSpec"] + self.crateNumbers = [u.Crate_CH,u.Crate_INJ,u.Crate_LHRS,u.Crate_RHRS] + self.buttonsList = [] + for counter in range(0,len(self.crateStrings)): + self.buttonsList.append(tk.Button(self.vx_frame, text=self.crateStrings[counter], bg=u.green_color, width=30, command=self.kill_server)) + self.buttonsList[counter].crateN = self.crateNumbers[counter] + self.buttonsList[counter].crateName = self.crateStrings[counter] + self.buttonsList[counter].config(command = lambda but=self.buttonsList[counter]: self.kill_server(but)) + + self.buttonsList[counter].grid(row=counter, column=0, padx=2, pady=2) self.vx_frame.place(relx=0.5, rely=0.5, anchor=tk.CENTER) + + def kill_server(self,but): + #packet = [10, 10, 1, 2, 3, "Kill Server", "N"] + #packet = [10, 10, 1, 2, 3, "Y", "Q"] + #packet = [10, 10, 1, 2, 3, "Y", "Kill Server"] + #packet = [10, 10, 1, 2, 3, "Kill Server", "Y"] + #packet = [10, 10, 1, 2, 3, 1, tmpVar] + packet = [10, 10, 1, 2, 3, "Not Q", "N"] + err_flag, reply = u.send_command(but.crateN, packet) + print("Reply = {}".format(reply)) + + if err_flag == u.SOCK_OK: + print("{}".format(but.crateName)) + + else: + print("ERROR, Could not access socket.") + return -1 diff --git a/utils.py b/utils.py index b75311b..31d2743 100644 --- a/utils.py +++ b/utils.py @@ -17,8 +17,12 @@ COMMAND_SCAN = 5000; COMMAND_ADC18 = 6000 COMMAND_VQWK = 7000 -Crate_CH = 0; Crate_INJ = 1 -Crate_LHRS = 2; Crate_RHRS = 3 +#Crate_CH = 0; Crate_INJ = 1 +#Crate_LHRS = 2; Crate_RHRS = 3 +#Crate_Test = 4 + +Crate_CH = 0; Crate_LHRS = 1 +Crate_RHRS = 2; Crate_INJ = 3 Crate_Test = 4 def set_text(entry, text): @@ -46,12 +50,23 @@ def send_command(crate_num, packet): err_flag = lib.GMSockCommand(crate_num, packet[0], packet[1], packet[2], packet[3], packet[4]) + replyBool = "Y" ind = 0; reply = [] fin = open('reply.txt') - for line in fin.readlines(): - if ind < 5: reply += [int(line)] - else: reply += [str(line)] - ind += 1 + if (len(packet)>6): + replyBool = packet[6] + #print("Reply status declared = {}".format(packet[6])) + if replyBool == "Y" or replyBool == 'Y': + #print("Reply requested") + for line in fin.readlines(): + if ind < 5: + reply += [int(line)] + else: + reply += [str(line)] + ind += 1 + else: + #print("Reply not requested") + reply = "No Reply" fin.close() os.remove('reply.txt')