def ChangeValueType(self, dtype): if dtype in self.defaults.keys(): if self.dtype is not None: self.remove_attribute("Value") self.dtype = dtype dev_class = self.get_device_class() attr_data = PyTango.AttrData( "Value", dev_class.get_name(), [[ self.defaults[self.dtype][2], self.defaults[self.dtype][1], PyTango.READ_WRITE ], { 'description': "dynamic attribute", }]) self.add_attribute(attr_data, r_meth=self.read_Value, w_meth=self.write_Value)
class AD5370DacDS(PyTango.Device_4Impl): # --------- Add your global variables here -------------------------- # ------------------------------------------------------------------ # Device constructor # ------------------------------------------------------------------ def __init__(self, cl, name): PyTango.Device_4Impl.__init__(self, cl, name) self.stream_lock = None self.attr_lock = None self.apply_immediate = None self.state_thread = None self.command_queue = None self.state_handler_dict = None self.stop_state_thread_flag = None self.AD5370_dac_device = None AD5370DacDS.init_device(self) # ------------------------------------------------------------------ # Device destructor # ------------------------------------------------------------------ def delete_device(self): with self.stream_lock: self.info_stream(''.join( ("[Device delete_device method] for device", self.get_name()))) self.stop_thread() # ------------------------------------------------------------------ # Device initialization # ------------------------------------------------------------------ def init_device(self): self.stream_lock = threading.Lock() with self.stream_lock: self.info_stream(''.join( ("In ", self.get_name(), "::init_device()"))) self.set_state(PyTango.DevState.UNKNOWN) self.get_device_properties(self.get_device_class()) # Try stopping the stateThread if it was started before. Will fail if this # is the initial start. try: self.stop_thread() except Exception, e: pass self.apply_immediate = False self.attr_lock = threading.Lock() self.state_thread = threading.Thread() threading.Thread.__init__(self.state_thread, target=self.state_handler_dispatcher) self.command_queue = Queue.Queue(100) try: # Add channel attributes if not already defined attrs = self.get_device_attr() for ch in range(40): try: attrs.get_attr_by_name(''.join(('channel', str(ch)))) self.info_stream(''.join( ('Channel ', str(ch), ' already defined.'))) except PyTango.DevFailed: # The attribute was not defined, so add it self.info_stream(''.join( ('Channel ', str(ch), ' not defined, adding attribute.'))) attr_info = [[ PyTango.DevDouble, PyTango.SCALAR, PyTango.READ_WRITE ], { 'description': "DAC output for channel", 'unit': 'V', 'Memorized': "true", }] attr_name = ''.join(('channel', str(ch))) attr_data = PyTango.AttrData(attr_name, self.get_name(), attr_info) self.add_attribute(attr_data, r_meth=self.read_channel, w_meth=self.write_channel, is_allo_meth=self.is_channel_allowed) except Exception, ex: with self.stream_lock: self.error_stream('Error when initializing device') self.error_stream(str(ex))