class PowerSupply(Device): __metaclass__ = DeviceMeta #attribute voltage only read voltage = attribute(label="Voltage", dtype=float, display_level=DispLevel.OPERATOR, access=AttrWriteType.READ, unit="V", format="8.4f", doc="the power supply voltage") #attribute current read and write both current = attribute(label="Current", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ_WRITE, unit="A", format="8.4f", min_value=0.0, max_value=8.5, min_alarm=0.1, max_alarm=8.4, min_warning=0.5, max_warning=8.0, fget="get_current", fset="set_current", doc="the power supply current") host = device_property(dtype=str) port = device_property(dtype=int, default_value=9788) def init_device(self): Device.init_device(self) self.__current = 0.0 self.set_state(DevState.STANDBY) def read_voltage(self): self.info_stream("read_voltage(%s, %d)", self.host, self.port) return 9.99, time.time(), AttrQuality.ATTR_WARNING def get_current(self): return self.__current def set_current(self, current): # should set the power supply current self.__current = current @command def TurnOn(self): self.set_state(DevState.ON) @command def TurnOff(self): # turn off the actual power supply here self.set_state(DevState.OFF)
class EventsTest(Device): """ Switches beetwen valid and invalid attribute`s values. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(EventsTest.class_variable) ENABLED START # # PROTECTED REGION END # // EventsTest.class_variable # ----------------- # Device Properties # ----------------- DeviceName = device_property(dtype='str', ) # ---------- # Attributes # ---------- Max = attribute(dtype='double', ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(EventsTest.init_device) ENABLED START # self.set_state(DevState.ON) self.proxy = AttributeProxy(self.DeviceName) # PROTECTED REGION END # // EventsTest.init_device def always_executed_hook(self): # PROTECTED REGION ID(EventsTest.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // EventsTest.always_executed_hook def delete_device(self): # PROTECTED REGION ID(EventsTest.delete_device) ENABLED START # pass # PROTECTED REGION END # // EventsTest.delete_device # ------------------ # Attributes methods # ------------------ def read_Max(self): # PROTECTED REGION ID(EventsTest.Attribute1_read) ENABLED START # value = self.proxy.read().value maximums = [] for row in value: maximums.append(max(row)) value = max(maximums) attr_quality = AttrQuality.ATTR_ALARM self.push_change_event("Max", float(value), time(), attr_quality) self.push_archive_event("Max", float(value), time(), attr_quality) return float(value), time(), attr_quality
def update_class(self, key, dct): """Create the attribute and read method.""" # Property prop = event_property(key, dtype=self.dtype, event="push_events", is_allowed=self.kwargs.get("fisallowed"), callback=self.callback, errback=self.errback) dct[attr_data_name(key)] = prop # Attribute dct[key] = attribute(fget=prop.read, **self.kwargs) dct["_class_dict"]["attributes"][key] = self
class WaterSwitch(Device): """ Simple device server to detect wheter water is flowing in a cooling water sensor """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(WaterSwitch.class_variable) ENABLED START # # PROTECTED REGION END # // WaterSwitch.class_variable # ---------- # Attributes # ---------- WaterFlowing = attribute(dtype='bool', ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(WaterSwitch.init_device) ENABLED START # GPIO.setmode(GPIO.BCM) GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) # PROTECTED REGION END # // WaterSwitch.init_device def always_executed_hook(self): # PROTECTED REGION ID(WaterSwitch.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // WaterSwitch.always_executed_hook def delete_device(self): # PROTECTED REGION ID(WaterSwitch.delete_device) ENABLED START # pass # PROTECTED REGION END # // WaterSwitch.delete_device # ------------------ # Attributes methods # ------------------ def read_WaterFlowing(self): # PROTECTED REGION ID(WaterSwitch.WaterFlowing_read) ENABLED START # reading = GPIO.input(21) if (reading): self.set_state(PyTango.DevState.OFF) return False else: self.set_state(PyTango.DevState.ON) return True
class PhaseshifterDS(Device): __metaclass__ = DeviceMeta phase = attribute(label="Phase", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="deg", format="3.2f", min_value=0.0, max_value=720.0, fget="get_phase", fset="set_phase", doc="RF phase", memorized=True, hw_memorized=True) dac_ds_name = device_property( dtype=str, doc="Name of the underlying AD5370 DAC device server") phase_volt_cal = device_property(dtype=float, doc="Calibration factor in degrees/volt", default_value=36.0) dac_channel = device_property(dtype=int, doc="Channel connected to the phase shifter", default_value=39) def init_device(self): self.debug_stream("In init_device:") Device.init_device(self) self.phase_val = 0.0 self.dac_dev = pt.DeviceProxy(self.dac_ds_name) self.set_state(pt.DevState.ON) def get_phase(self): self.debug_stream("In get_phase:") return self.phase_val, time.time(), pt.AttrQuality.ATTR_VALID def set_phase(self, new_phase): self.debug_stream("In set_phase: New phase " + str(new_phase)) self.phase_val = new_phase self.dac_dev.write_attribute( "".join(("channel", str(self.dac_channel))), new_phase / self.phase_volt_cal)
class Publish(Device): __metaclass__ = DeviceMeta POLLING = 30 coordinates = attribute(label="Destination co-ordinates", dtype=(int, ), unit="(meters, meters)", access=AttrWriteType.READ, polling_period=POLLING, fget="get_coordinates", fset="set_coordinates", max_dim_x=100, max_dim_y=100, doc="An attribute for Linear and angular \ displacements") def init_device(self): Device.init_device(self) self.__coordinates = (0, 0) self.set_state(DevState.STANDBY) @command def set_coord(self): self.__coordinates = tuple(co_ord) self.push_change_event('coordinates', tuple(self.__coordinates), 2) def get_coordinates(self): return self.__coordinates def set_coordinates(self, co_ordinates): # should set the power supply coordinates self.__coordinates = co_ordinates @command def TurnOn(self): # turn on the actual power supply here self.set_state(DevState.ON) @command def TurnOff(self): # turn off the actual power supply here self.set_state(DevState.OFF)
class Clock(Device): @attribute(dtype=float) def time(self): return time.time() gmtime = attribute(dtype=(int, ), max_dim_x=9) def read_gmtime(self): return time.gmtime() @command(dtype_in=float, dtype_out=str) def ctime(self, seconds): """ Convert a time in seconds since the Epoch to a string in local time. This is equivalent to asctime(localtime(seconds)). When the time tuple is not present, current time as returned by localtime() is used. """ return time.ctime(seconds) @command(dtype_in=(int, ), dtype_out=float) def mktime(self, tupl): return time.mktime(tupl)
class VarianMultiGauge(Device): """ Simple devicer server for the Varian Multigauge controller. Asumes it has a hot cathode gauge. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(VarianMultiGauge.class_variable) ENABLED START # # PROTECTED REGION END # // VarianMultiGauge.class_variable # ----------------- # Device Properties # ----------------- SerialPort = device_property( dtype='str', ) Speed = device_property( dtype='uint16', ) # ---------- # Attributes # ---------- Pressure_IG1 = attribute( dtype='double', unit="mbar", format="%.1e", ) Pressure_IG2 = attribute( dtype='double', unit="mbar", format="%.1e", ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(VarianMultiGauge.init_device) ENABLED START # try: self.ser=serial.Serial(self.SerialPort,baudrate=self.Speed,bytesize=8,parity="N",stopbits=1,timeout=1) self.ser.write("#0011\r") # Set units to mbar self.ser.inWaiting() resp=self.ser.readline() self.ser.write("#0032I1\r") # Check emission on IC1 self.ser.inWaiting() resp=self.ser.readline() except: self.set_state(PyTango.DevState.FAULT) self.set_status("Can't connect to Varian MultiGauge") self.debug_stream("Can't connect to Varian MultiGauge") return self.set_status("Connected to Varian MultiGauge") self.debug_stream("Connected to Varian MultiGauge") if (resp==">01\r"): # Only check first gauge to set device status self.set_state(PyTango.DevState.ON) else: self.set_state(PyTango.DevState.OFF) # PROTECTED REGION END # // VarianMultiGauge.init_device def always_executed_hook(self): # PROTECTED REGION ID(VarianMultiGauge.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // VarianMultiGauge.always_executed_hook def delete_device(self): # PROTECTED REGION ID(VarianMultiGauge.delete_device) ENABLED START # self.ser.close() # PROTECTED REGION END # // VarianMultiGauge.delete_device # ------------------ # Attributes methods # ------------------ def read_Pressure_IG1(self): # PROTECTED REGION ID(VarianMultiGauge.Pressure_IG1_read) ENABLED START # self.ser.write("#0002I1\r") self.ser.inWaiting() a=self.ser.readline() return(float(a[1:])) # PROTECTED REGION END # // VarianMultiGauge.Pressure_IG1_read def read_Pressure_IG2(self): # PROTECTED REGION ID(VarianMultiGauge.Pressure_IG2_read) ENABLED START # self.ser.write("#0002I2\r") self.ser.inWaiting() a=self.ser.readline() return(float(a[1:])) # PROTECTED REGION END # // VarianMultiGauge.Pressure_IG2_read # -------- # Commands # -------- @command( dtype_in='str', dtype_out='str', display_level=DispLevel.EXPERT, ) @DebugIt() def SendCommand(self, argin): # PROTECTED REGION ID(VarianMultiGauge.SendCommand) ENABLED START # self.ser.write(argin+"\r") self.ser.inWaiting() res=self.ser.readline() return(res)
class PIStageTango(Device, metaclass=DeviceMeta): controller_serial_number = sys.argv[1] stage = PIStage.PIStage(controller_serial=controller_serial_number) move_step_size = 0.001 def init_device(self): Device.init_device(self) self.set_state(DevState.OFF) # redirect stdout to store last line sys.stdout = TangoHelper.StoreStdOut() @command def connect(self): self.set_state(DevState.INIT) if self.stage.connect(): self.set_state(DevState.ON) else: self.set_state(DevState.FAULT) cmd_connect = attribute(access=AttrWriteType.WRITE) def write_cmd_connect(self, _): self.connect() @command def disconnect(self): self.stage.disconnect() self.set_state(DevState.OFF) cmd_disconnect = attribute(access=AttrWriteType.WRITE) def write_cmd_disconnect(self, _): self.disconnect() @attribute(dtype=str) def controller_serial(self): return self.controller_serial_number position = attribute(label="Position relative to set zero point", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ, unit="mm", min_value=stage.position_min, max_value=stage.position_max) def read_position(self): return self.stage.position_get() position_fs = attribute(label="Position relative to set zero point", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ, unit="fs", min_value=stage.position_min/299792458.0*10**12*2, max_value=stage.position_max/299792458.0*10**12*2) def read_position_fs(self): # speed of light and 12 orders of magnitude to get from fs to mm, factor 2 for 2-way-light-travel return self.stage.position_get()/299792458.0*10**12*2 position_um = attribute(label="Position relative to set zero point", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ, unit="um", min_value=stage.position_min, max_value=stage.position_max) def read_position_um(self): return self.stage.position_get()*1000.0 # unit conversion [mm -> um] position_unshifted_um = attribute(label="absolute position", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ, unit="um", min_value=stage.position_min * 1000.0, max_value=stage.position_max * 1000.0) def read_position_unshifted_um(self): return self.stage.position_unshifted_get() * 1000.0 # unit conversion [mm -> um] @command(dtype_in=float) def move_absolute(self, new_pos): self.set_state(DevState.MOVING) self.stage.move_absolute(new_pos) cmd_move_absolute = attribute(access=AttrWriteType.WRITE, dtype=float, unit="mm") def write_cmd_move_absolute(self, new_pos): self.move_absolute(new_pos) @command(dtype_in=float) def move_absolute_um(self, new_pos_um): new_pos_mm = new_pos_um / 1000.0 self.move_absolute(new_pos_mm) cmd_move_absolute_um = attribute(access=AttrWriteType.WRITE, dtype=float, unit="um") def write_cmd_move_absolute_um(self, new_pos): self.move_absolute_um(new_pos) @command(dtype_in=float) def move_absolute_fs(self, new_pos_fs): # speed of light and 12 orders of magnitude to get from fs to mm, factor 2 for 2-way-light-travel new_pos_mm = new_pos_fs*299792458.0*10**(-12)/2 self.move_absolute(new_pos_mm) cmd_move_absolute_fs = attribute(access=AttrWriteType.WRITE, dtype=float, unit="fs") def write_cmd_move_absolute_fs(self, new_pos): self.move_absolute_fs(new_pos) @command(dtype_in=float) def move_relative_um(self, step_um): step_mm = step_um/1000.0 self.move_relative(step_mm) cmd_move_relative_um = attribute(access=AttrWriteType.WRITE, dtype=float, unit="um") def write_cmd_move_relative_um(self, step_um): self.move_relative_um(step_um) @attribute(dtype=bool) def on_target_state(self): if self.stage.on_target_state(): self.set_state(DevState.ON) return True else: return False @attribute(dtype=float) def position_min_um(self): return self.stage.position_min * 1000.0 # unit conversion [mm -> um] @attribute(dtype=float) def position_max_um(self): return self.stage.position_max * 1000.0 # unit conversion [mm -> um] velocity = attribute(label="Velocity", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ_WRITE, unit="mm/s", fget="get_velocity", fset="set_velocity", doc="stage position") def get_velocity(self): return self.stage.velocity def set_velocity(self, velocity): self.stage.pi_set_velocity(velocity) velocity_umps = attribute(label="Velocity", dtype=float, display_level=DispLevel.EXPERT, access=AttrWriteType.READ_WRITE, unit="um/s", fget="get_velocity_umps", fset="set_velocity_umps", doc="stage position") def get_velocity_umps(self): return self.stage.velocity * 1000.0 # unit conversion [mm/s -> um/s] def set_velocity_umps(self, velocity_umps): velocity_mmps = velocity_umps / 1000.0 self.stage.pi_set_velocity(velocity_mmps) @command def set_zero_position(self): self.stage.set_zero_position() cmd_set_zero_position = attribute(access=AttrWriteType.WRITE) def write_cmd_set_zero_position(self, _): self.set_zero_position() @command def zero_reference_move(self): self.stage.pi_zero_reference_move() self.stage.pi_handle_limits() cmd_zero_reference_move = attribute(access=AttrWriteType.WRITE) def write_cmd_zero_reference_move(self, _): self.zero_reference_move() @command def stop_motion(self): self.stage.pi_stop_motion() self.set_state(DevState.ON) cmd_stop_motion = attribute(access=AttrWriteType.WRITE) def write_cmd_stop_motion(self, _): self.stop_motion() @attribute(dtype=str) def last_error(self): return str(self.stage.last_error) @command(dtype_in=float) def move_step(self, direction): self.set_state(DevState.MOVING) if direction >= 0: self.stage.move_relative(self.move_step_size) else: self.stage.move_relative(-1 * self.move_step_size) cmd_move_step = attribute(access=AttrWriteType.WRITE, dtype=float, label="moves stage by pregiven step in input direction", doc="moves stage by pregiven step in input direction") def write_cmd_move_step(self, direction): self.move_step(direction) @attribute(dtype=float, access=AttrWriteType.READ_WRITE) def move_step_size_um(self): return self.move_step_size * 1000.0 def write_move_step_size_um(self, step_um): self.move_step_size = step_um / 1000.0 @attribute(dtype=str) def server_message(self): return sys.stdout.read_stored_message()
class MicosPollux(PTS.Device, metaclass=PTS.DeviceMeta): # Device properties proxy = PTS.device_property(dtype=str, doc="Proxy device for serial communication") polling = PTS.device_property(dtype=np.uint32, doc="Polling period in ms") axis = PTS.device_property(dtype=np.uint32, doc="Axis number") # Attributes Position = PTS.attribute(label="Position", dtype=PT.DevDouble, format="%.4f", access=PT.AttrWriteType.READ_WRITE, unit="mm", doc="") Velocity = PTS.attribute(label="Velocity", dtype=PT.DevDouble, format="%.2f", access=PT.AttrWriteType.READ_WRITE, unit="mm/s", memorized=True, hw_memorized=True, doc="") Acceleration = PTS.attribute(label="Acceleration", dtype=PT.DevDouble, format="%.2f", access=PT.AttrWriteType.READ_WRITE, unit="mm/s^2", memorized=True, hw_memorized=True, doc="") def init_device(self): """ Initialize device """ # Set INIT state self.set_state(PT.DevState.INIT) # Call parent init PTS.Device.init_device(self) # Set polling on State self.poll_command("State", 500) # Start monitor thread self.monitor = PolluxPolling(self) def delete_device(self): if self.monitor: self.monitor.terminate() self.monitor.join() def read_Position(self): return self.monitor.getPosition() def write_Position(self, value): self.monitor.moveTo(value) def read_Velocity(self): return self.monitor.getVelocity() def write_Velocity(self, value): self.monitor.setVelocity(value) def read_Acceleration(self): return self.monitor.getAcceleration() def write_Acceleration(self, value): self.monitor.setAcceleration(value) @PTS.command() def setHome(self): self.monitor.setHome() @PTS.command() def goHome(self): self.monitor.moveTo(0.0)
class LakeShore218Tango(Device, metaclass=DeviceMeta): def init_device(self): sys.stdout = StoreStdOut() self.lake_shore = LakeShore218(sys.argv[1]) # default log options can be changed via attributes self.log_options = { 'continue_last_log': False, 'interval': 20, # time steps in s 'overwrite_at_full_memory': True, 'number_of_readings': 2 } # number of logged channels (/logged sensors) self.set_state(DevState.OFF) self.connect( ) # try to auto connect on server start. can also be done manually @attribute def read_temp_sensor1(self): return self.lake_shore.read_temp(1) @attribute def read_temp_sensor2(self): return self.lake_shore.read_temp(2) @attribute def read_temp_sensor3(self): return self.lake_shore.read_temp(3) @attribute def read_temp_sensor4(self): return self.lake_shore.read_temp(4) @attribute def read_temp_sensor5(self): return self.lake_shore.read_temp(5) @attribute def read_temp_sensor6(self): return self.lake_shore.read_temp(6) @attribute def read_temp_sensor7(self): return self.lake_shore.read_temp(7) @attribute def read_temp_sensor8(self): return self.lake_shore.read_temp(8) @command def connect(self): self.set_state(DevState.INIT) if self.lake_shore.connect(): self.set_state(DevState.ON) else: self.set_state(DevState.FAULT) cmd_connect = attribute(access=AttrWriteType.WRITE) def write_cmd_connect(self, _): self.connect() @command def disconnect(self): self.lake_shore.disconnect() self.set_state(DevState.OFF) cmd_disconnect = attribute(access=AttrWriteType.WRITE) def write_cmd_disconnect(self, _): self.disconnect() log_continue_last = attribute(access=AttrWriteType.READ_WRITE, dtype=bool) def read_log_continue_last(self): return self.log_options['continue_last_log'] def write_log_continue_last(self, continue_last_log): self.log_options['continue_last_log'] = continue_last_log log_interval = attribute(access=AttrWriteType.READ_WRITE, unit='s') def read_log_interval(self): return self.log_options['interval'] def write_log_interval(self, interval): self.log_options['interval'] = interval log_overwrite_at_full_memory = attribute(access=AttrWriteType.READ_WRITE, dtype=bool) def read_log_overwrite_at_full_memory(self): return self.log_options['overwrite_at_full_memory'] def write_log_overwrite_at_full_memory(self, overwrite_at_full_memory): self.log_options['overwrite_at_full_memory'] = overwrite_at_full_memory log_number_of_readings = attribute(access=AttrWriteType.READ_WRITE, dtype=int) def read_log_number_of_readings(self): return self.log_options['number_of_readings'] def write_log_number_of_readings(self, number_of_readings): self.log_options['number_of_readings'] = number_of_readings @command def log_start(self): self.lake_shore.log_start(**self.log_options) cmd_log_start = attribute(access=AttrWriteType.WRITE) def write_cmd_log_start(self, _): self.log_start() @command def log_stop(self): self.lake_shore.log_stop() cmd_log_stop = attribute(access=AttrWriteType.WRITE) def write_cmd_log_stop(self, _): self.log_stop() @pipe def log_read(self): """read the log used sensors are a range created from the number_of_readings setting in log_options """ sensor_list = list(range(1, self.log_options['number_of_readings'] + 1)) dict_of_sensor_temp_lists = self.lake_shore.log_read(sensor_list) return 'temperature log', dict_of_sensor_temp_lists @attribute(dtype=bool) def log_status(self): return self.lake_shore.log_status() @attribute(dtype=str) def server_message(self): return sys.stdout.read_stored_message()
class V4L2Camera(Device): """ A simple driver to obtain frames from a V4L2 Camera. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(V4L2Camera.class_variable) ENABLED START # # PROTECTED REGION END # // V4L2Camera.class_variable # ----------------- # Device Properties # ----------------- CaptureDevice = device_property(dtype='str', default_value="/dev/video0") # ---------- # Attributes # ---------- width = attribute( dtype='char', access=AttrWriteType.READ_WRITE, ) Height = attribute( dtype='char', access=AttrWriteType.READ_WRITE, ) View = attribute( dtype=(('float', ), ), max_dim_x=640, max_dim_y=480, ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(V4L2Camera.init_device) ENABLED START # self.video_capture = cv2.VideoCapture(0) if not self.video_capture.isOpened(): self.set_status("Cannnot connect to camera") self.debug_stream("Cannot connet to camera") self.set_state(PyTango.DevState.FAULT) self.set_status("Connected to camera") self.set_state(PyTango.DevState.ON) self.video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640) self.video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) # PROTECTED REGION END # // V4L2Camera.init_device def always_executed_hook(self): # PROTECTED REGION ID(V4L2Camera.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // V4L2Camera.always_executed_hook def delete_device(self): # PROTECTED REGION ID(V4L2Camera.delete_device) ENABLED START # video_capture.release() # PROTECTED REGION END # // V4L2Camera.delete_device # ------------------ # Attributes methods # ------------------ def read_width(self): # PROTECTED REGION ID(V4L2Camera.width_read) ENABLED START # return 0 # PROTECTED REGION END # // V4L2Camera.width_read def write_width(self, value): # PROTECTED REGION ID(V4L2Camera.width_write) ENABLED START # pass # PROTECTED REGION END # // V4L2Camera.width_write def read_Height(self): # PROTECTED REGION ID(V4L2Camera.Height_read) ENABLED START # return 0 # PROTECTED REGION END # // V4L2Camera.Height_read def write_Height(self, value): # PROTECTED REGION ID(V4L2Camera.Height_write) ENABLED START # pass # PROTECTED REGION END # // V4L2Camera.Height_write def read_View(self): # PROTECTED REGION ID(V4L2Camera.View_read) ENABLED START # ret, frame = self.video_capture.read() #img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) return gray
class RefA(SKABaseDevice): """ An Ref (Reference Elt) device of type A """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(RefA.class_variable) ENABLED START # # PROTECTED REGION END # // RefA.class_variable # ----------------- # Device Properties # ----------------- # ---------- # Attributes # ---------- attrR1 = attribute( dtype='str', doc="Attribute 1 for DevA", ) attrRW2 = attribute( dtype='str', access=AttrWriteType.READ_WRITE, doc="Attribute 2 for DevA", ) attrImportant1 = attribute( dtype='double', access=AttrWriteType.READ_WRITE, max_value=100, min_value=0, max_alarm=90, min_alarm=10, max_warning=80, min_warning=20, doc="An important attribute", ) # --------------- # General methods # --------------- def init_device(self): SKABaseDevice.init_device(self) # PROTECTED REGION ID(RefA.init_device) ENABLED START # # PROTECTED REGION END # // RefA.init_device def always_executed_hook(self): # PROTECTED REGION ID(RefA.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // RefA.always_executed_hook def delete_device(self): # PROTECTED REGION ID(RefA.delete_device) ENABLED START # pass # PROTECTED REGION END # // RefA.delete_device # ------------------ # Attributes methods # ------------------ def read_attrR1(self): # PROTECTED REGION ID(RefA.attrR1_read) ENABLED START # return '' # PROTECTED REGION END # // RefA.attrR1_read def read_attrRW2(self): # PROTECTED REGION ID(RefA.attrRW2_read) ENABLED START # return '' # PROTECTED REGION END # // RefA.attrRW2_read def write_attrRW2(self, value): # PROTECTED REGION ID(RefA.attrRW2_write) ENABLED START # pass # PROTECTED REGION END # // RefA.attrRW2_write def read_attrImportant1(self): # PROTECTED REGION ID(RefA.attrImportant1_read) ENABLED START # return 0.0 # PROTECTED REGION END # // RefA.attrImportant1_read def write_attrImportant1(self, value): # PROTECTED REGION ID(RefA.attrImportant1_write) ENABLED START # pass # PROTECTED REGION END # // RefA.attrImportant1_write # -------- # Commands # -------- @command() @DebugIt() def Reset(self): # PROTECTED REGION ID(RefA.Reset) ENABLED START # pass
class PowerSupply(Device): """ Dummy Power Supply for testing """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(PowerSupply.class_variable) ENABLED START # # PROTECTED REGION END # // PowerSupply.class_variable # ----------------- # Device Properties # ----------------- LoadImpedance = device_property(dtype='double', mandatory=True) HWUpdatetime = device_property(dtype='double', default_value=1) # ---------- # Attributes # ---------- Voltage = attribute( dtype='double', access=AttrWriteType.READ_WRITE, label="PSV", unit="V", max_value=100, min_value=0, max_alarm=50, max_warning=30, memorized=True, ) Current = attribute( dtype='double', unit="A", ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(PowerSupply.init_device) ENABLED START # self.voltage = 0. self.current = 0. self.set_state(DevState.OFF) # PROTECTED REGION END # // PowerSupply.init_device def always_executed_hook(self): # PROTECTED REGION ID(PowerSupply.always_executed_hook) ENABLED START # t = '%s state is %s\n' % (self.get_name(), self.get_state()) t += 'Voltage = %s, Current = %s' % (self.voltage, self.current) self.set_status(t) print(t) # PROTECTED REGION END # // PowerSupply.always_executed_hook def delete_device(self): # PROTECTED REGION ID(PowerSupply.delete_device) ENABLED START # self.set_state(DevState.UNKNOWN) # PROTECTED REGION END # // PowerSupply.delete_device # ------------------ # Attributes methods # ------------------ def read_Voltage(self): # PROTECTED REGION ID(PowerSupply.Voltage_read) ENABLED START # return self.voltage # PROTECTED REGION END # // PowerSupply.Voltage_read def write_Voltage(self, value): # PROTECTED REGION ID(PowerSupply.Voltage_write) ENABLED START # self.voltage = value self.current = self.voltage / self.LoadImpedance # PROTECTED REGION END # // PowerSupply.Voltage_write def read_Current(self): # PROTECTED REGION ID(PowerSupply.Current_read) ENABLED START # return self.current # PROTECTED REGION END # // PowerSupply.Current_read # -------- # Commands # -------- @command() @DebugIt() def On(self): # PROTECTED REGION ID(PowerSupply.On) ENABLED START # self.set_state(DevState.ON) # PROTECTED REGION END # // PowerSupply.On @command() @DebugIt() def Off(self): # PROTECTED REGION ID(PowerSupply.Off) ENABLED START # self.set_state(DevState.OFF)
class SKACapability(SKAObsDevice): """ Subarray handling device """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(SKACapability.class_variable) ENABLED START # # PROTECTED REGION END # // SKACapability.class_variable # ----------------- # Device Properties # ----------------- CapType = device_property(dtype='str', ) CapID = device_property(dtype='str', ) subID = device_property(dtype='str', ) # ---------- # Attributes # ---------- activationTime = attribute( dtype='double', unit="s", standard_unit="s", display_unit="s", doc="Time of activation in seconds since Unix epoch.", ) configuredInstances = attribute( dtype='uint16', doc= "Number of instances of this Capability Type currently in use on this subarray.", ) usedComponents = attribute( dtype=('str', ), max_dim_x=100, doc= "A list of components with no. of instances in use on this Capability.", ) # --------------- # General methods # --------------- def init_device(self): SKAObsDevice.init_device(self) # PROTECTED REGION ID(SKACapability.init_device) ENABLED START # self._activation_time = 0.0 self._configured_instances = 0 self._used_components = [""] # PROTECTED REGION END # // SKACapability.init_device def always_executed_hook(self): # PROTECTED REGION ID(SKACapability.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // SKACapability.always_executed_hook def delete_device(self): # PROTECTED REGION ID(SKACapability.delete_device) ENABLED START # pass # PROTECTED REGION END # // SKACapability.delete_device # ------------------ # Attributes methods # ------------------ def read_activationTime(self): # PROTECTED REGION ID(SKACapability.activationTime_read) ENABLED START # return self._activation_time # PROTECTED REGION END # // SKACapability.activationTime_read def read_configuredInstances(self): # PROTECTED REGION ID(SKACapability.configuredInstances_read) ENABLED START # return self._configured_instances # PROTECTED REGION END # // SKACapability.configuredInstances_read def read_usedComponents(self): # PROTECTED REGION ID(SKACapability.usedComponents_read) ENABLED START # return self._used_components # PROTECTED REGION END # // SKACapability.usedComponents_read # -------- # Commands # -------- @command( dtype_in='uint16', doc_in="The number of instances to configure for this Capability.", ) @DebugIt() def ConfigureInstances(self, argin): # PROTECTED REGION ID(SKACapability.ConfigureInstances) ENABLED START # self._configured_instances = argin
) ValuesFile = device_property( dtype='str', ) CacheTime = device_property( dtype='int', default_value=600 ) # ---------- # Attributes # ---------- AttributeList = attribute( dtype=('str',), max_dim_x=65536, ) AttributeOkList = attribute( dtype=('str',), max_dim_x=65536, ) AttributeNokList = attribute( dtype=('str',), max_dim_x=65536, ) AttributeOnList = attribute( dtype=('str',), max_dim_x=65536,
class SKAPowerSupplyGroup(SKABaseDevice): """ Description """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(SKAPowerSupplyGroup.class_variable) ENABLED START # # PROTECTED REGION END # // SKAPowerSupplyGroup.class_variable # ----------------- # Device Properties # ----------------- PowerSupplyGroup = device_property(dtype='str', mandatory=True) # ---------- # Attributes # ---------- PowerSupplyList = attribute( dtype=('str', ), max_dim_x=2048, ) Current = attribute( dtype=('double', ), max_dim_x=128, ) Voltage = attribute( dtype=('double', ), access=AttrWriteType.READ_WRITE, max_dim_x=128, ) # --------------- # General methods # --------------- def init_device(self): SKABaseDevice.init_device(self) # PROTECTED REGION ID(SKAPowerSupplyGroup.init_device) ENABLED START # self.tg = tango.Group('power supplies') self.setpoints = [0.0] # name of the group for the Power Supplies self.tg.add(self.PowerSupplyGroup) # PROTECTED REGION END # // SKAPowerSupplyGroup.init_device def always_executed_hook(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.always_executed_hook) ENABLED START # print(self.PowerSupplyGroup) print(self.tg.get_device_list()) r = self.tg.read_attribute('State') states = {} try: for b in r: name = b.dev_name() value = b.get_data( ).value if not b.has_failed() else DevState.FAULT states[name] = value self.set_status('\n'.join('%s: %s' % t for t in states.items())) stateset = list(set(states.values())) if not stateset: self.set_state(DevState.INIT) elif DevState.FAULT in stateset: self.set_state(DevState.FAULT) elif DevState.ALARM in stateset: self.set_state(DevState.ALARM) elif len(stateset) != 1: self.set_state(DevState.UNKNOWN) else: self.set_state(stateset[0]) except: self.logger.error(traceback.format_exc()) # PROTECTED REGION END # // SKAPowerSupplyGroup.always_executed_hook def delete_device(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.delete_device) ENABLED START # pass # PROTECTED REGION END # // SKAPowerSupplyGroup.delete_device # ------------------ # Attributes methods # ------------------ def read_PowerSupplyList(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.PowerSupplyList_read) ENABLED START # devs = list(self.tg.get_device_list()) if not len(devs): self.set_state(DevState.FAULT) raise Exception('No Power Supplies running?') return list(sorted(devs)) # PROTECTED REGION END # // SKAPowerSupplyGroup.PowerSupplyList_read def read_Current(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.Current_read) ENABLED START # r = self.tg.read_attribute('Current') currents = {} try: for b in r: name = b.dev_name() value = b.get_data().value if not b.has_failed() else math.nan currents[name] = value except: self.logger.error(traceback.format_exc()) return list(v for k, v in sorted(currents.items())) # PROTECTED REGION END # // SKAPowerSupplyGroup.Current_read def read_Voltage(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.Voltage_read) ENABLED START # r = self.tg.read_attribute('Voltage') voltages = {} try: for b in r: name = b.dev_name() value = b.get_data().value if not b.has_failed() else math.nan if value != self.setpoints[0]: self.set_state(DevState.FAULT) voltages[name] = value except: self.logger.error(traceback.format_exc()) return list(v for k, v in sorted(voltages.items())) # PROTECTED REGION END # // SKAPowerSupplyGroup.Voltage_read def write_Voltage(self, value): # PROTECTED REGION ID(SKAPowerSupplyGroup.Voltage_write) ENABLED START # r = self.tg.write_attribute('Voltage', value) self.setpoints = value # PROTECTED REGION END # // SKAPowerSupplyGroup.Voltage_write # -------- # Commands # -------- @command() @DebugIt() def On(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.On) ENABLED START # self.tg.command_inout('On') # PROTECTED REGION END # // SKAPowerSupplyGroup.On @command() @DebugIt() def Off(self): # PROTECTED REGION ID(SKAPowerSupplyGroup.Off) ENABLED START # self.tg.command_inout('Off')
class MyDevice(Device): """ """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(MyDevice.class_variable) ENABLED START # image_maximum = 0.0 polled_ds = 0.0 quality_counter = 0 quality_list = [ AttrQuality.ATTR_VALID, AttrQuality.ATTR_INVALID, AttrQuality.ATTR_ALARM, AttrQuality.ATTR_CHANGING, AttrQuality.ATTR_WARNING ] # PROTECTED REGION END # // MyDevice.class_variable # ---------------- # Class Properties # ---------------- # ----------------- # Device Properties # ----------------- DeviceToRead = device_property(dtype='str', default_value="sys/tg_test/1") # ---------- # Attributes # ---------- PolledDoubleScalar = attribute(dtype='double', ) ImagineMaximum = attribute(dtype='double', ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(MyDevice.init_device) ENABLED START # self.set_state(DevState.ON) # PROTECTED REGION END # // MyDevice.init_device def always_executed_hook(self): # PROTECTED REGION ID(MyDevice.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // MyDevice.always_executed_hook def delete_device(self): # PROTECTED REGION ID(MyDevice.delete_device) ENABLED START # pass # PROTECTED REGION END # // MyDevice.delete_device # ------------------ # Attributes methods # ------------------ def read_PolledDoubleScalar(self): # PROTECTED REGION ID(MyDevice.PolledDoubleScalar_read) ENABLED START # attr_proxy = PyTango.AttributeProxy(self.DeviceToRead + '/double_scalar') self.polled_ds = attr_proxy.read().value self.debug_stream(str(self.polled_ds)) return self.polled_ds # PROTECTED REGION END # // MyDevice.PolledDoubleScalar_read def read_ImagineMaximum(self): # PROTECTED REGION ID(MyDevice.ImagineMaximum_read) ENABLED START # attr_proxy = PyTango.AttributeProxy(self.DeviceToRead + '/double_image_ro') value = attr_proxy.read().value maximums = [] for row in value: maximums.append(max(row)) self.image_maximum = max(maximums) attr_quality = AttrQuality.ATTR_VALID self.push_change_event("ImagineMaximum", self.image_maximum, time(), attr_quality) self.push_archive_event("ImagineMaximum", self.image_maximum, time(), attr_quality) if (self.image_maximum < 20): self.set_state(DevState.OFF) else: if (self.image_maximum < 30): self.set_state(DevState.WARNING) else: self.set_state(DevState.ON) return float(self.image_maximum), time(), attr_quality # PROTECTED REGION END # // MyDevice.ImagineMaximum_read # -------- # Commands # -------- @command @DebugIt() def ChangeDoubleScalarQuality(self): # PROTECTED REGION ID(MyDevice.ChangeDoubleScalarQuality) ENABLED START # self.quality_counter = (self.quality_counter + 1) % 5 self.PolledDoubleScalar.set_quality( self.quality_list[self.quality_counter])
class MVC3GaugeControllerTango(Device, metaclass=DeviceMeta): serial_address = device_property(dtype=int, # store address in decimal (can be 1 - 126) default_value=1, doc="this is the devices serial address in decimal. Connection on this device is " "not done by asking for the serial number (not supported by device) but by " "asking for the RS485 Serial Address (can also be set/requested in the here " "used RS232 mode). These were manually set with SSA (e.g. 'RSA46\r' sets this " "to hex value 46 which is 70 in decimal) command and are labeled on the case " "of each device. IMPORTANT: after setting the serial address the device must " "be switched to RS485 and can then be switched back to RS232 immediately. " "Otherwise the address will reset on next device restart") pressure_decimal_places = device_property(dtype=int, default_value=2, doc="number of displayed decimal places on pressure readings") def init_device(self): sys.stdout = StoreStdOut() self.get_device_properties() # otherwise self.serial will be None self.mvc3 = MVC3GaugeController(self.serial_address) self.set_state(DevState.OFF) self.connect() # try to auto connect on server start. can also be done manually def delete_device(self): self.mvc3.disconnect() print('device deleted') @attribute(dtype=str) def server_message(self): return sys.stdout.read_stored_message() @command def connect(self): self.get_device_properties() self.set_state(DevState.INIT) if self.mvc3.connect(): self.set_state(DevState.ON) else: self.set_state(DevState.FAULT) cmd_connect = attribute(access=AttrWriteType.WRITE) def write_cmd_connect(self, _): self.connect() @command def disconnect(self): self.mvc3.disconnect() self.set_state(DevState.OFF) cmd_disconnect = attribute(access=AttrWriteType.WRITE) def write_cmd_disconnect(self, _): self.disconnect() cmd_reconnect = attribute(access=AttrWriteType.WRITE) def write_cmd_reconnect(self, _): self.disconnect() self.connect() @attribute(dtype=str, #unit='mBar', access=AttrWriteType.READ) def P1(self): """writes out errors and info too""" try: pressure = self.mvc3.read_pressure(1, decimal_places=self.pressure_decimal_places) if self.get_state() == DevState.FAULT: self.set_state(DevState.ON) return pressure # yes, general exception catching is not good but cs studio otherwise hides this completely (even worse) except Exception as e: self.set_state(DevState.FAULT) return "ERROR: %s" % e @attribute(dtype=str, unit='mBar', access=AttrWriteType.READ) def P2(self): """writes out errors and info too""" try: pressure = self.mvc3.read_pressure(2, decimal_places=self.pressure_decimal_places) if self.get_state() == DevState.FAULT: self.set_state(DevState.ON) return pressure # yes, general exception catching is not good but cs studio otherwise hides this completely (even worse) except Exception as e: self.set_state(DevState.FAULT) return "ERROR: %s" % e @attribute(dtype=str, unit='mBar', access=AttrWriteType.READ) def P3(self): """writes out errors and info too""" try: pressure = self.mvc3.read_pressure(3, decimal_places=self.pressure_decimal_places) if self.get_state() == DevState.FAULT: self.set_state(DevState.ON) return pressure # yes, general exception catching is not good but cs studio otherwise hides this completely (even worse) except Exception as e: self.set_state(DevState.FAULT) return "ERROR: %s" % e
class SpectrometerCameraDS(Device): __metaclass__ = DeviceMeta exposuretime = attribute( label='ExposureTime', dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="us", format="%8.1f", min_value=0.0, max_value=1e7, fget="get_exposuretime", fset="set_exposuretime", doc="Camera exposure time in us", memorized=True, ) # hw_memorized=True) gain = attribute( label='Gain', dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="dB", format="%3.2f", min_value=0.0, max_value=1e2, fget="get_gain", fset="set_gain", doc="Camera gain in dB", memorized=True, ) # hw_memorized=True) wavelengthvector = attribute( label='WavelengthVector', dtype=[np.double], access=pt.AttrWriteType.READ, max_dim_x=16384, display_level=pt.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_wavelengthvector", doc="Wavelength vector", ) spectrum = attribute( label='Spectrum', dtype=[np.double], access=pt.AttrWriteType.READ, max_dim_x=16384, display_level=pt.DispLevel.OPERATOR, unit="a.u.", format="%5.2f", fget="get_spectrum", doc="Spectrum", ) width = attribute( label='Spectrum width FWHM', dtype=np.double, access=pt.AttrWriteType.READ, display_level=pt.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_width", doc= "FWHM for the peak in spectrum. Basic thresholding and peak detection is used.", ) peak = attribute( label='Spectrum peak', dtype=np.double, access=pt.AttrWriteType.READ, display_level=pt.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_peak", doc= "Wavelength for the peak in spectrum. Basic thresholding and peak detection is used.", ) sat_lvl = attribute( label='Saturation level', dtype=np.double, access=pt.AttrWriteType.READ, display_level=pt.DispLevel.OPERATOR, unit="relative", format="%2.2e", fget="get_satlvl", doc= "Relative amount of pixels that are saturated. This should be zero.", ) camera_name = device_property( dtype=str, doc="Tango name of the camera device", default_value="gunlaser/cameras/spectrometer_camera") watchdog_timeout = device_property( dtype=float, doc="Timeout for the watchdog resetting the hardware in s", default_value="2.0") dispersion = device_property( dtype=float, doc="Dispersion of the spectrometer in nm/px. " "Positive if wavelength increases to the right", default_value="0.056") central_wavelength = device_property( dtype=float, doc="Wavelength of the central pixel of the ROI in nm", default_value="2.0") roi = device_property( dtype=[int], doc="Pixel coordinates for the ROI: [left, top, width, height]", default_value=[0, 0, 100, 100]) saturation_level = device_property( dtype=int, doc="Saturation pixel value, used for estimating overexposure", default_value=65536) def __init__(self, klass, name): self.wavelengthvector_data = np.array([]) self.max_value = 1.0 self.dev_controller = None self.db = None Device.__init__(self, klass, name) def init_device(self): self.debug_stream("In init_device:") Device.init_device(self) self.db = pt.Database() self.set_state(pt.DevState.UNKNOWN) self.debug_stream("Init camera controller {0}".format( self.camera_name)) params = dict() params["imageoffsetx"] = self.roi[0] params["imageoffsety"] = self.roi[1] params["imagewidth"] = self.roi[2] params["imageheight"] = self.roi[3] params["triggermode"] = "Off" try: if self.dev_controller is not None: self.dev_controller.stop_thread() except Exception as e: self.error_info("Error stopping camera controller: {0}".format(e)) try: self.setup_spectrometer() self.dev_controller = SpectrometerCameraDeviceController( self.camera_name, params, self.wavelengthvector_data, self.max_value) # self.dev_controller = CameraDeviceController(self.camera_name, params) except Exception as e: self.error_stream( "Error creating camera controller: {0}".format(e)) return self.debug_stream("init_device finished") # self.set_state(pt.DevState.ON) self.dev_controller.add_state_callback(self.change_state) def setup_spectrometer(self): self.info_stream("Entering setup_camera") self.wavelengthvector_data = (self.central_wavelength + np.arange( -self.roi[2] / 2, self.roi[2] / 2) * self.dispersion) * 1e-9 self.max_value = self.saturation_level def change_state(self, new_state, new_status=None): self.debug_stream("Change state from {0} to {1}".format( self.get_state(), new_state)) if self.get_state( ) is pt.DevState.INIT and new_state is not pt.DevState.UNKNOWN: self.debug_stream("Set memorized attributes") data = self.db.get_device_attribute_property( self.get_name(), "gain") self.debug_stream( "Database returned data for \"gain\": {0}".format( data["gain"])) try: new_value = float(data["gain"]["__value"][0]) self.debug_stream("{0}".format(new_value)) self.dev_controller.write_attribute("gain", new_value) except (KeyError, TypeError, IndexError, ValueError): pass data = self.db.get_device_attribute_property( self.get_name(), "exposuretime") self.debug_stream( "Database returned data for \"exposuretime\": {0}".format( data["exposuretime"])) try: new_value = float(data["exposuretime"]["__value"][0]) self.dev_controller.write_attribute("exposuretime", new_value) except (KeyError, TypeError, IndexError, ValueError): pass self.set_state(new_state) if new_status is not None: self.debug_stream("Setting status {0}".format(new_status)) self.set_status(new_status) def get_spectrum(self): attr = self.dev_controller.get_attribute("image") try: spectrum = attr.value.sum(0) except AttributeError: spectrum = [] return spectrum, attr.time.totime(), attr.quality def get_wavelengthvector(self): self.debug_stream("get_wavelengthvector: size {0}".format( self.wavelengthvector_data.shape)) return self.wavelengthvector_data, time.time( ), pt.AttrQuality.ATTR_VALID def get_exposuretime(self): attr = self.dev_controller.get_attribute("exposuretime") return attr.value, attr.time.totime(), attr.quality def set_exposuretime(self, new_exposuretime): self.debug_stream( "In set_exposuretime: New value {0}".format(new_exposuretime)) self.debug_stream("Type dev_controller: {0}".format( type(self.dev_controller))) self.dev_controller.write_attribute("exposuretime", new_exposuretime) def get_gain(self): attr = self.dev_controller.get_attribute("gain") return attr.value, attr.time.totime(), attr.quality def set_gain(self, new_gain): self.debug_stream("In set_gain: New value {0}".format(new_gain)) self.dev_controller.write_attribute("gain", new_gain) def get_width(self): attr = self.dev_controller.get_attribute("width") return attr def get_peak(self): attr = self.dev_controller.get_attribute("peak") return attr def get_satlvl(self): attr = self.dev_controller.get_attribute("satlvl") return attr
class RefSubarray(SKASubarray): """ Ref (Reference Element) device of Type Subarray """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(RefSubarray.class_variable) ENABLED START # # PROTECTED REGION END # // RefSubarray.class_variable # ----------------- # Device Properties # ----------------- # ---------- # Attributes # ---------- obsState = attribute( dtype='DevEnum', doc="Observing State", ) obsMode = attribute( dtype='DevEnum', doc="Observing Mode", ) configurationProgress = attribute( dtype='uint16', unit="%", max_value=100, min_value=0, doc="Percentage configuration progress", ) configurationDelayExpected = attribute( dtype='uint16', unit="seconds", doc="Configuration delay expected in seconds", ) # --------------- # General methods # --------------- def init_device(self): SKASubarray.init_device(self) # PROTECTED REGION ID(RefSubarray.init_device) ENABLED START # # PROTECTED REGION END # // RefSubarray.init_device def always_executed_hook(self): # PROTECTED REGION ID(RefSubarray.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // RefSubarray.always_executed_hook def delete_device(self): # PROTECTED REGION ID(RefSubarray.delete_device) ENABLED START # pass # PROTECTED REGION END # // RefSubarray.delete_device # ------------------ # Attributes methods # ------------------ def read_obsState(self): # PROTECTED REGION ID(RefSubarray.obsState_read) ENABLED START # return 0 # PROTECTED REGION END # // RefSubarray.obsState_read def read_obsMode(self): # PROTECTED REGION ID(RefSubarray.obsMode_read) ENABLED START # return 0 # PROTECTED REGION END # // RefSubarray.obsMode_read def read_configurationProgress(self): # PROTECTED REGION ID(RefSubarray.configurationProgress_read) ENABLED START # return 0 # PROTECTED REGION END # // RefSubarray.configurationProgress_read def read_configurationDelayExpected(self): # PROTECTED REGION ID(RefSubarray.configurationDelayExpected_read) ENABLED START # return 0 # PROTECTED REGION END # // RefSubarray.configurationDelayExpected_read # -------- # Commands # -------- @command( dtype_out='str', doc_out="Observation state", ) @DebugIt() def ObsState(self): # PROTECTED REGION ID(RefSubarray.ObsState) ENABLED START # return "" # PROTECTED REGION END # // RefSubarray.ObsState @command() @DebugIt() def Reset(self): # PROTECTED REGION ID(RefSubarray.Reset) ENABLED START # pass
class SEAWaterflowmeter(Device,metaclass=DeviceMeta): """ Device server to interface a Raspberry PI using the GPIO to the SEA YF-S201 water flow sensor. """ # PROTECTED REGION ID(SEAWaterflowmeter.class_variable) ENABLED START # # PROTECTED REGION END # // SEAWaterflowmeter.class_variable # ----------------- # Device Properties # ----------------- channels = device_property( dtype='str', default_value="6,13,19,26" ) channelnames = device_property( dtype='str', default_value="turbo,xraygun,doser,p2lens" ) calibration = device_property( dtype='double', default_value=7.5 ) time = device_property( dtype='double', default_value=1.0 ) # ---------- # Attributes # ---------- channel0 = attribute( dtype='double', label="turbo", unit="l/min", format="%3.1f", ) channel1 = attribute( dtype='double', label="xray gun", unit="l/min", format="%3.1f", ) channel2 = attribute( dtype='double', label="doser", unit="l/min", format="%3.1f", ) channel3 = attribute( dtype='double', label="p2 lens", unit="l/min", format="%3.1f", ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(SEAWaterflowmeter.init_device) ENABLED START # self.channel0data=0.0 self.channel1data=0.0 self.channel2data=0.0 self.channel3data=0.0 for i in self.channels.split(","): count[int(i)]=0.0 self.listofnames=self.channelnames.split(",") #print(self.channel0.get_attribute_list) #self.channel0.set_label(listofnames[0]) #self.channel1.set_label(listofnames[1]) #self.channel2.set_label(listofnames[2]) #self.channel3.set_label(listofnames[3]) GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering for i in count: GPIO.setup(i,GPIO.IN) for i in count: GPIO.add_event_detect(i, GPIO.RISING, callback=my_callback) self.set_state(PyTango.DevState.ON) self.set_status("Measurement thread is running") self.stop_ctrloop = 0 ctrlloop = ControlThread(self) ctrlloop.start() # PROTECTED REGION END # // SEAWaterflowmeter.init_device def always_executed_hook(self): # PROTECTED REGION ID(SEAWaterflowmeter.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // SEAWaterflowmeter.always_executed_hook def delete_device(self): # PROTECTED REGION ID(SEAWaterflowmeter.delete_device) ENABLED START # self.ds.stop_ctrloop = 0 GPIO.cleanup() # PROTECTED REGION END # // SEAWaterflowmeter.delete_device # ------------------ # Attributes methods # ------------------ def read_channel0(self): # PROTECTED REGION ID(SEAWaterflowmeter.channel0_read) ENABLED START # return self.channel0data # PROTECTED REGION END # // SEAWaterflowmeter.channel0_read def read_channel1(self): # PROTECTED REGION ID(SEAWaterflowmeter.channel1_read) ENABLED START # return self.channel1data # PROTECTED REGION END # // SEAWaterflowmeter.channel1_read def read_channel2(self): # PROTECTED REGION ID(SEAWaterflowmeter.channel2_read) ENABLED START # return self.channel2data # PROTECTED REGION END # // SEAWaterflowmeter.channel2_read def read_channel3(self): # PROTECTED REGION ID(SEAWaterflowmeter.channel3_read) ENABLED START # return self.channel3data # PROTECTED REGION END # // SEAWaterflowmeter.channel3_read # -------- # Commands # -------- @command( ) @DebugIt() def turnON(self): # PROTECTED REGION ID(SEAWaterflowmeter.turnON) ENABLED START # state=self.get_state() if (state==PyTango.DevState.ON): return elif (state==PyTango.DevState.OFF): self.stop_ctrloop = 0 ctrlloop = ControlThread(self) ctrlloop.start() self.set_state(PyTango.DevState.ON) self.set_status("Measurement thread is running") # PROTECTED REGION END # // SEAWaterflowmeter.turnON @command( ) @DebugIt() def turnOFF(self): # PROTECTED REGION ID(SEAWaterflowmeter.turnOFF) ENABLED START # state=self.get_state() if (state==PyTango.DevState.OFF): return elif (state==PyTango.DevState.ON): self.stop_ctrloop = 1 self.set_state(PyTango.DevState.OFF) self.set_status("Measurement thread is NOT running")
class SecondOrderImpulseResponse(Device): """ This is a sample DS for simulating a impulse response of a second-order intertial object. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(SecondOrderImpulseResponse.class_variable) ENABLED START # amplification = 1.0 time_constant_1 = 1.0 time_constant_2 = 1.0 output = [0.0] # PROTECTED REGION END # // SecondOrderImpulseResponse.class_variable # ---------------- # Class Properties # ---------------- # ----------------- # Device Properties # ----------------- TimeRange = device_property(dtype='str', ) # ---------- # Attributes # ---------- TimeConstant_1 = attribute( dtype='double', access=AttrWriteType.READ_WRITE, ) Amplification = attribute( dtype='double', access=AttrWriteType.READ_WRITE, ) TimeConstant_2 = attribute( dtype='double', access=AttrWriteType.READ_WRITE, ) Output = attribute( dtype=('double', ), max_dim_x=10000, ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(SecondOrderImpulseResponse.init_device) ENABLED START # self.set_state(DevState.ON) self.set_status("Second Order working!") # PROTECTED REGION END # // SecondOrderImpulseResponse.init_device def always_executed_hook(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // SecondOrderImpulseResponse.always_executed_hook def delete_device(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.delete_device) ENABLED START # pass # PROTECTED REGION END # // SecondOrderImpulseResponse.delete_device # ------------------ # Attributes methods # ------------------ def read_TimeConstant_1(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.TimeConstant_1_read) ENABLED START # return self.time_constant_1 # PROTECTED REGION END # // SecondOrderImpulseResponse.TimeConstant_1_read def write_TimeConstant_1(self, value): # PROTECTED REGION ID(SecondOrderImpulseResponse.TimeConstant_1_write) ENABLED START # self.time_constant_1 = value # PROTECTED REGION END # // SecondOrderImpulseResponse.TimeConstant_1_write def read_Amplification(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.Amplification_read) ENABLED START # return self.amplification # PROTECTED REGION END # // SecondOrderImpulseResponse.Amplification_read def write_Amplification(self, value): # PROTECTED REGION ID(SecondOrderImpulseResponse.Amplification_write) ENABLED START # self.amplification = value # PROTECTED REGION END # // SecondOrderImpulseResponse.Amplification_write def read_TimeConstant_2(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.TimeConstant_2_read) ENABLED START # return self.time_constant_2 # PROTECTED REGION END # // SecondOrderImpulseResponse.TimeConstant_2_read def write_TimeConstant_2(self, value): # PROTECTED REGION ID(SecondOrderImpulseResponse.TimeConstant_2_write) ENABLED START # self.time_constant_2 = value # PROTECTED REGION END # // SecondOrderImpulseResponse.TimeConstant_2_write def read_Output(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.Output_read) ENABLED START # return self.output # PROTECTED REGION END # // SecondOrderImpulseResponse.Output_read # -------- # Commands # -------- @command @DebugIt() def CalculateResponse(self): # PROTECTED REGION ID(SecondOrderImpulseResponse.CalculateResponse) ENABLED START # try: h_times = arange(0.0, float(self.TimeRange), 1) sys = signal.lti(self.amplification, [1, self.time_constant_1, self.time_constant_2]) impulse_response = sys.impulse(T=h_times)[1] self.output = impulse_response except Exception as e: self.set_state(DevState.FAULT) self.set_status("Exception caught in CalculateResponse:\n%s" % e)
class Keithley2100(Device): """ Server for Keithley DVMM 61/2 digits """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(Keithley2100.class_variable) ENABLED START # # PROTECTED REGION END # // Keithley2100.class_variable # ----------------- # Device Properties # ----------------- idProduct = device_property( dtype='uint', default_value=8448 ) idVendor = device_property( dtype='uint', default_value=1510 ) # ---------- # Attributes # ---------- Field = attribute( dtype='double', unit="T", format="%5.4f", ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(Keithley2100.init_device) ENABLED START # #instr=usbtmc.Instrument(idVendor,idProduct) self.instr=usbtmc.Instrument(0x05e6,0x2100) self.set_status("Connected to DVMM Keithley 2100") self.debug_stream("Connected to DVMM Keithley 2100") self.set_state(PyTango.DevState.ON) # PROTECTED REGION END # // Keithley2100.init_device def always_executed_hook(self): # PROTECTED REGION ID(Keithley2100.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // Keithley2100.always_executed_hook def delete_device(self): # PROTECTED REGION ID(Keithley2100.delete_device) ENABLED START # pass # PROTECTED REGION END # // Keithley2100.delete_device # ------------------ # Attributes methods # ------------------ def read_Field(self): # PROTECTED REGION ID(Keithley2100.Field_read) ENABLED START # return float(self.instr.ask("MEAS:VOLT:DC?"))*10.0 # PROTECTED REGION END # // Keithley2100.Field_read # -------- # Commands # -------- @command( dtype_in='str', dtype_out='str', ) @DebugIt() def sendCommand(self, argin): # PROTECTED REGION ID(Keithley2100.sendCommand) ENABLED START # return self.instr.ask(argin)
class SpectrometerCameraDS(Device): __metaclass__ = DeviceMeta exposuretime = attribute( label='ExposureTime', dtype=float, access=tango.AttrWriteType.READ_WRITE, unit="us", format="%8.1f", min_value=0.0, max_value=1e7, fget="get_exposuretime", fset="set_exposuretime", doc="Camera exposure time in us", memorized=True, ) gain = attribute( label='Gain', dtype=float, access=tango.AttrWriteType.READ_WRITE, unit="dB", format="%3.2f", min_value=0.0, max_value=1e2, fget="get_gain", fset="set_gain", doc="Camera gain in dB", memorized=True, ) wavelengthvector = attribute( label='WavelengthVector', dtype=[np.double], access=tango.AttrWriteType.READ, max_dim_x=16384, display_level=tango.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_wavelengthvector", doc="Wavelength vector", ) spectrum = attribute( label='Spectrum', dtype=[np.double], access=tango.AttrWriteType.READ, max_dim_x=16384, display_level=tango.DispLevel.OPERATOR, unit="a.u.", format="%5.2f", fget="get_spectrum", doc="Spectrum", ) width = attribute( label='Spectrum width FWHM', dtype=np.double, access=tango.AttrWriteType.READ, display_level=tango.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_width", doc= "FWHM for the peak in spectrum. Basic thresholding and peak detection is used.", ) peak = attribute( label='Spectrum peak', dtype=np.double, access=tango.AttrWriteType.READ, display_level=tango.DispLevel.OPERATOR, unit="m", format="%5.2e", fget="get_peak", doc= "Wavelength for the peak in spectrum. Basic thresholding and peak detection is used.", ) sat_lvl = attribute( label='Saturation level', dtype=np.double, access=tango.AttrWriteType.READ, display_level=tango.DispLevel.OPERATOR, unit="relative", format="%2.2e", fget="get_satlvl", doc= "Relative amount of pixels that are saturated. This should be zero.", ) camera_name = device_property( dtype=str, doc="Tango name of the camera device", default_value="gunlaser/cameras/spectrometer_camera") watchdog_timeout = device_property( dtype=float, doc="Timeout for the watchdog resetting the hardware in s", default_value="2.0") dispersion = device_property( dtype=float, doc="Dispersion of the spectrometer in nm/px. " "Positive if wavelength increases to the right", default_value="0.056") central_wavelength = device_property( dtype=float, doc="Wavelength of the central pixel of the ROI in nm", default_value="2.0") roi = device_property( dtype=[int], doc="Pixel coordinates for the ROI: [left, top, width, height]", default_value=[0, 0, 100, 100]) saturation_level = device_property( dtype=int, doc="Saturation pixel value, used for estimating overexposure", default_value=65536) def __init__(self, klass, name): self.wavelengthvector_data = np.array([]) self.max_value = 1.0 self.controller = None # type: SpectrometerCameraController self.state_dispatcher = None # type: StateDispatcher self.db = None Device.__init__(self, klass, name) def init_device(self): self.debug_stream("In init_device:") Device.init_device(self) self.db = tango.Database() self.set_state(tango.DevState.UNKNOWN) try: if self.state_dispatcher is not None: self.state_dispatcher.stop() except Exception as e: self.error_info("Error stopping state dispatcher: {0}".format(e)) try: self.controller = SpectrometerCameraController(self.camera_name) self.controller.add_state_notifier(self.change_state) except Exception as e: self.error_stream( "Error creating camera controller: {0}".format(e)) return self.setup_params() self.setup_spectrometer() self.state_dispatcher = StateDispatcher(self.controller) self.state_dispatcher.start() self.debug_stream("init_device finished") def setup_params(self): params = dict() params["imageoffsetx"] = self.roi[0] params["imageoffsety"] = self.roi[1] params["imagewidth"] = self.roi[2] params["imageheight"] = self.roi[3] params["triggermode"] = "Off" self.controller.setup_params = params def setup_spectrometer(self): self.info_stream("Entering setup_camera") self.wavelengthvector_data = (self.central_wavelength + np.arange( -self.roi[2] / 2, self.roi[2] / 2) * self.dispersion) * 1e-9 self.max_value = self.saturation_level wavelength_attr = tango.DeviceAttribute() wavelength_attr.name = "wavelengths" wavelength_attr.quality = tango.AttrQuality.ATTR_VALID wavelength_attr.value = self.wavelengthvector_data # wavelength_attr.data_format = tango.AttrDataFormat.SPECTRUM wavelength_attr.time = tango.time_val.TimeVal(time.time()) max_value_attr = tango.DeviceAttribute() max_value_attr.name = "max_value" max_value_attr.quality = tango.AttrQuality.ATTR_VALID max_value_attr.value = self.max_value # max_value_attr.data_format = tango.AttrDataFormat.SCALAR max_value_attr.time = tango.time_val.TimeVal(time.time()) with self.controller.state_lock: self.controller.camera_result["wavelengths"] = wavelength_attr self.controller.camera_result["max_value"] = max_value_attr def change_state(self, new_state, new_status=None): self.info_stream("Change state: {0}, status {1}".format( new_state, new_status)) # Map new_state string to tango state if new_state in ["running"]: tango_state = tango.DevState.RUNNING elif new_state in ["on"]: tango_state = tango.DevState.ON elif new_state in ["device_connect", "setup_attributes"]: tango_state = tango.DevState.INIT elif new_state in ["fault"]: tango_state = tango.DevState.FAULT else: tango_state = tango.DevState.UNKNOWN # Set memorized attributes when entering init from unknown state: if self.get_state( ) is tango.DevState.INIT and new_state is not tango.DevState.UNKNOWN: self.debug_stream("Set memorized attributes") try: data = self.db.get_device_attribute_property( self.get_name(), "gain") self.debug_stream( "Database returned data for \"gain\": {0}".format( data["gain"])) except TypeError as e: self.warn_stream("Gain not found in database. {0}".format(e)) try: new_value = float(data["gain"]["__value"][0]) self.debug_stream("{0}".format(new_value)) self.controller.write_attribute("gain", "camera", new_value) except (KeyError, TypeError, IndexError, ValueError): pass try: data = self.db.get_device_attribute_property( self.get_name(), "exposuretime") self.debug_stream( "Database returned data for \"exposuretime\": {0}".format( data["exposuretime"])) except TypeError as e: self.warn_stream( "Exposuretime not found in database. {0}".format(e)) try: new_value = float(data["exposuretime"]["__value"][0]) self.controller.write_attribute("exposuretime", "camera", new_value) except (KeyError, TypeError, IndexError, ValueError): pass if tango_state != self.get_state(): self.debug_stream("Change state from {0} to {1}".format( self.get_state(), new_state)) self.set_state(tango_state) if new_status is not None: self.debug_stream("Setting status {0}".format(new_status)) self.set_status(new_status) def get_spectrum(self): attr = self.controller.get_attribute("spectrum") try: self.debug_stream("get_spectrum: {0}".format(attr.value.shape)) except Exception as e: self.warn_stream("Could not format attribute: {0}".format(e)) return attr.value, attr.time.totime(), attr.quality def get_wavelengthvector(self): self.debug_stream("get_wavelengthvector: size {0}".format( self.wavelengthvector_data.shape)) attr = self.controller.get_attribute("wavelengths") return attr.value, attr.time.totime(), attr.quality def get_exposuretime(self): attr = self.controller.get_attribute("exposuretime") try: self.debug_stream("get_exposuretime: {0}".format(attr)) except Exception as e: self.warn_stream("Could not format attribute: {0}".format(e)) return attr.value, attr.time.totime(), attr.quality def set_exposuretime(self, new_exposuretime): self.debug_stream( "In set_exposuretime: New value {0}".format(new_exposuretime)) # self.controller.write_attribute("exposuretime", "camera", new_exposuretime) try: old_exposure = self.controller.get_attribute("exposuretime").value except AttributeError: old_exposure = 0.0 tol = np.abs(new_exposuretime - old_exposure) * 0.1 self.controller.check_attribute("exposuretime", "camera", new_exposuretime, tolerance=tol, write=True) def get_gain(self): attr = self.controller.get_attribute("gain") return attr.value, attr.time.totime(), attr.quality def set_gain(self, new_gain): self.debug_stream("In set_gain: New value {0}".format(new_gain)) self.controller.write_attribute("gain", "camera", new_gain) self.controller.read_attribute("gain", "camera") def get_width(self): attr = self.controller.get_attribute("width") return attr.value, attr.time.totime(), attr.quality def get_peak(self): attr = self.controller.get_attribute("peak") return attr.value, attr.time.totime(), attr.quality def get_satlvl(self): attr = self.controller.get_attribute("satlvl") return attr.value, attr.time.totime(), attr.quality @command(doc_in="Start spectrometer.") def start(self): """Start spectrometer camera""" self.info_stream("Starting spectrometer") self.state_dispatcher.send_command("start") @command(doc_in="Stop spectrometer.") def stop(self): """Stop spectrometer camera""" self.info_stream("Stopping spectrometer") self.state_dispatcher.send_command("stop")
class TangoTest(Device): """ A device to test generic clients. It offers a \``echo\`` like command for each TANGO data type (i.e. each command returns an exact copy of <argin>). """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(TangoTest.class_variable) ENABLED START # # PROTECTED REGION END # // TangoTest.class_variable # ---------------- # Class Properties # ---------------- # ----------------- # Device Properties # ----------------- Mthreaded_impl = device_property(dtype='int16', ) Sleep_period = device_property(dtype='int', ) UShort_image_ro_size = device_property(dtype='int', default_value=251) # ---------- # Attributes # ---------- ampli = attribute( dtype='double', access=AttrWriteType.WRITE, ) boolean_scalar = attribute( dtype='bool', access=AttrWriteType.READ_WRITE, label="boolean_scalar", doc="A boolean scalar attribute", ) double_scalar = attribute( dtype='double', access=AttrWriteType.READ_WRITE, ) double_scalar_rww = attribute( dtype='double', access=AttrWriteType.READ_WITH_WRITE, ) double_scalar_w = attribute( dtype='double', access=AttrWriteType.WRITE, ) float_scalar = attribute( dtype='float', access=AttrWriteType.READ_WRITE, label="float_scalar", doc="A float attribute", ) long64_scalar = attribute( dtype='int64', access=AttrWriteType.READ_WRITE, ) long_scalar = attribute( dtype='int', access=AttrWriteType.READ_WRITE, ) long_scalar_rww = attribute( dtype='int', access=AttrWriteType.READ_WITH_WRITE, ) long_scalar_w = attribute( dtype='int', access=AttrWriteType.WRITE, ) no_value = attribute(dtype='int', ) short_scalar = attribute( dtype='int16', access=AttrWriteType.READ_WRITE, ) short_scalar_ro = attribute(dtype='int16', ) short_scalar_rww = attribute( dtype='int16', access=AttrWriteType.READ_WITH_WRITE, ) short_scalar_w = attribute( dtype='int16', access=AttrWriteType.WRITE, ) string_scalar = attribute( dtype='str', access=AttrWriteType.READ_WRITE, ) throw_exception = attribute(dtype='int', ) uchar_scalar = attribute( dtype='char', access=AttrWriteType.READ_WRITE, label="uchar_scalar", ) ulong64_scalar = attribute( dtype='uint64', access=AttrWriteType.READ_WRITE, ) ushort_scalar = attribute( dtype='uint16', access=AttrWriteType.READ_WRITE, label="ushort_scalar", ) ulong_scalar = attribute( dtype='uint', access=AttrWriteType.READ_WRITE, ) boolean_spectrum = attribute( dtype=('bool', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, label="boolean_spectrum", ) boolean_spectrum_ro = attribute( dtype=('bool', ), max_dim_x=4096, ) double_spectrum = attribute( dtype=('double', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, ) double_spectrum_ro = attribute( dtype=('double', ), max_dim_x=4096, ) float_spectrum = attribute( dtype=('float', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, label="float_spectrum", doc="A float spectrum attribute", ) float_spectrum_ro = attribute( dtype=('float', ), max_dim_x=4096, ) long64_spectrum_ro = attribute( dtype=('int64', ), max_dim_x=4096, ) long_spectrum = attribute( dtype=('int', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, ) long_spectrum_ro = attribute( dtype=('int', ), max_dim_x=4096, ) short_spectrum = attribute( dtype=('int16', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, ) short_spectrum_ro = attribute( dtype=('int16', ), max_dim_x=4096, ) string_spectrum = attribute( dtype=('str', ), access=AttrWriteType.READ_WRITE, max_dim_x=256, ) string_spectrum_ro = attribute( dtype=('str', ), max_dim_x=256, ) uchar_spectrum = attribute( dtype=('char', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, label="uchar_spectrum", max_value=255, min_value=0, doc="An unsigned char spectrum attribute", ) uchar_spectrum_ro = attribute( dtype=('char', ), max_dim_x=4096, ) ulong64_spectrum_ro = attribute( dtype=('uint64', ), max_dim_x=4096, ) ulong_spectrum_ro = attribute( dtype=('uint', ), max_dim_x=4096, ) ushort_spectrum = attribute( dtype=('uint16', ), access=AttrWriteType.READ_WRITE, max_dim_x=4096, label="ushort_spectrum", doc="An unsigned short spectrum attribute", ) ushort_spectrum_ro = attribute( dtype=('uint16', ), max_dim_x=4096, ) wave = attribute( dtype=('double', ), max_dim_x=4096, ) boolean_image = attribute( dtype=(('bool', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) boolean_image_ro = attribute( dtype=(('bool', ), ), max_dim_x=251, max_dim_y=251, label="boolean_image", ) double_image = attribute( dtype=(('double', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) double_image_ro = attribute( dtype=(('double', ), ), max_dim_x=251, max_dim_y=251, ) float_image = attribute( dtype=(('float', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) float_image_ro = attribute( dtype=(('float', ), ), max_dim_x=251, max_dim_y=251, label="float_image", max_value=255, min_value=0, doc="A float image attribute", ) long64_image_ro = attribute( dtype=(('int64', ), ), max_dim_x=251, max_dim_y=251, ) long_image = attribute( dtype=(('int', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) long_image_ro = attribute( dtype=(('int', ), ), max_dim_x=251, max_dim_y=251, ) short_image = attribute( dtype=(('int16', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) short_image_ro = attribute( dtype=(('int16', ), ), max_dim_x=251, max_dim_y=251, ) string_image = attribute( dtype=(('str', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=256, max_dim_y=256, ) string_image_ro = attribute( dtype=(('str', ), ), max_dim_x=256, max_dim_y=256, ) uchar_image = attribute( dtype=(('char', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) uchar_image_ro = attribute( dtype=(('char', ), ), max_dim_x=251, max_dim_y=251, label="uchar_image", max_value=255, min_value=0, doc="An unsigned char image attribute", ) ulong64_image_ro = attribute( dtype=(('uint64', ), ), max_dim_x=251, max_dim_y=251, ) ulong_image_ro = attribute( dtype=(('uint', ), ), max_dim_x=251, max_dim_y=251, ) ushort_image = attribute( dtype=(('uint16', ), ), access=AttrWriteType.READ_WRITE, max_dim_x=251, max_dim_y=251, ) ushort_image_ro = attribute( dtype=(('uint16', ), ), max_dim_x=8192, max_dim_y=8192, label="ushort_image_ro", max_value=255, min_value=0, doc="An unsigned short image attribute", ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(TangoTest.init_device) ENABLED START # # PROTECTED REGION END # // TangoTest.init_device def always_executed_hook(self): # PROTECTED REGION ID(TangoTest.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // TangoTest.always_executed_hook def delete_device(self): # PROTECTED REGION ID(TangoTest.delete_device) ENABLED START # pass # PROTECTED REGION END # // TangoTest.delete_device # ------------------ # Attributes methods # ------------------ def write_ampli(self, value): # PROTECTED REGION ID(TangoTest.ampli_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ampli_write def read_boolean_scalar(self): # PROTECTED REGION ID(TangoTest.boolean_scalar_read) ENABLED START # return False # PROTECTED REGION END # // TangoTest.boolean_scalar_read def write_boolean_scalar(self, value): # PROTECTED REGION ID(TangoTest.boolean_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.boolean_scalar_write def read_double_scalar(self): # PROTECTED REGION ID(TangoTest.double_scalar_read) ENABLED START # return 0.0 # PROTECTED REGION END # // TangoTest.double_scalar_read def write_double_scalar(self, value): # PROTECTED REGION ID(TangoTest.double_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.double_scalar_write def read_double_scalar_rww(self): # PROTECTED REGION ID(TangoTest.double_scalar_rww_read) ENABLED START # return 0.0 # PROTECTED REGION END # // TangoTest.double_scalar_rww_read def write_double_scalar_rww(self, value): # PROTECTED REGION ID(TangoTest.double_scalar_rww_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.double_scalar_rww_write def write_double_scalar_w(self, value): # PROTECTED REGION ID(TangoTest.double_scalar_w_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.double_scalar_w_write def read_float_scalar(self): # PROTECTED REGION ID(TangoTest.float_scalar_read) ENABLED START # return 0.0 # PROTECTED REGION END # // TangoTest.float_scalar_read def write_float_scalar(self, value): # PROTECTED REGION ID(TangoTest.float_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.float_scalar_write def read_long64_scalar(self): # PROTECTED REGION ID(TangoTest.long64_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.long64_scalar_read def write_long64_scalar(self, value): # PROTECTED REGION ID(TangoTest.long64_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long64_scalar_write def read_long_scalar(self): # PROTECTED REGION ID(TangoTest.long_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.long_scalar_read def write_long_scalar(self, value): # PROTECTED REGION ID(TangoTest.long_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long_scalar_write def read_long_scalar_rww(self): # PROTECTED REGION ID(TangoTest.long_scalar_rww_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.long_scalar_rww_read def write_long_scalar_rww(self, value): # PROTECTED REGION ID(TangoTest.long_scalar_rww_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long_scalar_rww_write def write_long_scalar_w(self, value): # PROTECTED REGION ID(TangoTest.long_scalar_w_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long_scalar_w_write def read_no_value(self): # PROTECTED REGION ID(TangoTest.no_value_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.no_value_read def read_short_scalar(self): # PROTECTED REGION ID(TangoTest.short_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.short_scalar_read def write_short_scalar(self, value): # PROTECTED REGION ID(TangoTest.short_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.short_scalar_write def read_short_scalar_ro(self): # PROTECTED REGION ID(TangoTest.short_scalar_ro_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.short_scalar_ro_read def read_short_scalar_rww(self): # PROTECTED REGION ID(TangoTest.short_scalar_rww_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.short_scalar_rww_read def write_short_scalar_rww(self, value): # PROTECTED REGION ID(TangoTest.short_scalar_rww_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.short_scalar_rww_write def write_short_scalar_w(self, value): # PROTECTED REGION ID(TangoTest.short_scalar_w_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.short_scalar_w_write def read_string_scalar(self): # PROTECTED REGION ID(TangoTest.string_scalar_read) ENABLED START # return '' # PROTECTED REGION END # // TangoTest.string_scalar_read def write_string_scalar(self, value): # PROTECTED REGION ID(TangoTest.string_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.string_scalar_write def read_throw_exception(self): # PROTECTED REGION ID(TangoTest.throw_exception_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.throw_exception_read def read_uchar_scalar(self): # PROTECTED REGION ID(TangoTest.uchar_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.uchar_scalar_read def write_uchar_scalar(self, value): # PROTECTED REGION ID(TangoTest.uchar_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.uchar_scalar_write def read_ulong64_scalar(self): # PROTECTED REGION ID(TangoTest.ulong64_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.ulong64_scalar_read def write_ulong64_scalar(self, value): # PROTECTED REGION ID(TangoTest.ulong64_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ulong64_scalar_write def read_ushort_scalar(self): # PROTECTED REGION ID(TangoTest.ushort_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.ushort_scalar_read def write_ushort_scalar(self, value): # PROTECTED REGION ID(TangoTest.ushort_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ushort_scalar_write def read_ulong_scalar(self): # PROTECTED REGION ID(TangoTest.ulong_scalar_read) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.ulong_scalar_read def write_ulong_scalar(self, value): # PROTECTED REGION ID(TangoTest.ulong_scalar_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ulong_scalar_write def read_boolean_spectrum(self): # PROTECTED REGION ID(TangoTest.boolean_spectrum_read) ENABLED START # return [False] # PROTECTED REGION END # // TangoTest.boolean_spectrum_read def write_boolean_spectrum(self, value): # PROTECTED REGION ID(TangoTest.boolean_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.boolean_spectrum_write def read_boolean_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.boolean_spectrum_ro_read) ENABLED START # return [False] # PROTECTED REGION END # // TangoTest.boolean_spectrum_ro_read def read_double_spectrum(self): # PROTECTED REGION ID(TangoTest.double_spectrum_read) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.double_spectrum_read def write_double_spectrum(self, value): # PROTECTED REGION ID(TangoTest.double_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.double_spectrum_write def read_double_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.double_spectrum_ro_read) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.double_spectrum_ro_read def read_float_spectrum(self): # PROTECTED REGION ID(TangoTest.float_spectrum_read) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.float_spectrum_read def write_float_spectrum(self, value): # PROTECTED REGION ID(TangoTest.float_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.float_spectrum_write def read_float_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.float_spectrum_ro_read) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.float_spectrum_ro_read def read_long64_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.long64_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.long64_spectrum_ro_read def read_long_spectrum(self): # PROTECTED REGION ID(TangoTest.long_spectrum_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.long_spectrum_read def write_long_spectrum(self, value): # PROTECTED REGION ID(TangoTest.long_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long_spectrum_write def read_long_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.long_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.long_spectrum_ro_read def read_short_spectrum(self): # PROTECTED REGION ID(TangoTest.short_spectrum_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.short_spectrum_read def write_short_spectrum(self, value): # PROTECTED REGION ID(TangoTest.short_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.short_spectrum_write def read_short_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.short_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.short_spectrum_ro_read def read_string_spectrum(self): # PROTECTED REGION ID(TangoTest.string_spectrum_read) ENABLED START # return [''] # PROTECTED REGION END # // TangoTest.string_spectrum_read def write_string_spectrum(self, value): # PROTECTED REGION ID(TangoTest.string_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.string_spectrum_write def read_string_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.string_spectrum_ro_read) ENABLED START # return [''] # PROTECTED REGION END # // TangoTest.string_spectrum_ro_read def read_uchar_spectrum(self): # PROTECTED REGION ID(TangoTest.uchar_spectrum_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.uchar_spectrum_read def write_uchar_spectrum(self, value): # PROTECTED REGION ID(TangoTest.uchar_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.uchar_spectrum_write def read_uchar_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.uchar_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.uchar_spectrum_ro_read def read_ulong64_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.ulong64_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.ulong64_spectrum_ro_read def read_ulong_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.ulong_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.ulong_spectrum_ro_read def read_ushort_spectrum(self): # PROTECTED REGION ID(TangoTest.ushort_spectrum_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.ushort_spectrum_read def write_ushort_spectrum(self, value): # PROTECTED REGION ID(TangoTest.ushort_spectrum_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ushort_spectrum_write def read_ushort_spectrum_ro(self): # PROTECTED REGION ID(TangoTest.ushort_spectrum_ro_read) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.ushort_spectrum_ro_read def read_wave(self): # PROTECTED REGION ID(TangoTest.wave_read) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.wave_read def read_boolean_image(self): # PROTECTED REGION ID(TangoTest.boolean_image_read) ENABLED START # return [[False]] # PROTECTED REGION END # // TangoTest.boolean_image_read def write_boolean_image(self, value): # PROTECTED REGION ID(TangoTest.boolean_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.boolean_image_write def read_boolean_image_ro(self): # PROTECTED REGION ID(TangoTest.boolean_image_ro_read) ENABLED START # return [[False]] # PROTECTED REGION END # // TangoTest.boolean_image_ro_read def read_double_image(self): # PROTECTED REGION ID(TangoTest.double_image_read) ENABLED START # return [[0.0]] # PROTECTED REGION END # // TangoTest.double_image_read def write_double_image(self, value): # PROTECTED REGION ID(TangoTest.double_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.double_image_write def read_double_image_ro(self): # PROTECTED REGION ID(TangoTest.double_image_ro_read) ENABLED START # return [[0.0]] # PROTECTED REGION END # // TangoTest.double_image_ro_read def read_float_image(self): # PROTECTED REGION ID(TangoTest.float_image_read) ENABLED START # return [[0.0]] # PROTECTED REGION END # // TangoTest.float_image_read def write_float_image(self, value): # PROTECTED REGION ID(TangoTest.float_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.float_image_write def read_float_image_ro(self): # PROTECTED REGION ID(TangoTest.float_image_ro_read) ENABLED START # return [[0.0]] # PROTECTED REGION END # // TangoTest.float_image_ro_read def read_long64_image_ro(self): # PROTECTED REGION ID(TangoTest.long64_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.long64_image_ro_read def read_long_image(self): # PROTECTED REGION ID(TangoTest.long_image_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.long_image_read def write_long_image(self, value): # PROTECTED REGION ID(TangoTest.long_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.long_image_write def read_long_image_ro(self): # PROTECTED REGION ID(TangoTest.long_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.long_image_ro_read def read_short_image(self): # PROTECTED REGION ID(TangoTest.short_image_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.short_image_read def write_short_image(self, value): # PROTECTED REGION ID(TangoTest.short_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.short_image_write def read_short_image_ro(self): # PROTECTED REGION ID(TangoTest.short_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.short_image_ro_read def read_string_image(self): # PROTECTED REGION ID(TangoTest.string_image_read) ENABLED START # return [['']] # PROTECTED REGION END # // TangoTest.string_image_read def write_string_image(self, value): # PROTECTED REGION ID(TangoTest.string_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.string_image_write def read_string_image_ro(self): # PROTECTED REGION ID(TangoTest.string_image_ro_read) ENABLED START # return [['']] # PROTECTED REGION END # // TangoTest.string_image_ro_read def read_uchar_image(self): # PROTECTED REGION ID(TangoTest.uchar_image_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.uchar_image_read def write_uchar_image(self, value): # PROTECTED REGION ID(TangoTest.uchar_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.uchar_image_write def read_uchar_image_ro(self): # PROTECTED REGION ID(TangoTest.uchar_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.uchar_image_ro_read def read_ulong64_image_ro(self): # PROTECTED REGION ID(TangoTest.ulong64_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.ulong64_image_ro_read def read_ulong_image_ro(self): # PROTECTED REGION ID(TangoTest.ulong_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.ulong_image_ro_read def read_ushort_image(self): # PROTECTED REGION ID(TangoTest.ushort_image_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.ushort_image_read def write_ushort_image(self, value): # PROTECTED REGION ID(TangoTest.ushort_image_write) ENABLED START # pass # PROTECTED REGION END # // TangoTest.ushort_image_write def read_ushort_image_ro(self): # PROTECTED REGION ID(TangoTest.ushort_image_ro_read) ENABLED START # return [[0]] # PROTECTED REGION END # // TangoTest.ushort_image_ro_read # -------- # Commands # -------- @command @DebugIt() def CrashFromDevelopperThread(self): # PROTECTED REGION ID(TangoTest.CrashFromDevelopperThread) ENABLED START # pass # PROTECTED REGION END # // TangoTest.CrashFromDevelopperThread @command @DebugIt() def CrashFromOmniThread(self): # PROTECTED REGION ID(TangoTest.CrashFromOmniThread) ENABLED START # pass # PROTECTED REGION END # // TangoTest.CrashFromOmniThread @command(dtype_in='bool', doc_in="Any boolean value", dtype_out='bool', doc_out="Echo of the argin value") @DebugIt() def DevBoolean(self, argin): # PROTECTED REGION ID(TangoTest.DevBoolean) ENABLED START # return False # PROTECTED REGION END # // TangoTest.DevBoolean @command(dtype_in='double', doc_in="Any DevDouble value", dtype_out='double', doc_out="Echo of the argin value") @DebugIt() def DevDouble(self, argin): # PROTECTED REGION ID(TangoTest.DevDouble) ENABLED START # return 0.0 # PROTECTED REGION END # // TangoTest.DevDouble @command(dtype_in='float', doc_in="Any DevFloat value", dtype_out='float', doc_out="Echo of the argin value") @DebugIt() def DevFloat(self, argin): # PROTECTED REGION ID(TangoTest.DevFloat) ENABLED START # return 0.0 # PROTECTED REGION END # // TangoTest.DevFloat @command(dtype_in='int', doc_in="Any DevLong value", dtype_out='int', doc_out="Echo of the argin value") @DebugIt() def DevLong(self, argin): # PROTECTED REGION ID(TangoTest.DevLong) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevLong @command(dtype_in='int64', doc_in="Any DevLong64 value", dtype_out='int64', doc_out="Echo of the argin value") @DebugIt() def DevLong64(self, argin): # PROTECTED REGION ID(TangoTest.DevLong64) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevLong64 @command(dtype_in='int16', doc_in="Any DevShort value", dtype_out='int16', doc_out="Echo of the argin value") @DebugIt() def DevShort(self, argin): # PROTECTED REGION ID(TangoTest.DevShort) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevShort @command(dtype_in='str', doc_in="-", dtype_out='str', doc_out="-") @DebugIt() def DevString(self, argin): # PROTECTED REGION ID(TangoTest.DevString) ENABLED START # return "" # PROTECTED REGION END # // TangoTest.DevString @command(dtype_in='uint', doc_in="Any DevULong", dtype_out='uint', doc_out="Echo of the argin value") @DebugIt() def DevULong(self, argin): # PROTECTED REGION ID(TangoTest.DevULong) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevULong @command(dtype_in='uint64', doc_in="Any DevULong64 value", dtype_out='uint64', doc_out="Echo of the argin value") @DebugIt() def DevULong64(self, argin): # PROTECTED REGION ID(TangoTest.DevULong64) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevULong64 @command(dtype_in='uint16', doc_in="Any DevUShort value", dtype_out='uint16', doc_out="Echo of the argin value") @DebugIt() def DevUShort(self, argin): # PROTECTED REGION ID(TangoTest.DevUShort) ENABLED START # return 0 # PROTECTED REGION END # // TangoTest.DevUShort @command(dtype_in=('char', ), doc_in="-", dtype_out=('char', ), doc_out="-") @DebugIt() def DevVarCharArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarCharArray) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarCharArray @command(dtype_in=('double', ), doc_in="-", dtype_out=('double', ), doc_out="-") @DebugIt() def DevVarDoubleArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarDoubleArray) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.DevVarDoubleArray @command(dtype_in='DevVarDoubleStringArray', doc_in="-", dtype_out='DevVarDoubleStringArray', doc_out="-") @DebugIt() def DevVarDoubleStringArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarDoubleStringArray) ENABLED START # return [[0.0], [""]] # PROTECTED REGION END # // TangoTest.DevVarDoubleStringArray @command(dtype_in=('float', ), doc_in="-", dtype_out=('float', ), doc_out="-") @DebugIt() def DevVarFloatArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarFloatArray) ENABLED START # return [0.0] # PROTECTED REGION END # // TangoTest.DevVarFloatArray @command( dtype_in=('int64', ), dtype_out=('int64', ), ) @DebugIt() def DevVarLong64Array(self, argin): # PROTECTED REGION ID(TangoTest.DevVarLong64Array) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarLong64Array @command(dtype_in=('int', ), doc_in="-", dtype_out=('int', ), doc_out="-") @DebugIt() def DevVarLongArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarLongArray) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarLongArray @command(dtype_in='DevVarLongStringArray', doc_in="-", dtype_out='DevVarLongStringArray', doc_out="-") @DebugIt() def DevVarLongStringArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarLongStringArray) ENABLED START # return [[0], [""]] # PROTECTED REGION END # // TangoTest.DevVarLongStringArray @command(dtype_in=('int16', ), doc_in="-", dtype_out=('int16', ), doc_out="-") @DebugIt() def DevVarShortArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarShortArray) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarShortArray @command(dtype_in=('str', ), doc_in="-", dtype_out=('str', ), doc_out="-") @DebugIt() def DevVarStringArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarStringArray) ENABLED START # return [""] # PROTECTED REGION END # // TangoTest.DevVarStringArray @command( dtype_in=('uint64'), dtype_out=('uint64'), ) @DebugIt() def DevVarULong64Array(self, argin): # PROTECTED REGION ID(TangoTest.DevVarULong64Array) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarULong64Array @command(dtype_in=('uint', ), doc_in="-", dtype_out=('uint', ), doc_out="-") @DebugIt() def DevVarULongArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarULongArray) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarULongArray @command(dtype_in=('uint16', ), doc_in="-", dtype_out=('uint16', ), doc_out="-") @DebugIt() def DevVarUShortArray(self, argin): # PROTECTED REGION ID(TangoTest.DevVarUShortArray) ENABLED START # return [0] # PROTECTED REGION END # // TangoTest.DevVarUShortArray @command @DebugIt() def DevVoid(self): # PROTECTED REGION ID(TangoTest.DevVoid) ENABLED START # pass # PROTECTED REGION END # // TangoTest.DevVoid @command @DebugIt() def DumpExecutionState(self): # PROTECTED REGION ID(TangoTest.DumpExecutionState) ENABLED START # pass # PROTECTED REGION END # // TangoTest.DumpExecutionState @command @DebugIt() def SwitchStates(self): # PROTECTED REGION ID(TangoTest.SwitchStates) ENABLED START # pass
class SKASubarray(SKAObsDevice): """ SubArray handling device """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(SKASubarray.class_variable) ENABLED START # def _is_command_allowed(self, command_name): """Determine whether the command specified by the command_name parameter should be allowed to execute or not. Parameters ---------- command_name: str The name of the command which is to be executed. Returns ------- True or False: boolean A True is returned when the device is in the allowed states and modes to execute the command. Returns False if the command name is not in the list of commands with rules specified for them. Raises ------ PyTango.DevFailed: If the device is not in the allowed states and/modes to execute the command. """ dp = DeviceProxy(self.get_name()) obstate_labels = list(dp.attribute_query('obsState').enum_labels) obs_idle = obstate_labels.index('IDLE') obs_ready = obstate_labels.index('READY') admin_labels = list(dp.attribute_query('adminMode').enum_labels) admin_online = admin_labels.index('ON-LINE') admin_maintenance = admin_labels.index('MAINTENANCE') admin_offline = admin_labels.index('OFF-LINE') admin_not_fitted = admin_labels.index('NOT-FITTED') current_admin_mode = self.read_adminMode() if command_name in ["ReleaseResources", "AssignResources"]: if current_admin_mode in [admin_offline, admin_not_fitted]: Except.throw_exception("Command failed!", "Subarray adminMode is" " 'OFF-LINE' or 'NOT-FITTED'.", command_name, ErrSeverity.ERR) if self.read_obsState() == obs_idle: if current_admin_mode in [admin_online, admin_maintenance]: return True else: Except.throw_exception("Command failed!", "Subarray adminMode not" "'ON-LINE' or not in 'MAINTENANCE'.", command_name, ErrSeverity.ERR) else: Except.throw_exception("Command failed!", "Subarray obsState not 'IDLE'.", command_name, ErrSeverity.ERR) elif command_name in ['ConfigureCapability', 'DeconfigureCapability', 'DeconfigureAllCapabilities']: if self.get_state() == DevState.ON and self.read_adminMode() == admin_online: if self.read_obsState() in [obs_idle, obs_ready]: return True else: Except.throw_exception( "Command failed!", "Subarray obsState not 'IDLE' or 'READY'.", command_name, ErrSeverity.ERR) else: Except.throw_exception( "Command failed!", "Subarray State not 'ON' and/or adminMode not" " 'ON-LINE'.", command_name, ErrSeverity.ERR) return False def _validate_capability_types(self, command_name, capability_types): """Check the validity of the input parameter passed on to the command specified by the command_name parameter. Parameters ---------- command_name: str The name of the command which is to be executed. capability_types: list A list strings representing capability types. Raises ------ PyTango.DevFailed: If any of the capabilities requested are not valid. """ invalid_capabilities = list( set(capability_types) - set(self._configured_capabilities)) if invalid_capabilities: Except.throw_exception( "Command failed!", "Invalid capability types requested {}".format( invalid_capabilities), command_name, ErrSeverity.ERR) def _validate_input_sizes(self, command_name, argin): """Check the validity of the input parameters passed on to the command specified by the command_name parameter. Parameters ---------- command_name: str The name of the command which is to be executed. argin: PyTango.DevVarLongStringArray A tuple of two lists representing [number of instances][capability types] Raises ------ PyTango.DevFailed: If the two lists are not equal in length. """ capabilities_instances, capability_types = argin if len(capabilities_instances) != len(capability_types): Except.throw_exception("Command failed!", "Argin value lists size mismatch.", command_name, ErrSeverity.ERR) def is_AssignResources_allowed(self): return self._is_command_allowed("AssignResources") def is_ReleaseResources_allowed(self): return self._is_command_allowed("ReleaseResources") def is_ReleaseAllResources_allowed(self): return self._is_command_allowed("ReleaseResources") def is_ConfigureCapability_allowed(self): return self._is_command_allowed('ConfigureCapability') def is_DeconfigureCapability_allowed(self): return self._is_command_allowed('DeconfigureCapability') def is_DeconfigureAllCapabilities_allowed(self): return self._is_command_allowed('DeconfigureAllCapabilities') # PROTECTED REGION END # // SKASubarray.class_variable # ----------------- # Device Properties # ----------------- CapabilityTypes = device_property( dtype=('str',), ) SubID = device_property( dtype='str', ) # ---------- # Attributes # ---------- activationTime = attribute( dtype='double', unit="s", standard_unit="s", display_unit="s", doc="Time of activation in seconds since Unix epoch.", ) assignedResources = attribute( dtype=('str',), max_dim_x=100, doc="The list of resources assigned to the subarray.", ) configuredCapabilities = attribute( dtype=('str',), max_dim_x=10, doc="A list of capability types with no. of instances in use on this subarray; e.g.\nCorrelators:512, PssBeams:4, PstBeams:4, VlbiBeams:0.", ) # --------------- # General methods # --------------- def init_device(self): SKAObsDevice.init_device(self) # PROTECTED REGION ID(SKASubarray.init_device) ENABLED START # # Initialize attribute values. self._activation_time = 0.0 self._assigned_resources = [""] # self._configured_capabilities is gonna be kept as a dictionary internally. The # keys and value will represent the capability type name and the number of # instances, respectively. try: self._configured_capabilities = dict.fromkeys(self.CapabilityTypes, 0) except TypeError: # Might need to have the device property be mandatory in the database. self._configured_capabilities = {} # When Subarray in not in use it reports: self.set_state(DevState.DISABLE) # PROTECTED REGION END # // SKASubarray.init_device def always_executed_hook(self): # PROTECTED REGION ID(SKASubarray.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.always_executed_hook def delete_device(self): # PROTECTED REGION ID(SKASubarray.delete_device) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.delete_device # ------------------ # Attributes methods # ------------------ def read_activationTime(self): # PROTECTED REGION ID(SKASubarray.activationTime_read) ENABLED START # return self._activation_time # PROTECTED REGION END # // SKASubarray.activationTime_read def read_assignedResources(self): # PROTECTED REGION ID(SKASubarray.assignedResources_read) ENABLED START # return self._assigned_resources # PROTECTED REGION END # // SKASubarray.assignedResources_read def read_configuredCapabilities(self): # PROTECTED REGION ID(SKASubarray.configuredCapabilities_read) ENABLED START # configured_capabilities = [] for capability_type, capability_instances in ( self._configured_capabilities.items()): configured_capabilities.append( "{}:{}".format(capability_type, capability_instances)) return sorted(configured_capabilities) # PROTECTED REGION END # // SKASubarray.configuredCapabilities_read # -------- # Commands # -------- @command( ) @DebugIt() def Abort(self): # PROTECTED REGION ID(SKASubarray.Abort) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.Abort @command( dtype_in='DevVarLongStringArray', doc_in="[Number of instances to add][Capability types]", ) @DebugIt() def ConfigureCapability(self, argin): # PROTECTED REGION ID(SKASubarray.ConfigureCapability) ENABLED START # command_name = 'ConfigureCapability' dp = DeviceProxy(self.get_name()) obstate_labels = list(dp.attribute_query('obsState').enum_labels) obs_configuring = obstate_labels.index('CONFIGURING') capabilities_instances, capability_types = argin self._validate_capability_types(command_name, capability_types) self._validate_input_sizes(command_name, argin) # Set obsState to 'CONFIGURING'. self._obs_state = obs_configuring # Perform the configuration. for capability_instances, capability_type in izip( capabilities_instances, capability_types): self._configured_capabilities[capability_type] += capability_instances # Change the obsState to 'READY'. obs_ready = obstate_labels.index('READY') self._obs_state = obs_ready # PROTECTED REGION END # // SKASubarray.ConfigureCapability @command( dtype_in='str', doc_in="Capability type", ) @DebugIt() def DeconfigureAllCapabilities(self, argin): # PROTECTED REGION ID(SKASubarray.DeconfigureAllCapabilities) ENABLED START #i self._validate_capability_types('DeconfigureAllCapabilities', [argin]) self._configured_capabilities[argin] = 0 # PROTECTED REGION END # // SKASubarray.DeconfigureAllCapabilities @command( dtype_in='DevVarLongStringArray', doc_in="[Number of instances to remove][Capability types]", ) @DebugIt() def DeconfigureCapability(self, argin): # PROTECTED REGION ID(SKASubarray.DeconfigureCapability) ENABLED START # command_name = 'DeconfigureCapability' capabilities_instances, capability_types = argin self._validate_capability_types(command_name, capability_types) self._validate_input_sizes(command_name, argin) # Perform the deconfiguration for capability_instances, capability_type in izip( capabilities_instances, capability_types): if self._configured_capabilities[capability_type] < int(capability_instances): self._configured_capabilities[capability_type] = 0 else: self._configured_capabilities[capability_type] -= ( int(capability_instances)) # PROTECTED REGION END # // SKASubarray.DeconfigureCapability @command( dtype_in=('str',), doc_in="List of Resources to add to subarray.", dtype_out=('str',), doc_out="A list of Resources added to the subarray.", ) @DebugIt() def AssignResources(self, argin): # PROTECTED REGION ID(SKASubarray.AssignResources) ENABLED START # argout = [] resources = self._assigned_resources[:] for resource in argin: if resource not in resources: self._assigned_resources.append(resource) argout.append(resource) return argout @command( dtype_in=('str',), doc_in="List of resources to remove from the subarray.", dtype_out=('str',), doc_out="List of resources removed from the subarray.", ) @DebugIt() def ReleaseResources(self, argin): # PROTECTED REGION ID(SKASubarray.ReleaseResources) ENABLED START # argout = [] # Release resources... resources = self._assigned_resources[:] for resource in argin: if resource in resources: self._assigned_resources.remove(resource) argout.append(resource) return argout # PROTECTED REGION END # // SKASubarray.ReleaseResources @command( ) @DebugIt() def EndSB(self): # PROTECTED REGION ID(SKASubarray.EndSB) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.EndSB @command( ) @DebugIt() def EndScan(self): # PROTECTED REGION ID(SKASubarray.EndScan) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.EndScan @command( ) @DebugIt() def Pause(self): # PROTECTED REGION ID(SKASubarray.Pause) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.Pause @command( dtype_out=('str',), doc_out="List of resources removed from the subarray.", ) @DebugIt() def ReleaseAllResources(self): # PROTECTED REGION ID(SKASubarray.ReleaseAllResources) ENABLED START # resources = self._assigned_resources[:] released_resources = self.ReleaseResources(resources) return released_resources # PROTECTED REGION END # // SKASubarray.ReleaseAllResources @command( dtype_in=('str',), doc_in="List of resources to remove from the subarray.", dtype_out=('str',), doc_out="List of resources removed from the subarray.", ) @DebugIt() def ReleaseResources(self, argin): # PROTECTED REGION ID(SKASubarray.ReleaseResources) ENABLED START # return [""] # PROTECTED REGION END # // SKASubarray.ReleaseResources @command( ) @DebugIt() def Resume(self): # PROTECTED REGION ID(SKASubarray.Resume) ENABLED START # pass # PROTECTED REGION END # // SKASubarray.Resume @command( dtype_in=('str',), ) @DebugIt() def Scan(self, argin): # PROTECTED REGION ID(SKASubarray.Scan) ENABLED START # pass
class RefB(SKABaseDevice): """ Ref (Reference Element) device of type B. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(RefB.class_variable) ENABLED START # # PROTECTED REGION END # // RefB.class_variable # ----------------- # Device Properties # ----------------- # ---------- # Attributes # ---------- attr1 = attribute( dtype='str', doc="Attribute 1 for DevB", ) attr2 = attribute( dtype='str', doc="Attribute 2 for DevB", ) importantState = attribute( dtype='DevEnum', access=AttrWriteType.READ_WRITE, enum_labels=[ "OK", "GOOD", "BAD", "VERY-BAD", ], ) # --------------- # General methods # --------------- def init_device(self): SKABaseDevice.init_device(self) # PROTECTED REGION ID(RefB.init_device) ENABLED START # # PROTECTED REGION END # // RefB.init_device def always_executed_hook(self): # PROTECTED REGION ID(RefB.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // RefB.always_executed_hook def delete_device(self): # PROTECTED REGION ID(RefB.delete_device) ENABLED START # pass # PROTECTED REGION END # // RefB.delete_device # ------------------ # Attributes methods # ------------------ def read_attr1(self): # PROTECTED REGION ID(RefB.attr1_read) ENABLED START # return '' # PROTECTED REGION END # // RefB.attr1_read def read_attr2(self): # PROTECTED REGION ID(RefB.attr2_read) ENABLED START # return '' # PROTECTED REGION END # // RefB.attr2_read def read_importantState(self): # PROTECTED REGION ID(RefB.importantState_read) ENABLED START # return 0 # PROTECTED REGION END # // RefB.importantState_read def write_importantState(self, value): # PROTECTED REGION ID(RefB.importantState_write) ENABLED START # pass # PROTECTED REGION END # // RefB.importantState_write # -------- # Commands # -------- @command() @DebugIt() def Reset(self): # PROTECTED REGION ID(RefB.Reset) ENABLED START # pass
class SyncDevice(Device, metaclass=DeviceMeta): """ Tango Sync device class. Parameters ---------- None Examples -------- >>> from PyTango.server import server_run >>> server_run((SyncDevice,)) """ time = attribute() # read only is default error_handler = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) device = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) counter_input = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) counter_output = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) pulse_freq = attribute( dtype=float, access=AttrWriteType.READ_WRITE, ) output_path = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) line_labels = attribute( dtype=str, access=AttrWriteType.READ_WRITE, ) # ------------------------------------------------------------------------------ # INIT # ------------------------------------------------------------------------------ def init_device(self): """ Device constructor. Automatically run by Tango upon device export. """ self.set_state(DevState.ON) self.set_status("READY") self.attr_error_handler = "" self.attr_device = 'Dev1' self.attr_counter_input = 'ctr0' self.attr_counter_output = 'ctr2' self.attr_counter_bits = 64 self.attr_event_bits = 24 self.attr_pulse_freq = 10000000.0 self.attr_output_path = "C:/sync/output/test.h5" self.attr_line_labels = "[]" print("Device initialized...") # ------------------------------------------------------------------------------ # Attribute R/W # ------------------------------------------------------------------------------ def read_time(self): return time.time() def read_error_handler(self): return self.attr_error_handler def write_error_handler(self, data): self.attr_error_handler = data def read_device(self): return self.attr_device def write_device(self, data): self.attr_device = data def read_counter_input(self): return self.attr_counter_input def write_counter_input(self, data): self.attr_counter_input = data def read_counter_output(self): return self.attr_counter_output def write_counter_output(self, data): self.attr_counter_output = data def read_pulse_freq(self): return self.attr_pulse_freq def write_pulse_freq(self, data): self.attr_pulse_freq = data def read_output_path(self): return self.attr_output_path def write_output_path(self, data): self.attr_output_path = data def read_line_labels(self): return self.attr_line_labels def write_line_labels(self, data): self.attr_line_labels = data # ------------------------------------------------------------------------------ # Commands # ------------------------------------------------------------------------------ @command(dtype_in=str, dtype_out=str) def echo(self, data): """ For testing. Just echos whatever string you send. """ return data @command(dtype_in=str, dtype_out=None) def throw(self, msg): print(("Raising exception:", msg)) # Send to error handler or sequencing engine @command(dtype_in=None, dtype_out=None) def start(self): """ Starts an experiment. """ print("Starting experiment...") self.sync = Sync( device=self.attr_device, counter_input=self.attr_counter_input, counter_output=self.attr_counter_output, counter_bits=self.attr_counter_bits, event_bits=self.attr_event_bits, output_path=self.attr_output_path, freq=self.attr_pulse_freq, verbose=True, force_sync_callback=False, ) lines = eval(self.attr_line_labels) for index, line in enumerate(lines): self.sync.add_label(index, line) self.sync.start() @command(dtype_in=None, dtype_out=None) def stop(self): """ Stops an experiment and clears the NIDAQ tasks. """ print("Stopping experiment...") try: self.sync.stop() except Exception as e: print(e) self.sync.clear(self.attr_output_path) self.sync = None del self.sync @command(dtype_in=str, dtype_out=None) def load_config(self, path): """ Loads a configuration from a .pkl file. """ print(("Loading configuration: %s" % path)) with open(path, 'rb') as f: config = pickle.load(f) self.attr_device = config['device'] self.attr_counter_input = config['counter'] self.attr_counter_output = config['pulse'] self.attr_counter_bits = int(config['counter_bits']) self.attr_event_bits = int(config['event_bits']) self.attr_pulse_freq = float(config['freq']) self.attr_output_path = config['output_dir'] self.attr_line_labels = str(config['labels']) @command(dtype_in=str, dtype_out=None) def save_config(self, path): """ Saves a configuration to a .pkl file. """ print(("Saving configuration: %s" % path)) config = { 'device': self.attr_device, 'counter': self.attr_counter_input, 'pulse': self.attr_counter_output, 'freq': self.attr_pulse_freq, 'output_dir': self.attr_output_path, 'labels': eval(self.attr_line_labels), 'counter_bits': self.attr_counter_bits, 'event_bits': self.attr_event_bits, } with open(path, 'wb') as f: pickle.dump(config, f) @command(dtype_in=str, dtype_out=None) def copy_dataset(self, folder): """ Copies last dataset to specified folder. """ source = self.attr_output_path dest = os.path.join(folder, os.path.basename(source)) copyfile(source, dest)
class Sending(Device): __metaclass__ = DeviceMeta """Attributes for setting logging levels for element storage and central""" elementLoggingLevel = attribute(label="ElementLogginglevel", dtype=int, fget="get_elementLoggingLevel", fset="set_elementLoggingLevel", doc="Sets element logging level") storageLoggingLevel = attribute(label="StorgeLoggingLevel", dtype=int, fget="get_storageLoggingLevel", fset="set_storageLoggingLevel", doc="Sets syslog logging level") centralLoggingLevel = attribute(label="CentralLoggingLevel", dtype=int, fget="get_centralLoggingLevel", fset="set_centralLoggingLevel", doc="Sets Central logging level") def init_device(self): Device.init_device(self) self.set_state(DevState.STANDBY) self.__elementLoggingLevel = 5 self.__storageLoggingLevel = 5 self.__centralLoggingLevel = 5 logger.setLevel(logging.DEBUG) def get_elementLoggingLevel(self): return self.__elementLoggingLevel def set_elementLoggingLevel(self, elementLoggingLevel): self.__elementLoggingLevel = elementLoggingLevel return elementLoggingLevel def get_centralLoggingLevel(self): return self.__centralLoggingLevel def set_centralLoggingLevel(self, centralLoggingLevel): self.__centralLoggingLevel = centralLoggingLevel return centralLoggingLevel def get_storageLoggingLevel(self): return self.__storageLoggingLevel def set_storageLoggingLevel(self, storageLoggingLevel): self.debug_stream("In set_StorageLogginglevel") self.__storageLoggingLevel = storageLoggingLevel if self.__storageLoggingLevel == 1: logger.setLevel(logging.FATAL) elif self.__storageLoggingLevel == 2: logger.setLevel(logging.ERROR) elif self.__storageLoggingLevel == 3: logger.setLevel(logging.WARNING) elif self.__storageLoggingLevel == 4: logger.setLevel(logging.INFO) elif self.__storageLoggingLevel == 5: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.DEBUG) return storageLoggingLevel @command def TurnOn(self): # turn on the sending device. self.set_state(DevState.ON) self.debug_stream("TurnOn Sending DEBUG") self.info_stream("TurnOn Sending INFO") self.warn_stream("TurnOn Sending WARNING") self.error_stream("TurnOn Sending ERROR") self.fatal_stream("TurnOn Sending FATAL") logger.debug("TurnOn Sending debug") logger.info("TurnOn Sending info") logger.warning("TurnOn Sending warn") logger.error("TurnOn Sending error") logger.fatal("TurnOn Sending fatal") @command def TurnOff(self): # turn off the sending device self.set_state(DevState.OFF) self.debug_stream("TurnOff Sending DEBUG") self.info_stream("TurnOff Sending INFO") self.warn_stream("TurnOff Sending WARNING") self.error_stream("TurnOff Sending ERROR") self.fatal_stream("TurnOff Sending FATAL") logger.debug("TurnOff Sending debug") logger.info("TurnOff Sending info") logger.warning("TurnOff Sending warn") logger.error("TurnOff Sending error") logger.fatal("TurnOff Sending fatal")
class TMCM6110MotoraxisDS(Device): __metaclass__ = DeviceMeta # --- Operator attributes # Position = attribute(label="position", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="mm", format="%6.2f", min_value=-100000.0, max_value=100000.0, fget="get_position", fset="set_position", doc="Motor position in mm", memorized=True, hw_memorized=True) Velocity = attribute(label="velocity", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="mm / s", format="%6.2f", min_value=-100000.0, max_value=100000.0, fget="get_velocity", fset="set_velocity", doc="Motor velocity in mm/s", memorized=True, hw_memorized=True) DialPosition = attribute( label="dial position", dtype=float, access=pt.AttrWriteType.READ, unit="mm", format="%6.2f", min_value=-100000.0, max_value=100000.0, fget="get_dialposition", fset="set_dialposition", doc="Absolute motor position in mm with offset applied", ) Offset = attribute(label="offset", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="mm", format="%6.2f", min_value=-100000.0, max_value=100000.0, fget="get_offset", fset="set_offset", doc="Motor offset in mm", memorized=True, hw_memorized=True) Acceleration = attribute(label="acceleration", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="mm / s**2", format="%6.2f", min_value=-1000000.0, max_value=1000000.0, fget="get_acceleration", fset="set_acceleration", doc="Motor acceleration in mm/s**2", memorized=True, hw_memorized=True) Deceleration = attribute(label="deceleration", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="mm / s**2", format="%6.2f", min_value=-1000000.0, max_value=1000000.0, fget="get_deceleration", fset="set_deceleration", doc="Motor deceleration in mm/s**2", memorized=True, hw_memorized=True) Base_rate = attribute( label="base rate", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="a.u.", format="%6.2f", min_value=-1000000.0, max_value=1000000.0, fget="get_baserate", fset="set_baserate", doc="Motor base rate... whatever that is", memorized=True, ) SimulationMode = attribute( label="simulation mode", dtype=bool, access=pt.AttrWriteType.READ, unit="", fget="get_simulationmode", doc="Motor simulation mode", ) Step_per_unit = attribute(label="step per unit", dtype=float, access=pt.AttrWriteType.READ_WRITE, unit="steps/mm", format="%6.2f", min_value=-1000000.0, max_value=1000000.0, fget="get_stepperunit", fset="set_stepperunit", doc="Motor steps per unit", memorized=True, hw_memorized=True) Backlash = attribute(label="backlash", dtype=bool, access=pt.AttrWriteType.READ_WRITE, unit="", format="%d", fget="get_backlash", fset="set_backlash", doc="Motor backlash", memorized=True, hw_memorized=True) Limit_switches = attribute( label="limit switches", dtype=(bool, ), max_dim_x=3, access=pt.AttrWriteType.READ, unit="", format="%d", fget="get_limitswitches", doc="Limit switches state", ) Load_level = attribute( label="load level", dtype=float, access=pt.AttrWriteType.READ, unit="", format="%6.2f", min_value=-1000000.0, max_value=1000000.0, fget="get_loadlevel", doc="Motor load level in normalized units", ) # --- Device properties # TMCM6110_device = device_property( dtype=str, doc="Tango name of mother Trinamic_TMCM6110_DS", ) Axis = device_property( dtype=int, doc="Motor axis", ) Motor_current = device_property( dtype=float, doc="Motor maxiumum current", ) Microsteps = device_property( dtype=int, doc="Microstep resolution: 1, 2, 4, 8, or 16", ) Limit0Enable = device_property( dtype=bool, doc="Enable limit switch 0?", ) Limit1Enable = device_property( dtype=bool, doc="Enable limit switch 1?", ) def __init__(self, klass, name): self.controller = None # type: TMCM6110MotoraxisController self.setup_attr_params = dict() self.state_dispatcher = None # type: StateDispatcher self.state_thread = None # type: threading.Thread self.stop_state_thread = False self.offset_value = 0 self.baserate_value = 0 self.backlash_value = False self.simulation_value = False Device.__init__(self, klass, name) def init_device(self): self.debug_stream("In init_device:") Device.init_device(self) if self.controller is not None: self.stop_state_thread = True self.state_thread.join(1.0) self.controller.close() self.debug_stream( "Device: {0}, axis {1}, motor_current {2}, microsteps {3}".format( self.TMCM6110_device, self.Axis, self.Motor_current, self.Microsteps)) self.controller = TMCM6110MotoraxisController( self.TMCM6110_device, self.Axis, self.Motor_current, 1, self.Microsteps, self.Limit0Enable, self.Limit1Enable) self.state_thread = threading.Thread(target=self._read_state) self.state_thread.daemon = True self.state_thread.start() def get_position(self): # self.debug_stream("In get_position:") if self.controller is None: self.error_stream("No controller") return None data = self.controller.get_position() try: value = data.value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def set_position(self, pos): self.debug_stream("In set_position: {0}".format(pos)) if self.controller is None: self.error_stream("set_position: NO CONTROLLER") return self.controller.set_position(pos) return 0 def get_velocity(self): # self.debug_stream("In get_velocity:") data = self.controller.get_speed() try: value = data.value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def set_velocity(self, value): self.debug_stream("In set_velocity: {0}".format(value)) if self.controller is None: self.error_stream("set_velocity: NO CONTROLLER") return self.controller.set_speed(value) return 0 def get_dialposition(self): # self.debug_stream("In get_dialposition:") data = self.controller.get_position() try: value = data.value - self.offset_value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def get_offset(self): # self.debug_stream("In get_offset:") value = self.offset_value quality = pt.AttrQuality.ATTR_VALID t = time.time() return value, t, quality def set_offset(self, value): self.debug_stream("In set_offset: {0}".format(value)) self.offset_value = value return 0 def get_acceleration(self): # self.debug_stream("In get_acceleration:") data = self.controller.get_acceleration() try: value = data.value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def set_acceleration(self, value): self.debug_stream("In set_acceleration: {0}".format(value)) if self.controller is None: self.error_stream("set_acceleration: NO CONTROLLER") return self.controller.set_acceleration(value) return 0 def get_deceleration(self): # self.debug_stream("In get_deceleration:") data = self.controller.get_acceleration() try: value = data.value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def set_deceleration(self, value): self.debug_stream("In set_deceleration: {0}".format(value)) if self.controller is None: self.error_stream("set_deceleration: NO CONTROLLER") return self.controller.set_acceleration(value) return 0 def get_baserate(self): # self.debug_stream("In get_baserate:") value = self.baserate_value quality = pt.AttrQuality.ATTR_VALID t = time.time() return value, t, quality def set_baserate(self, value): self.debug_stream("In set_baserate: {0}".format(value)) self.baserate_value = value return 0 def get_simulationmode(self): # self.debug_stream("In get_simulationmode:") value = self.simulation_value quality = pt.AttrQuality.ATTR_VALID t = time.time() return value, t, quality def set_simulationmode(self, value): self.debug_stream("In set_simulationmode: {0}".format(value)) self.simulation_value = value return 0 def get_stepperunit(self): # self.debug_stream("In get_stepperunit:") if self.controller is None: return None value = self.controller.get_stepperunit() quality = pt.AttrQuality.ATTR_VALID t = time.time() return value, t, quality def set_stepperunit(self, value): self.debug_stream("In set_stepperunit: {0}".format(value)) if self.controller is None: return self.controller.set_stepperunit(value) return 0 def get_backlash(self): # self.debug_stream("In get_backlash:") value = self.backlash_value quality = pt.AttrQuality.ATTR_VALID t = time.time() return value, t, quality def set_backlash(self, value): self.debug_stream("In set_backlash: {0}".format(value)) self.backlash_value = value return 0 def get_limitswitches(self): # self.debug_stream("In get_limitswitches:") data = self.controller.get_limitswitches() try: value = [data[0].value, data[1].value] t = data[0].time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = [False, False] quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def get_loadlevel(self): # self.debug_stream("In get_loadlevel:") data = self.controller.get_loadlevel() try: value = data.value t = data.time.totime() quality = pt.AttrQuality.ATTR_VALID except AttributeError: value = 0 quality = pt.AttrQuality.ATTR_INVALID t = time.time() return value, t, quality def _read_state(self): self.debug_stream("Starting read state thread") old_state = "--" while not self.stop_state_thread: state, status = self.controller.get_state() if state in ["unknown"]: if old_state != state: self.info_stream("Changing state to UNKNOWN") self.set_state(pt.DevState.UNKNOWN) self.set_status(status) elif state in ["init"]: if old_state != state: self.info_stream("Changing state to INIT") self.set_state(pt.DevState.INIT) self.set_status(status) elif state in ["on"]: if old_state != state: self.info_stream("Changing state to ON") self.set_state(pt.DevState.ON) self.set_status(status) elif state in ["moving"]: if old_state != state: self.info_stream("Changing state to MOVING") self.set_state(pt.DevState.MOVING) self.set_status(status) elif state in ["fault"]: if old_state != state: self.info_stream("Changing state to FAULT") self.set_state(pt.DevState.FAULT) self.set_status(status) elif state in ["alarm"]: if old_state != state: self.info_stream("Changing state to ALARM") self.set_state(pt.DevState.ALARM) self.set_status(status) else: self.info_stream("Unknown state,setting UNKNOWN") self.set_state(pt.DevState.UNKNOWN) old_state = state time.sleep(0.1)
class CryoCon32(Device): """ Minimalistic driver for the Cryocon32 controller used in our Mossbauer transmission setup. """ __metaclass__ = DeviceMeta # PROTECTED REGION ID(CryoCon32.class_variable) ENABLED START # # PROTECTED REGION END # // CryoCon32.class_variable # ----------------- # Device Properties # ----------------- SerialPort = device_property(dtype='str', default_value="/dev/ttyS0") SerialSpeed = device_property(dtype='uint16', default_value=9600) # ---------- # Attributes # ---------- TemperatureA = attribute( dtype='double', unit="K", standard_unit="K", display_unit="K", format="%4.1f", max_value=1000.0, min_value=0.0, ) SetPoint = attribute( dtype='double', access=AttrWriteType.READ_WRITE, label="SetPoint", unit="K", standard_unit="K", display_unit="K", format="%4.1f", max_value=1000.0, min_value=0.0, ) TemperatureB = attribute( dtype='double', unit="K", ) HeaterLevel = attribute( dtype='DevEnum', access=AttrWriteType.READ_WRITE, enum_labels=[ "LOW", "MID", "HIGH", ], ) # --------------- # General methods # --------------- def init_device(self): Device.init_device(self) # PROTECTED REGION ID(CryoCon32.init_device) ENABLED START # try: self.ser = serial.Serial(self.SerialPort, self.SerialSpeed, bytesize=8, parity="N", stopbits=1, timeout=0.5) self.ser.write("*IDN?\n") idn = self.ser.readline() if (idn[0:16] != "Cryocon Model 32"): self.set_status("Not a CryoCon32 on serial port") self.debug_stream("Not a CryoCon32 on serial port") return self.ser.write("INPUT A:UNITS K\n") self.ser.write("LOOP 1:TYPE PID\n") self.ser.write("CONTROL?\n") mode = self.ser.readline() if mode[0:3] == "OFF": self.set_state(PyTango.DevState.OFF) else: self.set_state(PyTango.DevState.ON) except: self.set_state(PyTango.DevState.FAULT) self.set_status("Can't connect to CryoCon32") self.debug_stream("Can't connect to CryoCon32") return self.set_status("Connected to CryoCon32") self.debug_stream("Connected to CryoCon32") # PROTECTED REGION END # // CryoCon32.init_device def always_executed_hook(self): # PROTECTED REGION ID(CryoCon32.always_executed_hook) ENABLED START # pass # PROTECTED REGION END # // CryoCon32.always_executed_hook def delete_device(self): # PROTECTED REGION ID(CryoCon32.delete_device) ENABLED START # self.ser.close() # PROTECTED REGION END # // CryoCon32.delete_device # ------------------ # Attributes methods # ------------------ def read_TemperatureA(self): # PROTECTED REGION ID(CryoCon32.TemperatureA_read) ENABLED START # self.ser.write("INPUT? A\n") temperature = float(self.ser.readline()) return (temperature) # PROTECTED REGION END # // CryoCon32.TemperatureA_read def read_SetPoint(self): # PROTECTED REGION ID(CryoCon32.SetPoint_read) ENABLED START # self.ser.write("LOOP 1:SETPT?\n") temperature = float(self.ser.readline() [:-2]) # Remove \n and units (assume we are in K!) return (temperature) # PROTECTED REGION END # // CryoCon32.SetPoint_read def write_SetPoint(self, value): # PROTECTED REGION ID(CryoCon32.SetPoint_write) ENABLED START # self.ser.write("LOOP 1:SETPT %f \n" % (value)) # PROTECTED REGION END # // CryoCon32.SetPoint_write def read_TemperatureB(self): # PROTECTED REGION ID(CryoCon32.TemperatureB_read) ENABLED START # self.ser.write("INPUT? B\n") temperature = float(self.ser.readline()) return (temperature) # PROTECTED REGION END # // CryoCon32.TemperatureB_read def read_HeaterLevel(self): # PROTECTED REGION ID(CryoCon32.HeaterLevel_read) ENABLED START # self.ser.write("LOOP 1:RANGE?\n") res = self.ser.readline() if (res[:-1] == "LOW"): return 0 elif (res[:-1] == "MID"): return 1 else: return 2 # PROTECTED REGION END # // CryoCon32.HeaterLevel_read def write_HeaterLevel(self, value): # PROTECTED REGION ID(CryoCon32.HeaterLevel_write) ENABLED START # if (value == 0): self.ser.write("LOOP 1:RANGE LOW\n") elif (value == 1): self.ser.write("LOOP 1:RANGE MID\n") elif (value == 2): self.ser.write("LOOP 1:RANGE HI\n") return # PROTECTED REGION END # // CryoCon32.HeaterLevel_write # -------- # Commands # -------- @command() @DebugIt() def On(self): # PROTECTED REGION ID(CryoCon32.On) ENABLED START # self.ser.write("CONTROL ON\n") self.set_state(PyTango.DevState.ON) pass # PROTECTED REGION END # // CryoCon32.On @command() @DebugIt() def Off(self): # PROTECTED REGION ID(CryoCon32.Off) ENABLED START # self.ser.write("STOP\n") self.set_state(PyTango.DevState.OFF) pass # PROTECTED REGION END # // CryoCon32.Off @command( dtype_in='str', ) @DebugIt() def SendCmd(self, argin): # PROTECTED REGION ID(CryoCon32.SendCmd) ENABLED START # self.ser.write(argin + "\n") return "" # PROTECTED REGION END # // CryoCon32.SendCmd @command( dtype_in='str', dtype_out='str', ) @DebugIt() def SendQuery(self, argin): # PROTECTED REGION ID(CryoCon32.SendQuery) ENABLED START # self.ser.write(argin + "\n") return self.ser.readline()