Dear all,
I write you about some issues regarding yat4tango library. I’m currently using it to dynamically add attributes to my device server (it is more flexible than the current suggested way to add dyn attributes in Tango and it seems possible also to add forwarded attributes).
I’ve found this issue when adding spectrum attributes and then setting attribute properties. The sample code is (try-catch block not shown):
//Create dyn attr manager
DynamicAttributeManager* m_dam = new yat4tango::DynamicAttributeManager(this);
//Create dyn attr info
yat4tango::DynamicAttributeInfo dai;
dai.dev = this;
dai.tai.name = attr_name;
dai.tai.writable = write_type;
dai.tai.data_format = Tango::SPECTRUM;
dai.tai.data_type= data_type;
dai.tai.max_dim_x= data_size;//this seems ineffective since yat4tango initialize spectrum attr with size LONG_MAX
//Add attribute to manager
m_dam->add_attribute(dai);
//Retrieve attribute found
long attr_index= get_device_attr()->get_attr_ind_by_name(attr_name.c_str());
std::vector<Tango::Attribute*> attribute_list= get_device_attr()->get_attribute_list();
//Set my properties
Tango::MultiAttrProp<Tango::DevFloat>* multi_attr_prop= ...
attribute_list[attr_index]->set_properties(*multi_attr_prop);
The last line produces this exception:
Tango exception
Severity = ERROR
Error reason = API_AttrNotAllowed
Desc : Attribute property max_dim_x is not changeable at run time
Origin : Attribute::check_hard_coded_properties()
This has driven me nuts the whole day (think it is a bug but better ask…). The error seems in the
get_properties(Tango::AttributeConfig_3 &conf) and get_properties(Tango::AttributeConfig_5 &conf) methods of the attrgetsetprop.cpp. When converting from AttributeConfig_3 to AttributeConfig_5 the max_dim_x property (which is initialized to LONG_MAX by yat for spectrum & image attrs) seems implicitly converted to int (e.g. conf.max_dim_x= -1). Hence, when conf.max_dim_x and max_dim_x are compared in the sanity check there is a mismatch. By the way the set_properties() method should not supposed to change the hard-coded properties, no?
Do you have suggestions or could you in case confirm if it is a bug or not?
I’ve temporarily fixed the issue by modifying the constructor of spectrum dyn attributes (did the same for image) from:
DynamicSpectrumAttribute (const DynamicAttributeInfo& i)
: Tango::SpectrumAttr (i.lan.c_str(), i.tai.data_type, i.tai.writable, LONG_MAX, i.tai.disp_level),...
to:
DynamicSpectrumAttribute (const DynamicAttributeInfo& i)
: Tango::SpectrumAttr (i.lan.c_str(), i.tai.data_type, i.tai.writable, i.tai.max_dim_x, i.tai.disp_level),
I thank you very much for your help,
Simone