Commit d343134d authored by Julio Tambara's avatar Julio Tambara
Browse files

Cursor add, ROI arrumada, DeadTime modificado

Verção para organizar o repositório git
parent 04d8efa2
import numpy as np
import Tkinter as tk
import matplotlib.pyplot as plt
class Graficos:
def __init__(self, Nmr):
self.Nmr_serial= Nmr
self.limupdtx=True
self.limupdty=True
self.limupdt=True
self.limctrl=False
self.x0=0
self.y0=0
self.x1=512
self.y1=0
self.pressx=0.
self.pressy=0.
self.limtrans=False
self.dx=0.
self.dy=0.
self.Nmr_serial= None
self.f= plt.figure()
self.title=None # poderia tirar direto do grafico
self.a= self.f.add_subplot(111, axisbg='#555555')
self.temp=None
self.dataPlot=None
self.Frame=None
self.Cursor=dict(x=256,line=self.a.axvline(x=256,color='red'))
...@@ -9,24 +9,22 @@ from array import * ...@@ -9,24 +9,22 @@ from array import *
class Modulo: class Modulo:
Data=array('L',[0]*8192)
Controle=dict(pause=1,Nmr_serial=0,Nmr_canais=512, ON=0)
Livetime = dict(ADC_Conversion=0 , Time=0. , LiveTime=0.)
child= None
def __init__(self, Nmr_modulo): def __init__(self, Nmr_modulo):
self.child = pexpect.spawn('./N957Run '+ Nmr_modulo) self.child = pexpect.spawn('./N957Run '+ Nmr_modulo)
#self.Controle['Nmr_serial']=Serial #self.Controle['Nmr_serial']=Serial
self.Data=array('L',[0]*8192)
self.Controle=dict(pause=1,Nmr_serial=0,Nmr_canais=512, ON=0)
self.Livetime = dict(ADC_Conversion=0 , Time=0. , DeadTime=0.)
def start(self): def start(self):
self.child.send('s') self.child.send('s')
msg=(self.child.readline().strip("\r\n")) msg=(self.child.readline().strip("\r\n"))
if msg == 'OK': return msg
return 1
else:
return msg
def set_fator(self, canais): # Define o fator para conversao do numero de canais def set_fator(self, canais): # Define o fator para conversao do numero de canais
...@@ -65,17 +63,18 @@ class Modulo: ...@@ -65,17 +63,18 @@ class Modulo:
self.Data = eval(self.child.readline().strip("\r\n")) self.Data = eval(self.child.readline().strip("\r\n"))
self.Livetime['ADC_Conversion'] = int(self.child.readline().strip("\r\n")) self.Livetime['ADC_Conversion'] = int(self.child.readline().strip("\r\n"))
self.Livetime['Time'] = float(self.child.readline().strip("\r\n")) self.Livetime['Time'] = float(self.child.readline().strip("\r\n"))
self.Livetime['LiveTime'] = float(self.child.readline().strip("\r\n")) self.Livetime['DeadTime'] = (self.Livetime['Time'] - float(self.child.readline().strip("\r\n")))*100/self.Livetime['Time']
return msg return msg
def dump(self): # Sinal para programa coletor enviar os dados def dump(self): # Sinal para programa coletor enviar os dados
self.child.send('i') self.child.send('i')
def reset(self,size): def reset(self):
for k in range(size):
self.Data[k] = 0
self.child.send('r') self.child.send('r')
for k in range(self.Controle['Nmr_canais']):
self.Data[k] = 0
def pause(self): def pause(self):
self.child.send('p') self.child.send('p')
......
MCA = 113
#MCB = 175
#MCC = 174
...@@ -11,7 +11,6 @@ import tkMessageBox ...@@ -11,7 +11,6 @@ import tkMessageBox
import tkFileDialog import tkFileDialog
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time import time
import subprocess
from pylab import * from pylab import *
from os.path import basename from os.path import basename
#from clsbeep import * #from clsbeep import *
...@@ -23,6 +22,7 @@ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolb ...@@ -23,6 +22,7 @@ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolb
# implement the default mpl key bindings # implement the default mpl key bindings
from matplotlib.figure import Figure from matplotlib.figure import Figure
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
import Tkinter as Tk import Tkinter as Tk
...@@ -30,6 +30,7 @@ else: ...@@ -30,6 +30,7 @@ else:
import tkinter as Tk import tkinter as Tk
Plot=dict( Data=dict(), Plotbuttons=list(), Pcontrol=list(), Name=list() ) Plot=dict( Data=dict(), Plotbuttons=list(), Pcontrol=list(), Name=list() )
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())
...@@ -39,12 +40,23 @@ n=0;#numero de botoes removidos (facilita) ...@@ -39,12 +40,23 @@ n=0;#numero de botoes removidos (facilita)
Axis=dict( x_max=int , x_min=int, y_max=int, y_min=int, x_click=float, y_click=float) Axis=dict( x_max=int , x_min=int, y_max=int, y_min=int, x_click=float, y_click=float)
root = Tk.Tk() root = Tk.Tk()
root.minsize(825,640) root.minsize(825,640)
root.wm_title("Buffer") root.wm_title("Buffer")
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
f = plt.Figure(figsize=(5,4), dpi=100) f = plt.Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111) a = f.add_subplot(111)
...@@ -76,16 +88,15 @@ def plot_select(name_plot, button): ...@@ -76,16 +88,15 @@ def plot_select(name_plot, button):
Plot['Pcontrol'][j] = 1 Plot['Pcontrol'][j] = 1
refresh() refresh()
def add_plot(): def add_plot(Name):
global j, Plot global j, Plot
newfile = tkFileDialog.askopenfilename() Plot['Data'][j] = np.loadtxt(Name)
Plot['Data'][j] = np.loadtxt(newfile)
Plot['Pcontrol'].insert(j,1) Plot['Pcontrol'].insert(j,1)
Plot['Name'].insert(j,basename(newfile)) Plot['Name'].insert(j,basename(Name))
Plot['Plotbuttons'].insert(j, tk.Button(pltbutfrm, text=basename(newfile), height=1,relief='sunken', command = lambda j=j : plot_select(basename(newfile),Plot['Plotbuttons']))) Plot['Plotbuttons'].insert(j, tk.Button(pltbutfrm, text=basename(Name), height=1,relief='sunken', command = lambda j=j : plot_select(basename(Name),Plot['Plotbuttons'])))
#Plot['Plotbuttons'][j].grid( row = len(Plot['Plotbuttons'])) #Plot['Plotbuttons'][j].grid( row = len(Plot['Plotbuttons']))
Plot['Plotbuttons'][j].pack(fill='x') Plot['Plotbuttons'][j].pack(fill='x')
remove_menu.add_command(label=basename(newfile), command=lambda:remove_plot(basename(newfile))) remove_menu.add_command(label=basename(Name), command=lambda:remove_plot(basename(Name)))
j = j + 1 j = j + 1
refresh() refresh()
...@@ -110,13 +121,14 @@ def remove_plot(name_plot): ...@@ -110,13 +121,14 @@ def remove_plot(name_plot):
refresh() refresh()
######################################################################## ########################################################################
######################################################################## ########################################################################
# Menu # Menu
menubar = Tk.Menu(root, relief='raised', bd=2) menubar = Tk.Menu(root, relief='raised', bd=2)
filemenu = Tk.Menu(menubar, tearoff=0) filemenu = Tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open",command = lambda:add_plot()) filemenu.add_command(label="Open",command = lambda:add_plot(tkFileDialog.askopenfilename()))
filemenu.add_command(label ="Save") #, command = lambda i=i: save('g12')) filemenu.add_command(label ="Save") #, command = lambda i=i: save('g12'))
filemenu.add_command(label ="Save As") #, command = lambda i=i: saveas('g12')) filemenu.add_command(label ="Save As") #, command = lambda i=i: saveas('g12'))
filemenu.add_command(label="Exit",command = lambda:_quit()) #, command = _quit) filemenu.add_command(label="Exit",command = lambda:_quit()) #, command = _quit)
...@@ -183,11 +195,23 @@ Interface['frames'][3].bind("<ButtonRelease-3>", mouse_TR )#top_right ...@@ -183,11 +195,23 @@ Interface['frames'][3].bind("<ButtonRelease-3>", mouse_TR )#top_right
######################################################################## ########################################################################
######################################################################## ########################################################################
try:
add_plot('Buffer.MCA')
except IOError:
print tkMessageBox.askretrycancel("ERRO", "ERRO_10 ")
_quit()
try:
add_plot('Buffer.MCB')
except IOError:
None
try:
add_plot('Buffer.MCC')
except IOError:
None
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
......
File mode changed from 100644 to 100755
...@@ -98,11 +98,7 @@ int main(int argc, char **argv) ...@@ -98,11 +98,7 @@ int main(int argc, char **argv)
///////////////////////////////////////// /////////////////////////////////////////
memset( &user_setting, 0, sizeof( user_setting)); memset( &user_setting, 0, sizeof( user_setting));
if((argc+'0')>= 2)
user_setting.m_bd_num= atoi(argv[1]);
else
user_setting.m_bd_num=0; // tem problemas "falha de segmentação", mas eu n to usando.
// init user setting module // init user setting module
...@@ -130,6 +126,12 @@ int main(int argc, char **argv) ...@@ -130,6 +126,12 @@ int main(int argc, char **argv)
} }
memset( histo_buff, 0, N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff)); memset( histo_buff, 0, N957_MAX_HISTO_SAMPLES* sizeof( *histo_buff));
if((argc+'0')>= 2)
user_setting.m_bd_num= atoi(argv[1]);
else
user_setting.m_bd_num=0; // tem problemas "falha de segmentação", mas eu n to usando.
do_exit= FALSE; do_exit= FALSE;
while( !do_exit) { while( !do_exit) {
...@@ -177,11 +179,12 @@ int main(int argc, char **argv) ...@@ -177,11 +179,12 @@ int main(int argc, char **argv)
case 's': case 's':
case 'S': case 'S':
/// input parameter check /// input parameter check
if( !user_settings_parse_input_param( &user_setting, argc, (char**)argv)) if( !parse_config_file( &user_setting))
{ {
TRACE("erro_2\n"); TRACE("erro_2\n");
N957_End(user_setting.m_N957_handle);
break; break;
//goto exit_point;
} }
///////////////////////////////////////// /////////////////////////////////////////
...@@ -198,20 +201,19 @@ int main(int argc, char **argv) ...@@ -198,20 +201,19 @@ int main(int argc, char **argv)
{ {
TRACE("erro_3"); TRACE("erro_3");
break; break;
//goto exit_point;
} }
} }
if( N957_GetScaler(user_setting.m_N957_handle, &data32)) if( N957_GetScaler(user_setting.m_N957_handle, &data32))
{ {
TRACE("erro_5"); TRACE("erro_5");
//goto exit_point; break;
} }
if(N957_StartAcquire( user_setting.m_N957_handle, user_setting.m_mode)) if(N957_StartAcquire( user_setting.m_N957_handle, user_setting.m_mode))
{ {
TRACE("erro_6"); TRACE("erro_6");
//goto exit_point; break;
} }
if( user_setting.m_debug) { if( user_setting.m_debug) {
...@@ -219,10 +221,17 @@ int main(int argc, char **argv) ...@@ -219,10 +221,17 @@ int main(int argc, char **argv)
{ {
TRACE("erro_7"); TRACE("erro_7");
//goto exit_point; break;
} }
} }
if((N957_StopAcquire( user_setting.m_N957_handle)))
{
TRACE("erro_24\n");
goto exit_point;
}
start= TRUE; start= TRUE;
paused=TRUE;
TRACE("OK\n"); TRACE("OK\n");
break; break;
...@@ -296,6 +305,7 @@ int main(int argc, char **argv) ...@@ -296,6 +305,7 @@ int main(int argc, char **argv)
case 'a': // 8192 canais case 'a': // 8192 canais
fator = 1; fator = 1;
break; break;
case 'b':// 4096 canais case 'b':// 4096 canais
fator = 2; fator = 2;
break; break;
......
This diff is collapsed.
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
//////////////////////////////////////////// ////////////////////////////////////////////
// File local methods declaration // File local methods declaration
//////////////////////////////////////////// ////////////////////////////////////////////
static BOOL parse_config_file( user_setting_data* p_data); //static BOOL parse_config_file( user_setting_data* p_data);
static char* trim( char charset[], int n_chars, const char* string); static char* trim( char charset[], int n_chars, const char* string);
//////////////////////////////////////////// ////////////////////////////////////////////
...@@ -100,10 +100,10 @@ BOOL user_settings_close( user_setting_data* p_data) { ...@@ -100,10 +100,10 @@ BOOL user_settings_close( user_setting_data* p_data) {
/************************************************** /**************************************************
**************************************************/ **************************************************/
BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char* argv[]) { /*BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char* argv[]) {
//BOOL help_to_show= FALSE; //BOOL help_to_show= FALSE;
int i; int i;
for( i= 1; i< argc; i++) /*for( i= 1; i< argc; i++)
{ {
if( !strcmp( argv[i], "-h")|| if( !strcmp( argv[i], "-h")||
!strcmp( argv[i], "-H")) !strcmp( argv[i], "-H"))
...@@ -123,7 +123,7 @@ BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char* ...@@ -123,7 +123,7 @@ BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char*
TRACE("\n restart with -h flag for help on usage\n"); TRACE("\n restart with -h flag for help on usage\n");
help_to_show= TRUE; help_to_show= TRUE;
}*/ }
} }
if( !parse_config_file( p_data)) if( !parse_config_file( p_data))
return FALSE; return FALSE;
...@@ -132,19 +132,19 @@ BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char* ...@@ -132,19 +132,19 @@ BOOL user_settings_parse_input_param( user_setting_data* p_data, int argc, char*
/************************************************** /**************************************************
**************************************************/ **************************************************/
BOOL parse_config_file( user_setting_data* p_data) { BOOL parse_config_file( user_setting_data* p_data) {
char tmp_filename[ MAX_FILENAME_LENGHT]; //char tmp_filename[ MAX_FILENAME_LENGHT];
char line[ 200]; char line[ 200];
char *str; char *str;
FILE *p_conf_file= NULL; FILE *p_conf_file= NULL;
BOOL ret_val= TRUE; BOOL ret_val= TRUE;
N957ErrorCodes N957_error_code; // returned error code N957ErrorCodes N957_error_code; // returned error code
char trim_space_charset[]= {' ', '\t'}; char trim_space_charset[]= {' ', '\t'};
char trim_text_charset[]= {' ', '\t', '"'}; //char trim_text_charset[]= {' ', '\t', '"'};
if( ( p_conf_file= fopen( p_data->m_config_filename, "r"))== NULL){ if( ( p_conf_file= fopen( p_data->m_config_filename, "r"))== NULL){
TRACE1("Can't open configuration file %s\n", p_data->m_config_filename); TRACE1("Can't open configuration file %s\n", p_data->m_config_filename);
return FALSE; return FALSE;
} }
if( (N957_Init( (short)p_data->m_bd_num, &p_data->m_N957_handle))) if( (N957_Init( (short)p_data->m_bd_num, &p_data->m_N957_handle)))
{ {
......
...@@ -28,14 +28,14 @@ typedef struct ...@@ -28,14 +28,14 @@ typedef struct
char* m_gnu_plot_path; // gnuplot path char* m_gnu_plot_path; // gnuplot path
long m_max_num_samples; // The maximum number of samples to acquire long m_max_num_samples; // The maximum number of samples to acquire
N957_UINT16 m_bldim; // block dimension: maximum number of samples per call to retrive N957_UINT16 m_bldim; // block dimension: maximum number of samples per call to retrive
BOOL m_debug; // debugging features enabled BOOL m_debug; // debugging features enabled
N957ControlModes m_mode; // acqusition mode N957ControlModes m_mode; // acqusition mode
int32_t m_N957_handle; // Board handle int32_t m_N957_handle; // Board handle
int m_bd_num; // N957 board number int m_bd_num; // N957 board number
N957_BYTE m_lld; // LLD Threshold N957_BYTE m_lld; // LLD Threshold
BOOL m_log_to_file; // Write Data to output file BOOL m_log_to_file; // Write Data to output file
int m_gnu_plot_refresh; // Gnu Plot refresh rate (msec) // int m_gnu_plot_refresh; // Gnu Plot refresh rate (msec)
float m_gnu_plot_x_scale; // Gnu Plot X convertsion factor // float m_gnu_plot_x_scale; // Gnu Plot X convertsion factor
} user_setting_data; } user_setting_data;
//////////////////////////////////////////// ////////////////////////////////////////////
// Global variables declaration // Global variables declaration
......
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