Skip to content
Snippets Groups Projects
Commit 3e919f60 authored by Sonia Minolli's avatar Sonia Minolli
Browse files

Add saturation management (TANGODEVIC-1238)

parent d21ab0b4
Branches
Tags
No related merge requests found
......@@ -202,7 +202,6 @@ void Spectrometer::init_device()
}
catch (...)
{
ERROR_STREAM << "DLL initialization failed - unknown error" << std::endl;
set_status ("DLL initialization failed [unknown error]");
set_state (Tango::FAULT);
......@@ -226,6 +225,7 @@ void Spectrometer::init_device()
set_status("initialization failed [see device log for details]");
return;
}
//- initialize trigger mode
try
{
......@@ -259,6 +259,8 @@ void Spectrometer::init_device()
cfg.wrapper = m_wrapper;
#endif
cfg.spectrometer_index = spectrometerIndex;
cfg.stop_acq_on_saturation = stopAcqOnSaturation;
cfg.alarm_on_saturation = alarmOnSaturation;
//- allocate the task
DEBUG_STREAM << "Spectrometer::init_device::allocating task" << std::endl;
......@@ -315,6 +317,8 @@ void Spectrometer::get_device_property()
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("TriggerMode"));
dev_prop.push_back(Tango::DbDatum("SpectrometerIndex"));
dev_prop.push_back(Tango::DbDatum("StopAcqOnSaturation"));
dev_prop.push_back(Tango::DbDatum("AlarmOnSaturation"));
// Call database and extract values
//--------------------------------------------
......@@ -347,6 +351,28 @@ void Spectrometer::get_device_property()
// And try to extract SpectrometerIndex value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> spectrometerIndex;
// Try to initialize StopAcqOnSaturation from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> stopAcqOnSaturation;
else {
// Try to initialize StopAcqOnSaturation from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> stopAcqOnSaturation;
}
// And try to extract StopAcqOnSaturation value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> stopAcqOnSaturation;
// Try to initialize AlarmOnSaturation from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> alarmOnSaturation;
else {
// Try to initialize AlarmOnSaturation from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> alarmOnSaturation;
}
// And try to extract AlarmOnSaturation value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> alarmOnSaturation;
// End of Automatic code generation
......@@ -355,6 +381,9 @@ void Spectrometer::get_device_property()
// Check device property data members init
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, Tango::DevUShort(1), "SpectrometerIndex");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, Tango::DevUShort(0), "TriggerMode");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, Tango::DevBoolean(1), "StopAcqOnSaturation");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, Tango::DevBoolean(0), "AlarmOnSaturation");
//-Check the trigger mode
......@@ -910,6 +939,4 @@ void Spectrometer::get_task_values()
}
} // namespace
......@@ -70,6 +70,7 @@ namespace Spectrometer_ns
* Tango::RUNNING : acquisition is running
* Tango::STANDBY : acquisition is in standby
* Tango::FAULT : error occurred during acquisition time
* Tango::ALARM : Acquired spectrum is saturated (only if AlarmOnSaturation flag is set to true)
*/
......@@ -123,6 +124,14 @@ public :
* USB index if there is several spectrometers
*/
Tango::DevUShort spectrometerIndex;
/**
* This property enables/disables the acquisition stop on spectrum saturation.
*/
Tango::DevBoolean stopAcqOnSaturation;
/**
* Device change to ALARM state if saturated
*/
Tango::DevBoolean alarmOnSaturation;
//@}
/**
......
......@@ -545,6 +545,35 @@ void SpectrometerClass::set_default_property()
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "StopAcqOnSaturation";
prop_desc = "This property enables/disables the acquisition stop on spectrum saturation.";
prop_def = "true";
vect_data.clear();
vect_data.push_back("true");
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "AlarmOnSaturation";
prop_desc = "Device change to ALARM state if saturated";
prop_def = "false";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
}
//+----------------------------------------------------------------------------
//
......
......@@ -106,7 +106,7 @@ void SpectrometerTask::process_message( yat::Message& msg )
//- THREAD_TIMEOUT -------------------
case yat::TASK_TIMEOUT:
{
//- not used in this example
//- not used here
}
break;
......@@ -275,6 +275,7 @@ void SpectrometerTask::periodic_job_i()
int nb_spec = m_cfg.wrapper.highSpdAcq_GetNumberOfSpectraAcquired();
int nb_points = 0;
bool prob = false;
bool l_saturated = false;
//- check snap mode
if (m_is_snap == true)
......@@ -286,21 +287,35 @@ void SpectrometerTask::periodic_job_i()
{
for (unsigned short idx = 0; idx <= m_frames_number-1; idx++)
{
//- get intensity
if (m_cfg.wrapper.highSpdAcq_IsSaturated(m_cfg.spectrometer_index) == false)
//- check wether acquired spectrum is saturated
l_saturated = m_cfg.wrapper.highSpdAcq_IsSaturated(idx);
if ( (!l_saturated) || // no saturation
(l_saturated && !m_cfg.stop_acq_on_saturation)) // saturation but compute spectrum
{
//- get intensity
m_intensity_array = m_cfg.wrapper.highSpdAcq_GetSpectrum(idx);
m_buff_snap[idx] = m_intensity_array.getDoubleValues();
nb_points = m_intensity_array.getLength();
}
else
{
prob = true;
m_cfg.host_device->set_status("HARDWARE SATURATION - The acquired spectrum is saturated!");
if (m_cfg.alarm_on_saturation)
{
m_cfg.host_device->set_state(Tango::ALARM);
}
else
{
m_cfg.host_device->set_state(Tango::FAULT);
m_cfg.host_device->set_status("HARDWARE FAILURE - The spectrum is saturated");
THROW_DEVFAILED(_CPTC("HARDWARE FAILURE"),
_CPTC("One spectrum is saturated !!!"),
}
THROW_DEVFAILED(
_CPTC("HARDWARE SATURATION"),
_CPTC("The acquired spectrum is saturated!"),
_CPTC("SpectrometerTask::periodic_job_i "));
prob = true;
}
}
......@@ -328,8 +343,26 @@ void SpectrometerTask::periodic_job_i()
m_data.lambda = m_lambda_array.getDoubleValues();
m_data.lambdaPtsNb = m_lambda_array.getLength();
}
// set state & status
if (l_saturated)
{
if (m_cfg.alarm_on_saturation)
{
m_cfg.host_device->set_state(Tango::ALARM);
m_cfg.host_device->set_status("HARDWARE SATURATION - The acquired spectrum is saturated!");
}
else
{
m_cfg.host_device->set_state(Tango::STANDBY);
m_cfg.host_device->set_status("The acquisition is finished");
m_cfg.host_device->set_status("TThe acquisition (saturated) is finished.");
}
}
else
{
m_cfg.host_device->set_state(Tango::STANDBY);
m_cfg.host_device->set_status("The acquisition is finished.");
}
}
}
}
......@@ -344,22 +377,27 @@ void SpectrometerTask::periodic_job_i()
//- get data
if (nb_spec == 1)
{
if (m_cfg.wrapper.highSpdAcq_IsSaturated(m_cfg.spectrometer_index) == false)
//- check wether acquired spectrum is saturated
l_saturated = m_cfg.wrapper.highSpdAcq_IsSaturated(nb_spec-1);
if ( (!l_saturated) || // no saturation
(l_saturated && !m_cfg.stop_acq_on_saturation)) // saturation but continue acquisition
{
m_intensity_array = m_cfg.wrapper.highSpdAcq_GetSpectrum(0);
m_intensity_array = m_cfg.wrapper.highSpdAcq_GetSpectrum(nb_spec-1);
m_lambda_array = m_cfg.wrapper.getWavelengths(m_cfg.spectrometer_index);
DoubleBufPtr buf_ptr = new DoubleBuf;
buf_ptr->capacity(m_data.intensityPtsNb);
buf_ptr->force_length(m_data.intensityPtsNb);
*buf_ptr = m_data.intensity;
{ //- set data
yat::AutoMutex<> _lock(m_mtx);
m_data.intensity = m_intensity_array.getDoubleValues();
m_data.intensityPtsNb = m_intensity_array.getLength();
m_data.lambda = m_lambda_array.getDoubleValues();
m_data.lambdaPtsNb = m_lambda_array.getLength();
// put spectra in history buffer
DoubleBufPtr buf_ptr = new DoubleBuf;
buf_ptr->capacity(m_data.intensityPtsNb);
buf_ptr->force_length(m_data.intensityPtsNb);
*buf_ptr = m_data.intensity;
m_data.m_intensity_buf.push_back(buf_ptr);
if( m_max_buffer_depth > 0 && m_data.m_intensity_buf.size() > m_max_buffer_depth )
......@@ -370,25 +408,56 @@ void SpectrometerTask::periodic_job_i()
}
}
// set state & status
if (!l_saturated)
{
m_cfg.host_device->set_state(Tango::RUNNING);
m_cfg.host_device->set_status("The acquisition is running...");
}
else
{
if (m_cfg.alarm_on_saturation)
{
m_cfg.host_device->set_state(Tango::ALARM);
m_cfg.host_device->set_status("HARDWARE SATURATION - The acquired spectrum is saturated!");
}
else
{
m_cfg.host_device->set_state(Tango::RUNNING);
m_cfg.host_device->set_status("The acquisition (saturated) is running...");
}
}
post(kDO_ACQ_MSG);
}
else
{
// stop if saturated
if (m_cfg.alarm_on_saturation)
{
m_cfg.host_device->set_state(Tango::ALARM);
}
else
{
m_cfg.host_device->set_state(Tango::FAULT);
//post(kDO_ACQ_MSG);
m_cfg.host_device->set_status("HARDWARE FAILURE - The spectrum is saturated");
THROW_DEVFAILED(_CPTC("HARDWARE FAILURE"),
_CPTC("The spectrum is saturated !!!"),
}
m_cfg.host_device->set_status("HARDWARE SATURATION - The acquired spectrum is saturated!");
THROW_DEVFAILED(
_CPTC("HARDWARE SATURATION"),
_CPTC("The acquired spectrum is saturated!"),
_CPTC("SpectrometerTask::periodic_job_i "));
}
}
else
{
m_cfg.host_device->set_state(Tango::FAULT);
m_cfg.host_device->set_status("HARDWARE FAILURE - The spectrum is not present");
m_cfg.host_device->set_status("HARDWARE FAILURE - No spectra acquired!");
THROW_DEVFAILED(_CPTC("HARDWARE FAILURE"),
_CPTC("The spectrum is not present"),
THROW_DEVFAILED(
_CPTC("HARDWARE FAILURE"),
_CPTC("No spectra acquired!"),
_CPTC("SpectrometerTask::periodic_job_i "));
}
}
......@@ -490,7 +559,7 @@ void SpectrometerTask::start_i()
{
DEBUG_STREAM << "SpectrometerTask::start_i" << std::endl;
m_cfg.host_device->set_state(Tango::RUNNING);
m_cfg.host_device->set_status("The acquisition is running");
m_cfg.host_device->set_status("The acquisition is running...");
m_is_snap = false;
m_is_acq = true;
m_data.m_intensity_buf.clear();
......@@ -519,7 +588,7 @@ void SpectrometerTask::snap_i()
//- snap
m_cfg.host_device->set_state(Tango::RUNNING);
m_cfg.host_device->set_status("The device is snapping");
m_cfg.host_device->set_status("The device is snapping...");
m_is_snap = true;
//- buffer preparation
......
......@@ -59,7 +59,9 @@ public:
#ifndef NO_DRIVER
wrapper(),
#endif
spectrometer_index(0)
spectrometer_index(0),
stop_acq_on_saturation(true),
alarm_on_saturation(false)
{}
//- copy ctor
......@@ -81,6 +83,8 @@ public:
wrapper = src.wrapper;
#endif
spectrometer_index = src.spectrometer_index;
stop_acq_on_saturation = src.stop_acq_on_saturation;
alarm_on_saturation = src.alarm_on_saturation;
return *this;
}
......@@ -98,6 +102,13 @@ public:
//- spectrometer index
unsigned short spectrometer_index;
//- saturation flag
bool stop_acq_on_saturation;
//- Alarm flag
bool alarm_on_saturation;
} Config;
//- the data return values for monitoring
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment