Commit 0d687cc9 authored by Matheus Müller's avatar Matheus Müller
Browse files

Tempo de aquisicao e pause implementados

modificada a forma de leitura dos dados
pequenas melhorias graficas
parent 53031a68
......@@ -270,28 +270,6 @@ int main(int argc, char **argv)
while( !do_exit) {
N957_UINT16 data_read;
//// Check for user commands
while( paused){
if( kbhit()) {
switch( getch()) {
case 'r':
case 'R':
// // reset the histogram here
memset( histo_buff, 0, N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff));
break;
case 'd':
while(getch() != 'e')
Sleep( 1);
case 'p':
case 'P':
paused= !paused;
break;
default:
ret_val= 0;
goto exit_point;
}
}
Sleep( 1);
}
data_read= user_setting.m_bldim;
if( user_setting.m_max_num_samples> 0){
......@@ -355,14 +333,24 @@ int main(int argc, char **argv)
fator = 128;
break;
case 'i':
TRACE("[");
for(w=0; w<(8192-fator+1); w)
{
for(i=w; i<=(w+fator-1); i++)
temp = temp + histograma[i];
TRACE1("%i\n",temp);
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);
N957_GetTimer(user_setting.m_N957_handle, &data32);
TRACE1("%d\n",data32);
N957_GetLiveTime(user_setting.m_N957_handle, &data32);
TRACE1("%d\n",data32);
break;
case 'z':
log = fopen("save.dat", "w+");
......@@ -388,7 +376,8 @@ int main(int argc, char **argv)
// Log to file (if enabled)
if( out_file) {
sprintf( aux_string, "%04d\n", data_buff[ i]);
histograma[atoi(aux_string)+1] = histograma[atoi(aux_string)+1] +1;
if (!paused)
histograma[atoi(aux_string)+1] = histograma[atoi(aux_string)+1] +1;
//TRACE1("%d \n", atoi(aux_string));
}
}
......@@ -409,39 +398,6 @@ int main(int argc, char **argv)
// TRACE( "Ok");
}
//Scaler Reading
// TRACE("\nADC Conversions Number : ");
if( ( N957_error_code=N957_GetScaler(user_setting.m_N957_handle, &data32)!= N957Success))
{
// TRACE( N957_DecodeError( N957_error_code));
// TRACE( "\n");
ret_val= -21;
goto exit_point;
}
TRACE1("%d\n", data32);
//Timer Reading
// TRACE("\nTime (ms) : ");
if( ( N957_error_code=N957_GetTimer(user_setting.m_N957_handle, &data32)!= N957Success))
{
// TRACE( N957_DecodeError( N957_error_code));
// TRACE( "\n");
ret_val= -22;
goto exit_point;
}
TRACE1("%d\n", data32);
//Live Time Reading
// TRACE("\nLive Time (ms) : ");
if( ( N957_error_code=N957_GetLiveTime(user_setting.m_N957_handle, &data32)!= N957Success))
{
// TRACE( N957_DecodeError( N957_error_code));
// TRACE( "\n");
ret_val= -23;
goto exit_point;
}
TRACE1("%d\n",data32);
exit_point:
/////////////////////////////////////////
// Library specific
......
......@@ -3,6 +3,7 @@
import os
import pexpect
import numpy as np
import Tkinter as tk
import tkMessageBox
import matplotlib.pyplot as plt
......@@ -20,12 +21,13 @@ import tkFileDialog
child = pexpect.spawn('./N957Run')
time.sleep(3.3)
child.send('s')
paused = False
##############################################################################
##############################################################################
# Histrogram
t = 2000
t = 2000 #Refresh rate
bmin = 0
bmax = 8192
Data=list()
......@@ -37,17 +39,28 @@ for a in range(8192):
# Main window
root = tk.Tk()
root.minsize(400,350)
root.minsize(825,640)
root.title('Modulo Multicanal')
#root.geometry('670x470+200+200')
##############################################################################
##############################################################################
# Atualiza grade do plot de acordo com regiao escolhida
def grid(a, n):
a.xaxis.set_major_locator(MultipleLocator(n/8))
a.xaxis.set_minor_locator(MultipleLocator(n/64))
a.grid(True)
a.xaxis.grid(True,'minor')
a.xaxis.grid(True,'major',linewidth=2)
##############################################################################
##############################################################################
Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(), entries=list(), labelframes=list())
Livetime = dict(ADC_Conversion='0' , Time='0' , LiveTime='0' )
def set_fator():
def set_fator(): # Define o fator para conversao do numero de canais
global Interface, child, bmax
if int(Interface['spinboxes'][0].get()) == 8192:
child.send('a')
......@@ -74,63 +87,74 @@ def set_fator():
child.send('h')
bmax = 64
def dump():
global child
child.send('i')
def settime():
Livetime['ADC_Conversion'] = child.readline().strip("\r\n")
Livetime['Time'] = child.readline().strip("\r\n")
Livetime['LiveTime'] = child.readline().strip("\r\n")
Interface['labels'][0].configure(text='ADC Conversions: %s' %Livetime['ADC_Conversion'])
Interface['labels'][1].configure(text='Total Time: %s' %Livetime['Time'])
Interface['labels'][2].configure(text='Live Time: %s' %Livetime['LiveTime'])
def graphic():
global child, Data, Interface, bmin, bmax
for n in arange(0, int(Interface['spinboxes'][0].get())):
Data[n] = int(child.readline().strip("\r\n"))
def graphic2(Data):
global Interface, bmin, bmax
temp.set_xdata(range(int(Interface['spinboxes'][0].get())))
temp.set_ydata(Data)
f.canvas.draw()
#plt.fill_between(range(8192),Data,0,color='0.8')
plt.xlim(bmin, bmax)
plt.ylim(0, max(Data[bmin:bmax])*1.1)
#show()
plt.ylim(0, max(Data[bmin:bmax])*1.2)
grid(a, int(Interface['spinboxes'][0].get()))
f.canvas.draw()
def graphic(): # Le os dados e plota o grafico
global child, Data
Data = eval(child.readline().strip("\r\n"))
graphic2(Data)
settime()
def dump(): # Sinal para programa coletor enviar os dados
global child
child.send('i')
def realtimeplot():
global t
dump()
try:
root.after(t, realtimeplot)
graphic()
except ValueError:
pass
def realtimeplot(): # Funcao recursiva pra plot em tempo real
global t, paused
if not paused:
dump()
try:
root.after(t, realtimeplot)
graphic()
except ValueError:
pass
##############################################################################
##############################################################################
# Control functions
def finish():
global child
child.send('j')
Livetime['ADC_Conversion'] = child.readline().strip("\r\n")
Livetime['Time'] = child.readline().strip("\r\n")
Livetime['LiveTime'] = child.readline().strip("\r\n")
Interface['labels'][0].configure(text='ADC Conversions: %s' %Livetime['ADC_Conversion'])
Interface['labels'][1].configure(text='Total Time: %s' %Livetime['Time'])
Interface['labels'][2].configure(text='Live Time: %s' %Livetime['LiveTime'])
def reset():
def reset(): # Zera o vetor de aquisicao
global child
child.send('r')
def pause():
global child
def pause(): # Para/Continua a aquisicao de dados
global child, paused
paused = not paused
child.send('p')
def restart():
def restart(): # Reinicia o programa de aquisicao
global child
child.send('j')
time.sleep(0.3)
child = pexpect.spawn('./N957Run')
time.sleep(3.3)
child.send('s')
def save():
global child
child.send('z')
def save(): # Salva os dados no arquivo selecionado
global child, Data
fname = tkFileDialog.asksaveasfile(mode='w')
for n in range(int(Interface['spinboxes'][0].get())):
fname.write(str(n+1)+' '+str(Data[n])+'\n')
fname.close()
#child.send('z')
def load():
def load(): # Manda os dados carregados para leitura
global child
child.send('y')
......@@ -143,10 +167,10 @@ def plotting():
else:
tkMessageBox.showinfo("Error", "Invalid values: Must be from 0 to 8192")
def refreshrate():
def refreshrate(): # Define a frequencia de atualizacao do grafico
global t
if Interface['entries'][2].get().isdigit():
if int(Interface['entries'][2].get()) > 799:
if int(Interface['entries'][2].get()) > 499: # Valores muito baixos causam stack overflow
t = int(Interface['entries'][2].get())
Interface['labelframes'][1].configure(text = 'Refresh Rate - %ims' %t)
else:
......@@ -203,19 +227,18 @@ for i in range(3):
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Plot', command = lambda i=i: realtimeplot(), bd=2, width=11, height=1))
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0], text = 'Pause', command = lambda i=i: pause(), bd=2, width=11, height=1))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0], text = 'Reset', command = lambda i=i: reset(), bd=2, width=11, height=1))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Finish', command = lambda i=i: finish(), bd=2, width=11, height=1))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Restart', command = lambda i=i: restart(), bd=2, width=11, height=1))
Interface['buttons'].insert(5, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=11, height=1))
Interface['buttons'].insert(6, tk.Button(Interface['frames'][0], text = 'Load', command = lambda i=i: load(), bd=2, width=11, height=1))
Interface['buttons'].insert(7, tk.Button(Interface['labelframes'][0], text = 'Change', command = lambda i=i: plotting(), bd=2, width=7, height=1))
Interface['buttons'].insert(8, tk.Button(Interface['labelframes'][1], text = 'Change', command = lambda i=i: refreshrate(), bd=2, width=13, height=1))
for i in range(9):
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Restart', command = lambda i=i: restart(), bd=2, width=11, height=1))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=11, height=1))
Interface['buttons'].insert(5, tk.Button(Interface['frames'][0], text = 'Load', command = lambda i=i: load(), bd=2, width=11, height=1))
Interface['buttons'].insert(6, tk.Button(Interface['labelframes'][0], text = 'Change', command = lambda i=i: plotting(), bd=2, width=7, height=1))
Interface['buttons'].insert(7, tk.Button(Interface['labelframes'][1], text = 'Change', command = lambda i=i: refreshrate(), bd=2, width=13, height=1))
for i in range(8):
Interface['buttons'][i].pack(side = 'left')
##############################################################################
##############################################################################
# Plotting
# Plotting embedded
f = plt.figure()
a = f.add_subplot(111)
......@@ -223,18 +246,13 @@ dataPlot = FigureCanvasTkAgg(f, master=root)
dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)
xx = arange(0, 8192)
temp, = a.plot(xx, xx*0, 'y.', lw=0.9)
temp, = a.plot(xx, xx*0, 'red', lw=0.9)
xlabel('Channel')
ylabel('Counts')
a.xaxis.set_major_locator(MultipleLocator(1024))
a.xaxis.set_minor_locator(MultipleLocator(128))
a.grid(True)
a.xaxis.grid(True,'minor')
a.xaxis.grid(True,'major',linewidth=2)
##############################################################################
##############################################################################
# Menu
menubar = tk.Menu(root, bg='grey', relief='flat', bd=0)
filemenu = tk.Menu(menubar, tearoff=0)
......
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