Skip to content
Snippets Groups Projects
Commit e3d05be3 authored by Alexandre MALFREYT's avatar Alexandre MALFREYT Committed by Florent LANGLOIS
Browse files

fix: always synchronize read and write values (except during ramps)

parent 5551cf17
No related branches found
No related tags found
2 merge requests!4develop -> main,!3EnableRamps and OutputMemorizedChannelsAtInit properties
...@@ -455,7 +455,6 @@ void SingleShotAO::init_device() ...@@ -455,7 +455,6 @@ void SingleShotAO::init_device()
dai_channel.tai.min_value = "-10.0"; dai_channel.tai.min_value = "-10.0";
dai_channel.tai.description = "Output value for channel " + oss.str() + " (in measurementUnit)."; dai_channel.tai.description = "Output value for channel " + oss.str() + " (in measurementUnit).";
dai_channel.tai.format = "%1.2f"; dai_channel.tai.format = "%1.2f";
dai_channel.memorized = true;
dai_channel.cdb = false; dai_channel.cdb = false;
//- read callback //- read callback
...@@ -494,7 +493,6 @@ void SingleShotAO::init_device() ...@@ -494,7 +493,6 @@ void SingleShotAO::init_device()
dai_speed.tai.format = "%1.2f"; dai_speed.tai.format = "%1.2f";
//- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db) //- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db)
dai_speed.memorized = true;
dai_speed.cdb = false; dai_speed.cdb = false;
//- read callback //- read callback
...@@ -528,7 +526,6 @@ void SingleShotAO::init_device() ...@@ -528,7 +526,6 @@ void SingleShotAO::init_device()
dai_initial.tai.format = "%1.2f"; dai_initial.tai.format = "%1.2f";
//- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db) //- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db)
dai_initial.memorized = true;
dai_initial.cdb = false; dai_initial.cdb = false;
//- read callback //- read callback
...@@ -595,7 +592,12 @@ void SingleShotAO::init_device() ...@@ -595,7 +592,12 @@ void SingleShotAO::init_device()
std::string attrName = attrPrefix + oss.str(); std::string attrName = attrPrefix + oss.str();
double val = yat4tango::PropertyHelper::get_memorized_attribute<double>(this, attrName); double val = yat4tango::PropertyHelper::get_memorized_attribute<double>(this, attrName);
DEBUG_STREAM << "Found memorized value for " << attrName << ": " << val << endl; DEBUG_STREAM << "Found memorized value for " << attrName << ": " << val << endl;
// Write the value to the manager (that contains the "read" attributes values)
(m_manager->*setter)(l_cpt, val); (m_manager->*setter)(l_cpt, val);
// Write the value to the "write" attributes using helper function
setDynamicAttributeWriteValue(attrName, val);
} }
catch (...) { catch (...) {
// nothing to do // nothing to do
...@@ -954,6 +956,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -954,6 +956,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData &
{ {
double l_val; double l_val;
cbd.tga->get_write_value(l_val); cbd.tga->get_write_value(l_val);
cbd.tga->set_write_value(l_val);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name, kCHANNEL); // extract channel nb yat::uint16 l_idx = extractNumber(l_attr_name, kCHANNEL); // extract channel nb
...@@ -981,7 +984,12 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -981,7 +984,12 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData &
DEBUG_STREAM << "SingleShotAO::write_channel(): channel " << l_idx << " value set to " << l_val << endl; DEBUG_STREAM << "SingleShotAO::write_channel(): channel " << l_idx << " value set to " << l_val << endl;
yat4tango::PropertyHelper::set_memorized_attribute(this, l_attr_name, l_val); yat4tango::PropertyHelper::set_memorized_attribute(this, l_attr_name, l_val);
yat4tango::PropertyHelper::set_memorized_attribute(this, kINITIAL + std::to_string(l_idx), l_val);
// Update the initial attribute to match the channel value
std::string initialAttrName = kINITIAL + std::to_string(l_idx);
yat4tango::PropertyHelper::set_memorized_attribute(this, initialAttrName, l_val);
setDynamicAttributeWriteValue(initialAttrName, l_val);
DEBUG_STREAM << "SingleShotAO::write_channel(): memorized attribute " << l_attr_name << " set to " << l_val << endl; DEBUG_STREAM << "SingleShotAO::write_channel(): memorized attribute " << l_attr_name << " set to " << l_val << endl;
} }
...@@ -1116,6 +1124,37 @@ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -1116,6 +1124,37 @@ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData &
} }
//+------------------------------------------------------------------
/**
* set the write value of a dynamic attribute
* used to keep read and write values in sync
*/
bool SingleShotAO::setDynamicAttributeWriteValue(const std::string& attrName, double value)
{
try {
Tango::DeviceImpl* dev = static_cast<Tango::DeviceImpl*>(this);
Tango::DevDouble val_to_write = value;
// Get the attribute
Tango::WAttribute& attr = dev->get_device_attr()->get_w_attr_by_name(attrName.c_str());
// Set the write value
attr.set_write_value(&val_to_write, 1);
DEBUG_STREAM << "Set write value for " << attrName << " to " << value << endl;
return true;
}
catch (Tango::DevFailed &df) {
ERROR_STREAM << "Failed to set write value for " << attrName
<< ": " << df << endl;
return false;
}
catch (...) {
ERROR_STREAM << "Unknown exception setting write value for "
<< attrName << endl;
return false;
}
}
//+------------------------------------------------------------------ //+------------------------------------------------------------------
/** /**
* method: SingleShotAO::abort * method: SingleShotAO::abort
...@@ -1160,11 +1199,15 @@ void SingleShotAO::_abort() ...@@ -1160,11 +1199,15 @@ void SingleShotAO::_abort()
DEBUG_STREAM << "Channel " << l_cpt << " is running. Memorizing values..." << std::endl; DEBUG_STREAM << "Channel " << l_cpt << " is running. Memorizing values..." << std::endl;
double l_val_channel = m_manager->get_channel(l_cpt); double l_val_channel = m_manager->get_channel(l_cpt);
yat4tango::PropertyHelper::set_memorized_attribute(this, kCHANNEL + std::to_string(l_cpt), l_val_channel); std::string l_channel_attr_name = kCHANNEL + std::to_string(l_cpt);
DEBUG_STREAM << "Memorizing channel " << l_cpt << " to " << l_val_channel << std::endl; yat4tango::PropertyHelper::set_memorized_attribute(this, l_channel_attr_name, l_val_channel);
setDynamicAttributeWriteValue(l_channel_attr_name, l_val_channel);
yat4tango::PropertyHelper::set_memorized_attribute(this, kINITIAL + std::to_string(l_cpt), l_val_channel); DEBUG_STREAM << "Memorizing " << l_channel_attr_name << " to " << l_val_channel << std::endl;
DEBUG_STREAM << "Memorizing initial " << l_cpt << " to " << l_val_channel << std::endl;
std::string l_initial_attr_name = kINITIAL + std::to_string(l_cpt);
yat4tango::PropertyHelper::set_memorized_attribute(this, l_initial_attr_name, l_val_channel);
setDynamicAttributeWriteValue(l_initial_attr_name, l_val_channel);
DEBUG_STREAM << "Memorizing " << l_initial_attr_name << " to " << l_val_channel << std::endl;
} }
} }
m_manager->abort(); m_manager->abort();
......
...@@ -290,6 +290,10 @@ protected : ...@@ -290,6 +290,10 @@ protected :
void _abort(); void _abort();
// set the write value of a dynamic attribute
// used to keep read and write values in sync
bool setDynamicAttributeWriteValue(const std::string& attrName, double value);
}; };
} // namespace_ns } // namespace_ns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment