source: trigger/CommunicateWithVME.py@ 113

Last change on this file since 113 was 77, checked in by rissim, 15 years ago
trigger: gui added, interface modified
File size: 11.7 KB
Line 
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
13import GlobalVariables
14import threading
15import _VME
16import time
17def GetRate(module,channel):
18 _VME.V560_Clear_Scales( module)
19 beginCounter=_VME. V560_Read_Counter( module, channel)
20 GlobalVariables.ServerMessage = "Evaluating rates (2 seconds)..."
21 time.sleep(2)
22 endCounter = _VME. V560_Read_Counter( module, channel)
23 return (endCounter-beginCounter)/2000.
24
25def 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 = ["rates",
36 0,0,0,0,
37 0,0,0,0,
38 0,0,0,0,
39 0,0,0,0]
40
41 for i in range(0,16):
42 beginCounter[i]=_VME. V560_Read_Counter( module, i)
43 #GlobalVariables.ServerMessage = str(beginCounter[i])
44 #GlobalVariables.ServerMessage = "Evaluating rates..."
45 time.sleep(2)
46 for i in range(0,16):
47 endCounter[i] = _VME. V560_Read_Counter( module, i)
48 #GlobalVariables.ServerMessage = str(endCounter[i])
49 rates[i+1] =(endCounter[i]-beginCounter[i])/2000.
50 return rates
51
52class GimmeRates(threading.Thread):
53 rates=["rates",
54 0,0,0,0,
55 0,0,0,0,
56 0,0,0,0,
57 0,0,0,0]
58 module = 1
59 def run(self):
60 oldcommand=GlobalVariables.UserInput
61 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"):
62 time.sleep(0.001)
63 newrates = GetRates(self.module)
64 self.rates=newrates
65
66class ParseUserInput(threading.Thread):
67 gimmeRates=GimmeRates()
68 def Parse(self,Command):
69 Command = Command[1:]
70 #GlobalVariables.ServerMessage = "PARSING: " + Command
71 sCommand=Command.split()
72 error_code=0
73 #python lacks switch...
74 try:
75 VMEModule=sCommand[0]
76 if(VMEModule == "help"):
77 GlobalVariables.ServerMessage = "please use \'<V812|V560|Triggerboard> help\' "
78 #GlobalVariables.ServerMessage="please use \'<V812|V560|Triggerboard> help\' "
79
80 # now do the stuff for the V560:
81 if(VMEModule == "V560"):
82 V560Command=sCommand[1]
83 if(V560Command=="help"):
84 GlobalVariables.ServerMessage = "available functions are: \n"
85 GlobalVariables.ServerMessage += "V560 GetRate <module#> <channel#>\n"
86 GlobalVariables.ServerMessage += "V560 GetRates <module#\n "
87 time.sleep(0.05)
88
89 if(V560Command=="GetRate"):
90 #GlobalVariables.ServerMessage = "trying to get rate"
91 #time.sleep(0.05)
92
93
94 try:
95 module = int(sCommand[2])
96 channel= int(sCommand[3])
97 if(module!= self.gimmeRates.module):
98 self.gimmeRates.module=module
99 GlobalVariables.ServerMessage = "please wait... (5sec)"
100 time.sleep(5)
101
102 GlobalVariables.ServerMessage = str(self.gimmeRates.rates[channel])
103 time.sleep(0.01)
104 except:
105 GlobalVariables.ServerMessage = "Syntax Error (GetRate)"
106 time.sleep(0.01)
107 #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel))
108
109 if(V560Command=="GetRates" or V560Command=="GR"):
110 GlobalVariables.ServerMessage = "trying to get rates"
111 time.sleep(0.01)
112 try:
113 module = int(sCommand[2])
114 if(module!= self.gimmeRates.module):
115 self.gimmeRates.module=module
116 GlobalVariables.ServerMessage = "please wait... (5sec)"
117 time.sleep(5)
118 #GlobalVariables.ServerMessage = "RATES:"
119 GlobalVariables.ServerMessage = str(self.gimmeRates.rates)
120 time.sleep(0.01)
121 except:
122 GlobalVariables.ServerMessage = "Syntax Error (GetRates)"
123 time.sleep(0.05)
124 #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel))
125
126
127 # now do the stuff for the V812:
128 elif(VMEModule == "V812"):
129 V812Command=sCommand[1]
130 if(V812Command=="help"):
131 GlobalVariables.ServerMessage = "available functions are: \n"
132 GlobalVariables.ServerMessage += "V812 SetHexPat <module#[1-10]> <HexPattern[0x0000-0xFFFF>\n"
133 GlobalVariables.ServerMessage += "V812 SetThresh <module#[1-10]> <channel#[0-15]> <thresh[0-255]>\n"
134 GlobalVariables.ServerMessage += "V812 SetAllThresh <module#[1-10]> <thresh[0-255]>\n"
135 GlobalVariables.ServerMessage += "V812 SetMajLevel <module#[1-10]> <MajLev[1-20]>\n"
136 GlobalVariables.ServerMessage += "V812 SetMajThresh <module#[1-10]> <MajThr[0-255]>\n"
137 GlobalVariables.ServerMessage += "V812 SetDeadTime <module#[1-10]> <Block [0-1]> <DeadTime[0-255]>\n"
138 time.sleep(0.05)
139 #set the hexpattern:
140 elif(V812Command=="SetHexPat"):
141 GlobalVariables.ServerMessage = "trying to set the hexpattern:"
142 time.sleep(0.05)
143 try:
144 module = int(sCommand[2])
145 hexpat = int(sCommand[3],16)
146 #print hexpat
147 # hexpat="ddd"
148 GlobalVariables.ServerMessage = "setting module "+str(module)+" to hexpat: "+str(hex(hexpat))
149 time.sleep(0.05)
150 try:
151 print "setting it now..."
152 error_code=_VME.V812_Set_Pattern_Inhibit_Hex(module, hexpat)
153 GlobalVariables.ServerMessage = "success! "
154 time.sleep(0.05)
155
156 except:
157 VME_ErrorPrint(error_code)
158 print "FAILED"
159 except:
160 GlobalVariables.ServerMessage = "Syntax error (SetHexPat)"
161
162
163 time.sleep(0.05)
164 elif(V812Command=="SetAllThresh"):
165 print "trying to set all the threshold:"
166 try:
167 module = int(sCommand[2])
168 thresh = int(sCommand[3])
169 GlobalVariables.ServerMessage="Setting all thresholds...\n"
170 for channel in range(0,16):
171 GlobalVariables.ServerMessage += "setting threshold of channel: "+str(channel)+ " in module "+str(module)+" to: "+str(thresh)+"\n"
172 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel, thresh))+"\n"
173 time.sleep(0.05)
174
175
176 except:
177 print "Syntax error (SetAllThresh) "
178 elif(V812Command=="SetThresh"):
179 GlobalVariables.ServerMessage = "trying to set the threshold:"
180 time.sleep(0.05)
181 try:
182 module = int(sCommand[2])
183 channel = int(sCommand[3])
184 thresh = int(sCommand[4])
185 GlobalVariables.ServerMessage = "setting threshold of channel: "+str(channel)+ " in module "+str(module)+" to: "+str(thresh)
186 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel, thresh))
187 time.sleep(0.05)
188 except:
189 GlobalVariables.ServerMessage = "Syntax error (SetThresh) "
190 time.sleep(0.05)
191 elif(V812Command=="SetMajLevel"):
192 GlobalVariables.ServerMessage = "trying to set the majority level:"
193 time.sleep(0.05)
194 try:
195 module = int(sCommand[2])
196 level = int(sCommand[3])
197 GlobalVariables.ServerMessage = "setting maj. level of module "+str(module)+" to: "+str(level)
198 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Majority_Level(module,level))
199 time.sleep(0.05)
200 except:
201 GlobalVariables.ServerMessage = "Syntax error (SetMajLevel)"
202 time.sleep(0.05)
203
204 elif(V812Command=="SetMajThresh"):
205 GlobalVariables.ServerMessage = "trying to set the majority threshold:"
206 time.sleep(0.05)
207 try:
208 module = int(sCommand[2])
209 thresh = int(sCommand[3])
210 GlobalVariables.ServerMessage = "setting maj. level of module "+str(module)+" to: "+str(thresh)
211 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Majority_Threshold(module, thresh))
212 time.sleep(0.05)
213 except:
214 GlobalVariables.ServerMessage = "Syntax error (SetMajThresh)"
215 time.sleep(0.05)
216
217 elif(V812Command=="SetDeadTime"):
218 GlobalVariables.ServerMessage = "trying to set the majority threshold:"
219 time.sleep(0.05)
220 try:
221 module = int(sCommand[2])
222 block = int(sCommand[3])
223 deadtime= int(sCommand[4])
224 GlobalVariables.ServerMessage = "setting deadtime of module "+str(module)+" block: "+str(block)+ " to: "+str(deadtime)
225 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Dead_Time(module, block, deadtime))
226 time.sleep(0.05)
227 except:
228 GlobalVariables.ServerMessage = "Syntax error (SetMajThresh)"
229 time.sleep(0.05)
230
231 else:
232 GlobalVariables.ServerMessage = "Syntax Error (V812)"
233 time.sleep(0.05)
234
235 except:
236 GlobalVariables.ServerMessage = "syntax error"
237 time.sleep(0.05)
238 #_VME.V812_Set_Threshold(1, 0, 255)
239
240 def __init__(self):
241 threading.Thread.__init__(self)
242 def run(self):
243 self.gimmeRates.start()
244 oldcommand=GlobalVariables.UserInput
245 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"):
246 CommandToParse=GlobalVariables.UserInput
247 if(oldcommand!=CommandToParse):
248 self.Parse(CommandToParse)
249 oldcommand=CommandToParse
250 time.sleep(0.05)
251
252
253
254 GlobalVariables.ServerMessage = "EXITING PARSER...press <enter> to exit"
255 time.sleep(0.05)
256
Note: See TracBrowser for help on using the repository browser.