- Timestamp:
- 09/24/09 15:45:24 (15 years ago)
- Location:
- trigger
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trigger/CommSocket.py
r77 r115 5 5 6 6 """ 7 A basic, multiclient 'chat server' using Python's select module8 with interrupt handling.9 10 Entering any line of input at the terminal will exit the server.11 7 """ 12 8 -
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) -
trigger/GlobalVariables.py
r77 r115 6 6 #global UserInput 7 7 UserInput ='' 8 Rates = [16] 8 Rates = [0,0,0,0, 9 0,0,0,0, 10 0,0,0,0, 11 0,0,0,0] 12 9 13 ServerMessage='' 10 14 Flag=1 11 15 counter = 0 16 TriggerThresholds = [0,0,0,0, 17 0,0,0,0, 18 0,0,0,0, 19 0,0,0,0] 20 HexPattern = '0x0000' 21 MajorityLevel = 0 -
trigger/ListenToArduino.py
r77 r115 9 9 month = datetime.date.today().month 10 10 day = datetime.date.today().day 11 hour = time.localtime(time.time())[3] 12 minute = time.localtime(time.time())[4] 11 13 date=str(year) 12 date+="0" 13 date+=str(month) 14 date+=str(day) 15 filename="Arduino_testing_"+date+".txt" 14 15 16 date+="%(month)02d" % {"month":month} 17 date+="%(day)02d" % {"day":day} 18 date+="_" 19 date+="%(hour)02d" % {"hour":hour} 20 date+="%(minute)02d" % {"minute":minute} 21 filename="/ct3data/SlowData/Trigger_"+date+".slow" 16 22 fileHandle = open ( filename, 'w' ) 17 23 fileHandle.close() -
trigger/Main.py
r77 r115 19 19 import GlobalVariables 20 20 import CommunicateWithVME 21 import ListenToArduino21 import ReadTemperatures 22 22 import time 23 23 #connecting to the crates: 24 print "\n\n\n" 25 print " ####################################" 26 print " # #" 27 print " # Trigger Control Program #" 28 print " # M. Rissi 2009 #" 29 print " # #" 30 print " ####################################" 31 print "\n\n\n" 24 32 print "connecting to the crates..." 33 25 34 _VME.VME_Open() 26 35 _VME.V560_Open() … … 34 43 35 44 GlobalVariables.UserInput = '' 36 print "start the shell... "45 #print "start the shell... " 37 46 inputShell= PythonShell.InputShell() 38 47 #inputShell.daemon=True … … 40 49 41 50 # start the server: 42 print "start the server... "51 #print "start the server... " 43 52 commServer = CommSocket.CommServer(3492,5) 44 53 commServer.start() 45 54 46 print "start the parser..."55 #print "start the parser..." 47 56 parseUserInput= CommunicateWithVME.ParseUserInput() 48 57 parseUserInput.start() 49 58 50 print "listening to Arduino..."51 listenToArduino = ListenToArduino.ListenToArduino()52 listenToArduino.start()59 #print "listening to Arduino..." 60 readTemperatures = ReadTemperatures.ReadTemperatures() 61 readTemperatures.start() 53 62 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"): 54 63 time.sleep(0.1) -
trigger/PythonShell.py
r77 r115 38 38 #print "\n(SHELL) You entered:",GlobalVariables.ServerMessage 39 39 #sys.stdout.write( "SHELL2 >>>") 40 print GlobalVariables.ServerMessage 40 if GlobalVariables.ServerMessage[0]!="[": 41 print GlobalVariables.ServerMessage 41 42 self.lastvar=GlobalVariables.ServerMessage 42 43 -
trigger/VME.i
r77 r115 29 29 int V812_Set_Pattern_Inhibit(short module, char channel[16]); 30 30 int V812_Set_Pattern_Inhibit_Hex(short module, int pattern); 31 int V812_Set_Output_Width(short module, charchannel_block, short width);31 int V812_Set_Output_Width(short module, short channel_block, short width); 32 32 int V812_Set_Dead_Time(short module, short channel_block, short dead_time); 33 33 int V812_Set_Majority_Level(short module, short majority_level); -
trigger/VME_wrap.c
r77 r115 1007 1007 PyObject *resultobj; 1008 1008 short arg1 ; 1009 chararg2 ;1009 short arg2 ; 1010 1010 short arg3 ; 1011 1011 int result; 1012 1012 1013 if(!PyArg_ParseTuple(args,(char *)"h ch:V812_Set_Output_Width",&arg1,&arg2,&arg3)) goto fail;1013 if(!PyArg_ParseTuple(args,(char *)"hhh:V812_Set_Output_Width",&arg1,&arg2,&arg3)) goto fail; 1014 1014 result = (int)V812_Set_Output_Width(arg1,arg2,arg3); 1015 1015 -
trigger/communication.py
r77 r115 16 16 value = str(len(buf)) 17 17 #size = struct.pack("i",value) 18 print "length: ",len(buf)18 #rint "length: ",len(buf) 19 19 #print "SIZE: ",repr(size) 20 20 #channel.send(value) -
trigger/gui/t72/humidity.cpp
r77 r115 35 35 val=vall; 36 36 int bblue= (int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); 37 37 //int white = 255-bblue; 38 38 //int bblue=255-(int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); 39 39 //printf("%i %i\n",rred,bblue); 40 bgColor->setRgb( 0,0,bblue);40 bgColor->setRgb(255,bblue,0); 41 41 //QPalette::ColorRole 42 42 QPalette *mypalette=new QPalette(); -
trigger/gui/t72/main.cpp
r78 r115 213 213 connect(timer, SIGNAL(timeout()),this , SLOT(updateRates())); 214 214 215 timer->start( 7000);215 timer->start(5000); 216 216 217 217 -
trigger/v560.c
r52 r115 107 107 //if(v560_modules[i].registers->manufacturer_type==0x0818) { 108 108 if(v560_modules[i].registers->manufacturer_type==0x083A) { 109 109 //printf("v560-module %i found at address 0x%08x:\n\tMaster mapping: %i\n\tVirtual address: 0x%08x\n\n",i+1,tmp_base_address,v560_modules[i].master_mapping,v560_modules[i].registers); 110 110 v560_modules[i].present = 1; 111 111 } -
trigger/v812.c
r77 r115 54 54 //reading the hex address 55 55 if(!sscanf(&line[2],"%8x",&tmp_base_address)) { 56 56 printf("Reading input file v812_base.dat: non-comment line without address found. Please delete or comment this line.\n"); 57 57 } 58 58 … … 81 81 82 82 if(v812_modules[i].registers->manufacturer_type==0x0851) { 83 83 //printf("v812-module %i found at address 0x%08x:\n\tMaster mapping: %i\n\tVirtual address: 0x%08x\n\n",i+1,tmp_base_address,v812_modules[i].master_mapping,v812_modules[i].registers); 84 84 v812_modules[i].present = 1; 85 85 } … … 174 174 //****************************************************************************** 175 175 176 int V812_Set_Output_Width(short module, charchannel_block, short width)176 int V812_Set_Output_Width(short module, short channel_block, short width) 177 177 { 178 178 //channel_block: 0 for ch0-ch7, 1 for ch8-ch15 … … 271 271 for(i=0; i<NMAX_V812_MODULES; i++) { 272 272 if(v812_modules[i].present != 1) { 273 //printf("Module %i is not present.\n",i+1);273 printf("Module %i is not present.\n",i+1); 274 274 continue; 275 275 } -
trigger/v812.h
r77 r115 60 60 int V812_Set_Threshold(short module, short channel, short threshold); 61 61 int V812_Set_Pattern_Inhibit(short module, char channel[16]); 62 int V812_Set_Output_Width(short module, charchannel_block, short width);62 int V812_Set_Output_Width(short module,short channel_block, short width); 63 63 int V812_Set_Dead_Time(short module, short channel_block, short dead_time); 64 64 int V812_Set_Majority_Level(short module, short majority_level);
Note:
See TracChangeset
for help on using the changeset viewer.