diff --git a/src/SingleShotAO.cpp b/src/SingleShotAO.cpp index 7bcea21ce003adc36dcfb868f6193e45a3e42802..76ce807891ec5abce8aecb47da452e4e8f17870f 100755 --- a/src/SingleShotAO.cpp +++ b/src/SingleShotAO.cpp @@ -455,7 +455,6 @@ void SingleShotAO::init_device() dai_channel.tai.min_value = "-10.0"; dai_channel.tai.description = "Output value for channel " + oss.str() + " (in measurementUnit)."; dai_channel.tai.format = "%1.2f"; - dai_channel.memorized = true; dai_channel.cdb = false; //- read callback @@ -494,7 +493,6 @@ void SingleShotAO::init_device() 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) - dai_speed.memorized = true; dai_speed.cdb = false; //- read callback @@ -528,7 +526,6 @@ void SingleShotAO::init_device() 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) - dai_initial.memorized = true; dai_initial.cdb = false; //- read callback @@ -595,7 +592,12 @@ void SingleShotAO::init_device() std::string attrName = attrPrefix + oss.str(); double val = yat4tango::PropertyHelper::get_memorized_attribute<double>(this, attrName); 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); + + // Write the value to the "write" attributes using helper function + setDynamicAttributeWriteValue(attrName, val); } catch (...) { // nothing to do @@ -954,6 +956,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & { double 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(); yat::uint16 l_idx = extractNumber(l_attr_name, kCHANNEL); // extract channel nb @@ -981,7 +984,12 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & 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, 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; } @@ -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 @@ -1160,11 +1199,15 @@ void SingleShotAO::_abort() DEBUG_STREAM << "Channel " << l_cpt << " is running. Memorizing values..." << std::endl; 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); - DEBUG_STREAM << "Memorizing channel " << l_cpt << " to " << l_val_channel << std::endl; - - yat4tango::PropertyHelper::set_memorized_attribute(this, kINITIAL + std::to_string(l_cpt), l_val_channel); - DEBUG_STREAM << "Memorizing initial " << l_cpt << " to " << l_val_channel << std::endl; + std::string l_channel_attr_name = kCHANNEL + std::to_string(l_cpt); + yat4tango::PropertyHelper::set_memorized_attribute(this, l_channel_attr_name, l_val_channel); + setDynamicAttributeWriteValue(l_channel_attr_name, l_val_channel); + DEBUG_STREAM << "Memorizing " << l_channel_attr_name << " 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(); diff --git a/src/SingleShotAO.h b/src/SingleShotAO.h index 7cee441f51308aedf5a49c106de306a9849bcdfe..17e2b74745fc27ed2ef311a644cf782ac711aeb2 100755 --- a/src/SingleShotAO.h +++ b/src/SingleShotAO.h @@ -290,6 +290,10 @@ protected : 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