diff --git a/src/ADLinkContinuousAO.cpp b/src/ADLinkContinuousAO.cpp old mode 100644 new mode 100755 index d9a634279e9b0a9d5f6c54ce01c7febbc16e7222..278c0af748d90309cb27db61cf65d7631b6e3f66 --- a/src/ADLinkContinuousAO.cpp +++ b/src/ADLinkContinuousAO.cpp @@ -26,9 +26,9 @@ ADLinkContinuousAO::~ADLinkContinuousAO (void) void ADLinkContinuousAO::handle_error (const asl::DAQException& de) { cout<<"error occured during acquisition"<<endl; - this->lock_data(); + lock_data(); err_ctr++; - this->unlock_data(); + unlock_data(); _ASL_TO_TANGO_EXCEPTION(de, df); ERROR_STREAM<<"error occured during acquisition"<<endl; ERROR_STREAM<<df<<endl; diff --git a/src/ADLinkContinuousAO.h b/src/ADLinkContinuousAO.h old mode 100644 new mode 100755 index 95544f5f9a8cd621b7b043ec279c808a3258d112..59eeff3d0f8c2cca46146d2278cf3f2ca9d2a8bd --- a/src/ADLinkContinuousAO.h +++ b/src/ADLinkContinuousAO.h @@ -24,14 +24,14 @@ public: */ inline void lock_data(void) { - this->data_lock_.acquire(); + data_lock_.acquire(); }; /** * Release the mutex */ inline void unlock_data(void) { - this->data_lock_.release(); + data_lock_.release(); }; unsigned long err_ctr; private: diff --git a/src/RetrigAO.cpp b/src/RetrigAO.cpp old mode 100644 new mode 100755 index 3c710dc1bc954c75d2aafc3e22e9ab70b5b8eeba..5d5a0dd652edb652d809309adb274c3e4da2bd9e --- a/src/RetrigAO.cpp +++ b/src/RetrigAO.cpp @@ -200,6 +200,8 @@ void RetrigAO::init_device() ch5 = 0; ch6 = 0; ch7 = 0; + m_error_message = "An error has occured"; + // Initialise variables to default values //-------------------------------------------- get_device_property(); @@ -216,7 +218,7 @@ void RetrigAO::init_device() attr_frequency.set_write_value(frequency); write_frequency(attr_frequency); - this->init_board(); + init_board(); } @@ -1072,7 +1074,7 @@ void RetrigAO::get_device_property() //----------------------------------------------------------------------------- void RetrigAO::always_executed_hook() { - this->set_internal_state(); + set_internal_state(); } //+---------------------------------------------------------------------------- @@ -1091,7 +1093,7 @@ void RetrigAO::read_attr_hardware(vector<long> &attr_list) //--------------------------------- ao->lock_data(); - this->err_ctr = ao->err_ctr; + err_ctr = ao->err_ctr; ao->unlock_data(); @@ -1121,7 +1123,7 @@ void RetrigAO::write_frequency(Tango::WAttribute &attr) DEBUG_STREAM << "RetrigAO::write_frequency(Tango::WAttribute &attr) entering... "<< endl; attr.get_write_value(frequency); store_value_as_property(frequency, "Frequency"); - this->init_board(); + init_board(); } //+---------------------------------------------------------------------------- @@ -1149,7 +1151,7 @@ void RetrigAO::write_bufferDepth(Tango::WAttribute &attr) DEBUG_STREAM << "RetrigAO::write_bufferDepth(Tango::WAttribute &attr) entering... "<< endl; attr.get_write_value(bufferDepth); store_value_as_property(bufferDepth, "BufferDepth"); - this->init_board(); + init_board(); } //+---------------------------------------------------------------------------- @@ -1176,7 +1178,7 @@ void RetrigAO::read_useBoardFifo(Tango::Attribute &attr) { DEBUG_STREAM << "RetrigAO::read_useBoardFifo(Tango::Attribute &attr) entering... "<< endl; // the information about data loading on fifo in available only after Start command. - if(this->get_state() == Tango::RUNNING) + if(get_state() == Tango::RUNNING) attr.set_value(&use_fifo); else attr.set_quality(Tango::ATTR_INVALID); @@ -1433,10 +1435,10 @@ void RetrigAO::start() // give the configuration _ASL_TRY_ACTION ( - ao->configure(this->config), + ao->configure(config), "configure", "RetrigAO::start", - this->set_internal_state() + set_internal_state() ); _ASL_TRY_ACTION @@ -1444,12 +1446,12 @@ void RetrigAO::start() ao->start(), "start", "RetrigAO::start", - this->set_internal_state() + set_internal_state() ); // get if the output data have been loaded in the onboard FIFO. // depends on the size of the buffer. - this->use_fifo = ao->use_board_fifo(); + use_fifo = ao->use_board_fifo(); } @@ -1472,10 +1474,10 @@ void RetrigAO::stop() ao->stop(), "stop", "RetrigAO::stop", - this->set_internal_state() + set_internal_state() );*/ - if(this->get_state() == Tango::RUNNING) - this->stop_with_zero_forcing(); + if(get_state() == Tango::RUNNING) + stop_with_zero_forcing(); } //+------------------------------------------------------------------ @@ -1493,18 +1495,18 @@ void RetrigAO::stop_with_zero_forcing() DEBUG_STREAM << "RetrigAO::stop(): entering... !" << endl; // save the configuration - //this->config = ao->configuration(); + //config = ao->configuration(); _ASL_TRY_ACTION ( ao->stop(), "stop", "RetrigAO::stop_with_zero_forcing", - this->set_internal_state() + set_internal_state() ); // get the current configuration - this->stop_config = ao->configuration(); + stop_config = ao->configuration(); // set buffer with 0 volts asl::AOScaledData data(bufferDepth); @@ -1512,33 +1514,33 @@ void RetrigAO::stop_with_zero_forcing() (data)[i] = 0; if(channel0Enable) - this->stop_config.set_channel_periodic_data(0, data); + stop_config.set_channel_periodic_data(0, data); if(channel1Enable) - this->stop_config.set_channel_periodic_data(1, data); + stop_config.set_channel_periodic_data(1, data); if(channel2Enable) - this->stop_config.set_channel_periodic_data(2, data); + stop_config.set_channel_periodic_data(2, data); if(channel3Enable) - this->stop_config.set_channel_periodic_data(3, data); + stop_config.set_channel_periodic_data(3, data); if(channel4Enable) - this->stop_config.set_channel_periodic_data(4, data); + stop_config.set_channel_periodic_data(4, data); if(channel5Enable) - this->stop_config.set_channel_periodic_data(5, data); + stop_config.set_channel_periodic_data(5, data); if(channel6Enable) - this->stop_config.set_channel_periodic_data(6, data); + stop_config.set_channel_periodic_data(6, data); if(channel7Enable) - this->stop_config.set_channel_periodic_data(7, data); + stop_config.set_channel_periodic_data(7, data); // configure trigger mode (no trigger to generate immediatly) - this->stop_config.disable_retrigger(); - this->stop_config.set_trigger_source(adl::internal_software); + stop_config.disable_retrigger(); + stop_config.set_trigger_source(adl::internal_software); // give the configuration the new channel _ASL_TRY_ACTION ( - ao->configure(this->stop_config), + ao->configure(stop_config), "configure", "RetrigAO::stop_with_zero_forcing", - this->set_internal_state() + set_internal_state() ); _ASL_TRY_ACTION @@ -1546,7 +1548,7 @@ void RetrigAO::stop_with_zero_forcing() ao->start(), "start", "RetrigAO::stop_with_zero_forcing", - this->set_internal_state() + set_internal_state() ); _ASL_TRY_ACTION @@ -1554,11 +1556,17 @@ void RetrigAO::stop_with_zero_forcing() ao->stop(), "stop", "RetrigAO::stop_with_zero_forcing", - this->set_internal_state() + set_internal_state() ); //correction bug: aftera stop, start doesn't work !! - this->init_board(); + init_board(); +} + +void RetrigAO::raise_error(std::string p_error_message) +{ + m_error_message = p_error_message; + set_state(Tango::FAULT); } //+------------------------------------------------------------------ @@ -1569,19 +1577,15 @@ void RetrigAO::stop_with_zero_forcing() void RetrigAO::init_board(void) { - this->delete_device(); + delete_device(); //- create a continuous analog output daq ao = new ADLinkContinuousAO(this); //- check memory allocation if (ao == 0) { - this->set_internal_state(); - Tango::Except::throw_exception( - (const char*)("OUT_OF_MEMORY"), - (const char*)("out of memory error"), - (const char*)("RetrigAO::init_device") - ); + raise_error("RetrigAO::init_board\nout of memory error while initializing ADLinkContinuousAO"); + return; } asl::ContinuousAOConfig _config; @@ -1595,13 +1599,8 @@ void RetrigAO::init_board(void) ch7 = new double[bufferDepth]; if(ch0 == 0 || ch1 == 0 || ch2 == 0 || ch3 == 0 || ch4 == 0 || ch5 == 0 ||ch6 == 0 || ch7 == 0) { - this->set_internal_state(); - this->delete_device(); - Tango::Except::throw_exception( - (const char*)("OUT_OF_MEMORY"), - (const char*)("out of memory error"), - (const char*)("RetrigAO::init_device") - ); + raise_error("RetrigAO::init_device\nout of memory error while initializing channel's datas"); + return; } @@ -1619,10 +1618,10 @@ void RetrigAO::init_board(void) (default_waveformA)[i] = ::sin((double)i * 2. * 3.14159 / (double) bufferDepth) * max_valA; } - ACE_OS::memcpy(this->ch0, default_waveformA.base(), default_waveformA.size()); - ACE_OS::memcpy(this->ch1, default_waveformA.base(), default_waveformA.size()); - ACE_OS::memcpy(this->ch2, default_waveformA.base(), default_waveformA.size()); - ACE_OS::memcpy(this->ch3, default_waveformA.base(), default_waveformA.size()); + ACE_OS::memcpy(ch0, default_waveformA.base(), default_waveformA.size()); + ACE_OS::memcpy(ch1, default_waveformA.base(), default_waveformA.size()); + ACE_OS::memcpy(ch2, default_waveformA.base(), default_waveformA.size()); + ACE_OS::memcpy(ch3, default_waveformA.base(), default_waveformA.size()); // default waveform for group B (channel 4 to 7) asl::AOScaledData default_waveformB(bufferDepth); @@ -1641,10 +1640,10 @@ void RetrigAO::init_board(void) { default_waveformB[i] = -max_valB + 0.01; } - ACE_OS::memcpy(this->ch4, default_waveformB.base(), default_waveformB.size()); - ACE_OS::memcpy(this->ch5, default_waveformB.base(), default_waveformB.size()); - ACE_OS::memcpy(this->ch6, default_waveformB.base(), default_waveformB.size()); - ACE_OS::memcpy(this->ch7, default_waveformB.base(), default_waveformB.size()); + ACE_OS::memcpy(ch4, default_waveformB.base(), default_waveformB.size()); + ACE_OS::memcpy(ch5, default_waveformB.base(), default_waveformB.size()); + ACE_OS::memcpy(ch6, default_waveformB.base(), default_waveformB.size()); + ACE_OS::memcpy(ch7, default_waveformB.base(), default_waveformB.size()); //--------------------------channels config------------------------------------ asl::ActiveAOChannel ac; @@ -1665,7 +1664,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch0[i] = 0; - this->load_waveform(ch0,"Channel0Waveform"); + load_waveform(ch0,"Channel0Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch0[i]; @@ -1708,7 +1707,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch1[i] = 0; - this->load_waveform(ch1,"Channel1Waveform"); + load_waveform(ch1,"Channel1Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch1[i]; @@ -1748,7 +1747,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch2[i] = 0; - this->load_waveform(ch2,"Channel2Waveform"); + load_waveform(ch2,"Channel2Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch2[i]; @@ -1788,7 +1787,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch3[i] = 0; - this->load_waveform(ch3,"Channel3Waveform"); + load_waveform(ch3,"Channel3Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch3[i]; @@ -1829,7 +1828,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch4[i] = 0; - this->load_waveform(ch4,"Channel4Waveform"); + load_waveform(ch4,"Channel4Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch4[i]; @@ -1870,7 +1869,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch5[i] = 0; - this->load_waveform(ch5,"Channel5Waveform"); + load_waveform(ch5,"Channel5Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch5[i]; @@ -1911,7 +1910,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch6[i] = 0; - this->load_waveform(ch6,"Channel6Waveform"); + load_waveform(ch6,"Channel6Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch6[i]; @@ -1951,7 +1950,7 @@ void RetrigAO::init_board(void) for (int i = 0; i < bufferDepth; i++) ch7[i] = 0; - this->load_waveform(ch7,"Channel7Waveform"); + load_waveform(ch7,"Channel7Waveform"); asl::AOScaledData data(bufferDepth); for(i=0; i<bufferDepth; i++) data[i] = ch7[i]; @@ -2018,23 +2017,40 @@ void RetrigAO::init_board(void) //config.set_stop_mode (adl::wait_end_waveform); DEBUG_STREAM<<"RetrigAO::init_device : init acq"<<std::endl; - _ASL_TRY_ACTION - ( - ao->init(adl::DAQ2502, boardNum), - "init", - "RetrigAO::init_device", - this->set_internal_state() - ); - - this->config = _config; - /*DEBUG_STREAM<<"RetrigAO::init_device : config acq"<<std::endl; - _ASL_TRY_ACTION - ( - ao->configure(_config), - "configure", - "RetrigAO::init_device", - this->set_internal_state() - ); */ + try{ + _ASL_TRY_ACTION + ( + ao->init(adl::DAQ2502, boardNum), + "init", + "RetrigAO::init_device", + set_internal_state() + ); + + config = _config; + + /*DEBUG_STREAM<<"RetrigAO::init_device : config acq"<<std::endl; + try + { + _ASL_TRY_ACTION + ( + ao->configure(_config), + "configure", + "RetrigAO::init_device", + set_internal_state() + ); + } + catch (...) + { + raise_error("RetrigAO::init_device\nError while configurating drivers"); + return; + } + */ + } + catch (...) + { + raise_error("RetrigAO::init_device\nError while initializing drivers"); + return; + } } //+------------------------------------------------------------------ /** @@ -2085,7 +2101,7 @@ void RetrigAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin) ao->stop(), "stop", "RetrigAO::set_aoscaled_data", - this->set_internal_state() + set_internal_state() ); // get the configuration @@ -2128,7 +2144,7 @@ void RetrigAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin) //NB: if a chan hasn't been enable with properties, 'ao' will do nothing // cout << "RetrigAO::set_aoscaled_data - set periodic channel : " <<chan - '0'<< endl; - this->config.set_channel_periodic_data(chan - '0', data); + config.set_channel_periodic_data(chan - '0', data); // copy the new data in the attributes of the device. switch(chan) @@ -2136,42 +2152,42 @@ void RetrigAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin) case '0': ::memcpy(ch0, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch0, "Channel0Waveform"); + save_waveform(ch0, "Channel0Waveform"); break; case '1': ::memcpy(ch1, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch1, "Channel1Waveform"); + save_waveform(ch1, "Channel1Waveform"); break; case '2': ::memcpy(ch2, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch2, "Channel2Waveform"); + save_waveform(ch2, "Channel2Waveform"); break; case '3': ::memcpy(ch3, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch3, "Channel3Waveform"); + save_waveform(ch3, "Channel3Waveform"); break; case '4': ::memcpy(ch4, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch4, "Channel4Waveform"); + save_waveform(ch4, "Channel4Waveform"); break; case '5': ::memcpy(ch5, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch5, "Channel5Waveform"); + save_waveform(ch5, "Channel5Waveform"); break; case '6': ::memcpy(ch6, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch6, "Channel6Waveform"); + save_waveform(ch6, "Channel6Waveform"); break; case '7': ::memcpy(ch7, data.base(), data.size()); //save the waveform in the database - this->save_waveform(ch7, "Channel7Waveform"); + save_waveform(ch7, "Channel7Waveform"); break; default: Tango::Except::throw_exception( @@ -2182,14 +2198,14 @@ void RetrigAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin) break; } - // this->config = _config; + // config = _config; /* DEBUG_STREAM<<"RetrigAO::init_device : init acq"<<std::endl; _ASL_TRY_ACTION ( ao->init(adl::DAQ2502, boardNum), "init", "RetrigAO::init_device", - this->set_internal_state() + set_internal_state() ); // give the configuration the new channel @@ -2198,7 +2214,7 @@ void RetrigAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin) ao->configure(_config), "configure", "RetrigAO::set_aoscaled_data", - this->set_internal_state() + set_internal_state() );*/ } @@ -2211,30 +2227,30 @@ void RetrigAO::set_internal_state(void) { if(ao == 0) { - this->set_state(Tango::UNKNOWN); - this->set_status("The acquisition was not initialized properly"); + set_state(Tango::UNKNOWN); + set_status("The acquisition was not initialized properly"); } else { switch(ao->state()) { case asl::ContinuousAO::STANDBY: - this->set_state(Tango::STANDBY); - this->set_status("The generation is stopped"); + set_state(Tango::STANDBY); + set_status("The generation is stopped"); break; case asl::ContinuousAO::RUNNING: case asl::ContinuousAO::ABORTING: - this->set_state(Tango::RUNNING); - this->set_status("The generation is running"); + set_state(Tango::RUNNING); + set_status("The generation is running"); break; case asl::ContinuousAO::FAULT: - this->set_state(Tango::FAULT); - this->set_status("An error has occured"); - break; + set_state(Tango::FAULT); + set_status(m_error_message); + break; case asl::ContinuousAO::UNKNOWN: default: - this->set_state(Tango::UNKNOWN); - this->set_status("The generation is in an unknown state"); + set_state(Tango::UNKNOWN); + set_status("The generation is in an unknown state"); break; } } @@ -2268,7 +2284,7 @@ void RetrigAO::save_waveform(double* waveform, string wfm_channel) "ContinuousAO::save_waveform", );*/ // save temporaly in file because of slow tangodb - string device_name = this->get_name(); + string device_name = get_name(); long idx = 0; while( (idx =device_name.find("/", idx)) != string::npos) { @@ -2293,7 +2309,7 @@ void RetrigAO::save_waveform(double* waveform, string wfm_channel) (const char *)"RetrigAO::save_waveform"); } - for(int i=0; i<this->bufferDepth; i++) + for(int i=0; i<bufferDepth; i++) file<<waveform[i] << endl; file.close(); @@ -2319,7 +2335,7 @@ void RetrigAO::save_waveform(double* waveform, string wfm_channel) void RetrigAO::load_waveform(double* waveform, string wfm_channel) { // saved temporaly in file because of slow tangodb - string device_name = this->get_name(); + string device_name = get_name(); long idx = 0; while( (idx =device_name.find("/", idx)) != string::npos) { @@ -2333,7 +2349,7 @@ void RetrigAO::load_waveform(double* waveform, string wfm_channel) string fileline; if(! file.fail() ) // file has been found { - for(int i=0; i<this->bufferDepth; i++) + for(int i=0; i<bufferDepth; i++) { getline(file, fileline); waveform[i] = XString<double>::convertFromString(fileline); diff --git a/src/RetrigAO.h b/src/RetrigAO.h old mode 100644 new mode 100755 index 53015b07ba86d2a2d25b4afbb68bd16e26a599e2..ccbd460a9b0450d56cd16d6773fb8fb4db099c0e --- a/src/RetrigAO.h +++ b/src/RetrigAO.h @@ -539,6 +539,7 @@ protected : ADLinkContinuousAO* ao; void set_internal_state(void); void stop_with_zero_forcing(); + void raise_error(std::string p_error_message); double* ch0; double* ch1; double* ch2; @@ -549,6 +550,7 @@ protected : double* ch7; double err_ctr; short use_fifo; + std::string m_error_message; //- Store the values into the property //- Properties stuff int FindIndexFromPropertyName(Tango::DbData& dev_prop, string property_name);