Beispiel #1
0
def TuneSwitch():
    """
    TuneSwitch() switches bewteen the listed tunes.
    """
    RunN = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Runcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Runcurrn += 1
    if Runcurrn > RunN:
        Runcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Runcurrn)

    #Tunes, currn, CurrentTune = zip(*Midas.dirlist(TuneSwitchPath))[1]
    Tunes = Midas.varget(TuneSwitchPath + "TunesList")
    currn = Midas.varget(TuneSwitchPath + "CurrentTuneIndex")
    #CurrentTune = Midas.varget(TuneSwitchPath + "CurrentTuneName")

    currn = int(currn)
    Tunes = StringToList(Tunes)

    currn += 1
    if currn > len(Tunes):
        currn = 1
    Midas.varset(TuneSwitchPath + "CurrentTuneIndex", currn)
    currn -= 1

    ChangeTune(Tunes[currn])
    Midas.varset(TuneSwitchPath + "CurrentTuneName", Tunes[currn])
    return "Tune is \"" + Tunes[currn] + "\""
def TuneSwitch():
    """
    TuneSwitch() switches bewteen the listed tunes.
    """
    RunN = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Runcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Runcurrn += 1
    if Runcurrn > RunN:
        Runcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Runcurrn)

    #Tunes, currn, CurrentTune = zip(*Midas.dirlist(TuneSwitchPath))[1]
    Tunes = Midas.varget(TuneSwitchPath + "TunesList")
    currn = Midas.varget(TuneSwitchPath + "CurrentTuneIndex")
    #CurrentTune = Midas.varget(TuneSwitchPath + "CurrentTuneName")

    currn = int(currn)
    Tunes = StringToList(Tunes)

    currn += 1
    if currn > len(Tunes):
        currn = 1
    Midas.varset(TuneSwitchPath + "CurrentTuneIndex", currn)
    currn -= 1

    ChangeTune(Tunes[currn])
    Midas.varset(TuneSwitchPath + "CurrentTuneName", Tunes[currn])
    return "Tune is \"" + Tunes[currn] + "\""
    def afgSetFreqList(self):
        '''Over-ride the default afgSetFreqList, and instead
        program the afg into burst mode with the given
        centre frequency, and take the frequency modulation
        to be the phase offset.
        '''
        self.afgClear()

        print "In Here"

        RFAmp = float(Midas.varget(self.varRFAMP))

        # Get frequency, and if it's a list, only take the first element
        #self.getFrequencyCentre()
        centfreq = float(Midas.varget(self.varFreqC))
        centfreq = str(centfreq / 1000000.) + "E06"

        # Get frequency modulation, and use it as the phase offset
        # If it's a list, only take the first element
        #self.getFrequencyModulation()
        #phase = self.FreqMod[0]
        phase = float(Midas.varget(self.varFreqMod))

        self.afgWrite("APPL:SIN " + centfreq + ", " + str(RFAmp) + " VPP, 0")
        print "APPL:SIN " + centfreq + ", " + str(RFAmp) + " VPP, 0"
        self.afgSetTigger()
        self.afgWrite("BURS:MODE GATED")
        self.afgWrite("BURS:PHAS " + str(phase))
        self.afgWrite("BURS:STAT ON")

        self.afgOnOff()
    def afgSetFreqList(self):
        '''Over-ride the default afgSetFreqList, and instead
        program the afg into burst mode with the given
        centre frequency, and take the frequency modulation
        to be the phase offset.
        '''
        self.afgClear()

        print "In Here"

        RFAmp = float(Midas.varget(self.varRFAMP))

        # Get frequency, and if it's a list, only take the first element
        #self.getFrequencyCentre()
        centfreq = float(Midas.varget(self.varFreqC))
        centfreq = str(centfreq / 1000000.) + "E06"

        # Get frequency modulation, and use it as the phase offset
        # If it's a list, only take the first element
        #self.getFrequencyModulation()
        #phase = self.FreqMod[0]
        phase = float(Midas.varget(self.varFreqMod))

        self.afgWrite("APPL:SIN " + centfreq + ", " + str(RFAmp) + " VPP, 0")
        print "APPL:SIN " + centfreq + ", " + str(RFAmp) + " VPP, 0"
        self.afgSetTigger()
        self.afgWrite("BURS:MODE GATED")
        self.afgWrite("BURS:PHAS " + str(phase))
        self.afgWrite("BURS:STAT ON")

        self.afgOnOff()
Beispiel #5
0
def main():
    StartScan = Midas.varget(RCActive)
    try:  # If called from the command line parse the arguements
        print sys.argv
        if len(sys.argv) == 2:
            # Start a PerlRC scan
            if sys.argv[1] == "start":
                Midas.varset(RCActive, 'y')
                StartScan = 'y'
            # Stop a PerlRC scan
            if sys.argv[1] == "stop":
                Midas.varset(RCActive, 'n')
                StartScan = 'n'
        # Change to a tune
        elif len(sys.argv) == 3 and sys.argv[1] == "tune":
            try:
                ChangeTune(sys.argv[2])
                LogSwitchedTune(sys.argv[2])
            except:
                LogSwitchedTune(sys.argv[2], True)
    except:  # calling it as a module, so ignore the stuff above
        pass

    # If we're doing a PerlRC scan, do what's in the ODB.
    if StartScan == 'y':
        ScanFuncs = {
            "SCAN1D": Scan1D,
            "SCAN2D": Scan2D,
            "TUNESWITCH": TuneSwitch
        }

        # Get the scan type and convert to uppercase
        ScanType = Midas.varget(RunControlPath + "RCType").upper()
        try:
            # call scan function based on the ScanType
            scanoutput = ScanFuncs[ScanType]()
            # Write some info to the log file
            # LogScanStart and LogScanStop only write something
            # if it's the beginning or end of a PerlRC scan.
            LogScanStart()
            LogScanVarStep(scanoutput)
            LogScanStop()

            # Sleep for a second so that scepics can update
            # the values
            time.sleep(1)
            Midas.startrun()
        except:
            # Error occurred. Stop future runs, and write an error message
            Midas.varset(RCActive, 'n')
            LogScanError()
            Midas.sendmessage(
                "pythonrc", "There was a problem. " +
                "Please check input variables and values, " +
                "and the message log for more info.")
def main():
    StartScan = Midas.varget(RCActive)
    try:  # If called from the command line parse the arguements
        print sys.argv
        if len(sys.argv) == 2:
            # Start a PerlRC scan
            if sys.argv[1] == "start":
                Midas.varset(RCActive, 'y')
                StartScan = 'y'
            # Stop a PerlRC scan
            if sys.argv[1] == "stop":
                Midas.varset(RCActive, 'n')
                StartScan = 'n'
        # Change to a tune
        elif len(sys.argv) == 3 and sys.argv[1] == "tune":
            try:
                ChangeTune(sys.argv[2])
                LogSwitchedTune(sys.argv[2])
            except:
                LogSwitchedTune(sys.argv[2], True)
    except:  # calling it as a module, so ignore the stuff above
        pass

    # If we're doing a PerlRC scan, do what's in the ODB.
    if StartScan == 'y':
        ScanFuncs = {"SCAN1D": Scan1D,
                     "SCAN2D": Scan2D,
                     "TUNESWITCH": TuneSwitch}

        # Get the scan type and convert to uppercase
        ScanType = Midas.varget(RunControlPath + "RCType").upper()
        try:
            # call scan function based on the ScanType
            scanoutput = ScanFuncs[ScanType]()
            # Write some info to the log file
            # LogScanStart and LogScanStop only write something
            # if it's the beginning or end of a PerlRC scan.
            LogScanStart()
            LogScanVarStep(scanoutput)
            LogScanStop()

            # Sleep for a second so that scepics can update
            # the values
            time.sleep(1)
            Midas.startrun()
        except:
            # Error occurred. Stop future runs, and write an error message
            Midas.varset(RCActive, 'n')
            LogScanError()
            Midas.sendmessage("pythonrc", "There was a problem. " +
                              "Please check input variables and values, " +
                              "and the message log for more info.")
Beispiel #7
0
def LogScanStop():
    """
    Write iformation to the PerlRC.log file at the end of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))
    NRuns = int(Midas.varget(RunControlPath + "RCTotalRuns"))

    if CurrentScan == NRuns:
        with open(LogFile, 'a') as myfile:
            myfile.write("===             Finished PerlRC scan" + "===\n")
            myfile.write("====================================" +
                         "================\n")

        # Deactivate the Scans
        Midas.varset(RCActive, 'n')
    def test_varget(self, mock_odbcommand):
        mock_odbcommand.return_value = "return value"

        result = Midas.varget("key")

        self.assertEqual(result, "return value")
        mock_odbcommand.assert_called_with("ls -v", "key")
Beispiel #9
0
    def test_varget(self, mock_odbcommand):
        mock_odbcommand.return_value = "return value"

        result = Midas.varget("key")

        self.assertEqual(result, "return value")
        mock_odbcommand.assert_called_with("ls -v", "key")
def LogScanStop():
    """
    Write iformation to the PerlRC.log file at the end of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))
    NRuns = int(Midas.varget(RunControlPath + "RCTotalRuns"))

    if CurrentScan == NRuns:
        with open(LogFile, 'a') as myfile:
            myfile.write("===             Finished PerlRC scan" +
                         "===\n")
            myfile.write("====================================" +
                         "================\n")

        # Deactivate the Scans
        Midas.varset(RCActive, 'n')
def GetVarName(perlVarName):
    """
    Given the PerlRC variable name, return the path to the location of the ODB
    variable.
    *** Essentially return the value associated with the variable in the
    /PerlRC/ControlVariable directory.
    """
    global ControlVarPath
    return Midas.varget(ControlVarPath + perlVarName)
Beispiel #12
0
def GetVarName(perlVarName):
    """
    Given the PerlRC variable name, return the path to the location of the ODB
    variable.
    *** Essentially return the value associated with the variable in the
    /PerlRC/ControlVariable directory.
    """
    global ControlVarPath
    return Midas.varget(ControlVarPath + perlVarName)
def LogScanVarStep(ScanString=""):
    """
    Write the ScanString to PerlRC.log.
    """

    CurrentRun = int(Midas.varget("/Runinfo/Run number")) + 1
    CurrentRun = str(CurrentRun)

    with open(LogFile, 'a') as myfile:
        myfile.write("<Run #" + CurrentRun + "> " + ScanString + "\n")
 def openConnection(self, ipAddress="", Port="5024"):
     if ipAddress is "":
         ipAddress = Midas.varget(self.afgAddress)
         print ipAddress
     self.setip(ipAddress)
     self.setPort(Port)
     #print self.host
     self.telnet = telnetlib.Telnet(self.host, self.port, 9999)
     if self.telnet.expect(self.regex)[0] > -1:
         self.connectionOpen = True
Beispiel #15
0
def LogScanVarStep(ScanString=""):
    """
    Write the ScanString to PerlRC.log.
    """

    CurrentRun = int(Midas.varget("/Runinfo/Run number")) + 1
    CurrentRun = str(CurrentRun)

    with open(LogFile, 'a') as myfile:
        myfile.write("<Run #" + CurrentRun + "> " + ScanString + "\n")
Beispiel #16
0
    def getReference(self):
        '''Get the RF calibration from the ODB'''

        self.refname = Midas.varget("/Experiment/Variables/" +
                                    "MPET RF Calibration/Reference Ion")
        self.reffreq = float(Midas.varget("/Experiment/Variables/" +
                                          "MPET RF Calibration/" +
                                          "Reference Frequency"))
        self.refcharge = float(Midas.varget("/Experiment/Variables/" +
                                            "MPET RF Calibration/" +
                                            "Reference Charge"))
        self.refmagnetron = float(Midas.varget("/Experiment/Variables/" +
                                               "MPET RF Calibration/" +
                                               "FreqMinus (Hz)"))
        try:
            self.reffreqerr = float(Midas.varget("/Experiment/Variables/" +
                                                 "MPET RF Calibration/" +
                                                 "Reference Frequency Error"))
        except:
            self.reffreqerr = 0.0
def LogScanStart():
    """
    Writes information to the PerlRC.log file at the beginning of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    if CurrentScan == 1:
        CurrentTime = GetTime()
        CurrentTune = Midas.varget(RunControlPath +
                                   "TuneSwitch/CurrentTuneName")
        ScanType = Midas.varget(RunControlPath + "RCType")
        NRuns = Midas.varget(RunControlPath + "RCTotalRuns")

        with open(LogFile, 'a') as myfile:
            myfile.write("=== NEW PerlRC scan at " + CurrentTime + " ===\n")
            myfile.write("=== Scan type is \"" + ScanType + "\"; "
                         + "Current Tune is \"" + CurrentTune + "\" ===\n")
            myfile.write("=== Number of runs in this scan is " +
                         NRuns + " ===\n")
Beispiel #18
0
def LogScanStart():
    """
    Writes information to the PerlRC.log file at the beginning of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    if CurrentScan == 1:
        CurrentTime = GetTime()
        CurrentTune = Midas.varget(RunControlPath +
                                   "TuneSwitch/CurrentTuneName")
        ScanType = Midas.varget(RunControlPath + "RCType")
        NRuns = Midas.varget(RunControlPath + "RCTotalRuns")

        with open(LogFile, 'a') as myfile:
            myfile.write("=== NEW PerlRC scan at " + CurrentTime + " ===\n")
            myfile.write("=== Scan type is \"" + ScanType + "\"; " +
                         "Current Tune is \"" + CurrentTune + "\" ===\n")
            myfile.write("=== Number of runs in this scan is " + NRuns +
                         " ===\n")
Beispiel #19
0
    def setAmplitude(self):
        rfamp = float(Midas.varget(self.varRFAmp))
        self.RFAmplitude = rfamp

        self.RFAmplitude = (self.RFAmplitude
                            if self.RFAmplitude > self.minRFAmp else
                            self.minRFAmp)
        self.RFAmplitude = (self.RFAmplitude
                            if self.RFAmplitude < self.maxRFAmp else
                            self.maxRFAmp)

        self.afgWrite("VOLT " + str(rfamp))
    def getFrequencyModulation(self):
        """
        Get the frequency modulation from the ODB.

        If the variable is empty, set the frequency modulation to zero.
        """
        self.FreqMod = str(Midas.varget(self.varFreqMod))
        try:
            self.FreqMod = [float(x.strip()) for x in self.FreqMod.split(";")]
        except ValueError:
            self.FreqMod = [0.0]
        print self.FreqMod
    def setAmplitude(self):
        rfamp = float(Midas.varget(self.varRFAmp))
        self.RFAmplitude = rfamp

        self.RFAmplitude = (self.RFAmplitude
                            if self.RFAmplitude > self.minRFAmp
                            else self.minRFAmp)
        self.RFAmplitude = (self.RFAmplitude
                            if self.RFAmplitude < self.maxRFAmp
                            else self.maxRFAmp)

        self.afgWrite("VOLT " + str(rfamp))
Beispiel #22
0
    def getReference(self):
        '''Get the RF calibration from the ODB'''

        self.refname = Midas.varget("/Experiment/Variables/" +
                                    "MPET RF Calibration/Reference Ion")
        self.reffreq = float(
            Midas.varget("/Experiment/Variables/" + "MPET RF Calibration/" +
                         "Reference Frequency"))
        self.refcharge = float(
            Midas.varget("/Experiment/Variables/" + "MPET RF Calibration/" +
                         "Reference Charge"))
        self.refmagnetron = float(
            Midas.varget("/Experiment/Variables/" + "MPET RF Calibration/" +
                         "FreqMinus (Hz)"))
        try:
            self.reffreqerr = float(
                Midas.varget("/Experiment/Variables/" +
                             "MPET RF Calibration/" +
                             "Reference Frequency Error"))
        except:
            self.reffreqerr = 0.0
    def calcRFAmplitude(self):
        ExTime = self.getExcitationTime()
        calExTime = float(Midas.varget(self.varCalExTime))
        calVoltage = float(Midas.varget(self.varCalVolatage))
        takeUser = Midas.varget(self.varTakeUser)

        if takeUser == "y":
            RFAmpCalc = float(Midas.varget(self.varRFUserAmp))
        else:
            RFAmpCalc = calVoltage * calExTime / ExTime

        # Ensure RF amplitude is at least the minimum, and less than 2.0V
        if RFAmpCalc < self.minRFAmp:
            RFAmpCalc = self.minRFAmp
        elif RFAmpCalc > self.maxRFAmp:
            RFAmpCalc = self.maxRFAmp

        # Update RF amplitude in ODB with the calculated value
        Midas.varset(self.varRFUserAmp, str(RFAmpCalc))

        return RFAmpCalc
Beispiel #24
0
def Scan1D():
    """
    Scan1D() does a 1D scan
    """
    Scan1Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan1Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    # Update the current scan number in the RunControlPath
    Scan1Dcurrn += 1
    if Scan1Dcurrn > Scan1Dn:
        Scan1Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan1Dcurrn)
    Scan1Dcurrn -= 1  # To get the right scan range.

    # Get the varibales to be scanned, and the start and stop values
    Variables = Midas.varget(Scan1DPath + "Variables")
    Start = Midas.varget(Scan1DPath + "VarStart")
    Stop = Midas.varget(Scan1DPath + "VarStop")
    # Don't need the totalsteps or currentstep for 1D scan
    #n = Midas.varget(Scan2DPath + "VarSteps")
    #currn = Midas.varget(Scan2DPath + "VarCurrentStep")

    print Variables

    Variables, Start, Stop = map(StringToList, [Variables, Start, Stop])
    Start, Stop = map(StringListToFloatList, [Start, Stop])

    NextVariableStep = map(
        lambda x, y: NextVariableSetPoint(x, y, Scan1Dn, Scan1Dcurrn), Start,
        Stop)

    returnstr = ""
    for var, val in zip(Variables, NextVariableStep):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
def Scan1D():
    """
    Scan1D() does a 1D scan
    """
    Scan1Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan1Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    # Update the current scan number in the RunControlPath
    Scan1Dcurrn += 1
    if Scan1Dcurrn > Scan1Dn:
        Scan1Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan1Dcurrn)
    Scan1Dcurrn -= 1  # To get the right scan range.

    # Get the varibales to be scanned, and the start and stop values
    Variables = Midas.varget(Scan1DPath + "Variables")
    Start = Midas.varget(Scan1DPath + "VarStart")
    Stop = Midas.varget(Scan1DPath + "VarStop")
    # Don't need the totalsteps or currentstep for 1D scan
    #n = Midas.varget(Scan2DPath + "VarSteps")
    #currn = Midas.varget(Scan2DPath + "VarCurrentStep")

    print Variables

    Variables, Start, Stop = map(StringToList, [Variables, Start, Stop])
    Start, Stop = map(StringListToFloatList, [Start, Stop])

    NextVariableStep = map(lambda x, y:
                           NextVariableSetPoint(x, y, Scan1Dn, Scan1Dcurrn),
                           Start, Stop)

    returnstr = ""
    for var, val in zip(Variables, NextVariableStep):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
    def getExcitationTime(self):
        ExTime = 0.
        transition = 2
        while True:
            try:
                temp = Midas.varget("/Equipment/TITAN_ACQ/ppg cycle/" +
                                    "transition_QUAD" +
                                    str(transition) +
                                    "/time offset (ms)")
                transition += 2
                ExTime += float(temp)
            except:
                break

        return ExTime
Beispiel #27
0
def check_run_state():
    """
    Check the run state.
    """
    path = "/Runinfo/State"
    state = int(Midas.varget(path))

    if state == 1:
        return "stopped"
    if state == 2:
        return "paused"
    if state == 3:
        return "running"

    # should never get here, but return "running" so that we don't
    # mess anything up.
    return "running"
    def getFrequencyCentre(self):
        """
        Get user input from the ODB and calculate the respective centre
        frequencies using the "calcFreq" module.

        Expected Midas Variable Structure:
            semi-colon delimited and equal-length lists.

        If any list is too short, the last value in the list is appended
        so that each list is the same length.
        """
        self.FreqC = str(Midas.varget(self.varFreqC))
        self.FreqC = [x.strip() for x in self.FreqC.split(";")]
        #print self.FreqC

        temp = self.afgGetSpecies()
        #print temp

        self.Charge = self.afgGetCharge()
        #print self.Charge

        listmax = max([len(x) for x in [self.FreqC, temp, self.Charge]])
        #print listmax

        for mylist in [self.FreqC, temp, self.Charge]:
            if mylist == [""]:
                raise Exception("afgcontrol: An ODB variable is empty!")
            while len(mylist) < listmax:
                mylist.append(mylist[-1])
            #print mylist

        self.Species = []
        for i in range(len(temp)):
            self.Species.append(temp[i] + " " + self.Charge[i])
            if self.FreqC[i].lower() == 'freqc':
                self.FreqC[i] = self.CF.cyclotron_frequencies(
                    self.Species[i])[0]
            elif self.FreqC[i].lower() == 'freqp':
                self.FreqC[i] = self.CF.dipole_frequencies(
                    self.Species[i])[0]
            else:
                self.FreqC[i] = float(self.FreqC[i])
        print self.FreqC
    def __init__(self):
        afg.__init__(self)
        #self.openConnection('142.90.119.225')
        afgAddress = Midas.varget("/Experiment/Variables/AFG Addresses/Burst")
        print afgAddress
        #self.openConnection('mpetswift')
        self.openConnection(ipAddress=afgAddress)
        #self.afgName = 'swiftdipole'
        self.afgName = 'Burst'
        self.varOnOff = '/Experiment/Variables/Burst/AFG On'
        self.varFreqC = ('/Experiment/Variables/Burst/' +
                         'Center Frequency (Hz)')
        self.varFreqMod = ('/Experiment/Variables/Burst/Phase (degrees)')
        self.varRFAMP = ('/Experiment/Variables/Burst/RF Amplitude (V)')
        #self.varSpecies = '/Experiment/Variables/SwiftDipole/Species'
        #self.afgClear()
        #self.afgSetSine()
        #self.afgSetModeList()
        #self.CF = CF.calcFreq()
        #self.CF.getReference()

        self.afgOnPath = "/Experiment/Variables/Burst/AFG On"
    def __init__(self):
        afg.__init__(self)
        #self.openConnection('142.90.119.225')
        afgAddress = Midas.varget("/Experiment/Variables/AFG Addresses/Burst")
        print afgAddress
        #self.openConnection('mpetswift')
        self.openConnection(ipAddress=afgAddress)
        #self.afgName = 'swiftdipole'
        self.afgName = 'Burst'
        self.varOnOff = '/Experiment/Variables/Burst/AFG On'
        self.varFreqC = ('/Experiment/Variables/Burst/' +
                         'Center Frequency (Hz)')
        self.varFreqMod = ('/Experiment/Variables/Burst/Phase (degrees)')
        self.varRFAMP = ('/Experiment/Variables/Burst/RF Amplitude (V)')
        #self.varSpecies = '/Experiment/Variables/SwiftDipole/Species'
        #self.afgClear()
        #self.afgSetSine()
        #self.afgSetModeList()
        #self.CF = CF.calcFreq()
        #self.CF.getReference()

        self.afgOnPath = "/Experiment/Variables/Burst/AFG On"
Beispiel #31
0
    def __init__(self):
        afg.__init__(self)
        afgAddress = Midas.varget("/Experiment/Variables/AFG Addresses/Dipole")
        print afgAddress

        self.openConnection(ipAddress=afgAddress)

        self.afgName = 'Dipole'
        self.varRFAmp = '/Experiment/Variables/SwiftDipole/RF Amplitude (V)'
        self.varFreqC = ('/Experiment/Variables/SwiftDipole/' +
                         'Center Frequency (Hz)')
        self.varFreqMod = ('/Experiment/Variables/SwiftDipole/' +
                           'Frequency Modulation (Hz)')
        self.varSpecies = '/Experiment/Variables/SwiftDipole/Species'
        self.varCharge = '/Experiment/Variables/SwiftDipole/Species'
        self.varFreqList = "/Experiment/Variables/Dipole FreqList"

        self.CF = CF.calcFreq()
        self.CF.getReference()

        self.afgOnPath = "/Experiment/Variables/SwiftDipole/AFG On"

        self.varStartFreq = "/Experiment/Variables/StringDump"
        self.varStopFreq = "/Experiment/Variables/StringDump"
    def __init__(self):
        afg.__init__(self)
        afgAddress = Midas.varget("/Experiment/Variables/AFG Addresses/Dipole")
        print afgAddress

        self.openConnection(ipAddress=afgAddress)

        self.afgName = 'Dipole'
        self.varRFAmp = '/Experiment/Variables/SwiftDipole/RF Amplitude (V)'
        self.varFreqC = ('/Experiment/Variables/SwiftDipole/' +
                         'Center Frequency (Hz)')
        self.varFreqMod = ('/Experiment/Variables/SwiftDipole/' +
                           'Frequency Modulation (Hz)')
        self.varSpecies = '/Experiment/Variables/SwiftDipole/Species'
        self.varCharge = '/Experiment/Variables/SwiftDipole/Species'
        self.varFreqList = "/Experiment/Variables/Dipole FreqList"

        self.CF = CF.calcFreq()
        self.CF.getReference()

        self.afgOnPath = "/Experiment/Variables/SwiftDipole/AFG On"

        self.varStartFreq = "/Experiment/Variables/StringDump"
        self.varStopFreq = "/Experiment/Variables/StringDump"
import pythonmidas.pythonmidas as Midas
import time
import smtplib

# Time command was last executed
VacuumAlarmFirstTriggered = "/Alarms/Alarms/MPET Vacuum/Time triggered first"

# Check when the last time the command was executed.
# If it is '0', then it is the first time the alarm is executed,
# so we should send an email.
# Otherwise, if the last time the command was executed is greater
# than zero, we should not send an email.

# Get the time the alarm was first triggered
try:
    FirstTriggered = time.strptime(Midas.varget(VacuumAlarmFirstTriggered),
                                   "%a %b %d %H:%M:%S %Y")
    FirstTriggered = time.mktime(FirstTriggered)
except:
    FirstTriggered = 0
    print "First Triggered Time is empty!"

# Get the current time
CurrentTime = time.mktime(time.localtime())

# If the current time and first triggered time are close together
# send an email to the mailing list
if CurrentTime - FirstTriggered < 10:
    SERVER = "localhost"
    FROM = "*****@*****.**"
    # Get list of addresses for email
    def afgGetSpecies(self):
        species = Midas.varget(self.varSpecies).replace("+", "")
        species = [x.split()[0].strip() for x in species.split(";")]
        print species

        return species
    def afgGetCharge(self):
        charge = Midas.varget(self.varCharge).replace("+", "")
        charge = [x.split()[-1].strip() for x in charge.split(";")]
        print charge

        return charge
 def afgOnOff(self):
     state = Midas.varget(self.afgOnPath)
     if state == 'y':
         self.afgWrite("OUTP ON")
     else:
         self.afgWrite("OUTP OFF")
    def afgGetCharge(self):
        charge = Midas.varget(self.varCharge)
        charge = [x.strip() for x in charge.split(";")]

        return charge
 def afgStartMenuOnOff(self):
     userstate = Midas.varget(self.afgOnPath)
     userstate = (userstate == 'y')
     self.afgTurnOnOff(userstate)
Beispiel #39
0
 def afgOnOff(self):
     state = Midas.varget("/Experiment/Variables/SwiftDipole/AFG On")
     if state == 'y':
         self.afgWrite("OUTP ON")
     else:
         self.afgWrite("OUTP OFF")
    def afgGetSpecies(self):
        species = Midas.varget(self.varSpecies)
        species = [x.strip() for x in species.split(";")]

        return species
Beispiel #41
0
    def afgGetCharge(self):
        charge = Midas.varget(self.varCharge).replace("+", "")
        charge = [x.split()[-1].strip() for x in charge.split(";")]
        print charge

        return charge
Beispiel #42
0
    def afgGetSpecies(self):
        species = Midas.varget(self.varSpecies).replace("+", "")
        species = [x.split()[0].strip() for x in species.split(";")]
        print species

        return species
Beispiel #43
0
#!/usr/bin/python
# A.A. Kwiatkowski February 2013
# stop RFQ PSD, based off A.T. Gallant's test.py

import pythonmidas.pythonmidas as Midas

#print "\nTesting sendmessage: name=test msg=test message"
Midas.sendmessage("Alarm:", "An ISAC Exhaust Fan has failed: Kill RFQ PSD")

print Midas.varget("/Equipment/Beamline/Variables/Measured[124]")

# The Demand isn't set again if it is the same value as previously used.
Midas.varset("/Equipment/Beamline/Variables/Demand[124]", 1)
Midas.varset("/Equipment/Beamline/Variables/Demand[124]", 0)
        print "Element in input", name, "does not exist in AME table."
        #passes = False
        Midas.sendmessage("DipoleCalculator", "Element in input " + name +
                          " does not exist in AME table.")

    return passes


#####################
# Start the program
#####################

if __name__ == "__main__":
    #args = sys.argv

    #if len(args) > 1 and args[1] == "dipole":
        names = Midas.varget("/Experiment/Variables/Contaminants/" +
                             "Contaminant List")

        reducedCyclotron = CF.dipole_frequencies(names)
        cyclotron = CF.cyclotron_frequencies(names)
        freqerrs = CF.calc_freqerr(names)

        Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqPlus",
                     ", ".join(["%0.3f" % x for x in reducedCyclotron]))
        Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqC",
                     ", ".join(["%0.3f" % x for x in cyclotron]))
        Midas.varset("/Experiment/Variables/Contaminants/" +
                     "Contaminant FreqC Error",
                     ", ".join(["%0.3f" % x for x in freqerrs]))
Beispiel #45
0
def Scan2D():
    """
    Scan2D() does a 2D scan
    """
    Scan2Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan2Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Scan2Dcurrn += 1
    if Scan2Dcurrn > Scan2Dn:
        Scan2Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan2Dcurrn)

    # Lots of variables in a 2D scan, so list them:
    dirKeys = [
        "Variables1", "Var1Start", "Var1Stop", "Var1Steps", "Var1CurrentStep",
        "Variables2", "Var2Start", "Var2Stop", "Var2Steps", "Var2CurrentStep"
    ]
    # Get the values of the variables:
    Variables1, Start1, Stop1, n1, currn1, \
        Variables2, Start2, Stop2, n2, currn2 = \
        [Midas.varget(Scan2DPath + x) for x in dirKeys]
    # Convert into a list
    Variables1, Start1, Stop1, Variables2, Start2, Stop2 = \
        map(StringToList, [Variables1, Start1,
                           Stop1, Variables2, Start2, Stop2])
    # Convert into floats
    Start1, Stop1, Start2, Stop2 = \
        map(StringListToFloatList, [Start1, Stop1, Start2, Stop2])

    # Check that currn's are correct
    currn1 = int(currn1)
    n1 = int(n1)
    currn2 = int(currn2)
    n2 = int(n2)

    # Update the 2D scan counters.
    # Ensure that if either currn1 or currn2 are at their max values that
    # they are reset back to 1.
    currn2 += 1
    if currn2 > n2:
        currn2 = 1

        currn1 += 1
        if currn1 > n1:
            currn1 = 1
    Midas.varset(Scan2DPath + "Var1CurrentStep", currn1)
    Midas.varset(Scan2DPath + "Var2CurrentStep", currn2)
    # de-increment to calculate the scan value
    currn1 -= 1
    currn2 -= 1

    NextVariableStep1 = map(
        lambda x, y: NextVariableSetPoint(x, y, n1, currn1), Start1, Stop1)
    NextVariableStep2 = map(
        lambda x, y: NextVariableSetPoint(x, y, n2, currn2), Start2, Stop2)

    # Write out the list of variables
    # Each variable is separated by a ';', while the 2D scans
    # are separated by ';;'
    returnstr = ""
    for var, val in zip(Variables1, NextVariableStep1):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    returnstr += ";"
    for var, val in zip(Variables2, NextVariableStep2):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
 def afgOnOff(self):
     state = Midas.varget("/Experiment/Variables/SwiftDipole/AFG On")
     if state == 'y':
         self.afgWrite("OUTP ON")
     else:
         self.afgWrite("OUTP OFF")
 def afgOnOff(self):
     state = Midas.varget(self.afgOnPath)
     if state == 'y':
         self.afgWrite("OUTP ON")
     else:
         self.afgWrite("OUTP OFF")
 def getNumberOfPoints(self):
     self.NumberPoints = int(Midas.varget("/Equipment/TITAN_ACQ/" +
                                          "ppg cycle/begin_ramp/" +
                                          "loop count"))
     print self.NumberPoints