class TangolightPneu(Device):
    states = {
        0: "out",
        1: "in",
    }

    READ_CMD, READ_OUT = (0, 1)

    def __init__(self, name):
        Device.__init__(self, name)

        #self.wagoidin  = None
        #self.wagoidout = None
        self.wagokyin = None
        self.wagokyout = None
        #self.logic     = 1
        #self.readmode  = WagoPneu.READ_OUT
        self.wagoState = "unknown"
        self.__oldValue = None
        self.device = None
        self.hutch = None
        self.lastState = None
        self.simulation = False

    def init(self):
        try:
            self.device = DeviceProxy(self.getProperty("tangoname"))
        except:
            logging.getLogger("HWR").error("%s: unknown pss device name",
                                           self.getProperty("tangoname"))

        try:
            self.device_beamstop = DeviceProxy(self.getProperty("tangoname2"))
        except:
            logging.getLogger("HWR").error("%s: unknown  device name",
                                           self.getProperty("tangoname2"))

        try:
            self.device_detdist = DeviceProxy(self.getProperty("tangoname3"))
        except:
            logging.getLogger("HWR").error("%s: unknown  device name",
                                           self.getProperty("tangoname3"))

        if self.device and self.device_beamstop and self.device_detdist:
            self.setIsReady(True)

    def valueChanged(self, value):
        state = self.getWagoState()
        self.emit('wagoStateChanged', (state, ))

    def getTangoState(self):
        return str(self.device.State())

    def getWagoState(self):
        value = int(self.device.isInserted)

        if value in TangolightPneu.states:
            self.wagoState = TangolightPneu.states[value]
        else:
            self.wagoState = "unknown"
        logging.getLogger("HWR").info("%s: TangolightPneu.getWagoState, %s",
                                      self.name(), self.wagoState)

        return self.wagoState

    def wagoIn(self):
        logging.getLogger("HWR").info("%s: TangolightPneu.wagoIn", self.name())
        if self.isReady():
            if self.simulation == True:
                self.device.isInserted = True
            else:
                # PL. 2010.01.22: Les etats du DS BPS ne sont pas mis a jour pour l'instant.
                # Il n'y a pas de butees pour cela. On force donc l'extraction du BStop.
                if str(self.device_beamstop.State()) != "EXTRACT":
                    self.device_beamstop.Extract()
                while str(self.device_beamstop.State()) != "EXTRACT":
                    qApp.processEvents()
                #qApp.processEvents()
                detposition = self.device_detdist.position
                min_detposition = 269.5
                if detposition < min_detposition:
                    msg = "Can't insert Light-arm, detector distance too close:"
                    msg += "%.1f  You need to set the distance to > %.1f mm." %\
                                 (detposition, min_detposition)
                    logging.getLogger("HWR").error("%s: " + msg, self.name())
                    return
                time.sleep(0.2)
                self.device.Insert()
                timeout = 0
                while self.getTangoState() != "INSERT":
                    time.sleep(0.2)
                    timeout += 0.2
                    if timeout >= 4.0:
                        break
                if self.getTangoState() != "INSERT":
                    logging.getLogger("HWR").error(
                        "%s: LIGHT ARM NOT CORRECTLY INSERTED", self.name())

    def wagoOut(self):
        logging.getLogger("HWR").info("%s: TangolightPneu.wagoOut",
                                      self.name())
        if self.isReady():
            if self.simulation == True:
                self.device.isInserted = False
            else:
                self.device.Extract()
                pass
示例#2
0
class TangoBeamStop(Device):
    beamstopState = {
        None: 'unknown',
        'UNKNOWN': 'unknown',
        'CLOSE': 'closed',
        'OPEN': 'opened',
        'INSERT': 'opened',
        'EXTRACT': 'closed',
        'MOVING': 'moving',
        'RUNNING': 'moving',
        '_': 'automatic',
        'FAULT': 'fault',
        'DISABLE': 'disabled',
        'OFF': 'fault',
        'ON': 'unknown'
    }

    def __init__(self, name):
        Device.__init__(self, name)

        self.shutterStateValue = 0
        self.lastState = None
        #self.PSSdevice = None

    def init(self):
        #stateChan = self.addChannel({ 'type': 'tango', 'name': 'state', 'polling':500 }, "State")
        #self.addCommand({'type': 'tango', 'name': 'open' }, "Open")
        #self.addCommand({'type': 'tango', 'name': 'close' }, "Close")
        self.setIsReady(True)
        # Connect to device PSS "tangoname2" in the xml file
        #try :
        #    self.PSSdevice = SimpleDevice(self.getProperty("tangoname2"), verbose=False)
        #except :
        #       #     self.errorDeviceInstance(self.getProperty("tangoname2"))
        #     logging.getLogger("HWR").info("%s: unknown pss device name", self.getProperty("tangoname2"))
        try:
            self.LightArm = DeviceProxy(self.getProperty("tangoname2"))
        except:
            logging.getLogger("HWR").info("%s: unknown lightarm device name",
                                          self.getProperty("tangoname2"))
        stateChan = self.getChannelObject(
            "state"
        )  # utile seulement si statechan n'est pas defini dans le code
        stateChan.connectSignal("update", self.stateChanged)

    def stateChanged(self, state):
        logging.getLogger().debug(
            "TangoBeamStop : stateChanged - new state = %s", state)
        if state is None or str(state) == "":
            return
        state = str(state)
        if self.lastState != state:
            try:
                self.emit("shutterStateChanged",
                          (TangoBeamStop.beamstopState[state], ))
            except KeyError:
                self.emit("shutterStateChanged", ("unknown", ))
                logging.getLogger("HWR").error("%s: unknown shutter state %s",
                                               self.name(), state)
            self.lastState = state

    def getShutterState(self):
        #logging.getLogger().debug("TangoBeamStop : passe dans getShutterState.")
        #if self.isPssOk:
        return TangoBeamStop.beamstopState[self.lastState]

    def isShutterOk(self):
        logging.getLogger().debug("TangoBeamStop : isSutterOK")
        stateShutter = not self.getShutterState() in (
            'unknown', 'moving', 'fault', 'disabled', 'error')
        return stateShutter

    #def isPssOk(self):
    #    statePSS = True
    #    if self.PSSdevice:
    #        statePSS = self.PSSdevice.pssStatusEH == 1
    #        if statePSS == False :
    #              logging.getLogger("HWR").error("%s: experimental hutch search is not finished",self.name())
    #    return statePSS

    def openShutter(self):
        logging.getLogger().debug("TangoBeamStop : passe dans openShutter")

        #        if self.isReady() and self.isShutterOk() and self.isPssOk():
        #if self.isShutterOk() and self.isPssOk():
        #   logging.getLogger().debug("TangoBeamStop : passe dans openShutter 2")
        if self.isShutterOk():
            if str(self.LightArm.State()) == "INSERT":
                self.LightArm.Extract()
                time.sleep(2)
            cmdOpen = self.getCommandObject("open")
            #logging.getLogger().debug("TangoBeamStop : passe dans openShutter 3")
            cmdOpen()
            #logging.getLogger().debug("TangoBeamStop : passe dans openShutter : shutter open")
        #else:
        #    logging.getLogger("HWR").error("%s: cannot open shutter (%s)", self.name(), self.getShutterState())

    def closeShutter(self):
        #        if self.isReady() and self.isShutterOk():
        logging.getLogger().debug("TangoBeamStop : passe dans closeShutter")
        if self.isShutterOk():
            #if self.LightArm.State == "INSERT":
            #    self.LightArm.Extract()
            #    time.sleep(2)
            cmdClose = self.getCommandObject("close")
            cmdClose()
        else:
            logging.getLogger("HWR").error("%s: cannot close shutter (%s)",
                                           self.name(), self.getShutterState())