Commit 5e99bd6e authored by Matheus Müller's avatar Matheus Müller
Browse files

Pause longo nao causa mais buffer overflow, interface ajustada para tela menor

log scale e channel to energy ainda nao funcionam, bugs de infinite float e desconhecido, respectivamente
parent 4534a75b
......@@ -229,6 +229,146 @@ int main(int argc, char **argv)
}
}
if( kbhit()) {
switch( getch()) {
case 'r':
case 'R':
// reset the histogram here
//memset( histo_buff, 0, N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff));
for(w=0; w<8192; w++)
histograma[w] = 0;
if( ( N957_error_code= N957_SwClear(user_setting.m_N957_handle)!= N957Success))
{
ret_val= -25;
goto exit_point;
}
tempo_pause = 0;
nmr_ADC_pause=0;
tempo_pause_vivo=0;
break;
case 'p':
case 'P':
if(!paused)
{
if( ( N957_error_code= N957_StopAcquire( user_setting.m_N957_handle))!= N957Success)
{
ret_val= -24;
goto exit_point;
}
}
if(paused)
{
N957_GetScaler(user_setting.m_N957_handle, &data32);
nmr_ADC_pause= nmr_ADC_pause + data32;
N957_GetTimer(user_setting.m_N957_handle, &data32);
tempo_pause = tempo_pause + data32;
N957_GetLiveTime(user_setting.m_N957_handle, &data32);
tempo_pause_vivo = tempo_pause_vivo + data32;
if( ( N957_error_code= N957_StartAcquire( user_setting.m_N957_handle, user_setting.m_mode))!= N957Success)
{
ret_val= -8;
goto exit_point;
}
if( user_setting.m_debug) {
if( ( N957_error_code= N957_SetSwConvFlag( user_setting.m_N957_handle, N957_TRUE))!= N957Success)
{
ret_val= -9;
goto exit_point;
}
}
data_buff= malloc( user_setting.m_bldim* sizeof( N957_UINT16));
if( data_buff== NULL)
{
ret_val= -10;
goto exit_point;
}
histo_buff= malloc( N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff));
if( histo_buff== NULL)
{
ret_val= -11;
goto exit_point;
}
memset( histo_buff, 0, N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff));
}
paused= !paused;
break;
case 'a':
fator = 1;
break;
case 'b':
fator = 2;
break;
case 'c':
fator = 4;
break;
case 'd':
fator = 8;
break;
case 'e':
fator = 16;
break;
case 'f':
fator = 32;
break;
case 'g':
fator = 64;
break;
case 'h':
fator = 128;
break;
case 'i':
TRACE("[");
for(w=0; w<(8192-fator+1); w)
{
for(ii=w; ii<=(w+fator-1); ii++)
temp = temp + histograma[ii];
TRACE1("%i",temp);
if (w!=(8192-fator))
TRACE(",");
temp = 0;
w=w+fator;
}
TRACE("]\n");
N957_GetScaler(user_setting.m_N957_handle, &data32);
TRACE1("%d\n",data32 + nmr_ADC_pause);
N957_GetTimer(user_setting.m_N957_handle, &data32);
TRACE1("%d\n",data32 +tempo_pause);
N957_GetLiveTime(user_setting.m_N957_handle, &data32);
TRACE1("%d\n",data32 +tempo_pause_vivo);
break;
case 'j':
lldt = lldt + 1;
break;
case 'l':
N957_SetLLD( user_setting.m_N957_handle, lldt);
lldt=0;
break;
case 'z':
log = fopen("save.dat", "w+");
for(w=0; w<8192; w++)
fprintf(log, "%i\n", histograma[w]);
fclose(log);
break;
case 'y':
log = fopen("save.dat", "r");
for(w=0; w<(8192-fator+1); w=w+fator)
{
fscanf(log, "%i", &temp);
for(i=w; i<=(w+fator-1); i++)
histograma[i] = temp/fator;
}
fclose(log);
break;
default:
do_exit= TRUE;
break;
}
do_exit= FALSE;
while( !do_exit) {
......
......@@ -14,6 +14,7 @@ from pylab import *
from clsbeep import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib import pyplot
##############################################################################
##############################################################################
......@@ -31,9 +32,10 @@ sys.setrecursionlimit(5000)
f = plt.figure()
a = f.add_subplot(111)
Control = dict(t=1200, bmin=0, bmax=8192, bmaxold=512, j=0, filename='temp', count=0, paused=False, ROIctrl=list())
PlotLimControl = dict(limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0., area=f.canvas.get_tk_widget().create_rectangle(0,0,0,0))
PlotLimControl = dict(limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0., area=f.canvas.get_tk_widget().create_rectangle(0,0,0,0), ctoe=False, a=0, b=0)
Data=list()
ROIs=list()
LSvar = 0
for j in range(8192):
Data.insert(j, 0)
......@@ -140,7 +142,7 @@ def roiroi():
##############################################################################
##############################################################################
Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(), entries=list(), labelframes=list())
Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(), entries=list(), labelframes=list(), checkboxes=list())
Livetime = dict(ADC_Conversion=0 , Time=0. , LiveTime=0. )
def set_fator(canais): # Define o fator para conversao do numero de canais
......@@ -187,8 +189,13 @@ def settime():
Interface['labels'][2].configure(text='Live Time: %ss' %str(Livetime['LiveTime']/1000))
def graphic2(Data): #Plot
temp.set_xdata(range(int(Interface['spinboxes'][0].get())))
if PlotLimControl['ctoe'] == True:
temp.set_xdata(range(int(Interface['spinboxes'][0].get()))*PlotLimControl['a']+PlotLimControl['b'])
else:
temp.set_xdata(range(int(Interface['spinboxes'][0].get())))
temp.set_ydata(Data)
if LSvar == 1:
a.set_yscale('log')
if PlotLimControl['limupdt']:
plt.xlim(Control['bmin'], Control['bmax'])
plt.ylim(0, max(Data[int(Control['bmin']):int(Control['bmax'])])*1.2)
......@@ -322,6 +329,39 @@ def lldt():
lldtbut.pack(side='left')
lldtwin.mainloop()
def ctoe():
ctoewin = tk.Tk()
ctoewin.title('Channel to Energy')
ctoeent = tk.Entry(ctoewin)
ctoeent.pack(side='left')
ctoelab = tk.Label(ctoewin, text='ax')
ctoelab.pack(side='left')
ctoeent2 = tk.Entry(ctoewin)
ctoeent2.pack(side='left')
ctoelab = tk.Label(ctoewin, text='+b')
ctoelab.pack(side='left')
ctoeent2 = tk.Entry(ctoewin)
ctoeent2.pack(side='left')
ctoelab = tk.Label(ctoewin, text='Unit(Kev, MeV,...)')
ctoelab.pack(side='left')
def setlldt():
global child
if ctoeent.get().isdigit() and ctoeent2.get().isdigit() :
if int(ctoeent.get()) == 0 and int(ctoeent2.get()) == 0 :
PlotLimControl['ctoe']=False
else:
PlotLimControl['ctoe']=True
PlotLimControl['a']=int(ctoeent.get())
PlotLimControl['b']=int(ctoeent2.get())
ctoewin.destroy()
else:
tkMessageBox.showinfo("Error", "Invalid value")
ctoebut = tk.Button(ctoewin, text = 'Set', command = lambda i=i: setlldt(), bd=2, width=7, height=1)
ctoebut.pack(side='left')
ctoewin.mainloop()
##############################################################################
##############################################################################
# Safe Exit
......@@ -346,9 +386,9 @@ Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][0], relief='
for i in range(2):
Interface['labelframes'][i].pack(side='right')
Interface['labels'].insert(0,tk.Label(Interface['labelframes'][1], text='ADC Conversions: %s' %Livetime['ADC_Conversion'], width=25, height=1, bg='grey'))
Interface['labels'].insert(1,tk.Label(Interface['labelframes'][1], text='Total Time: %s' %Livetime['Time'], width=22, height=1, bg='grey'))
Interface['labels'].insert(2,tk.Label(Interface['labelframes'][1], text='Live Time: %s' %Livetime['LiveTime'], width=22, height=1, bg='grey'))
Interface['labels'].insert(0,tk.Label(Interface['labelframes'][1], text='ADC Conversions: %s' %Livetime['ADC_Conversion'], width=19, height=2, bg='grey'))
Interface['labels'].insert(1,tk.Label(Interface['labelframes'][1], text='Total Time: %s' %Livetime['Time'], width=18, height=2, bg='grey'))
Interface['labels'].insert(2,tk.Label(Interface['labelframes'][1], text='Live Time: %s' %Livetime['LiveTime'], width=18, height=2, bg='grey'))
for i in range(3):
Interface['frames'].insert((i+4), tk.Frame(Interface['labelframes'][0]))
......@@ -358,14 +398,24 @@ for i in range(3):
Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][0], command = lambda i=i: set_fator(Interface['spinboxes'][0].get()), values=[64,128,256,512,1024,2048,4096,8192], state = 'readonly', bg='grey'))
Interface['spinboxes'][0].pack()
def lsvartog():
global LSvar
if LSvar == 0:
LSvar = 1
else:
LSvar = 0
Interface['checkboxes'].insert(0, tk.Checkbutton(Interface['labelframes'][0], text='Log Scale', bg='grey', command= lambda i=i: lsvartog()))
Interface['checkboxes'][0].pack()
##############################################################################
# Menu
menubar = tk.Menu(root, relief='raised', bd=2)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command = lambda i=i:load())
filemenu.add_command(label="Exit", command = sys.exit)
settings = tk.Menu(menubar, tearoff=0)
settings.add_command(label="Channel to Energy conversion", command = lambda i=i:ctoe())
settings.add_command(label="Low level detect treshold", command = lambda i=i:lldt())
settings.add_command(label="Plot Refresh Rate", command = lambda i=i:refreshrate())
settings.add_command(label="Regions of Interest", command = lambda i=i: roiroi())
......@@ -375,11 +425,11 @@ menubar.add_cascade(label="Settings", menu=settings)
root.config(menu=menubar)
##############################################################################
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Start', command = lambda i=i: realtimeplot(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0], text = 'Pause', command = lambda i=i: pause(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0], text = 'Clear', command = lambda i=i: reset(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Save As', command = lambda i=i: saveas(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Start', command = lambda i=i: realtimeplot(), bd=2, width=8, height=1, bg='grey'))
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0], text = 'Pause', command = lambda i=i: pause(), bd=2, width=8, height=1, bg='grey'))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0], text = 'Clear', command = lambda i=i: reset(), bd=2, width=8, height=1, bg='grey'))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=8, height=1, bg='grey'))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Save As', command = lambda i=i: saveas(), bd=2, width=8, height=1, bg='grey'))
for i in range(4):
Interface['buttons'][i+1].pack(side = 'left', fill='both', expand=1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment