Changeset 115 for trigger/CommunicateWithVME.py
- Timestamp:
- 09/24/09 15:45:24 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trigger/CommunicateWithVME.py
r77 r115 15 15 import _VME 16 16 import time 17 import datetime 18 19 def GetStatus(): 20 print "Trigger thresholds: ", GlobalVariables.TriggerThresholds 21 print "Hex Pattern: ", GlobalVariables.HexPattern 22 print "Majority Level: ",GlobalVariables.MajorityLevel 23 24 25 26 27 17 28 def GetRate(module,channel): 18 29 _VME.V560_Clear_Scales( module) … … 23 34 return (endCounter-beginCounter)/2000. 24 35 36 37 25 38 def GetRates(module): 26 39 _VME.V560_Clear_Scales( module) … … 43 56 #GlobalVariables.ServerMessage = str(beginCounter[i]) 44 57 #GlobalVariables.ServerMessage = "Evaluating rates..." 45 time.sleep( 2)58 time.sleep(1) 46 59 for i in range(0,16): 47 60 endCounter[i] = _VME. V560_Read_Counter( module, i) 48 61 #GlobalVariables.ServerMessage = str(endCounter[i]) 49 rates[i+1] =(endCounter[i]-beginCounter[i])/ 2000.62 rates[i+1] =(endCounter[i]-beginCounter[i])/1000. 50 63 return rates 64 51 65 52 66 class GimmeRates(threading.Thread): … … 64 78 self.rates=newrates 65 79 80 81 82 83 class WriteOutput(threading.Thread): #thread that writes the rates and threshold to a file. 84 rates=["rates", 85 0,0,0,0, 86 0,0,0,0, 87 0,0,0,0, 88 0,0,0,0] 89 interval = 2 90 filename = "test.txt" 91 #gimmeRates =GimmeRates() 92 gimmeRates=GimmeRates() 93 #File=open(filename,'a') 94 def __init__(self, filename="test.txt", interval = 10): 95 threading.Thread.__init__(self) 96 #self.OpenNewFile(filename) 97 98 99 100 def writeToFile(self): 101 File = open(self.filename,'a') 102 #print "writing", (GlobalVariables.Rates) 103 #year = datetime.date.today().year 104 #month = datetime.date.today().month 105 #day = datetime.date.today().day 106 year = time.localtime(time.time())[0] 107 month =time.localtime(time.time())[1] 108 day = time.localtime(time.time())[2] 109 hour = time.localtime(time.time())[3] 110 minute = time.localtime(time.time())[4] 111 seconds = time.localtime(time.time())[5] 112 ms = time.localtime(time.time())[6] 113 #date=str(year) 114 #if (hour>=12): 115 # day = day+1 116 117 t = datetime.datetime.now() 118 EpochSeconds=int(time.mktime(t.timetuple())) 119 120 outstring = "Trigger " + " ThreshRate "+str(year) + " " + str(month) +" " + str(day) +" "+str(hour)+" " + str(minute) + " " + str(seconds)+ " "+str(ms)+" "+str(EpochSeconds)+" Thresh: " 121 File.write(outstring) 122 #print outstring 123 File.write(str(GlobalVariables.TriggerThresholds[0:]).strip('[]').replace(',', '')) 124 File.write(" rate: ") 125 GlobalVariables.Rates = self.gimmeRates.rates 126 File.write(str(GlobalVariables.Rates[0:]))#.strip('[]').replace(',', '')) 127 #print str(GlobalVariables.Rates[0:]).strip('[]').replace(',', '')) 128 129 130 #print str(GlobalVariables.TriggerThresholds[0:]).strip('[]').replace(',', '') 131 #print "\n" 132 133 File.write("\n") 134 File.close(); 135 136 137 138 def run(self): 139 self.gimmeRates.start() 140 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"): 141 time.sleep(0.001) 142 time.sleep(self.interval) 143 self.writeToFile() 144 145 146 147 148 149 150 151 152 153 154 66 155 class ParseUserInput(threading.Thread): 67 156 gimmeRates=GimmeRates() 157 writeOutput=WriteOutput() 68 158 def Parse(self,Command): 69 159 Command = Command[1:] … … 108 198 109 199 if(V560Command=="GetRates" or V560Command=="GR"): 110 GlobalVariables.ServerMessage = "trying to get rates"111 time.sleep(0.01)200 #GlobalVariables.ServerMessage = "trying to get rates" 201 #time.sleep(0.01) 112 202 try: 113 203 module = int(sCommand[2]) … … 132 222 GlobalVariables.ServerMessage += "V812 SetHexPat <module#[1-10]> <HexPattern[0x0000-0xFFFF>\n" 133 223 GlobalVariables.ServerMessage += "V812 SetThresh <module#[1-10]> <channel#[0-15]> <thresh[0-255]>\n" 224 GlobalVariables.ServerMessage += "V812 SetThreshDiff <module#[1-10]> <channel#[0-15]> <threshdiff[0-255]>\n" 134 225 GlobalVariables.ServerMessage += "V812 SetAllThresh <module#[1-10]> <thresh[0-255]>\n" 226 GlobalVariables.ServerMessage += "V812 SetAllThreshDiff <module#[1-10]> <threshdiff[0-255]>\n" 135 227 GlobalVariables.ServerMessage += "V812 SetMajLevel <module#[1-10]> <MajLev[1-20]>\n" 136 228 GlobalVariables.ServerMessage += "V812 SetMajThresh <module#[1-10]> <MajThr[0-255]>\n" 137 229 GlobalVariables.ServerMessage += "V812 SetDeadTime <module#[1-10]> <Block [0-1]> <DeadTime[0-255]>\n" 230 GlobalVariables.ServerMessage += "V812 SetOutputWidth <module#[1-10]> <Block [0-1]> <OutputWidth[0-255]>\n" 231 GlobalVariables.ServerMessage += "V812 Status\n" 232 GlobalVariables.ServerMessage += "V812 RateScan <module> <start> <step> <stop>\n" 233 138 234 time.sleep(0.05) 139 235 #set the hexpattern: … … 152 248 error_code=_VME.V812_Set_Pattern_Inhibit_Hex(module, hexpat) 153 249 GlobalVariables.ServerMessage = "success! " 250 GlobalVariables.HexPattern =str(hex(hexpat)) 154 251 time.sleep(0.05) 155 252 … … 163 260 time.sleep(0.05) 164 261 elif(V812Command=="SetAllThresh"): 165 print "trying to set allthe threshold:"262 print "trying to set the threshold:" 166 263 try: 167 264 module = int(sCommand[2]) … … 171 268 GlobalVariables.ServerMessage += "setting threshold of channel: "+str(channel)+ " in module "+str(module)+" to: "+str(thresh)+"\n" 172 269 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel, thresh))+"\n" 270 GlobalVariables.TriggerThresholds[channel] = thresh 173 271 time.sleep(0.05) 174 272 … … 176 274 except: 177 275 print "Syntax error (SetAllThresh) " 276 277 elif(V812Command=="SetAllThreshDiff"): 278 print "trying to set all the threshold (diff):" 279 try: 280 module = int(sCommand[2]) 281 threshdiff = int(sCommand[3]) 282 GlobalVariables.ServerMessage="Setting all thresholds (diff)...\n" 283 for channel in range(0,16): 284 GlobalVariables.ServerMessage += "increase threshold of channel: "+str(channel)+ " in module "+str(module)+" by: "+str(threshdiff)+"\n" 285 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel, GlobalVariables.TriggerThresholds[channel]+ threshdiff))+"\n" 286 GlobalVariables.TriggerThresholds[channel]+= threshdiff 287 time.sleep(0.05) 288 289 290 except: 291 print "Syntax error (SetAllThreshDiff) " 292 293 elif(V812Command=="SetThreshDiff"): 294 GlobalVariables.ServerMessage = "trying to set the threshold:" 295 time.sleep(0.05) 296 try: 297 module = int(sCommand[2]) 298 channel = int(sCommand[3]) 299 threshdiff = int(sCommand[4]) 300 #print module, channel, threshdiff 301 #print GlobalVariables.TriggerThresholds[channel] 302 newthresh = GlobalVariables.TriggerThresholds[channel] + threshdiff 303 #print newthresh 304 GlobalVariables.ServerMessage = "increase threshold of channel: "+str(channel)+ " in module "+str(module)+" by: "+str(threshdiff)+"\n" 305 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel,newthresh)) 306 GlobalVariables.TriggerThresholds[channel] = newthresh 307 time.sleep(0.05) 308 except: 309 GlobalVariables.ServerMessage = "Syntax error (SetThreshDiff) " 310 time.sleep(0.05) 311 178 312 elif(V812Command=="SetThresh"): 179 313 GlobalVariables.ServerMessage = "trying to set the threshold:" … … 185 319 GlobalVariables.ServerMessage = "setting threshold of channel: "+str(channel)+ " in module "+str(module)+" to: "+str(thresh) 186 320 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Threshold(module, channel, thresh)) 321 GlobalVariables.TriggerThresholds[channel] = thresh 187 322 time.sleep(0.05) 188 323 except: … … 197 332 GlobalVariables.ServerMessage = "setting maj. level of module "+str(module)+" to: "+str(level) 198 333 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Majority_Level(module,level)) 334 GlobalVariables.MajorityLevel = level 199 335 time.sleep(0.05) 200 336 except: … … 216 352 217 353 elif(V812Command=="SetDeadTime"): 218 GlobalVariables.ServerMessage = "trying to set the majoritythreshold:"354 GlobalVariables.ServerMessage = "trying to set deadtime threshold:" 219 355 time.sleep(0.05) 220 356 try: … … 226 362 time.sleep(0.05) 227 363 except: 228 GlobalVariables.ServerMessage = "Syntax error (SetMajThresh)" 229 time.sleep(0.05) 230 364 GlobalVariables.ServerMessage = "Syntax error (SetDeadTime)" 365 time.sleep(0.05) 366 elif(V812Command=="SetOutputWidth"): 367 GlobalVariables.ServerMessage = "trying to set output width " 368 time.sleep(0.05) 369 try: 370 module = int(sCommand[2]) 371 block = int(sCommand[3]) 372 outputw= int(sCommand[4]) 373 GlobalVariables.ServerMessage = "setting output width of module "+str(module)+" block: "+str(block)+ " to: "+str(outputw) 374 GlobalVariables.ServerMessage += "success: "+str(_VME.V812_Set_Output_Width(module, block, outputw)) 375 time.sleep(0.05) 376 except: 377 GlobalVariables.ServerMessage = "Syntax error (SetOutputTime)" 378 time.sleep(0.05) 379 elif(V812Command=="Status"): 380 GetStatus(); 381 382 elif(V812Command=="RateScan"): 383 GlobalVariables.ServerMessage = "trying to scan the rates " 384 time.sleep(0.05) 385 try: 386 module = int(sCommand[2]) 387 start = int(sCommand[3]) 388 step = int(sCommand[4]) 389 stop = int(sCommand[5]) 390 print module, start, step, stop 391 self.RateScan(module, start, step, stop) 392 393 394 except: 395 GlobalVariables.ServerMessage = "Syntax error (RateScan)" 396 time.sleep(0.05) 397 398 399 400 231 401 else: 232 402 GlobalVariables.ServerMessage = "Syntax Error (V812)" 233 403 time.sleep(0.05) 404 234 405 235 406 except: 236 407 GlobalVariables.ServerMessage = "syntax error" 237 408 time.sleep(0.05) 238 #_VME.V812_Set_Threshold(1, 0, 255) 409 def RateScan(self,module, start, step, stop): 410 #print module, start, step,stop 411 #print "IN\n" 412 #First stop the automatic rate writeup 413 oldinterval = self.writeOutput.interval 414 self.writeOutput.interval=15 415 rates = ["rates", 416 0,0,0,0, 417 0,0,0,0, 418 0,0,0,0, 419 0,0,0,0] 420 print "rates:" ,rates 421 CurrentThresholds =[0,0,0,0, 422 0,0,0,0, 423 0,0,0,0, 424 0,0,0,0] 425 for pix in range(0,16): 426 CurrentThresholds[pix] = GlobalVariables.TriggerThresholds[pix] 427 print "Threshs: ",CurrentThresholds,"\n" 428 NumberOfScanSteps = int((stop-start)/step) + 1 429 print "NumberOfScanSteps: ", NumberOfScanSteps 430 for StepNumber in range(0,NumberOfScanSteps): 431 print "Step#" ,StepNumber 432 for pix in range(0,16): 433 #print (CurrentThresholds[pix] + start) + step*StepNumber 434 GlobalVariables.TriggerThresholds[pix] = (CurrentThresholds[pix] + start) + step*StepNumber 435 #print pix, GlobalVariables.TriggerThresholds[pix] 436 _VME.V812_Set_Threshold(module, pix, GlobalVariables.TriggerThresholds[pix]) 437 438 time.sleep(2.1) 439 #print "Getting Rates: \n" 440 rates = self.gimmeRates.rates#GetRates(module); 441 self.writeOutput.writeToFile() 442 #print "Got rates..." 443 print "Thresh: ",GlobalVariables.TriggerThresholds, " rates: ",rates #_VME.V812_Set_Threshold(1, 0, 255) 444 445 446 self.writeOutput.interval = oldinterval 239 447 240 448 def __init__(self): 449 #self.writeOutput.OpenNewFile("test.txt") 241 450 threading.Thread.__init__(self) 242 451 def run(self): 243 452 self.gimmeRates.start() 453 454 self.writeOutput.start() 244 455 oldcommand=GlobalVariables.UserInput 245 456 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"): 246 457 CommandToParse=GlobalVariables.UserInput 458 #Filename to write: 459 #year = datetime.date.today().year 460 #month = datetime.date.today().month 461 #day = datetime.date.today().day 462 MyTime = time.time() 463 #print MyTime 464 465 466 hour = time.gmtime(MyTime)[3] 467 minute = time.gmtime(MyTime)[4] 468 #print hour, minute 469 if(hour>=13): 470 MyTime+=12*60*60 471 472 year = time.gmtime(MyTime)[0] 473 month =time.gmtime(MyTime)[1] 474 day = time.gmtime(MyTime)[2] 475 date=str(year) 476 #if (hour>=12): 477 # day = day+1 478 479 date+="%(month)02d" % {"month":month} 480 date+="%(day)02d" % {"day":day} 481 #date+="_" 482 #date+="%(hour)02d" % {"hour":hour} 483 #date+="%(minute)02d" % {"minute":minute} 484 self.writeOutput.filename="/ct3data/SlowData/Trigger_"+date+".slow" 485 486 487 #self.writeOutput.filename = "/ct3data/SlowData/Trigger_" 488 #self.writeOutput.filename 247 489 if(oldcommand!=CommandToParse): 248 490 self.Parse(CommandToParse)
Note:
See TracChangeset
for help on using the changeset viewer.