Modulos.py 2.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Tkinter as tk
import pexpect
import time
import numpy as np
from array import *

##############################################################################
##############################################################################
#Classe que faz o Pipe com o programa em C

class Modulo:

    

    def __init__(self, Nmr_modulo):
         self.child = pexpect.spawn('./N957Run '+ Nmr_modulo)    
         #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):
	self.child.send('s')
        msg=(self.child.readline().strip("\r\n"))

        return msg


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

        self.Controle['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"))
            self.Livetime['DeadTime'] = (self.Livetime['Time'] - float(self.child.readline().strip("\r\n")))*100/self.Livetime['Time']
  
        return msg

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

    def reset(self):
        self.child.send('r')
	for k in range(int(self.Controle['Nmr_canais'])):
            self.Data[k] = 0
        

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

    def exit(self):
        self.child.send('q')
        time.sleep(0.1)
        self.child.close(force=True)

    def set_AutoGate(self):
        self.child.send('m')

    def set_ExternalGate(self):
        self.child.send('n')