#!/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) GlobalVariables.ServerMessage = "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 = ["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) #GlobalVariables.ServerMessage = str(beginCounter[i]) #GlobalVariables.ServerMessage = "Evaluating rates..." time.sleep(2) for i in range(0,16): endCounter[i] = _VME. V560_Read_Counter( module, i) #GlobalVariables.ServerMessage = str(endCounter[i]) rates[i+1] =(endCounter[i]-beginCounter[i])/2000. return rates class GimmeRates(threading.Thread): rates=["rates", 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0] module = 1 def run(self): oldcommand=GlobalVariables.UserInput while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"): time.sleep(0.001) newrates = GetRates(self.module) self.rates=newrates class ParseUserInput(threading.Thread): gimmeRates=GimmeRates() def Parse(self,Command): Command = Command[1:] #GlobalVariables.ServerMessage = "PARSING: " + Command sCommand=Command.split() error_code=0 #python lacks switch... try: VMEModule=sCommand[0] if(VMEModule == "help"): GlobalVariables.ServerMessage = "please use \' help\' " #GlobalVariables.ServerMessage="please use \' help\' " # now do the stuff for the V560: if(VMEModule == "V560"): V560Command=sCommand[1] if(V560Command=="help"): GlobalVariables.ServerMessage = "available functions are: \n" GlobalVariables.ServerMessage += "V560 GetRate \n" GlobalVariables.ServerMessage += "V560 GetRates