Attribute update

Hello,

I am new to the Tango world. I would like to create a basic device driver, a device driver with a double attribute and with a boolean attribute (button).

I have followed the steps of the documentation ( https://tango-controls.readthedocs.io/en/latest/getting-started/development/cpp/cpp-quick-start.html ), adding the corresponding attributes –>

But the attributes do not update their values (using TaurusForm gui) –>

Even using a PyTango client it is not possible to see the assigned value.

Does anyone see a mistake in the procedure I have followed?

Thanks in advance, Adrián.
Hello,
could you show the code of the attributes read and write callback functions ?
Perhaps there is a problem in the attribute value update.
Sonia
Hi,

This part of the documentation is indeed not enough explicit.
You need to add some code in the files generated by Pogo to assign the value you want to the different attributes and add your business logic.

Here is an example for some attribute code in C++: https://tango-controls.readthedocs.io/en/latest/getting-started/development/cpp/first-device-class.html#the-three-attributes

What programming language are you using for your Device Class Implementation? C++, Java, Python?

Kind regards,
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Reynald
Hi,

This part of the documentation is indeed not enough explicit.
You need to add some code in the files generated by Pogo to assign the value you want to the different attributes and add your business logic.

Here is an example for some attribute code in C++: https://tango-controls.readthedocs.io/en/latest/getting-started/development/cpp/first-device-class.html#the-three-attributes

What programming language are you using for your Device Class Implementation? C++, Java, Python?

Kind regards,
Reynald

Hi Reynald,

I checked this example and the code generated by Pogo is quite similar:

I am using C++ for the Device Class.

Thanks, Adrián.
smi03
Hello,
could you show the code of the attributes read and write callback functions ?
Perhaps there is a problem in the attribute value update.
Sonia
Hi Sonia,

I attach the code:




Thanks, Adrián.
Hi,

If you want the Counter read value to be updated with the Counter write value when the Counter attribute is written, you should add the following lines in the PROTECTED REGION section in AdriTangoClass::write_counter(Tango::WAttribute &attr):

/*—– PROTECTED REGION ID(AdriTangoClass::write_counter) ENABLED START —–*/
*attr_counter_read = w_val;
/*—– PROTECTED REGION END —–*/ // AdriTangoClass::write_counter


You can also set *attr_counter_read to the value you want by code just before calling attr.set_value(attr_counter_read);

For instance, if you want to increment the value of the Counter, every time the Attribute is read on the device:


/*—– PROTECTED REGION ID(AdriTangoClass::read_counter) ENABLED START —–*/
*attr_counter_read = *attr_counter_read + 1;
// set the attribute value
attr.set_value(attr_counter_read);
/*—– PROTECTED REGION END —–*/ // AdriTangoClass::read_counter


It is important to put your business code inside the PROTECTED REGIONS because POGO won't overwrite/erase these parts of code when you regenerate some code with POGO (because you added a new command or attribute for instance).

Hoping this helps.
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Reynald
Hi,

If you want the Counter read value to be updated with the Counter write value when the Counter attribute is written, you should add the following lines in the PROTECTED REGION section in AdriTangoClass::write_counter(Tango::WAttribute &attr):

/*—– PROTECTED REGION ID(AdriTangoClass::write_counter) ENABLED START —–*/
*attr_counter_read = w_val;
/*—– PROTECTED REGION END —–*/ // AdriTangoClass::write_counter


You can also set *attr_counter_read to the value you want by code just before calling attr.set_value(attr_counter_read);

For instance, if you want to increment the value of the Counter, every time the Attribute is read on the device:


/*—– PROTECTED REGION ID(AdriTangoClass::read_counter) ENABLED START —–*/
*attr_counter_read = *attr_counter_read + 1;
// set the attribute value
attr.set_value(attr_counter_read);
/*—– PROTECTED REGION END —–*/ // AdriTangoClass::read_counter


It is important to put your business code inside the PROTECTED REGIONS because POGO won't overwrite/erase these parts of code when you regenerate some code with POGO (because you added a new command or attribute, for instance).

Hoping this helps.
Reynald

Hi Reynald,

Thanks for your help. Now it works!

But I still do not understand how the boolean attribute works. I click on the checkbox of the "button" attribute, but "write_button()" method is not executed.

This is the code for the "button" (boolean) attribute:

//——————————————————–
/**
* Read attribute button related method
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
//——————————————————–
void AdriTangoClass::read_button(Tango::Attribute &attr)
{
DEBUG_STREAM << "AdriTangoClass::read_button(Tango::Attribute &attr) entering… " << endl;
/*—– PROTECTED REGION ID(AdriTangoClass::read_button) ENABLED START —–*/
// Set the attribute value
attr.set_value(attr_button_read);

/*—– PROTECTED REGION END —–*/ // AdriTangoClass::read_button
}
//——————————————————–
/**
* Write attribute button related method
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
//——————————————————–
void AdriTangoClass::write_button(Tango::WAttribute &attr)
{
DEBUG_STREAM << "AdriTangoClass::write_button(Tango::WAttribute &attr) entering… " << endl;
// Retrieve write value
Tango::DevBoolean w_val;
attr.get_write_value(w_val);
/*—– PROTECTED REGION ID(AdriTangoClass::write_button) ENABLED START —–*/

cout << "BUTTON value = " << w_val << endl; //Never shown

/*—– PROTECTED REGION END —–*/ // AdriTangoClass::write_button
}


I would like to execute some action, like write the value of another attribute or increase the value of counter, every time I push the button checkbox.

Thanks, Adrián.
 
Register or login to create to post a reply.