Skip to content
Snippets Groups Projects
Commit 03bbea23 authored by BAHJI's avatar BAHJI
Browse files

[ICATHALES-213] The device must be in FAULT state if something goes wrong...

[ICATHALES-213] The device must be in FAULT state if something goes wrong during device initialization
parent dab753f1
Branches
Tags
1 merge request!1[ICATHALES-213] The device must be in FAULT state if something goes wrong...
......@@ -114,8 +114,8 @@ namespace SingleShotDIO
out = 0;
}
this->set_state(Tango::CLOSE);
this->set_status("The device is not usable");
set_state(Tango::CLOSE);
set_status("The device is not usable");
}
......@@ -129,38 +129,99 @@ namespace SingleShotDIO
void SingleShotDIO::init_device()
{
INFO_STREAM << "SingleShotDIO::SingleShotDIO() create device " << device_name << endl;
m_is_device_initialized = false;
m_status_message.str("");
this->set_state(Tango::UNKNOWN);
this->set_status("The device is not initialized");
set_state(Tango::UNKNOWN);
set_status("The device is not initialized");
//default init
in = 0;
out = 0;
this->_last_out_value = 0;
_last_out_value = 0;
try
{
//ctor input acquisition
in = new asl::SingleShotDI();
if(in == 0)
if(!in)
{
Tango::Except::throw_exception((const char*)("out of memory"),
(const char*)("out of memory error"),
(const char*)("SingleShotDIO::init_device"));
ERROR_STREAM << "SingleShotDIO::init_device() - failed to create SingleShotDI object" << endl;
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << "SingleShotDIO::init_device" << endl;
m_status_message << "Desc: " << "SingleShotDI object - out of memory error" << endl;
return;
}
}
catch(const asl::DAQException& de)
{
Tango::DevFailed df = daq_to_tango_exception(de);
ERROR_STREAM << df<<endl;
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << df.errors[0].origin << endl;
m_status_message << "Desc: " << df.errors[0].desc << endl;
return;
}
catch (...)
{
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << "SingleShotDIO::init_device" << endl;
m_status_message << "Desc: " << "out of memory error" << endl;
return;
}
try
{
//ctor output acquisition
out = new asl::SingleShotDO();
if(out== 0)
if(!out)
{
ERROR_STREAM << "SingleShotDIO::init_device() - failed to create SingleShotDO" << endl;
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << "SingleShotDIO::init_device" << endl;
m_status_message << "Desc: " << "SingleShotDO object - out of memory error" << endl;
return;
}
}
catch(const asl::DAQException& de)
{
Tango::DevFailed df = daq_to_tango_exception(de);
ERROR_STREAM << df<<endl;
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << df.errors[0].origin << endl;
m_status_message << "Desc: " << df.errors[0].desc << endl;
return;
}
catch (...)
{
this->delete_device();
Tango::Except::throw_exception((const char*)("out of memory"),
(const char*)("out of memory error"),
(const char*)("SingleShotDIO::init_device"));
m_status_message << "device initialization failed." << endl;
m_status_message << "Origin: " << "SingleShotDIO::init_device" << endl;
m_status_message << "Desc: " << "Failed to create SingleShotDO object" << endl;
return;
}
// Initialise variables to default values
//--------------------------------------------
try
{
get_device_property();
}
catch (Tango::DevFailed & df)
{
ERROR_STREAM << df << std::endl;
m_status_message << "Initialization failed - <get_device_property> failed [see device log for details]";
return;
}
catch (...)
{
ERROR_STREAM << "Initialization failed - unknown <get_device_property> error" << std::endl;
m_status_message << "Initialization failed [unknown <get_device_property> error]";
return;
}
try
{
......@@ -226,27 +287,25 @@ namespace SingleShotDIO
{
Tango::DevFailed df = daq_to_tango_exception(de);
ERROR_STREAM << df<<endl;
this->delete_device();
Tango::Except::re_throw_exception(df,
(const char*)("device initialization failed"),
(const char*)("caugth asl::DAQException"),
(const char*)("SingleShotDIO::init_device")
);
m_status_message << "device initialization failed ." << endl;
m_status_message << "Origin: " << df.errors[0].origin << endl;
m_status_message << "Desc: " << df.errors[0].desc << endl;
return;
}
catch(...)
{
ERROR_STREAM << "SingleShotDIO::init_device::unknown exception caught"<<std::endl;
this->delete_device();
Tango::Except::throw_exception(
(const char*)("device initialization failed"),
(const char*)("unknown exception caugth"),
(const char*)("SingleShotDIO::init_device")
);
m_status_message << "device initialization failed.\n" << endl;
m_status_message << "Origin: SingleShotDIO::init_device()" << endl;
m_status_message << "Desc: Unknown exception caugth" << endl;
return;
}
this->set_state(Tango::OPEN);
this->set_status("The device is initialized and ready to run");
m_is_device_initialized = true,
set_state(Tango::OPEN);
set_status("The device is initialized and ready to run");
}
......@@ -552,7 +611,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PA");
ls.lvalue[0] = attr_PortA_write;
this->write_port(&ls);
write_port(&ls);
}
else
{
......@@ -587,7 +646,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PB");
ls.lvalue[0] = attr_PortB_write;
this->write_port(&ls);
write_port(&ls);
}
else
Tango::Except::throw_exception(
......@@ -618,7 +677,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PC");
ls.lvalue[0] = attr_PortC_write;
this->write_port(&ls);
write_port(&ls);
}
else
Tango::Except::throw_exception(
......@@ -649,7 +708,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PD");
ls.lvalue[0] = attr_PortD_write;
this->write_port(&ls);
write_port(&ls);
}
else
Tango::Except::throw_exception(
......@@ -680,7 +739,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PE");
ls.lvalue[0] = attr_PortE_write;
this->write_port(&ls);
write_port(&ls);
}
else
Tango::Except::throw_exception(
......@@ -697,7 +756,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PE");
ls.lvalue[0] = attr_PortE_write;
this->write_port(&ls);
write_port(&ls);
}
}
else if (attr_name == "PortF")
......@@ -712,7 +771,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PF");
ls.lvalue[0] = attr_PortF_write;
this->write_port(&ls);
write_port(&ls);
}
else
Tango::Except::throw_exception(
......@@ -729,7 +788,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PF");
ls.lvalue[0] = attr_PortF_write;
this->write_port(&ls);
write_port(&ls);
}
}
else if (attr_name == "PortG")
......@@ -750,7 +809,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PG");
ls.lvalue[0] = attr_PortG_write;
this->write_port(&ls);
write_port(&ls);
}
}
else if (attr_name == "PortH")
......@@ -771,7 +830,7 @@ void SingleShotDIO::write_attr_hardware(vector<long> &attr_list)
ls.lvalue.length(1);
ls.svalue[0] = CORBA::string_dup("PH");
ls.lvalue[0] = attr_PortH_write;
this->write_port(&ls);
write_port(&ls);
}
}
......@@ -1620,22 +1679,22 @@ void SingleShotDIO::write_port(const Tango::DevVarLongStringArray *argin)
case 'E':
value = value;
//- reset byte
this->_last_out_value = this->_last_out_value & 0xFFFFFF00;
_last_out_value = _last_out_value & 0xFFFFFF00;
break;
case 'F':
value = value<<8;
//- reset byte
this->_last_out_value = this->_last_out_value & 0xFFFF00FF;
_last_out_value = _last_out_value & 0xFFFF00FF;
break;
case 'G':
value = value<<16;
//- reset byte
this->_last_out_value = this->_last_out_value & 0xFF00FFFF;
_last_out_value = _last_out_value & 0xFF00FFFF;
break;
case 'H':
value = value<<24;
//- reset byte
this->_last_out_value = this->_last_out_value & 0x00FFFFFF;
_last_out_value = _last_out_value & 0x00FFFFFF;
break;
default:
Tango::Except::throw_exception(
......@@ -1647,9 +1706,9 @@ void SingleShotDIO::write_port(const Tango::DevVarLongStringArray *argin)
}//switch
//- memorize the value
this->_last_out_value = value | _last_out_value;
_last_out_value = value | _last_out_value;
value = this->_last_out_value;
value = _last_out_value;
}//else
try
......@@ -1715,4 +1774,28 @@ Tango::DevFailed SingleShotDIO::daq_to_tango_exception(const asl::DAQException&
return Tango::DevFailed(error_list);
}
//+------------------------------------------------------------------
/**
* method: SingleShotDIO::dev_state
*
* description: method to execute "State"
* This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
*
* @return State Code
*
*/
Tango::DevState SingleShotDIO::dev_state()
{
Tango::DevState argout;
if(!m_is_device_initialized)
{
set_state(Tango::FAULT);
set_status(m_status_message.str());
argout = Tango::FAULT;
}
return argout;
}
} // namespace
......@@ -271,10 +271,19 @@ protected :
asl::SingleShotDI* in;
asl::SingleShotDO* out;
Tango::DevFailed daq_to_tango_exception(const asl::DAQException& de);
// Method to execute "State" command
virtual Tango::DevState dev_state();
short pa, pb, pc, pd, pe, pf, pg, ph;
long _last_out_value;
// device status
std::stringstream m_status_message;
//Equal to True if the device is correctly initialized, Otherwise False
bool m_is_device_initialized;
};
} // namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment