1 | #!/usr/bin/python
|
---|
2 | ##############################################################
|
---|
3 | #
|
---|
4 | # CommunicateWithVME.py
|
---|
5 | # Handles the communication with the VME crate
|
---|
6 | # can send commands to the VME crate
|
---|
7 | #
|
---|
8 | #
|
---|
9 | # Michael Rissi 05/2009
|
---|
10 | #
|
---|
11 | #############################################################
|
---|
12 |
|
---|
13 | import GlobalVariables
|
---|
14 | import threading
|
---|
15 | import _VME
|
---|
16 | import time
|
---|
17 | def GetRate(module,channel):
|
---|
18 | _VME.V560_Clear_Scales( module)
|
---|
19 | beginCounter=_VME. V560_Read_Counter( module, channel)
|
---|
20 | print "Evaluating rates (2 seconds)..."
|
---|
21 | time.sleep(2)
|
---|
22 | endCounter = _VME. V560_Read_Counter( module, channel)
|
---|
23 | return (endCounter-beginCounter)/2000.
|
---|
24 |
|
---|
25 | def GetRates(module):
|
---|
26 | _VME.V560_Clear_Scales( module)
|
---|
27 | beginCounter =[0,0,0,0,
|
---|
28 | 0,0,0,0,
|
---|
29 | 0,0,0,0,
|
---|
30 | 0,0,0,0]
|
---|
31 | endCounter = [0,0,0,0,
|
---|
32 | 0,0,0,0,
|
---|
33 | 0,0,0,0,
|
---|
34 | 0,0,0,0]
|
---|
35 | rates = [0,0,0,0,
|
---|
36 | 0,0,0,0,
|
---|
37 | 0,0,0,0,
|
---|
38 | 0,0,0,0]
|
---|
39 |
|
---|
40 | for i in range(0,16):
|
---|
41 | beginCounter[i]=_VME. V560_Read_Counter( module, i)
|
---|
42 | print beginCounter[i]
|
---|
43 | print "Evaluating rates..."
|
---|
44 | time.sleep(2)
|
---|
45 | for i in range(0,16):
|
---|
46 | endCounter[i] = _VME. V560_Read_Counter( module, i)
|
---|
47 | print endCounter[i]
|
---|
48 | rates[i] =(endCounter[i]-beginCounter[i])/2000.
|
---|
49 | return rates
|
---|
50 |
|
---|
51 | class ParseUserInput(threading.Thread):
|
---|
52 | def Parse(self,Command):
|
---|
53 | print "PARSING: ",Command
|
---|
54 | sCommand=Command.split()
|
---|
55 | error_code=0
|
---|
56 | #python lacks switch...
|
---|
57 | try:
|
---|
58 | VMEModule=sCommand[0]
|
---|
59 | if(VMEModule == "help"): print "please use \'<V812|V560|Triggerboard> help\' "
|
---|
60 |
|
---|
61 | # now do the stuff for the V560:
|
---|
62 | if(VMEModule == "V560"):
|
---|
63 | V560Command=sCommand[1]
|
---|
64 | if(V560Command=="help"):
|
---|
65 | print "available functions are: "
|
---|
66 | print "V560 GetRate <module#> <channel#>"
|
---|
67 | print "V560 GetRates <module#> "
|
---|
68 |
|
---|
69 | if(V560Command=="GetRate"):
|
---|
70 | print "trying to get rate"
|
---|
71 | try:
|
---|
72 | module = sCommand[2]
|
---|
73 | channel= sCommand[3]
|
---|
74 | print GetRate(int(module),int(channel))
|
---|
75 | except:
|
---|
76 | print "Syntax Error (GetRate)"
|
---|
77 | #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel))
|
---|
78 |
|
---|
79 | if(V560Command=="GetRates"):
|
---|
80 | print "trying to get rates"
|
---|
81 | try:
|
---|
82 | module = sCommand[2]
|
---|
83 |
|
---|
84 | print GetRates(int(module))
|
---|
85 | except:
|
---|
86 | print "Syntax Error (GetRates)"
|
---|
87 | #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel))
|
---|
88 |
|
---|
89 |
|
---|
90 | # now do the stuff for the V812:
|
---|
91 | elif(VMEModule == "V812"):
|
---|
92 | V812Command=sCommand[1]
|
---|
93 | if(V812Command=="help"):
|
---|
94 | print "available functions are: "
|
---|
95 | print "V812 SetHexPat <module#[1-10]> <HexPattern[0x0000-0xFFFF>"
|
---|
96 | print "V812 SetThresh <module#[1-10]> <channel#[0-15]> <thresh[0-255]>"
|
---|
97 | print "V812 SetMajLevel <module#[1-10]> <MajLev[1-20]>"
|
---|
98 | print "V812 SetMajThresh <module#[1-10]> <MajThr[0-255]>"
|
---|
99 | print "V812 SetDeadTime <module#[1-10]> <Block [0-1]> <DeadTime[0-255]>"
|
---|
100 |
|
---|
101 | #set the hexpattern:
|
---|
102 | elif(V812Command=="SetHexPat"):
|
---|
103 | print "trying to set the hexpattern:"
|
---|
104 | try:
|
---|
105 | module = int(sCommand[2])
|
---|
106 | hexpat = int(sCommand[3],16)
|
---|
107 | #hexpat="ddd"
|
---|
108 | print "setting module ",module," to hexpat: ",hex(hexpat)
|
---|
109 | try:
|
---|
110 | error_code=_VME.V812_Set_Pattern_Inhibit_Hex(module, hexpat)
|
---|
111 | print "success! "
|
---|
112 |
|
---|
113 | except:
|
---|
114 | VME_ErrorPrint(error_code)
|
---|
115 | except:
|
---|
116 | print "Syntax error (SetHexPat)"
|
---|
117 |
|
---|
118 |
|
---|
119 | elif(V812Command=="SetThresh"):
|
---|
120 | print "trying to set the threshold:"
|
---|
121 | try:
|
---|
122 | module = int(sCommand[2])
|
---|
123 | channel = int(sCommand[3])
|
---|
124 | thresh = int(sCommand[4])
|
---|
125 | print "setting threshold of channel: ",channel, " in module ",module," to: ",thresh
|
---|
126 | print "success: ",_VME.V812_Set_Threshold(module, channel, thresh)
|
---|
127 | except:
|
---|
128 | print "Syntax error (SetThresh) "
|
---|
129 |
|
---|
130 | elif(V812Command=="SetMajLevel"):
|
---|
131 | print "trying to set the majority level:"
|
---|
132 | try:
|
---|
133 | module = int(sCommand[2])
|
---|
134 | level = int(sCommand[3])
|
---|
135 | print "setting maj. level of module ",module," to: ",level
|
---|
136 | print "success: ",_VME.V812_Set_Majority_Level(module,level)
|
---|
137 | except:
|
---|
138 | print "Syntax error (SetMajLevel)"
|
---|
139 |
|
---|
140 | elif(V812Command=="SetMajThresh"):
|
---|
141 | print "trying to set the majority threshold:"
|
---|
142 | try:
|
---|
143 | module = int(sCommand[2])
|
---|
144 | thresh = int(sCommand[3])
|
---|
145 | print "setting maj. level of module ",module," to: ",thresh
|
---|
146 | print "success: ",_VME.V812_Set_Majority_Threshold(module, thresh)
|
---|
147 | except:
|
---|
148 | print "Syntax error (SetMajThresh)"
|
---|
149 |
|
---|
150 | elif(V812Command=="SetDeadTime"):
|
---|
151 | print "trying to set the majority threshold:"
|
---|
152 | try:
|
---|
153 | module = int(sCommand[2])
|
---|
154 | block = int(sCommand[3])
|
---|
155 | deadtime= int(sCommand[4])
|
---|
156 | print "setting deadtime of module ",module," block: ",block, " to: ",deadtime
|
---|
157 | print "success: ",_VME.V812_Set_Dead_Time(module, block, deadtime);
|
---|
158 | except:
|
---|
159 | print "Syntax error (SetMajThresh)"
|
---|
160 |
|
---|
161 | else:
|
---|
162 | print "Syntax Error (V812)"
|
---|
163 |
|
---|
164 | except:
|
---|
165 | print "syntax error"
|
---|
166 | #_VME.V812_Set_Threshold(1, 0, 255)
|
---|
167 |
|
---|
168 | def __init__(self):
|
---|
169 | threading.Thread.__init__(self)
|
---|
170 | def run(self):
|
---|
171 | oldcommand=GlobalVariables.UserInput
|
---|
172 | while(GlobalVariables.UserInput!="exit" and GlobalVariables.UserInput != "EXIT"):
|
---|
173 | CommandToParse=GlobalVariables.UserInput
|
---|
174 | if(oldcommand!=CommandToParse):
|
---|
175 | self.Parse(CommandToParse)
|
---|
176 | oldcommand=CommandToParse
|
---|
177 | time.sleep(0.05)
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 | print "EXITING PARSER...press <enter> to exit"
|
---|
182 |
|
---|