class Shopper(Facade):
    """
    This class implements Tango device server for control of shutter device (integrated shutter and stopper).
    Each Tango device represents one shutter, which can be open or closed.

    The Tango device works on a set of four PLC attributes of type bool, which must be
    exposed by PLC device server.

    OpenS PLC attribute should be True when shutter is open and False when it is closed
    ClosedS PLC attribute should be True when shutter is closed and False when it is opened

    OpenC PLC attribute should cause shutter to open if it is closed
    CloseC PLC attribute should cause shutter to close if it is open
    """
    def safe_init_device(self):
        """
        This is a method to safely initialize the Shopper device,
        overrode from Facade base class
        """
        super(Shopper, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running.")

    # proxy attributes

    ShopperOpen = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_OpenS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter open "
        "state.")

    ShopperClosed = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_ClosedS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter closed "
        "state.")

    ShopperInterlock = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_InterlockA",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter in "
        "interlock alarm.")

    # state attributes

    @state_attribute(bind=['ShopperInterlock'])
    def interlock_alarm(self, alarm):
        """
        This method changes state of device, accordingly to ShopperInterlock
        attribute. When it's on, the state is ALARM, otherwise the state is ON.
        :param alarm: ShopperInterlock
        :return: ALARM state when ShopperInterlock is on, ON state otherwise
        :rtype: DevState
        """
        if alarm:
            return DevState.ALARM, "Shutter is interlocked"
        return DevState.ON, "Device is running"

    # proxy commands

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_OpenC",
                   doc_out="True to PLCAttrName_OpenC")
    def Open(self, subcommand):
        """
         :rtype: bool
        """
        subcommand(True)
        return True

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_CloseC",
                   doc_out="True to PLCAttrName_CloseC")
    def Close(self, subcommand):
        """
        :rtype: bool
        """
        subcommand(True)
        return True
class FastValve(Valve):
    """

    InrushA1 should be True if air-inrush is detected on first sensor or False
    in normal state.
    InrushA2 should be True if air-inrush is detected on second sensor or False
    in normal state.
    """
    __doc__ = Valve.__doc__ + __doc__

    def safe_init_device(self):
        """
        This is a method to safely initialize the Valve device,
        overriding same method from Facade Device Class - Valve
        """
        super(FastValve, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running.")

    # proxy attributes

    InRush1A = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_Inrush1A",
        display_level=DispLevel.OPERATOR,
        description="Name of the PLC device attribute that represents PLC signal"
                    " for air inrush alarm on the first valve sensor.")

    InRush2A = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_Inrush2A",
        display_level=DispLevel.OPERATOR,
        description="Name of the PLC device attribute that represents PLC signal"
                    " for air inrush alarm on the second valve sensor.")

    # state attributes

    @state_attribute(
        bind=['ValveInterlock', 'ValveCutOff', 'ValveOpen', 'ValveClosed',
              'UnexpectedState', 'InRush1A', 'InRush2A'])
    def state_and_status_fast_valve(self, interlock, cutoff, opn, closed, unexp, rush1, rush2):
        """
        This method changes state of device, accordingly to device attributes.

        :param interlock: ValveInterlock
        :param cutoff: ValveCutOff
        :param opn: ValveOpen
        :param closed: ValveClosed
        :param unexp: UnexpectedState
        :param rush1: InRush1A
        :param rush2: InRush2A

        :return: appropriate device state and status

        :rtype: tuple(DevState, str)
        """

        state, status = self.state_and_status(interlock, cutoff, opn, closed,
                                                unexp)
        if rush1 or rush2:
            return DevState.ALARM, "One or both of the valve sensors is in " \
                                   "alarm state due to air inrush"
        else:
            return state, status
Beispiel #3
0
class Shutter(Facade):
    """
    This class implements Tango device server for control of shutter device
    (integrated shutter and stopper).
    Each Tango device represents one shutter, which can be in open or closed.

    The Tango device works on a set of four PLC attributes of type bool,
    which must be exposed by PLC device server.

    OpenS PLC attribute should be True when shutter is open and False when it
    is closed.
    ClosedS PLC attribute should be True when shutter is closed and False when
    it is opened.

    OpenC PLC attribute should cause shutter to open if it is closed.
    CloseC PLC attribute should cause shutter to close if it is open.
    """
    def safe_init_device(self):
        """
        This is a method to safely initialize the Shutter device,
        overrode from Facade base class
        """
        super(Shutter, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running.")

    # proxy attributes

    ShutterOpen = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_OpenS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter open "
        "state.")

    ShutterClosed = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_ClosedS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter closed "
        "state.")

    ShutterInterlock = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_InterlockA",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for shutter in "
        "interlock alarm.")

    # proxy commands

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_OpenC",
                   doc_out="True to PLCAttrName_OpenC")
    def Open(self, subcommand):
        """
         :rtype: bool
        """
        subcommand(1)
        return True

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_CloseC",
                   doc_out="True to PLCAttrName_CloseC")
    def Close(self, subcommand):
        """
        :rtype: bool
        """
        subcommand(1)
        return True
class LandauSHG(Facade):
    def safe_init_device(self):
        """
        Docstring for 'safe_init_device' - it is just safe initialization of the DS
        :return:
        """
        super(LandauSHG, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")

    # Proxy attributes

    FlowFGE1 = proxy_attribute(dtype=float,
                               property_name="FlowFGE1Source",
                               access=AttrWriteType.READ,
                               description="This attribute specifies FlowFGE1")

    FlowFGE2 = proxy_attribute(dtype=float,
                               property_name="FlowFGE2Source",
                               access=AttrWriteType.READ,
                               description="This attribute specifies FlowFGE2")

    Pressure = proxy_attribute(dtype=float,
                               property_name="PressureSource",
                               access=AttrWriteType.READ,
                               description="This attribute specifies pressure")

    LowPressureAlarm = proxy_attribute(
        dtype=float,
        property_name="LowPressureAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates low pressure alarm")

    CoolingCentralRod1Alarm = proxy_attribute(
        dtype=float,
        property_name="CoolingCentralRod1AlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates cooling central rod1 alarm")

    CoolingCentralRod2Alarm = proxy_attribute(
        dtype=float,
        property_name="CoolingCentralRod2AlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates cooling central rod2 alarm")

    CoolingMantelAlarm = proxy_attribute(
        dtype=float,
        property_name="CoolingMantelAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates cooling mantel alarm")

    PIDSetpoint = proxy_attribute(
        dtype=float,
        property_name="PIDSetpointSource",
        access=AttrWriteType.READ,
        description="This attribute specifies PID setpoint")

    SelectSensorsType = proxy_attribute(
        dtype=float,
        property_name="SelectSensorsTypeSource",
        access=AttrWriteType.READ,
        description="This attribute specifies sensor type selection")

    SelectReturnSensorsNumber = proxy_attribute(
        dtype=float,
        property_name="SelectReturnSensorsNumberSource",
        access=AttrWriteType.READ,
        description="This attribute specifies select return sensors number")

    TempTwoReturnSensorsMean = proxy_attribute(
        dtype=float,
        property_name="TempTwoReturnSensorsMeanSource",
        access=AttrWriteType.READ,
        description=
        "This attribute specifies Temperature two return sensors mean")

    TempFourReturnSensorsMean = proxy_attribute(
        dtype=float,
        property_name="TempFourReturnSensorsMeanSource",
        access=AttrWriteType.READ,
        description=
        "This attribute specifies Temperature four return sensors mean")

    TempSupplyPipeSensor = proxy_attribute(
        dtype=float,
        property_name="TempSupplyPipeSensorSource",
        access=AttrWriteType.READ,
        description="This attribute specifies Temperature supply pipe sensor")

    TempReturnPipeSensor = proxy_attribute(
        dtype=float,
        property_name="TempReturnPipeSensorSource",
        access=AttrWriteType.READ,
        description="This attribute specifies Temperature return pipe sensor")

    TempSurfaceSensorsMax = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensorsMaxSource",
        access=AttrWriteType.READ,
        description=
        "This attribute specifies maximum temperature surface sensors")

    TempSurfaceSensorsMin = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensorsMinSource",
        access=AttrWriteType.READ,
        description=
        "This attribute specifies minimum temperature surface sensors")

    TempSurfaceSensorsMean = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensorsMeanSource",
        access=AttrWriteType.READ,
        description="This attribute specifies Temperature surface sensors mean"
    )

    TempSurfaceSensor1 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor1Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature surface sensor1")

    TempSurfaceSensor2 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor2Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature surface sensor2")

    TempSurfaceSensor3 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor3Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature surface sensor3")

    TempSupplySensor1 = proxy_attribute(
        dtype=float,
        property_name="TempSupplySensor1Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature supply sensor1")

    TempSupplySensor2 = proxy_attribute(
        dtype=float,
        property_name="TempSupplySensor2Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature supply sensor2")

    TempReturnSensor1 = proxy_attribute(
        dtype=float,
        property_name="TempReturnSensor1Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature return sensor1")

    TempReturnSensor2 = proxy_attribute(
        dtype=float,
        property_name="TempReturnSensor2Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature return sensor2")

    TempSensorBeforeEV = proxy_attribute(
        dtype=float,
        property_name="TempSensorBeforeEVSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature sensor beforeEV")

    TempSensorAfterEV = proxy_attribute(
        dtype=float,
        property_name="TempSensorAfterEVSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature sensor afterEV")

    AtLeastTwoFaultySensors = proxy_attribute(
        dtype=float,
        property_name="AtLeastTwoFaultySensorsSource",
        access=AttrWriteType.READ,
        description="This attribute shows at least two faulty sensors")

    MainSetpoint = proxy_attribute(
        dtype=float,
        property_name="MainSetpointSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies main setpoint")

    SensorControl = proxy_attribute(
        dtype=float,
        property_name="SensorControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies sensor control")

    ValveControl = proxy_attribute(
        dtype=float,
        property_name="ValveControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies valve control")

    EVControl = proxy_attribute(
        dtype=float,
        property_name="EVControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies EV control")

    SetpointAfterValve = proxy_attribute(
        dtype=float,
        property_name="SetpointAfterValveSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies setpoint after valve")

    SetpointAfterHeater = proxy_attribute(
        dtype=float,
        property_name="SetpointAfterHeaterSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies setpoint after heater")

    ChangeSetpoint = proxy_attribute(
        dtype=float,
        property_name="ChangeSetpointSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute changes setpoint")

    ValveValue = proxy_attribute(
        dtype=float,
        property_name="ValveValueSource",
        access=AttrWriteType.READ,
        description="This attribute shows valve value")

    HeaterValue = proxy_attribute(
        dtype=float,
        property_name="HeaterValueSource",
        access=AttrWriteType.READ,
        description="This attribute shows heater value")

    ValveControlErrorAlarm = proxy_attribute(
        dtype=float,
        property_name="ValveControlErrorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates valve control error alarm")

    HeaterControlErrorAlarm = proxy_attribute(
        dtype=float,
        property_name="HeaterControlErrorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates heater control error alarm")

    PlungerTempSensor = proxy_attribute(
        dtype=float,
        property_name="PlungerTempSensorSource",
        access=AttrWriteType.READ,
        description="This attribute specifies plunger temperature sensor")

    StartPumpAttribute = proxy_attribute(
        dtype=bool,
        property_name="StartPumpSource",
        access=AttrWriteType.READ,
        description="This attribute starts the pump")

    StopPumpAttribute = proxy_attribute(
        dtype=bool,
        property_name="StopPumpSource",
        access=AttrWriteType.READ,
        description="This attribute stops the pump")

    ResetAttribute = proxy_attribute(
        dtype=bool,
        property_name="ResetSource",
        access=AttrWriteType.READ,
        description="This attribute resets the pump")

    # Proxy commands

    @proxy_command(property_name="StartPumpSource", write_attribute=True)
    def StartPump(self, subcommand):
        """
        This command starts the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="StopPumpSource", write_attribute=True)
    def StopPump(self, subcommand):
        """
        This command stops the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="ResetSource", write_attribute=True)
    def Reset(self, subcommand):
        """
        This command resets the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)
class DriveAmplifier(Facade):
    """
    DriveAmplifier Tango Device server exposes the state, attributes and
    command of the drive amplifier. All components are aggregated from the PLC
    device server. Writing and reading to and from DriveAmplifier device
    attributes is forwarded to reading and writing to and from the
    corresponding PLC signals. Executing commands of the DriveAmplifier Tango
    device is forwarded to writing to corresponding PLC signals. The state of
    the device is dictated by a set of PLC signals.
    """
    def safe_init_device(self):
        """
        This is method overriden from Facade base class. It is used to safely
        initialize DriveAmplifier device.
        """
        super(DriveAmplifier, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Amplifier is running")

    # proxy attributes

    Temperature_Alarm = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_TempA",
        description="Name of the PLC device attribute, corresponding to the "
        "temperature alarm of the amplifier.")

    VSWR_Alarm = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_VSWRA",
        description="Name of the PLC device attribute, corresponding to the "
        "Voltage Standing Wave Ratio alarm of the amplifier.")

    PSU_Status = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_PSUS",
        description="Name of the PLC device attribute, corresponding to the "
        "Power Supply Unit status of the amplifier.")

    Interlock = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_Interlock",
        description="Name of the PLC device attribute, corresponding to the "
        "safety interlock of the amplifier.")

    Power = proxy_attribute(
        dtype=float,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_Power",
        description="Name of the PLC device attribute, corresponding to the "
        "forwarded power of the amplifier.")

    AmplifierState = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_State",
        description="Name of the PLC device attribute, corresponding to the "
        "forwarded power of the amplifier.")

    Bypass = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        display_level=DispLevel.OPERATOR,
        property_name="PLCAttName_Bypass",
        description="Name of the PLC device attribute, corresponding to the "
        "bypass command of the amplifier.")

    # state attributes

    @state_attribute(bind=[
        'Temperature_Alarm', 'VSWR_Alarm', 'PSU_Status', 'Interlock',
        'AmplifierState'
    ])
    def check_alarms(self, temp, vswr, psu, inter, amplstate):
        """
        This attribute checks if any of the device alarms is on. If so,
        appropriate state and status are set for the device.

        :param temp: Temeprature_Alarm
        :param vswr: VSWR_Alarm
        :param psu: PSU_Status
        :param inter: Interlock
        :param amplstate: AmplifierState
        :return: ALARM, if any or the alarms is set
        :rtype: DevState
        """
        if temp or vswr or psu or inter or amplstate:
            return DevState.ALARM, "One or more alarms of the amplifier are active."

    # proxy commands

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttName_EnableTTL",
                   doc_out="True to PLCAttName_EnableTTL")
    def EnableTtl(self, subcommand):
        """
        :rtype: bool
        """
        subcommand(1)
        return True

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttName_DisableTTL",
                   doc_out="True to PLCAttName_DisableTTL")
    def DisableTtl(self, subcommand):
        """
        :rtype: bool
        """
        subcommand(1)
        return True
class SHG(Facade):
    def safe_init_device(self):
        """
        Docstring for 'safe_init_device' - it is just safe initialization of the DS
        :return:
        """
        super(SHG, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")

    # Proxy attributes

    Temperature = proxy_attribute(
        dtype=float,
        property_name="TemperatureModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature")

    TemperatureSetpoint = proxy_attribute(
        dtype=float,
        property_name="TemperatureSetpointModbus",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies temperature setpoint")

    SledSetpoint = proxy_attribute(
        dtype=float,
        property_name="SledSetpointModbus",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies Sled setpoint")

    SledMaster = proxy_attribute(
        dtype=float,
        property_name="SledMasterModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Sled master")

    SledSlave = proxy_attribute(
        dtype=float,
        property_name="SledSlaveModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Sled slave")

    SledHeaterOut = proxy_attribute(
        dtype=float,
        property_name="SledHeaterOutModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Sled heater OUT")

    Linac1Setpoint = proxy_attribute(
        dtype=float,
        property_name="Linac1SetpointModbus",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies Liniac1 setpoint")

    Linac1Master = proxy_attribute(
        dtype=float,
        property_name="Linac1MasterModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac1 master")

    Linac1Slave = proxy_attribute(
        dtype=float,
        property_name="Linac1SlaveModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac1 slave")

    Linac1HeaterOut = proxy_attribute(
        dtype=float,
        property_name="Linac1HeaterOutModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac1 heater OUT")

    Linac2Setpoint = proxy_attribute(
        dtype=float,
        property_name="Linac2SetpointModbus",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies Liniac2 setpoint")

    Linac2Master = proxy_attribute(
        dtype=float,
        property_name="Linac2MasterModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac2 master")

    Linac2Slave = proxy_attribute(
        dtype=float,
        property_name="Linac2SlaveModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac2 slave")

    Linac2HeaterOut = proxy_attribute(
        dtype=float,
        property_name="Linac2HeaterOutModbus",
        access=AttrWriteType.READ,
        description="This attribute specifies Liniac2 heater OUT")

    WaterSetpoint = proxy_attribute(
        dtype=float,
        property_name="WaterSetpointModbus",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies water setpoint")

    WaterIn = proxy_attribute(dtype=float,
                              property_name="WaterInModbus",
                              access=AttrWriteType.READ,
                              description="This attribute shows water IN")

    WaterOut = proxy_attribute(dtype=float,
                               property_name="WaterOutModbus",
                               access=AttrWriteType.READ,
                               description="This attribute shows water OUT")

    WaterAfterPump = proxy_attribute(
        dtype=float,
        property_name="WaterAfterPumpModbus",
        access=AttrWriteType.READ,
        description="This attribute shows water after the pump")

    Valve = proxy_attribute(dtype=float,
                            property_name="ValveModbus",
                            access=AttrWriteType.READ,
                            description="This attribute specifies valve state")

    Sled2 = proxy_attribute(dtype=float,
                            property_name="Sled2Modbus",
                            access=AttrWriteType.READ,
                            description="This attribute specifies sled")

    Flow = proxy_attribute(dtype=float,
                           property_name="FlowTag",
                           access=AttrWriteType.READ,
                           description="This attribute specifies flow")

    Pressure = proxy_attribute(dtype=float,
                               property_name="PressureTag",
                               access=AttrWriteType.READ,
                               description="This attribute specifies pressure")

    PressureSetpoint = proxy_attribute(
        dtype=float,
        property_name="PressureSetpointTag",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies pressure setpoint")

    PressureAlarm = proxy_attribute(
        dtype=float,
        property_name="PressureAlarmTag",
        access=AttrWriteType.READ,
        description="This attribute indicates pressure alarm")

    StartPump = proxy_attribute(dtype=bool,
                                property_name="StartPumpTag",
                                access=AttrWriteType.READ_WRITE,
                                description="This attribute starts the pump")

    StopPump = proxy_attribute(dtype=bool,
                               property_name="StopPumpTag",
                               access=AttrWriteType.READ_WRITE,
                               description="This attribute stops the pump")

    Reset = proxy_attribute(dtype=bool,
                            property_name="ResetTag",
                            access=AttrWriteType.READ_WRITE,
                            description="This attribute resets the pump")

    # Proxy commands

    @proxy_command(property_name="StartPumpTag", write_attribute=True)
    def StartPump(self, subcommand):
        """
        This command starts the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="StopPumpTag", write_attribute=True)
    def StopPump(self, subcommand):
        """
        This command stops the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="ResetPumpTag", write_attribute=True)
    def Reset(self, subcommand):
        """
        This command resets the pump.
        :param subcommand:
        :return:
        """
        subcommand(1)
class InformationForBeamlines(Facade):
    """
    This class specifies InformationForBeamlines facade.
    It is based on facadedevice library.
    It contains:

    - two attributes GeneralInfo and FillingPattern which provide string
      messages
    - two bool proxy attributes: InjectionStatus (true during injection process)
      ExperimentEnable (true when experiments can be performed)
    - two DevState proxy attributes: BIMState and MPSState which show states of those
    - logical attribute which indicates three possible statuses: Injection
      (InjectionStatus:true), ExperimentEnable (ExperimentEnable:true and current
      is higher than 1mA), MDT (in other cases)
    - state attribute that recognises states of MPS and BIM

    """

    filling_pattern = ''
    general_info = ''

    def safe_init_device(self):
        """
        Docstring for 'safe_init_device' - it is just safe
        initialization of the DS.
        :return:
        """
        super(InformationForBeamlines, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")
        self.set_change_event("GeneralInfo", True, False)
        self.set_change_event("Fillingpattern", True, False)
        self.general_info = 'No information.'
        self.filling_pattern = 'No filling pattern.'

    # ----------
    # Attributes
    # ----------

    GeneralInfo = attribute(
        dtype='str',
        access=AttrWriteType.READ_WRITE,
        label="General info",
        doc="General message from CR to all beamlines.",
    )

    FillingPattern = attribute(
        dtype='str',
        access=AttrWriteType.READ_WRITE,
        label="Filling Pattern",
        doc="The filling pattern currently used in the storage ring.",
    )

    # ----------
    # Proxy attributes
    # ----------

    InjectionStatus = proxy_attribute(
        dtype='bool',
        property_name="InjectionStatusTag",
        display_level=DispLevel.EXPERT,
        access=AttrWriteType.READ,
        doc="Forwarded injection status tag from MPS PLC."
    )

    ExperimentEnable = proxy_attribute(
        dtype='bool',
        property_name='ExperimentEnableTag',
        display_level=DispLevel.EXPERT,
        access=AttrWriteType.READ,
        doc='Forwarded experiment enable status tag from MPS PLC.'
    )

    @proxy_attribute(
        dtype='float',
        property_name='BeamCurrentAttr',
        unit='mA',
        label="Beam Current in mA",
        access=AttrWriteType.READ,
        display_level=DispLevel.EXPERT,
        doc="Forwarded beam current from BIM. It is displayed in mA."
    )
    def BeamCurrent(self,data):
        return data*1000

    BIMState = proxy_attribute(
        dtype="DevState",
        property_name="BIMStateTag",
        access=AttrWriteType.READ,
        display_level=DispLevel.EXPERT,
        doc="State of the beam intensity monitor."
    )

    MPSState = proxy_attribute(
        dtype="DevState",
        property_name="MPSStateTag",
        access=AttrWriteType.READ,
        display_level=DispLevel.EXPERT,
        doc="State of the MPS PLC device."
    )

    # ----------
    # Logical attributes
    # ----------

    @logical_attribute(
        dtype='str',
        label="Operation Status",
        bind=["BeamCurrent","ExperimentEnable","InjectionStatus"],
        doc="One of: Injection, MDT (Machine Dedicated Time), Experiment Enable.",)
    def OperationStatus(self, beam_c,exp_en,inj_stat):
        if inj_stat:
            return 'Injection'
        elif beam_c > 1 and exp_en:
            return 'Experiment Enable'
        else:
            return 'MDT'

    @state_attribute(
        bind=["MPSState","BIMState"])
    def state_from_data(self, mps, bim):
        if mps == DevState.FAULT:
            return DevState.FAULT, "MPS PLC device is in FAULT."
        elif mps != DevState.ON and mps != DevState.RUNNING:
            return DevState.ALARM, "MPS PLC device is in an unexpected state: %s" % str(mps)
        if bim == DevState.FAULT:
            return DevState.FAULT, "BIM device is in FAULT."
        elif bim != DevState.ON and bim != DevState.RUNNING:
            return DevState.ALARM, "BIM device is in an unexpected state: %s" % str(bim)
        else:
            return DevState.ON, "Everything is OK."

    # ------------------
    # Attributes methods
    # ------------------

    def read_GeneralInfo(self):
        return self.general_info

    def write_GeneralInfo(self, value):
        self.general_info = value
        self.push_change_event('GeneralInfo', value)
        self.push_data_ready_event('GeneralInfo', 0)

    def read_FillingPattern(self):
        return self.filling_pattern

    def write_FillingPattern(self, value):
        self.filling_pattern = value
        self.push_change_event('FillingPattern', value)
        self.push_data_ready_event('FillingPattern', 0)
Beispiel #8
0
class PhaseShifter(Facade):
    """
    This PhaseShifter class is based on the `facadedevice` library.
    Its main purpose is to change received voltage into degrees accordingly to
    the data provided in external file. During initialization, data from this file
    is imported into two lists: one for voltage and one for degrees. In order to
    do it user has to specify `ConfigurationPath` (path to the `.csv` file).
    Conversion itself is quite simple, it is just a comparison between two lists.
    """
    def safe_init_device(self):
        """
        Method `safe_init_device` - it is just safe initialization of
        the DS as well as reading voltages and degrees from conf file
        :return:
        """
        super(PhaseShifter, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")
        self.arrayVoltages = [0]
        self.arrayPhaseShifts = [0]
        with open(str(self.ConfigurationPath), 'rb') as f:
            reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
            conversionFlagPhaseShifter = 0
            for row in reader:
                try:
                    float(row[1])
                    conversionFlagPhaseShifter = 1
                except ValueError:
                    conversionFlagPhaseShifter = 0
                if self.arrayPhaseShifts == [0.0
                                             ] and conversionFlagPhaseShifter:
                    self.arrayPhaseShifts = [row[1]]
                elif conversionFlagPhaseShifter:
                    self.arrayPhaseShifts.append(row[1])

        with open(str(self.ConfigurationPath), 'rb') as f:
            reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
            conversionFlagVoltage = 0
            for row in reader:
                try:
                    float(row[0])
                    conversionFlagVoltage = 1
                except ValueError:
                    conversionFlagVoltage = 0
                if self.arrayVoltages == [0.0] and conversionFlagVoltage:
                    self.arrayVoltages = [row[0]]
                elif conversionFlagVoltage:
                    self.arrayVoltages.append(row[0])

    #proxy attribute
    Voltage = proxy_attribute(
        dtype=float,
        property_name="VoltageSource",
        access=AttrWriteType.READ,
        description="This attribute specifies received voltage which is"
        "meant to be changed into degrees")
    #conf path as a device property
    ConfigurationPath = device_property(dtype=str)

    # logical attribute
    @logical_attribute(
        dtype=float,
        bind=['Voltage'],
        description="This is an attribute which shows degrees accordingly to "
        "data in a .csv configuration")
    def Degrees(self, val):
        """
        This attribute changes voltage into degrees accordingly to data
        in a .csv configuration
        :param val:
        :return:
        """
        for i in range(len(self.arrayVoltages)):
            if float(self.arrayVoltages[i]) == val:
                return float(self.arrayPhaseShifts[i])
Beispiel #9
0
class RingSHG(Facade):
    def safe_init_device(self):
        """
        Docstring for 'safe_init_device' - it is just safe initialization of the DS
        :return:
        """
        super(RingSHG, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")

    # Proxy attributes

    PressurePump1Alarm = proxy_attribute(
        dtype=float,
        property_name="PressurePump1AlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates Pump1 pressure alarm")

    PressurePump2Alarm = proxy_attribute(
        dtype=float,
        property_name="PressurePump2AlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates Pump2 pressure alarm")

    FlowFGE1 = proxy_attribute(dtype=float,
                               property_name="FlowFGE1Source",
                               access=AttrWriteType.READ,
                               description="This attribute specifies flowFGE1")

    FlowFGE2 = proxy_attribute(dtype=float,
                               property_name="FlowFGE2Source",
                               access=AttrWriteType.READ,
                               description="This attribute specifies flowFGE2")

    PressureRead = proxy_attribute(
        dtype=float,
        property_name="PressureReadSource",
        access=AttrWriteType.READ,
        description="This attribute specifies pressure (read)")

    FlowCirculator = proxy_attribute(
        dtype=float,
        property_name="FlowCirculatorSource",
        access=AttrWriteType.READ,
        description="This attribute specifies flow circulator")

    InnerConductorAlarm = proxy_attribute(
        dtype=float,
        property_name="InnerConductorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates inner conductor alarm")

    OuterConductorAlarm = proxy_attribute(
        dtype=float,
        property_name="OuterConductorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates outer conductor alarm")

    MantelAlarm1 = proxy_attribute(
        dtype=float,
        property_name="MantelAlarm1Source",
        access=AttrWriteType.READ,
        description="This attribute indicates mantel alarm1")

    MantelAlarm2 = proxy_attribute(
        dtype=float,
        property_name="MantelAlarm2Source",
        access=AttrWriteType.READ,
        description="This attribute indicates mantel alarm2")

    MantelAlarm3 = proxy_attribute(
        dtype=float,
        property_name="MantelAlarm3Source",
        access=AttrWriteType.READ,
        description="This attribute indicates mantel alarm3")

    TuningEndcapAlarm = proxy_attribute(
        dtype=float,
        property_name="TuningEndcapAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates tuning endcap alarm")

    StaticEndcapAlarm = proxy_attribute(
        dtype=float,
        property_name="StaticEndcapAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates static endcap alarm")

    InnerRodAlarm1 = proxy_attribute(
        dtype=float,
        property_name="InnerRodAlarm1Source",
        access=AttrWriteType.READ,
        description="This attribute indicates inner rod alarm1")

    InnerRodAlarm2 = proxy_attribute(
        dtype=float,
        property_name="InnerRodAlarm2Source",
        access=AttrWriteType.READ,
        description="This attribute indicates inner rod alarm2")

    SHGAlarm = proxy_attribute(
        dtype=float,
        property_name="SHGAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates shg_ds alarm")

    CirculatorDummyLoadAlarm = proxy_attribute(
        dtype=float,
        property_name="CirculatorDummyLoadAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates circulator dummy load alarm")

    TransmitterAlarm1 = proxy_attribute(
        dtype=float,
        property_name="TransmitterAlarm1Source",
        access=AttrWriteType.READ,
        description="This attribute indicates transmitter alarm1")

    TransmitterAlarm2 = proxy_attribute(
        dtype=float,
        property_name="TransmitterAlarm2Source",
        access=AttrWriteType.READ,
        description="This attribute indicates transmitter alarm2")

    MobileDummyLoadAlarm = proxy_attribute(
        dtype=float,
        property_name="MobileDummyLoadAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates mobile dummy load alarm")

    RF1CirculatorAlarm = proxy_attribute(
        dtype=float,
        property_name="RF1CirculatorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates RF1 circulator alarm")

    PIDSetpoint = proxy_attribute(
        dtype=float,
        property_name="PIDSetpointSource",
        access=AttrWriteType.READ,
        description="This attribute specifies PID setpoint")

    TempBeforePump = proxy_attribute(
        dtype=float,
        property_name="TempBeforePumpSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature before pump")

    TempReturn = proxy_attribute(
        dtype=float,
        property_name="TempReturnSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature return")

    SelectedSensors = proxy_attribute(
        dtype=float,
        property_name="SelectedSensorsSource",
        access=AttrWriteType.READ,
        description="This attribute specifies selected sensors")

    TempSurfaceSensors = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensorsSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature surface sensors")

    TempImmerseSensors = proxy_attribute(
        dtype=float,
        property_name="TempImmerseSensorsSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature immerse sensors")

    MainSetpoint = proxy_attribute(
        dtype=float,
        property_name="MainSetpointSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies main setpoint")

    TempAfterPump = proxy_attribute(
        dtype=float,
        property_name="TempAfterPumpSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature after pump")

    TempAfterHeater = proxy_attribute(
        dtype=float,
        property_name="TempAfterHeaterSource",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature after heater")

    SetpointAfterValve = proxy_attribute(
        dtype=float,
        property_name="SetpointAfterValveSource",
        access=AttrWriteType.READ,
        description="This attribute specifies setpoint after valve")

    SetpointAfterHeater = proxy_attribute(
        dtype=float,
        property_name="SetpointAfterHeaterSource",
        access=AttrWriteType.READ,
        description="This attribute specifies setpoint after heater")

    ChangeHeaterSetpoint = proxy_attribute(
        dtype=float,
        property_name="ChangeHeaterSetpointSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute specifies heater setpoint change")

    TempSurfaceSensor1 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor1Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor1")

    TempSurfaceSensor2 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor2Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor2")

    TempSurfaceSensor3 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor3Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor")

    TempSurfaceSensor4 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor4Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor4")

    TempSurfaceSensor5 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor5Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor5")

    TempSurfaceSensor6 = proxy_attribute(
        dtype=float,
        property_name="TempSurfaceSensor6Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on surface sensor6")

    TempImmerseSensor1 = proxy_attribute(
        dtype=float,
        property_name="TempImmerseSensor1Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on immerse sensor1")

    TempImmerseSensor2 = proxy_attribute(
        dtype=float,
        property_name="TempImmerseSensor2Source",
        access=AttrWriteType.READ,
        description="This attribute specifies temperature on immerse sensor2")

    CavityControlErrorAlarm = proxy_attribute(
        dtype=float,
        property_name="CavityControlErrorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates cavity control error alarm")

    ValveControlErrorAlarm = proxy_attribute(
        dtype=float,
        property_name="ValveControlErrorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates valve control error alarm")

    HeaterControlErrorAlarm = proxy_attribute(
        dtype=float,
        property_name="HeaterControlErrorAlarmSource",
        access=AttrWriteType.READ,
        description="This attribute indicates heater control error alarm")

    ROLowLimit = proxy_attribute(
        dtype=float,
        property_name="ROLowLimitSource",
        access=AttrWriteType.READ,
        description="This attribute indicates RO low limit")

    ROHighLimit = proxy_attribute(
        dtype=float,
        property_name="ROHighLimitSource",
        access=AttrWriteType.READ,
        description="This attribute indicates RO high limit")

    ImmerseSensorsDefective = proxy_attribute(
        dtype=float,
        property_name="ImmerseSensorsDefectiveSource",
        access=AttrWriteType.READ,
        description="This attribute indicates immerse sensors defect")

    ImmerseSensorDefective = proxy_attribute(
        dtype=float,
        property_name="ImmerseSensorDefectiveSource",
        access=AttrWriteType.READ,
        description="This attribute indicates immerse sensor defect")

    SurfaceSensorsDefective = proxy_attribute(
        dtype=float,
        property_name="SurfaceSensorsDefectiveSource",
        access=AttrWriteType.READ,
        description="This attribute indicates surface sensors defect")

    SurfaceSensorDefective = proxy_attribute(
        dtype=float,
        property_name="SurfaceSensorDefectiveSource",
        access=AttrWriteType.READ,
        description="This attribute indicates surface sensor defect")

    SensorsControl = proxy_attribute(
        dtype=float,
        property_name="SensorsControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies sensors control")

    ValveControl = proxy_attribute(
        dtype=float,
        property_name="ValveControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies valve control")

    EVControl = proxy_attribute(
        dtype=float,
        property_name="EVControlSource",
        access=AttrWriteType.READ,
        description="This attribute specifies EV control")

    ValveControlValue = proxy_attribute(
        dtype=float,
        property_name="ValveControlValueSource",
        access=AttrWriteType.READ,
        description="This attribute specifies valve control value")

    HeaterControlValue = proxy_attribute(
        dtype=float,
        property_name="HeaterControlValueSource",
        access=AttrWriteType.READ,
        description="This attribute specifies heater control value")

    ResetAttribute = proxy_attribute(dtype=bool,
                                     property_name="ResetSource",
                                     access=AttrWriteType.READ_WRITE,
                                     description="This attribute resets pumps")

    StopPumpsAttribute = proxy_attribute(
        dtype=bool,
        property_name="StopPumpsSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute stops pumps")

    StartPump1Attribute = proxy_attribute(
        dtype=bool,
        property_name="StartPump1Source",
        access=AttrWriteType.READ_WRITE,
        description="This attribute starts pump1")

    StartPump2Attribute = proxy_attribute(
        dtype=bool,
        property_name="StartPump2Source",
        access=AttrWriteType.READ_WRITE,
        description="This attribute starts pump2")

    SwitchPumpsAttribute = proxy_attribute(
        dtype=bool,
        property_name="SwitchPumpsSource",
        access=AttrWriteType.READ_WRITE,
        description="This attribute switches pumps")

    # Proxy commands

    @proxy_command(property_name="ResetSource", write_attribute=True)
    def Reset(self, subcommand):
        """
        This command resets pumps
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="StopPumpsSource", write_attribute=True)
    def StopPumps(self, subcommand):
        """
        This command stops pumps.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="StartPump1Source", write_attribute=True)
    def StartPump1(self, subcommand):
        """
        This command starts pump1
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="StartPump2Source", write_attribute=True)
    def StartPump2(self, subcommand):
        """
        This command starts pump2.
        :param subcommand:
        :return:
        """
        subcommand(1)

    @proxy_command(property_name="SwitchPumpsSource", write_attribute=True)
    def SwitchPumps(self, subcommand):
        """
        This command switches pumps.
        :param subcommand:
        :return:
        """
        subcommand(1)
Beispiel #10
0
class Valve(Facade):
    """
    This class implements Tango device server for control of basic vacuum valves.
    Each Tango device represents one vacuum valve, which can be in open or closed.

    The Tango device works on a set of four PLC attributes of type bool,
    which must be exposed by PLC device server.

    OpenS PLC attribute should be True when valve is open and False when it is closed.
    ClosedS PLC attribute should be True when valve is closed and False when it is opened.

    OpenC PLC attribute should cause valve to open if it is closed.
    CloseC PLC attribute should cause valve to close if it is open.
    """
    def safe_init_device(self):
        """
        This is a method to safely initialize the Valve device,
        overrode from Facade base class
        """
        super(Valve, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running.")

    # proxy attributes

    ValveOpen = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_OpenS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for valve open "
        "state.")

    ValveClosed = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_ClosedS",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for valve closed "
        "state.")

    ValveInterlock = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_InterlockA",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for valve in "
        "interlock alarm.")

    ValveCutOff = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_CutOffA",
        display_level=DispLevel.OPERATOR,
        description="Attribute that represents PLC signal for valve in cut-off "
        "state. Valve can only be put to cut-off state via manual "
        "control on the device. In this state the valve is closed, "
        "power to the valve was cut off and remote control of the "
        "valve is not possible.")

    UnexpectedState = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_UnexpectedState",
        display_level=DispLevel.OPERATOR,
        description=
        "Attribute that represents PLC signal for valve in unexpected "
        "state.")

    # state attributes

    @state_attribute(bind=[
        'ValveInterlock', 'ValveCutOff', 'ValveOpen', 'ValveClosed',
        'UnexpectedState'
    ])
    def state_and_status(self, interlock, cutoff, opn, closed, unexp):
        """
        This method changes state of device, accordingly to device attributes.

        :param interlock: ValveInterlock
        :param cutoff: ValveCutOff
        :param opn: ValveOpen
        :param closed: ValveClosed
        :param unexp: UnexpectedState

        :return: appropriate device state and status

        :rtype: tuple(DevState, str)
        """
        if interlock:
            return DevState.ALARM, "Valve is interlocked"
        elif cutoff:
            return DevState.CLOSE, "Valve has been cut off. It's closed and " \
                                   "remote control is not possible"
        elif closed:
            return DevState.CLOSE, "Valve is closed"
        elif opn:
            return DevState.OPEN, "Valve is open"
        elif unexp:
            return DevState.UNKNOWN, "PLC attributes could not be read or were " \
                                     "inconsistent, therefore we do not know " \
                                     "what state the device is in."
        return DevState.ON, "Device is running"

    # proxy commands

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_OpenC",
                   doc_out="True to PLCAttrName_OpenC")
    def Open(self, subcommand):
        """
         :rtype: bool
        """
        subcommand(True)
        return True

    @proxy_command(dtype_out=bool,
                   write_attribute=True,
                   property_name="PLCAttrName_CloseC",
                   doc_out="True to PLCAttrName_CloseC")
    def Close(self, subcommand):
        """
        :rtype: bool
        """
        subcommand(True)
        return True
Beispiel #11
0
class Absorber(Facade):
    """
    Tango facade device class for vacuum absorbers

    This class contains four water flow alarms:

    * FSW_1
    * FSW_2
    * FSW_3
    * Achromat_FSW

    as well as attributes to hold names of PLCs for those alarms.

    There is also a whole mechanism of maintaining absorber:

    * name of PLCs for inserting and extracting absorberx
    * name of PLCs for changing state of absorber (inserted or extracted)
    * attribute for holding value of absorber state (inserted or extracted)
    * methods to Insert or Extract the absorber itself
    """

    # device initialization

    def safe_init_device(self):
        """
        This is safe_init_device method overriden from Facade base class. It's
        used to initialize facade device safely
        """
        super(Absorber, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running")

    # proxy attributes

    waterFlowAlarm_Achromat = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_AchromatFSW",
        description="PLC device and attribute name for alarm from water flow "
        "in the achromat")

    PLCAttrName_Extract = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_ExtractAttribute",
        description="PLC device and attribute name for extracting absorber")

    PLCAttrName_Insert = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ_WRITE,
        property_name="PLCAttrName_InsertAttribute",
        description="PLC device and attribute name for inserting absorber")

    waterFlowAlarm_1 = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_FSW_1",
        description="PLC device and attribute name for flow alarm")

    waterFlowAlarm_2 = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_FSW_2",
        description="PLC device and attribute name for flow alarm")

    waterFlowAlarm_3 = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_FSW_3",
        description="PLC device and attribute name for flow alarm")

    PLCAttrName_StateExtracted = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_StateExtractedAttribute",
        description="PLC device and attribute name for extracted state")

    PLCAttrName_StateInserted = proxy_attribute(
        dtype=bool,
        access=AttrWriteType.READ,
        property_name="PLCAttrName_StateInsertedAttribute",
        description="PLC device and attribute name for inserted state")

    # logical attributes

    @logical_attribute(
        dtype=bool,
        bind=['PLCAttrName_StateExtracted', 'PLCAttrName_StateInserted'],
        description="True: the absorber is inserted. False: the absorber "
        "is extracted. Based on PLCAttrName_StateExtracted and "
        "PLCAttrName_StateInserted")
    def InExStatus(self, ins, exs):
        return ins and not exs

    # commands

    @command()
    def Extract(self):
        """
        :return: False to PLCAttrName_Insert, then True to PLCAttrName_Extract
        :rtype: bool
        """
        # write False to PlcAttrName_Insert
        in_node = self.graph['PLCAttrName_Insert']
        value, stamp, quality = in_node.result()
        value = False
        new_result = triplet(value)
        in_node.set_result(new_result)
        # write True to PlcAttrName_Extract
        ex_node = self.graph['PLCAttrName_Extract']
        value, stamp, quality = ex_node.result()
        value = True
        new_result = triplet(value)
        ex_node.set_result(new_result)

    @command()
    def Insert(self):
        """
        :return: False to PLCAttrName_Extract, then True to PLCAttrName_Insert
        :rtype: bool
        """
        # write False to PlcAttrName_Extract
        ex_node = self.graph['PLCAttrName_Extract']
        value, stamp, quality = ex_node.result()
        value = False
        new_result = triplet(value)
        ex_node.set_result(new_result)
        # write True to PlcAttrName_Insert
        in_node = self.graph['PLCAttrName_Insert']
        value, stamp, quality = in_node.result()
        value = True
        new_result = triplet(value)
        in_node.set_result(new_result)
Beispiel #12
0
class BeamEnergy(Facade):
    """
    A facade device for calculating beam's energy, biased on magnet power 
    supply's current. In calculations has been used second order polynomial
    model:

    >>> energy = val ** 2 * a + val * b + c

    where:

    - a, b and c: square, linear and absolute factors of equation
    - val: value of magnet's current
    - energy: energy of the beam
    """

    # device initialization

    def safe_init_device(self):
        """
        This is a method to safely initialize the BeamEnergy device,
        overriden from Facade base class
        """
        super(BeamEnergy, self).safe_init_device()
        self.set_state(DevState.ON)
        self.set_status("Device is running.")

    # proxy attributes

    MagnetPS = proxy_attribute(
        dtype=str,
        access=AttrWriteType.READ_WRITE,
        property_name='MagnetPSAttribute',
        description="This is proper TANGO name of attribute (current), which "
        "will be used in energy calculations. For example: "
        "some/device/somewhere/attribute")

    # local attributes

    A = local_attribute(
        dtype=float,
        access=AttrWriteType.READ_WRITE,
        display_level=DispLevel.EXPERT,
        description="This is a square factor of energy calculation in second"
        " order polynomial")

    B = local_attribute(
        dtype=float,
        access=AttrWriteType.READ_WRITE,
        display_level=DispLevel.EXPERT,
        description="This is a linear factor of energy calculation in second"
        " order polynomial")

    C = local_attribute(
        dtype=float,
        access=AttrWriteType.READ_WRITE,
        display_level=DispLevel.EXPERT,
        description="This is an absolute factor of energy calculation in second"
        " order polynomial")

    # logical attributes

    @logical_attribute(
        dtype=float,
        bind=['A', 'B', 'C', 'MagnetPS'],
        description="This is an attribute holding value of calculated beam's "
        "energy. In calculation is used second order polynomial "
        "model, specified in class' documentation")
    def Energy(self, a, b, c, val):
        return val**2 * a + val * b + c