diff --git a/src/SingleShotAO.cpp b/src/SingleShotAO.cpp index 3257a7bf4ddc80960225c512fdf505217d64ebe7..cb204a00afe0d7c4075b2828d956b2015530fdb9 100755 --- a/src/SingleShotAO.cpp +++ b/src/SingleShotAO.cpp @@ -318,6 +318,7 @@ void SingleShotAO::init_device() m_nb_chan = 16; } + INFO_STREAM << "Board has " << m_nb_chan << " channels" << endl; // construct the AO manager //-------------------------------------------- @@ -377,6 +378,20 @@ void SingleShotAO::init_device() return; } + // Remove existing dynamic attributes to avoid duplicates or other issues + // -------------------------------------------- + if (m_dyn_attr_manager) { + try { + m_dyn_attr_manager->remove_attributes(); + delete m_dyn_attr_manager; + m_dyn_attr_manager = NULL; + DEBUG_STREAM << "Existing dynamic attributes manager cleaned up" << endl; + } + catch (...) { + ERROR_STREAM << "Error cleaning up existing dynamic attributes manager, continuing..." << endl; + // Continue anyway - we'll create a new one + } + } // Create dynamic attributes //-------------------------------------------- @@ -404,6 +419,17 @@ void SingleShotAO::init_device() // add dynamic attributes: channel, speed & initial for each channel std::vector<yat4tango::DynamicAttributeInfo> l_dynAttrList; + + // Log how many attributes we're going to create + INFO_STREAM << "Creating dynamic attributes for " << m_nb_chan << " channels."; + INFO_STREAM << "Total attributes: " << m_nb_chan * (enableRamps ? 3 : 1) << endl; + + // if enableRamps if false, skip speed and initial attributes + if (!enableRamps) + { + INFO_STREAM << "Ramps are disabled. Skipping speed and initial attributes" << std::endl; + } + for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++) { yat::OSStream oss; @@ -515,8 +541,45 @@ void SingleShotAO::init_device() l_dynAttrList.push_back(dai_initial); } - m_dyn_attr_manager->add_attributes(l_dynAttrList); + + // Log the size of our attribute list before adding to manager + INFO_STREAM << "Prepared " << l_dynAttrList.size() << " dynamic attributes for creation" << endl; + + // Add all attributes + try { + m_dyn_attr_manager->add_attributes(l_dynAttrList); + INFO_STREAM << "Successfully added all dynamic attributes" << endl; + } + catch (Tango::DevFailed &df) { + ERROR_STREAM << "Failed to add dynamic attributes: " << df << endl; + m_currStatus = "Failed to add dynamic attributes. See log for details"; + m_state = Tango::FAULT; + return; + } + catch (...) { + ERROR_STREAM << "Unknown exception when adding dynamic attributes" << endl; + m_currStatus = "Failed to add dynamic attributes. Unknown error"; + m_state = Tango::FAULT; + return; + } + // Initialize maps in manager class for all channels + try { + for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++) { + // Initialize with default values + m_manager->set_channel(l_cpt, 0.0); + if (enableRamps) { + m_manager->set_speed(l_cpt, 0.0); + m_manager->set_initial(l_cpt, 0.0); + } + } + } + catch (Tango::DevFailed &df) { + ERROR_STREAM << "Failed to initialize channel maps: " << df << endl; + m_currStatus = "Failed to initialize channel maps. See log for details"; + m_state = Tango::FAULT; + return; + } // Get memorized values from database for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++) @@ -531,6 +594,7 @@ void SingleShotAO::init_device() try { 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; (m_manager->*setter)(l_cpt, val); } catch (...) {