Ejemplo n.º 1
0
    def parseCommand(self, command):
        """
        This method parses the command inputed by the user from the command promp text control box.
        If the command is good it will return a list with the command that is sent to the server
        followed by the necessary arguments.  If the command is bad then a string is sent back that
        will be displayed to the user about what went wrong.  For any help commands this is delt with
        outside the parser.
        """
        scriptLine = command.split()
        print(scriptLine)

        command = None
        subcommand = None

        commandList = ["expose", "filter", "help", "set"]
        exposeSub = ["abort", "bias", "dark", "flat", "object", "help"]
        filterSub = ["home", "status", "help"]
        helpSub = ["expose", "filter", "set"]
        setSub = ["binning", "filter", "temp", "warmup", "help"]

        runList = []  # first entry is the command to send the next entries depend on the command being sent
        try:
            command = scriptLine[0]
            subcommand = scriptLine[1]
        except IndexError:
            return "ERROR: command and/or subcommand not given..."
        else:
            if command in commandList:

                # Possible commands (the order of time=X.X, basename=somename, and number=XX is ambiguous)
                # expose abort
                # expose bias basename=bias number=XX
                # expose dark time=X.X basename=dark number=XX
                # expose flat time=X.X basename=flat number=XX
                # expose object time=X.X basename=object number=XX
                # expose help abort
                # expose help bias
                # expose help dark
                # expose help flat
                # expose help object
                if command == "expose":

                    if subcommand in exposeSub:
                        if subcommand == "abort":
                            runList.append("abort")  # only command to send
                            return runList
                        elif subcommand == "bias":
                            print("exposing of this type")
                            try:
                                arg1 = scriptLine[2]
                                arg2 = scriptLine[3]
                            except IndexError:
                                return "ERROR: no basename or number arguements..."
                            else:
                                if len(scriptLine[0:]) > 4:
                                    return 'ERROR: too many arguments given in "expose bias"...'
                                arg1 = arg1.split("=")
                                arg2 = arg2.split("=")
                                argDict = {}
                                print(arg1, arg2)

                                if (len(arg1) == 2 and (arg1[0] in ["basename", "number"])) and (
                                    len(arg2) == 2 and (arg2[0] in ["basename", "number"])
                                ):
                                    # map arguements to be able to call them in order
                                    argDict[arg1[0]] = arg1[1]
                                    argDict[arg2[0]] = arg2[1]

                                    if als.isInt(argDict["number"]):
                                        if int(argDict["number"]) > 0:
                                            if argDict["basename"].strip() is not "":
                                                # final stop; everything has been checked so now we build up the list to return
                                                runList.append("series")
                                                runList.append(subcommand)
                                                runList.append(int(argDict["number"]))
                                                runList.append(argDict["basename"])
                                                print("The specified number of exposures is", float(argDict["number"]))
                                                return runList  # [series, bias, number, basename]
                                            else:
                                                return "ERROR: basename specified is empty..."
                                        else:
                                            return "ERROR: number of exposures needs to be above 0..."
                                    else:
                                        return "ERROR: specified number of exposures is not number..."
                                else:
                                    return "SyntaxError: basename or number of exposures is incorrectly specified..."

                        elif subcommand in ["dark", "flat", "object"]:
                            print("exposing of this type")
                            try:
                                arg1 = scriptLine[2]
                                arg2 = scriptLine[3]
                                arg3 = scriptLine[4]
                            except IndexError:
                                return "ERROR: no time, basename, and/or exposure number given..."
                            else:
                                if len(scriptLine[0:]) > 5:
                                    return 'ERROR: too many arugments given in "expose (dark/flat/object)"'

                                arg1 = arg1.split("=")
                                arg2 = arg2.split("=")
                                arg3 = arg3.split("=")
                                argDict = {}
                                print(arg1, arg2, arg3)
                                # Makes sure that when args are split by equals that there are two entries and that the first one is
                                # either time or basename.
                                if (
                                    (len(arg1) == 2 and (arg1[0] in ["time", "basename", "number"]))
                                    and (len(arg2) == 2 and (arg2[0] in ["time", "basename", "number"]))
                                    and (len(arg3) == 2 and (arg3[0] in ["time", "basename", "number"]))
                                ):
                                    # map arguments to be able to call them in order
                                    argDict[arg1[0]] = arg1[1]
                                    argDict[arg2[0]] = arg2[1]
                                    argDict[arg3[0]] = arg3[1]

                                    if als.isNumber(argDict["time"]) and als.isInt(argDict["number"]):
                                        # final stop; everything has been checked so now we build up the list to return
                                        if float(argDict["time"]) >= 0 or int(argDict["number"]) > 0:
                                            if argDict["basename"].strip() is not "":
                                                runList.append("series")
                                                runList.append(subcommand)
                                                runList.append(int(argDict["number"]))
                                                runList.append(float(argDict["time"]))
                                                runList.append(argDict["basename"])
                                                print("The specified time is", float(argDict["time"]))
                                                print("The specified number of exposures is", float(argDict["number"]))
                                                return runList  # [series, dark/flat/object, number, time, basename]
                                            else:
                                                return "ERROR: specified basename is empty..."
                                        else:
                                            return "ERROR: specified time is negative or the number of images is not 1 or more..."

                                    else:
                                        return "ERROR: specified time and/or number of exposures not a number..."
                                else:
                                    return (
                                        "SyntaxError: time argument, basename, and/or number of exposures is wrong..."
                                    )
                        else:
                            try:
                                helpArg = scriptLine[2]
                            except IndexError:
                                return 'ERROR: argument after "help" not given...'
                            else:
                                if len(scriptLine[0:]) > 3:
                                    return 'ERROR: too many arguments after "help"...'
                                runList.append(command)
                                runList.append(subcommand)
                                runList.append(helpArg)
                                return runList
                    else:
                        return "ERROR: not a recognized subcommand...", subcommand

                # possible commands (only one arg):
                # set binning (1 or 2)
                # set filter (1, 2, 3, 4, 5, or 6)
                # set temp (-80 to -10)
                # set help (binning, filter temp)
                if command == "set":

                    if subcommand in setSub:
                        try:
                            arg1 = scriptLine[2]
                        except IndexError:
                            return 'ERROR: didn\'t specify an argument after "subcommand"...'
                        else:
                            if len(scriptLine[0:]) > 3:
                                return "ERROR: there are too many arguments specified..."

                            if subcommand == "binning":
                                if als.isInt(arg1):
                                    if int(arg1) == 1 or int(arg1) == 2:

                                        runList.append(command)
                                        runList.append(subcommand)
                                        runList.append(arg1)
                                        return runList  # [set, binning, 1]
                                    else:
                                        return "ValueError: binning value is out of range, must be 1 or 2..."
                                else:
                                    return "SyntaxError: binning value is not an int..."
                            if subcommand == "temp":
                                if als.isInt(arg1):
                                    if int(arg1) >= -80 and int(arg1) <= -10:
                                        runList.append("setTEC")
                                        runList.append(arg1)
                                        return runList
                                    else:
                                        return "ValueError: temperature out of range of -80 to -10..."
                                elif arg1 == "warmup":
                                    runList.append("warmup")  # command for sending warmup
                                    return runList
                                else:
                                    return "SyntaxError: temperature is not a number..."
                            if subcommand == "filter":
                                if als.isInt(arg1):
                                    if int(arg1) >= 1 and int(arg1) <= 6:  # 6 filter positions: (1, 2, 3, 4, 5, 6)
                                        runList.append(command)
                                        runList.appedn(subcommand)
                                        runList.append(arg1)
                                        return runList
                                    else:
                                        return (
                                            "ValueError: filter position out of range, must specify int from 1 to 6..."
                                        )
                                else:
                                    return "SyntaxError: filter position given is not an int..."
                            if subcommand == "help":
                                if arg1 in ["binning", "temp"]:
                                    runList.append(command)
                                    runList.append(subcommand)
                                    runList.append(arg1)
                                    return runList
                                else:
                                    return 'ERROR: %s after "help" is not recognized...' % arg1
                    else:
                        return "ERROR: %s is not a recognized subcommand..." % subcommand

                # possible commands
                # filter home  # will slew filter to home
                # filter status # will give details on the state of connection
                # filter help (filter or home) # gives details on how to run the command and what it does
                if command == "filter":
                    if subcommand in filterSub:  # home, status, help

                        if subcommand == "home":
                            runList.append(command)
                            runList.append(subcommand)
                            return runList
                        if subcommand == "status":
                            runList.append(command)
                            runList.append(subcommand)
                            return runList
                        if subcommand == "help":
                            try:
                                arg1 = scriptLine[2]
                            except IndexError:
                                return 'ERROR: no argument after "filter help" specified...'
                            else:
                                if len(scriptLine[0:]) > 3:  # make sure there aren't anymore args given than needed
                                    return 'ERROR: extra argument after "help" given...'
                                if arg1 == "home":
                                    print("slews to filter")
                                if arg1 == "status":
                                    print("gives the status of the filter")
                                runList.append(command)
                                runList.append(subcommand)
                                runList.append(arg1)
                                return runList
                    else:
                        return "ERROR: %s is not a recognized subcommand..." % subcommand

                # possible commands
                # help expose
                # help set
                # help filter
                if command == "help":
                    if subcommand in helpSub:
                        runList.append(command)
                        runList.append(subcommand)
                        return runList
                    else:
                        return "ERROR: %s is not a recognized subcommand..." % subcommand
            else:
                return "ERROR: %s is not a recognized command..." % command
Ejemplo n.º 2
0
    def onExpose(self, event):
        """
        Executes when the expose button is pressed. It checks that the variable
        self.exposeToSend is a float. It it passes then this value is sent to Evora.  If it
        fails a dialog box tells the user the varible is not a number and will not send it
        to Evora.
        """
        if als.isNumber(self.timeToSend):
            if(float(self.timeToSend) < 0):
                dialog = wx.MessageDialog(None, "Exposure time can not be less than 0...will not expose", "", wx.OK|wx.ICON_ERROR)
                dialog.ShowModal()
                dialog.Destroy()

        else:
            dialog = wx.MessageDialog(None, "Exposure time not a number...will not expose.",
                                      "", wx.OK|wx.ICON_ERROR)
            dialog.ShowModal()
            dialong.Destroy()

        if self.nameToSend is "":
            dialog = wx.MessageDialog(None,"No name was given...will not expose", "",
                                      wx.OK|wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
        else:
            pass



        if als.isNumber(self.timeToSend) and self.nameToSend is not "":
            #self.protocol.sendLine("Exposing with name " + str(self.nameToSend) + " and time " + str(self.timeToSend) + " s")
            
            line = self.getAttributesToSend().split()
        
            # get image type 
            imType = int(line[0])
            itime = float(line[3])
        
            #self.expButton.SetLabel("Abort")
            if(imType == 1): # single exposure
                self.expButton.Enable(False)
                self.stopExp.Enable(True)
                self.abort = True
                line = " ".join(line[1:]) # bring all the parameters together
                d = self.protocol.sendCommand("expose " + line)
                d.addCallback(self.expose_callback_thread)
                thread.start_new_thread(self.exposeTimer, (itime,))

            if(imType == 2): # real time exposure
                self.expButton.Enable(False)
                self.stopExp.Enable(True)
                self.abort = True
                line = " ".join(line[1:])
                # start callback that looks for a path leading to a real image
                d = self.protocol.addDeferred("realSent")
                d.addCallback(self.displayRealImage_thread)

                d = self.protocol.sendCommand("real " + line)
                d.addCallback(self.realCallback) # this will clear the image path queue

                # start timer
                thread.start_new_thread(self.exposeTimer, (itime,))

            if(imType == 3): # series exposure
                dialog = wx.TextEntryDialog(None, "How many exposure?", "Entry", "1", wx.OK | wx.CANCEL)
                answer = dialog.ShowModal()
                dialog.Destroy()
                if answer == wx.ID_OK:
                    self.seriesImageNumber = dialog.GetValue()
                    if(als.isInt(self.seriesImageNumber)):
                        print "Number of image to be taken:", int(self.seriesImageNumber)
                        self.expButton.Enable(False)
                        self.stopExp.Enable(True)
                        self.abort = True

                        line[2] = self.seriesImageNumber
                        line = " ".join(line[1:])
                        
                        d = self.protocol.addDeferred("seriesSent")
                        d.addCallback(self.displaySeriesImage_thread)

                        d = self.protocol.sendCommand("series " + str(line))
                        d.addCallback(self.seriesCallback)
                        
                        # start timer
                        thread.start_new_thread(self.exposeTimer, (itime,))

                    else:
                        dialog = wx.MessageDialog(None, "Entry was not a valid integer!", "", wx.OK | wx.ICON_ERROR)
                        dialog.ShowModal()
                        dialog.Destroy()