#!/usr/bin/python ############################################################## # # CommunicateWithVME.py # Handles the communication with the VME crate # can send commands to the VME crate # # # Michael Rissi 05/2009 # ############################################################# import GlobalVariables import threading import _VME import time def GetRate(module,channel): _VME.V560_Clear_Scales( module) beginCounter=_VME. V560_Read_Counter( module, channel) print "Evaluating rates (2 seconds)..." time.sleep(2) endCounter = _VME. V560_Read_Counter( module, channel) return (endCounter-beginCounter)/2000. def GetRates(module): _VME.V560_Clear_Scales( module) beginCounter =[0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0] endCounter = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0] rates = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0] for i in range(0,16): beginCounter[i]=_VME. V560_Read_Counter( module, i) print beginCounter[i] print "Evaluating rates..." time.sleep(2) for i in range(0,16): endCounter[i] = _VME. V560_Read_Counter( module, i) print endCounter[i] rates[i] =(endCounter[i]-beginCounter[i])/2000. return rates class ParseUserInput(threading.Thread): def Parse(self,Command): print "PARSING: ",Command sCommand=Command.split() error_code=0 #python lacks switch... try: VMEModule=sCommand[0] if(VMEModule == "help"): print "please use \' help\' " # now do the stuff for the V560: if(VMEModule == "V560"): V560Command=sCommand[1] if(V560Command=="help"): print "available functions are: " print "V560 GetRate " print "V560 GetRates " if(V560Command=="GetRate"): print "trying to get rate" try: module = sCommand[2] channel= sCommand[3] print GetRate(int(module),int(channel)) except: print "Syntax Error (GetRate)" #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel)) if(V560Command=="GetRates"): print "trying to get rates" try: module = sCommand[2] print GetRates(int(module)) except: print "Syntax Error (GetRates)" #GlobalVariables.Rates[int(channel)] = GetRates(int(module),int(channel)) # now do the stuff for the V812: elif(VMEModule == "V812"): V812Command=sCommand[1] if(V812Command=="help"): print "available functions are: " print "V812 SetHexPat " print "V812 SetThresh " print "V812 SetMajLevel " print "V812 SetMajThresh " print "V812 SetDeadTime " #set the hexpattern: elif(V812Command=="SetHexPat"): print "trying to set the hexpattern:" try: module = int(sCommand[2]) hexpat = int(sCommand[3],16) #hexpat="ddd" print "setting module ",module," to hexpat: ",hex(hexpat) try: error_code=_VME.V812_Set_Pattern_Inhibit_Hex(module, hexpat) print "success! " except: VME_ErrorPrint(error_code) except: print "Syntax error (SetHexPat)" elif(V812Command=="SetThresh"): print "trying to set the threshold:" try: module = int(sCommand[2]) channel = int(sCommand[3]) thresh = int(sCommand[4]) print "setting threshold of channel: ",channel, " in module ",module," to: ",thresh print "success: ",_VME.V812_Set_Threshold(module, channel, thresh) except: print "Syntax error (SetThresh) " elif(V812Command=="SetMajLevel"): print "trying to set the majority level:" try: module = int(sCommand[2]) level = int(sCommand[3]) print "setting maj. level of module ",module," to: ",level print "success: ",_VME.V812_Set_Majority_Level(module,level) except: print "Syntax error (SetMajLevel)" elif(V812Command=="SetMajThresh"): print "trying to set the majority threshold:" try: module = int(sCommand[2]) thresh = int(sCommand[3]) print "setting maj. level of module ",module," to: ",thresh print "success: ",_VME.V812_Set_Majority_Threshold(module, thresh) except: print "Syntax error (SetMajThresh)" elif(V812Command=="SetDeadTime"): print "trying to set the majority threshold:" try: module = int(sCommand[2]) block = int(sCommand[3]) deadtime= int(sCommand[4]) print "setting deadtime of module ",module," block: ",block, " to: ",deadtime print "success: ",_VME.V812_Set_Dead_Time(module, block, deadtime); except: print "Syntax error (SetMajThresh)" else: print "Syntax Error (V812)" except: print "syntax error" #_VME.V812_Set_Threshold(1, 0, 255) def __init__(self): threading.Thread.__init__(self) def run(self): oldcommand=GlobalVariables.UserInput while(GlobalVariables.UserInput!="exit" and GlobalVariables.UserInput != "EXIT"): CommandToParse=GlobalVariables.UserInput if(oldcommand!=CommandToParse): self.Parse(CommandToParse) oldcommand=CommandToParse time.sleep(0.05) print "EXITING PARSER...press to exit"