Modulo.py 2.55 KB
Newer Older
Julio Tambara's avatar
Julio Tambara committed
1
2
import Tkinter as tk
import pexpect
Julio Tambara's avatar
Julio Tambara committed
3
import time
Julio Tambara's avatar
Julio Tambara committed
4
5
6
7
8
9
10
11
12
import numpy as np
from array import *

##############################################################################
##############################################################################


class Modulo:

13
    
Julio Tambara's avatar
Julio Tambara committed
14
15
16
17

    def __init__(self, Nmr_modulo):
         self.child = pexpect.spawn('./N957Run '+ Nmr_modulo)    
         #self.Controle['Nmr_serial']=Serial 
18
19
20
21
         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.)
       
Julio Tambara's avatar
Julio Tambara committed
22
23
24
25
26
27


    def start(self):
	self.child.send('s')
        msg=(self.child.readline().strip("\r\n"))

28
        return msg
Julio Tambara's avatar
Julio Tambara committed
29
30
31
32


    def set_fator(self, canais):  # Define o fator para conversao do numero de canais

Julio Tambara's avatar
Julio Tambara committed
33
        self.Controle['Nmr_canais']=canais
Julio Tambara's avatar
Julio Tambara committed
34
        if int(canais) == 8192:   # 8192 pontos
Julio Tambara's avatar
Julio Tambara committed
35

Julio Tambara's avatar
Julio Tambara committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
            self.child.send('a')   
        elif int(canais) == 4096: # 4096 pontos
            self.child.send('b') 
        elif int(canais) == 2048: # 2048 pontos
            self.child.send('c')
        elif int(canais) == 1024: # 1024 pontos
            self.child.send('d')
        elif int(canais) == 512:  # 512 pontos
            self.child.send('e')
        elif int(canais) == 256:  # 256 pontos
            self.child.send('f')
        elif int(canais) == 128:  # 128 pontos
            self.child.send('g')
        elif int(canais) == 64:   # 64 pontos
            self.child.send('h')

    def load(self): 
        self.child.send('y')

    def LLDT(self, lldt):

        self.child.send('j')
        self.child.send(chr(int(lldt)/10))
        self.child.send(chr(int(lldt)%10))

    def Read_Data(self):

        msg=(self.child.readline().strip("\r\n"))   
        if  msg == 'OK':
            self.Data = eval(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"))
68
            self.Livetime['DeadTime'] = (self.Livetime['Time'] - float(self.child.readline().strip("\r\n")))*100/self.Livetime['Time']
Julio Tambara's avatar
Julio Tambara committed
69
70
71
72
73
74
  
        return msg

    def dump(self): # Sinal para programa coletor enviar os dados
	self.child.send('i')

75
    def reset(self):
Julio Tambara's avatar
Julio Tambara committed
76
        self.child.send('r')
Julio Tambara's avatar
Julio Tambara committed
77
	for k in range(int(self.Controle['Nmr_canais'])):
78
79
            self.Data[k] = 0
        
Julio Tambara's avatar
Julio Tambara committed
80
81
82

    def pause(self):
        self.child.send('p')
Julio Tambara's avatar
Julio Tambara committed
83
84
85
86
87

    def exit(self):
        self.child.send('q')
        time.sleep(0.1)
        self.child.close(force=True)
Julio Tambara's avatar
Julio Tambara committed
88
89
90
91
92
93
94
95