#!/usr/bin/env python # -*- coding: iso-8859-15 -*- import os import pexpect import Tkinter as tk import tkMessageBox import matplotlib.pyplot as plt from pylab import * import time ############################################################################## ############################################################################## # Subprocess variable child = pexpect.spawn('./N957Run') time.sleep(3.3) child.send('s') ############################################################################## ############################################################################## # Histrogram t = 2000 bmin = 0 bmax = 8192 Data=list() for a in range(8192): Data.insert(a, 0) xx = arange(0, 8192) temp, = plot(xx, xx*0, 'y.', lw=0.9) plt.grid(True) plt.xlabel('Channel') plt.ylabel('Counts') ax = subplot(111) ax.xaxis.set_major_locator(MultipleLocator(1024)) ax.xaxis.set_minor_locator(MultipleLocator(128)) ax.xaxis.grid(True,'minor') ax.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(): global Interface, child, bmax if int(Interface['spinboxes'][0].get()) == 8192: child.send('a') bmax = 8192 elif int(Interface['spinboxes'][0].get()) == 4096: child.send('b') bmax = 4096 elif int(Interface['spinboxes'][0].get()) == 2048: child.send('c') bmax = 2048 elif int(Interface['spinboxes'][0].get()) == 1024: child.send('d') bmax = 1024 elif int(Interface['spinboxes'][0].get()) == 512: child.send('e') bmax = 512 elif int(Interface['spinboxes'][0].get()) == 256: child.send('f') bmax = 256 elif int(Interface['spinboxes'][0].get()) == 128: child.send('g') bmax = 128 elif int(Interface['spinboxes'][0].get()) == 64: child.send('h') bmax = 64 def dump(): global child child.send('i') 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")) temp.set_ydata(Data) #plt.fill_between(range(8192),Data,0,color='0.8') plt.xlim(bmin, bmax) plt.ylim(0, max(Data[bmin:bmax])*1.1) show() def realtimeplot(): global t dump() try: root.after(t, realtimeplot) graphic() except ValueError: pass ############################################################################# ############################################################################## # Main window root = tk.Tk() root.minsize(400,350) root.title('Modulo Multicanal') #root.geometry('670x470+200+200') ############################################################################## ############################################################################## # 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(): global child child.send('r') def pause(): return 0 def restart(): global child child = pexpect.spawn('./N957Run') time.sleep(3.3) child.send('s') def save(): global child child.send('z') def load(): global child child.send('y') def plotting(): global bmin, bmax if Interface['entries'][0].get().isdigit() and int(Interface['entries'][0].get()) >= 0 and Interface['entries'][1].get().isdigit() and int(Interface['entries'][1].get()) <= int(Interface['spinboxes'][0].get()) and int(Interface['entries'][1].get()) > int(Interface['entries'][0].get()): bmin = int(Interface['entries'][0].get()) bmax = int(Interface['entries'][1].get()) Interface['labelframes'][0].configure(text = 'Region of interest - %i to %i' %(bmin, bmax)) else: tkMessageBox.showinfo("Error", "Invalid values") def refreshrate(): global t if Interface['entries'][2].get().isdigit() and int(Interface['entries'][2].get()) > 499: t = int(Interface['entries'][2].get()) Interface['labelframes'][1].configure(text = 'Refresh Rate - %ims' %t) else: tkMessageBox.showinfo("Error", "Invalid value") ############################################################################## ############################################################################## # Safe Exit def shutdown(): sys.exit ############################################################################## ############################################################################## # Interface elements for i in range(2): Interface['frames'].insert(i, tk.Frame(root)) Interface['frames'][i].pack() Interface['labelframes'].insert(0,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Region of interest - 0 to 8192', bd=2)) Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Refresh Rate - 2000ms', bd=2)) Interface['labelframes'].insert(2,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Bins', bd=2)) Interface['labelframes'].insert(3,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Last Data', bd=2)) Interface['labels'].insert(0,tk.Label(Interface['labelframes'][3], text='ADC Conversions: %s' %Livetime['ADC_Conversion'])) Interface['labels'].insert(1,tk.Label(Interface['labelframes'][3], text='Total Time: %s' %Livetime['Time'])) Interface['labels'].insert(2,tk.Label(Interface['labelframes'][3], text='Live Time: %s' %Livetime['LiveTime'])) for i in range(3): Interface['labelframes'][i].pack() Interface['frames'].insert((i+2), tk.Frame(Interface['labelframes'][0])) Interface['frames'][(i+2)].pack(side='left') Interface['labels'][i].pack() Interface['labelframes'][3].pack() Interface['labels'].insert(3,tk.Label(Interface['frames'][3], text='to')) Interface['labels'][3].pack() Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][2], command = set_fator, values=[64,128,256,512,1024,2048,4096,8192])) Interface['spinboxes'][0].pack() Interface['spinboxes'][0].delete(0,len(Interface['spinboxes'][0].get())) Interface['spinboxes'][0].insert(0,8192) Interface['entries'].insert(0, tk.Entry(Interface['frames'][2], width=7)) Interface['entries'].insert(1, tk.Entry(Interface['frames'][4], width=7)) Interface['entries'].insert(2, tk.Entry(Interface['labelframes'][1], width=16)) for i in range(3): Interface['entries'][i].pack() 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'][i].pack() menubar = tk.Menu(root, bg='grey', relief='flat', bd=0) filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="Exit", command = sys.exit) menubar.add_cascade(label="File", menu=filemenu) root.config(menu=menubar) ############################################################################## ############################################################################## # Paralel processing root.mainloop() ############################################################################## ##############################################################################