Exemplo n.º 1
0
def ChangeTune(tuneName):
    """
    Change all the MIDAS values in the given tune path.
    """
    for var, val in Midas.dirlist(TunePath + tuneName):
        MidasSetVar(GetVarName(var), val)
    Midas.sendmessage("pythonrc", "Changed tune to: " + tuneName)
Exemplo n.º 2
0
def ChangeTune(tuneName):
    """
    Change all the MIDAS values in the given tune path.
    """
    for var, val in Midas.dirlist(TunePath + tuneName):
        MidasSetVar(GetVarName(var), val)
    Midas.sendmessage("pythonrc", "Changed tune to: " + tuneName)
 def afgTurnOnOff(self, state):
     #state = self.afgWrite("OUTP?")
     if state:
         self.afgOn()
         statemsg = "on"
     else:
         self.afgOff()
         statemsg = "off"
     Midas.sendmessage(self.afgName, "AFG is " + statemsg)
Exemplo n.º 4
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.")
Exemplo n.º 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.")
Exemplo n.º 6
0
def checkInput(name):
    names = CF.splitInput(name)

    passes = True

    elemList = np.hstack(([re.findall('\\d+', x) for x in names],
                          [re.findall('\\D+', x) for x in names]))
    try:
        [float(x[0]) * CF.getAtomicMass(x[0] + x[2] + x[1]) for x in elemList]
    except IndexError:
        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
Exemplo n.º 7
0
def MidasSetVar(varPath, varValue):
    """
    Wrapper for pythonmidas.setvar(key,val).
    Deals with some special cases in in ODB.
    """

    varValue = ConvertValueToString(varValue)
    print varValue
    try:
        Midas.varset(varPath, varValue)
    except Midas.FailedCommand as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
    except Midas.KeyNotFound as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
Exemplo n.º 8
0
def MidasSetVar(varPath, varValue):
    """
    Wrapper for pythonmidas.setvar(key,val).
    Deals with some special cases in in ODB.
    """

    varValue = ConvertValueToString(varValue)
    print varValue
    try:
        Midas.varset(varPath, varValue)
    except Midas.FailedCommand as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
    except Midas.KeyNotFound as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
Exemplo n.º 9
0
    def test_sendmessage(self, mock_odbcommand):
        name = "Test"
        message = "test message"

        result = Midas.sendmessage(name, message)

        self.assertEqual(result, None)
        mock_odbcommand.assert_called_once_with("msg " + name, message)
Exemplo n.º 10
0
    def freqListMessage(self, afgName=""):
        afgName = self.afgName + '(' + self.host + ')'
        fc = [str(x) for x in self.FreqC]
        fm = [str(x) for x in self.FreqMod]
        rfamp = str(self.RFAmplitude)

        msg = afgName + "{FreqC,FreqMod} = "
        for i in range(len(self.FreqC)):
            msg = msg + "{" + fc[i] + "," + fm[i] + "}, "
            #msg = msg + "RFAmp = " + rfamp
            print msg
            #XXX Is this a bug? Shouldn't really matter.....
            # should this be outside of the loop?
        msg = msg + "RFAmp = " + rfamp
        Midas.sendmessage("FreqList", msg)

        return msg
Exemplo n.º 11
0
    def test_sendmessage(self, mock_odbcommand):
        name = "Test"
        message = "test message"

        result = Midas.sendmessage(name, message)

        self.assertEqual(result, None)
        mock_odbcommand.assert_called_once_with("msg " + name, message)
Exemplo n.º 12
0
def checkInput(name):
    names = CF.splitInput(name)

    passes = True

    elemList = np.hstack(
        ([re.findall('\\d+', x)
          for x in names], [re.findall('\\D+', x) for x in names]))
    try:
        [float(x[0]) * CF.getAtomicMass(x[0] + x[2] + x[1]) for x in elemList]
    except IndexError:
        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
Exemplo n.º 13
0
import cycletime as ct
import pythonmidas.pythonmidas as Midas

try:
    runtime = ct.run_time()
    msg = "The next run will take: " + str(runtime) + " min."
except Exception as e:
    msg = "Error: " + str(e)

Midas.sendmessage("CycleTime", msg)
Exemplo n.º 14
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)
#!/home/mpet/local/bin/python2.7
import afg
import pythonmidas.pythonmidas as midas
import time

try:
    #mpetafg = afgcontrol.afg()
    mpetafg = afg.quad_afg()
    mpetafg.openConnection()
    mpetafg.afgSetOutputLoad()
    mpetafg.afgSetTigger()
    mpetafg.afgStartMenuOnOff()
    mpetafg.afgSetFreqList()
    mpetafg.closeConnection()
except:
    print "Failure."
    # Sleep 10s so that run starts, and then we can stop it.
    time.sleep(10)
    midas.stoprun()
    midas.sendmessage('AFGCONTROLERROR',
                      'Quadrupole AFG not programmed correctly. Abort.')
Exemplo n.º 16
0
#!/usr/bin/python
# A.A. Kwiatkowski October 2014
# stop TIS FIL, based off stopRFQ.py

import pythonmidas.pythonmidas as Midas

Midas.sendmessage("Alarm:", "TIS:IG1 pressure too high: Kill TIS1 FIL")

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

# The Demand isn't set again if it is the same value as previously used.
print Midas.varset("/Equipment/Beamline/Variables/Demand[129]", 1)
print Midas.varset("/Equipment/Beamline/Variables/Demand[129]", 0)