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 65c1bcf128543bce135e2f92df5a32c85b5ec3e7..294ac6d2bc2b723f556902746d03a58747d0258c --- a/src/ADLinkContinuousAO.h +++ b/src/ADLinkContinuousAO.h @@ -23,14 +23,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/ContinuousAO.cpp b/src/ContinuousAO.cpp old mode 100644 new mode 100755 index 1adec9072e7758e74b560dcd60aa12f5c5c2695a..0a5aee62ba10faec4b1b5621024b4aede90cc7ff --- a/src/ContinuousAO.cpp +++ b/src/ContinuousAO.cpp @@ -167,6 +167,7 @@ void ContinuousAO::init_device() ch5 = 0; ch6 = 0; ch7 = 0; + m_error_message = "An error has occured"; // Initialise variables to default values //-------------------------------------------- @@ -178,12 +179,8 @@ void ContinuousAO::init_device() //- 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*)("ContinuousAO::init_device") - ); + on_fault("ContinuousAO::init_device\nout of memory error while initializing ADLinkContinuousAO"); + return; } asl::ContinuousAOConfig config; @@ -197,13 +194,8 @@ void ContinuousAO::init_device() 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*)("ContinuousAO::init_device") - ); + on_fault("ContinuousAO::init_device\nout of memory error while initializing channel's datas"); + return; } @@ -221,10 +213,10 @@ void ContinuousAO::init_device() (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 A (channel 4 to 7) asl::AOScaledData default_waveformB(bufferDepth); @@ -243,10 +235,10 @@ void ContinuousAO::init_device() { 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; @@ -538,26 +530,26 @@ void ContinuousAO::init_device() config.set_output_rate(frequency); DEBUG_STREAM<<"ContinuousAO::init_device : init acq"<<std::endl; - _ASL_TRY //_ACTION - ( - ao->init(adl::DAQ2502, boardNum), - "init", - "ContinuousAO::init_device" //, - // this->set_internal_state() - ); + try{ + ao->init(adl::DAQ2502, boardNum); + + DEBUG_STREAM<<"ContinuousAO::init_device : config acq"<<std::endl; + try{ + ao->configure(config); + } + catch (...) + { + on_fault("ContinuousAO::init_device\nError while configuring driver"); + return; + } + } + catch (...) + { + on_fault("ContinuousAO::init_device\nError while initializing the driver"); + return; + } - //ao->configure(config); - - DEBUG_STREAM<<"ContinuousAO::init_device : config acq"<<std::endl; - _ASL_TRY //_ACTION - ( - ao->configure(config), - "configure", - "ContinuousAO::init_device" //, - //this->set_internal_state() - ); - - + //ao->configure(config); } @@ -1056,7 +1048,7 @@ void ContinuousAO::get_device_property() //----------------------------------------------------------------------------- void ContinuousAO::always_executed_hook() { - this->set_internal_state(); + set_internal_state(); } //+---------------------------------------------------------------------------- @@ -1075,7 +1067,7 @@ void ContinuousAO::read_attr_hardware(vector<long> &attr_list) //--------------------------------- ao->lock_data(); - this->err_ctr = ao->err_ctr; + err_ctr = ao->err_ctr; ao->unlock_data(); @@ -1160,7 +1152,7 @@ void ContinuousAO::read_attr(Tango::Attribute &attr) else if (attr_name == "useBoardFifo") { // 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); @@ -1232,12 +1224,12 @@ void ContinuousAO::start() ao->start(), "start", "ContinuousAO::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(); } @@ -1260,7 +1252,7 @@ void ContinuousAO::stop() ao->stop(), "stop", "ContinuousAO::stop", - this->set_internal_state() + set_internal_state() ); } @@ -1314,7 +1306,7 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin ao->stop(), "stop", "ContinuousAO::set_aoscaled_data", - this->set_internal_state() + set_internal_state() ); // get the configuration @@ -1333,42 +1325,42 @@ void ContinuousAO::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( @@ -1385,7 +1377,7 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin ao->configure(config), "configure", "ContinuousAO::set_aoscaled_data", - this->set_internal_state() + set_internal_state() ); } @@ -1398,30 +1390,30 @@ void ContinuousAO::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"); + 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; } } @@ -1457,4 +1449,10 @@ void ContinuousAO::save_waveform(double* waveform, string wfm_channel) "ContinuousAO::save_waveform", ); } + +void ContinuousAO::on_fault(std::string p_error_message) +{ + m_error_message = p_error_message; + set_state(Tango::FAULT); +} } // namespace diff --git a/src/ContinuousAO.h b/src/ContinuousAO.h old mode 100644 new mode 100755 index d5bf55952960e0bfea3d45a831540ac158ae4016..2b4ad6ea95a063f584674d95f5552eeb01c29857 --- a/src/ContinuousAO.h +++ b/src/ContinuousAO.h @@ -326,6 +326,7 @@ public : ADLinkContinuousAO* ao; // asl::ContinuousAOConfig* config; void set_internal_state(void); + void on_fault(std::string p_error_message); // save a channel waveform in the database void ContinuousAO::save_waveform(double* waveform, string wfm_channel); double* ch0; @@ -338,10 +339,7 @@ public : double* ch7; double err_ctr; short use_fifo; - - - - + std::string m_error_message; protected : // Add your own data members here