def stopDriver(self, icepap_name, addr):
     try:
         self._ctrl_icepap.stopDriver(icepap_name, addr)
     except:
         MessageDialogs.showWarningMessage(self._form,
                                           "StopDriver Icepap error",
                                           "Connection error")
 def setDriverMotionValues(self, icepap_name, addr, values):
     """ Sets speed and acceleration to a driver """
     try:
         return self._ctrl_icepap.setDriverMotionValues(
             icepap_name, addr, values)
     except:
         MessageDialogs.showWarningMessage(
             self._form, "SetDriverMotionValues Icepap error",
             "Connection error")
    def addIcepapSystem(self, host, port, description=None):
        """ Adds a new Icepap in the current location, 
        the parameters are the hostname, port and description, 
        this function checks if the icepap is available, the gets all the configuration 
        of all the driver and stores all these information in the database """
        QtGui.QApplication.instance().setOverrideCursor(
            QtGui.QCursor(QtCore.Qt.WaitCursor))
        try:
            icepap_name = host
            """ *TO-DO STORM review"""
            if self.IcepapSystemList.has_key(icepap_name):
                return None
            location = self.location.name
            try:
                icepap_system = IcepapSystem(icepap_name, host, port, location,
                                             description)

                # JUST IN CASE A USER WANTS TO RE-ADD A SYSTEM !?!?!?!?
                # A QUANTUM PROBABILITY TO BE ON TWO LOCATIONS AT THE SAME TIME... :-D
                db_icepap_system = self._db.getIcepapSystem(icepap_name)
                if db_icepap_system != None:
                    MessageDialogs.showErrorMessage(
                        self._form, "Adding Icepap System error",
                        "The icepap system is already in location: '%s'" %
                        (db_icepap_system.location_name))
                    QtGui.QApplication.instance().restoreOverrideCursor()
                    return None

                self._ctrl_icepap.openConnection(icepap_name, host, port)
                driver_list = self._ctrl_icepap.scanIcepapSystem(icepap_name)
                self._db.addIcepapSystem(icepap_system)
                self.IcepapSystemList[icepap_name] = icepap_system
                self.location.addSystem(icepap_system)
                for driver in driver_list.values():
                    icepap_system.addDriver(driver)
                    self._db.store(driver)
                self._db.commitTransaction()
                QtGui.QApplication.instance().restoreOverrideCursor()
                if len(driver_list) == 0:
                    MessageDialogs.showWarningMessage(
                        None, "Scanning Icepap Warning",
                        "The icepap system '" + icepap_name +
                        "' has ZERO drivers.\nPlease make sure that the CAN BUS TERMINATOR is connected."
                    )
                return icepap_system
            except IcePAPException, ie:
                MessageDialogs.showErrorMessage(
                    None, "Scanning Icepap Error",
                    "Could not scan the '" + icepap_name +
                    "' Icepap System.\nPlease make sure that the system '" +
                    (icepap_name) +
                    "' is in your subnetwork.\nException:\n\t" + str(ie))
            except Exception, e:
                print "Unknown exception:", e
 def undoDriverConfiguration(self, icepap_driver):
     undo_cfg = icepap_driver.getUndoList()
     new_cfg = self._ctrl_icepap.setDriverConfiguration(
         icepap_driver.icepapsystem_name, icepap_driver.addr,
         undo_cfg.toList())
     if new_cfg is None:
         MessageDialogs.showWarningMessage(self._form,
                                           "undoDriverConfig error",
                                           "Connection error")
         #self._form.checkIcepapConnection()
     else:
         icepap_driver.undo(new_cfg)
         return True
    def getDriverCfgInfoDictAndList(self, icepap_name, driver_addr):
        """
            Returns a dictionary with all the Driver params cfginfo
        """
        """ TO-DO STORM review"""
        # THE AVAILABLE OPTIONS FOR EACH PARAMETER ARE ALSO GIVEN BY THE DRIVER INSTEAD OF
        # FIXED VALUES FROM THE APPLICATION
        # THE CFGINFO IS NEEDED TO POPULATE THE QComboBoxes with correct available values
        cfginfo_str = self.getDriverCfgInfo(icepap_name, driver_addr)
        cfginfo_str = cfginfo_str.replace('$\r\n', "")
        cfginfo_str = cfginfo_str.replace('\r\n$', "")
        cfginfo_list = cfginfo_str.split("\r\n")
        cfginfo_dict = {}
        order_list = []
        for param_cfg in cfginfo_list:
            split = param_cfg.split(" ", 1)
            if len(split) > 1:
                param = split[0]
                values = split[1]
                values = values.replace("{", "")
                values = values.replace("}", "")
                cfginfo_dict[split[0]] = values.split()
                order_list.append(param)
            else:
                print "THE CONTROLLER DID NOT RECEIVE ALL THE CFGINFO FOR THE DRIVER " + str(
                    driver_addr)
                print "PLEASE, TRY TO RECONNECT TO THE " + str(
                    icepap_name) + " ICEPAP SYSTEM"
                print "AND REPORT THIS OUTPUT TO THE MANTAINER\n\n\n"

                MessageDialogs.showWarningMessage(
                    None, "Driver configuration",
                    "Could not retrive all the CFGINFO for the driver " +
                    str(driver_addr) + ". Please, try to reconnect to " +
                    str(icepap_name) + ".")
                #print "ALL INFO WAS (str): "+str(cfginfo_str)
                #print "ALL INFO WAS (list): "+str(cfginfo_list)
                #print "SOME ERROR GETTING CFGINFO: "+str(param_cfg)
        return (cfginfo_dict, order_list)
            if driver is None:
                return (-1, False, -1)
            if driver.conflict == Conflict.DRIVER_NOT_PRESENT or driver.conflict == Conflict.NO_CONNECTION:
                #print "OUPS! THIS DRIVER SHOULD NOT BE SCANNED"
                return (-1, False, -1)
            status = self._ctrl_icepap.getDriverStatus(icepap_name, addr)
            return status
        except IcePAPException, error:
            MessageDialogs.showErrorMessage(
                self._form, "GetDriverStatus Icepap error",
                "%s,%d Connection timeout" % (icepap_name, addr))
            self._form.refreshTree()
            return (-1, False, -1)
        except Exception, e:
            MessageDialogs.showWarningMessage(self._form,
                                              "GetDriverStatus error",
                                              "Connection error")
            self._form.checkIcepapConnection()
            #print "Unexpected error:", sys.exc_info()
            #print "error getting status : %s %d" % (icepap_name,addr)
            return (-1, False, -1)

    def getDriverTestStatus(self, icepap_name, addr, pos_sel, enc_sel):
        """ Driver Status used in the System and crate view
            Returns [status register, power state, [position register value, encoder register value]"""
        try:
            return self._ctrl_icepap.getDriverTestStatus(
                icepap_name, addr, pos_sel, enc_sel)
        except IcePAPException, error:
            MessageDialogs.showErrorMessage(
                self._form, "GetDriverTestStatus Icepap error",