Changeset 13806 for fact/tools
- Timestamp:
- 05/21/12 16:15:31 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/PyDimCtrl/service.py
r13793 r13806 257 257 Take(-1, 1000, 'drs-time') 258 258 Take(-1, 1000, 'drs-time-upshifted') 259 260 261 262 263 def Connect( verbose=True ): 264 265 prepare_ftm_control() 266 prepare_fsc_control() 267 feedback.stop() 268 prepare_bias_control() 269 prepare_feedback() 270 prepare_data_logger() 271 272 273 def prepare_fsc_control( verbose = True, timeout = 10, delay = 0.2): 274 msg = MSG( verbose ) 275 fsc = fsc_control 276 start_time = time.time() 277 if timeout == None: 278 timeout = float('inf') 279 if delay < 0.: 280 delay = 0. 281 282 while not fsc.stn == 2: #Connected 283 if time.time() > start_time + timeout: 284 return False 285 286 if (fsc.stn <= 0) or (fsc.stn >= 256): 287 msg.fail("FSC_CONTROL is in state "+fsc.sts) 288 msg.fail(prepare_fsc_control.__name__ + "does not know how to handle this") 289 return False 290 elif fsc.stn == 1: # Disconnected 291 fsc.reconnect() 292 return True 293 294 def prepare_ftm_control( verbose = True, timeout = 10, delay = 0.2): 295 msg = MSG( verbose ) 296 ftm = ftm_control 297 start_time = time.time() 298 if timeout == None: 299 timeout = float('inf') 300 if delay < 0.: 301 delay = 0. 302 303 while not ftm.stn == 3: 304 if time.time() > start_time + timeout: 305 return False 306 307 if (ftm.stn <= 0) or (ftm.stn >= 256): 308 msg.fail("FMT_CONTROL is in state "+ftm.sts) 309 msg.fail("ftm_to_Idle() does not know how to handle this") 310 return False 311 elif ftm.stn == 1: # Disconnected 312 ftm.reconnect() 313 elif ftm.stn == 2: #Connected 314 # just wait a second 315 time.sleep(1) 316 elif ftm.stn == 4: #TriggerOn 317 ftm.enable_trigger(0) #switch trigger off 318 elif ftm.stn in [5,6,7]: # some Configure state 319 ftm.reset_configure() 320 321 return True 322 323 def prepare_data_logger( verbose = True, timeout = 10, delay = 0.2): 324 msg = MSG(verbose) 325 dl = data_logger 326 if timeout == None: 327 timeout = float('inf') 328 if delay < 0.: 329 delay = 0. 330 start_time = time.time() 331 raise NotImplementedError('prepare_data_logger() is not yet implemented') 332 333 def prepare_fad_control( verbose = True, timeout = 10, delay = 0.2): 334 msg = MSG(verbose) 335 fad = fad_control 336 ftm = ftm_control 337 if timeout == None: 338 timeout = float('inf') 339 if delay < 0.: 340 delay = 0. 341 start_time = time.time() 342 343 while not fad.stn == 4: 344 # Timeout 345 if time.time() > start_time + timeout: 346 msg.fail("Timeout in " + prepare_fad_control.__name__) 347 return False 348 # Strange States 349 if (fad.stn <= 0) or (fad.stn >= 256): 350 msg.fail("FAD_CONTROL is in state "+fad.sts) 351 msg.fail(prepare_fad_control.__name__ + "does not know how to handle this") 352 return False 353 elif fad.stn == 1: # Disengaged 354 fad.start() 355 elif fad.stn == 2: # Disconnected 356 fad.start() 357 elif fad.stn == 3: # Connecting 358 # it might just need time 359 if time.time() - fad.last_st_change < 5: 360 time.sleep(2) 361 timeout += 1 362 else: 363 # there might be a problem with one of the boards 364 conns = map( ord, fad.connections()[0] ) 365 problems = {} 366 for fad,conn in enumerate(conns): 367 if conn < 255: 368 print "FAD:", fad, "has a problem" 369 if not fad/10 in problems: 370 problems[fad/10] = [] 371 else: 372 problems[fad/10].append( fad%10 ) 373 374 for fad in range(10): 375 for crate in problems.keys(): 376 fad.disconnect(crate*10+fad) 377 ftm.toggle_ftu(crate*10+fad) 378 for crate in problems.keys(): 379 time.sleep(1) 380 ftm.reset_crate(crate) 381 382 for fad in range(10): 383 for crate in problems.keys(): 384 time.sleep(3.5) 385 fad.connect(crate*10+fad) 386 ftm.toggle_ftu(crate*10+fad) 387 388 elif fad.stn == 5: # Configuring1 389 if time.time() - fad.last_st_change < 5: 390 time.sleep(1) 391 else: 392 msg.warn("FAD is in Configuring1 since more than 5sec") 393 394 elif fad.stn == 6: # Configuring2 395 if time.time() - fad.last_st_change < 5: 396 time.sleep(1) 397 else: 398 msg.warn("FAD is in Configuring2 since more than 5sec") 399 400 elif fad.stn == 7: # Configured 401 if time.time() - fad.last_st_change < 5: 402 time.sleep(1) 403 else: 404 msg.warn("FAD is in Configuring2 since more than 5sec") 405 406 elif fad.stn == 8: #WritingData 407 # I don't know how to get from WritingData to Connected 408 # well. .. one could wait for a timeout, but I hate that. 409 fad.close_open_files() 410 411 412 time.sleep(delay) 413 return True 414 415 def prepare_bias_control( verbose = True, timeout = 10, delay = 0.2): 416 msg = MSG(verbose) 417 bias = bias_control 418 419 if timeout == None: 420 timeout = float('inf') 421 if delay < 0.: 422 delay = 0. 423 start_time = time.time() 424 425 while (bias.stn != 4) and (bias.stn != 7): #Connected or VoltageOff 426 # Timeout 427 if time.time() > start_time + timeout: 428 msg.fail("Timeout in " + prepare_bias_control.__name__) 429 return False 430 # Strange States 431 if (bias.stn <= 0) or (bias.stn >= 256): 432 msg.fail("BIAS_CONTROL is in state "+bias.sts) 433 msg.fail(prepare_bias_control.__name__ + "does not know how to handle this") 434 return False 435 elif bias.stn == 1: # Disconnected 436 bias.reconnect() 437 elif bias.stn == 2: # Connecting 438 if time.time() - bias.last_st_change < 5: 439 time.sleep(1) 440 else: 441 msg.warn("BIAS_CONTROL is in Connecting since more than 5sec") 442 elif bias.stn == 3: # Initializing 443 if time.time() - bias.last_st_change < 5: 444 time.sleep(1) 445 else: 446 msg.warn("BIAS_CONTROL is in Initializing since more than 5sec") 447 elif bias.stn == 5: #Ramping 448 if time.time() - bias.last_st_change < 10: 449 time.sleep(1) 450 else: 451 msg.warn("BIAS_CONTROL is in Ramping since more than 10sec") 452 bias.stop() 453 elif bias.stn == 6: #OverCurrent 454 time.sleep(0.5) 455 bias.set_zero_voltage() 456 time.sleep(0.5) 457 bias.reset_over_current_status() 458 time.sleep(0.5) 459 elif bias.stn == 8: #NotReferenced 460 time.sleep(0.5) 461 bias.set_zero_voltage() 462 time.sleep(0.5) 463 elif bias.stn == 9: # VoltageOn 464 time.sleep(0.5) 465 bias.set_zero_voltage() 466 time.sleep(0.5) 467 elif bias.stn == 10: # ExpoertMode 468 msg.fail("BIAS is in ExportMode ... wtf") 469 return False 470 471 time.sleep(delay) 472 return True 473 474 def prepare_feedback( verbose = True, timeout = 10, delay = 0.2): 475 msg = MSG(verbose) 476 fb = feedback 477 if timeout == None: 478 timeout = float('inf') 479 if delay < 0.: 480 delay = 0. 481 start_time = time.time() 482 483 while not fb.stn == 6: #Connected 484 # Timeout 485 if time.time() > start_time + timeout: 486 msg.fail("Timeout in " + prepare_feedback.__name__) 487 return False 488 # Strange States 489 if (fb.stn <= 1) or (fb.stn >= 256): 490 msg.fail("FEEDBACK is in state "+fb.sts) 491 msg.fail(prepare_feedback.__name__ + "does not know how to handle this") 492 return False 493 elif fb.stn in [2,3,4,5]: 494 if time.time() - fb.last_st_change < 10: 495 time.sleep(1) 496 else: 497 msg.warn("BIAS_CONTROL is in "+fb.sts+" since more than 10sec") 498 499 elif fb.stn in [7,8,9]: 500 fb.stop() 501 502 elif fb.stn in [10,11,12]: 503 fb.enable_output(0) 504 fb.stop() 505 506 elif fb.stn == 13: 507 # maybe waiting helps 508 if time.time() - fb.last_st_change < 20: 509 time.sleep(1) 510 else: 511 msg.warn("FEEDBACK is in "+fb.sts+" since more than 20sec \n sending STOP") 512 fb.stop() 513 514 time.sleep(delay) 515 return True 516 259 517 260 518
Note:
See TracChangeset
for help on using the changeset viewer.