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

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


class Modulo:

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

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


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

27
        return msg
Julio Tambara's avatar
Julio Tambara committed
28
29
30
31
32
33
34
35
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


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

        self.Nmr_canais=canais
        if int(canais) == 8192:   # 8192 pontos
            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"))
66
            self.Livetime['DeadTime'] = (self.Livetime['Time'] - float(self.child.readline().strip("\r\n")))*100/self.Livetime['Time']
Julio Tambara's avatar
Julio Tambara committed
67
68
69
70
71
72
  
        return msg

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

73
    def reset(self):
Julio Tambara's avatar
Julio Tambara committed
74
        self.child.send('r')
75
76
77
	for k in range(self.Controle['Nmr_canais']):
            self.Data[k] = 0
        
Julio Tambara's avatar
Julio Tambara committed
78
79
80
81
82
83
84
85
86
87
88

    def pause(self):
        self.child.send('p')