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).
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.
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.
[quote=“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[/quote]
Hi Sonia,
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).
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[/quote]
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.