From 2d89895c5c9a5ed05916286faba46c57c0db19b8 Mon Sep 17 00:00:00 2001
From: Xavier Elattaoui <xavier.elattaoui@synchrotron-soleil.fr>
Date: Tue, 10 Apr 2012 09:23:08 +0000
Subject: [PATCH] minor changes.

---
 pom.xml                      |   2 +-
 src/KeithleySCPIProtocol.cpp | 716 +++++++++++++++++++++++++++--------
 src/TangoGpibLink.cpp        |  82 +++-
 src/TangoSerialLink.cpp      |  65 +++-
 4 files changed, 699 insertions(+), 166 deletions(-)

diff --git a/pom.xml b/pom.xml
index e2d5ade..a32a08b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
    </parent>
    <groupId>fr.soleil.lib</groupId>
    <artifactId>Electrometers-${aol}-${library}-${mode}</artifactId>
-   <version>2.5.3</version>
+   <version>2.5.4</version>
    <packaging>nar</packaging>
    <name>Electrometers library</name>
    <description>Electrometers library</description>
diff --git a/src/KeithleySCPIProtocol.cpp b/src/KeithleySCPIProtocol.cpp
index b642655..147c720 100644
--- a/src/KeithleySCPIProtocol.cpp
+++ b/src/KeithleySCPIProtocol.cpp
@@ -21,8 +21,6 @@
 #ifndef WIN32
 # include <unistd.h>
 #endif
-//# include 
-//#endif
 #include "KeithleySCPIProtocol.h"
 #include "TangoGpibLink.h"
 
@@ -59,22 +57,46 @@ bool KeithleySCPIProtocol::build_communicationLink()
   if (_commDevName.empty())
     return false;
 
-	_communication_link = new TangoGpibLink (_commDevName);
+	try
+	{
+		_communication_link = new TangoGpibLink (_commDevName);
+	}
+	catch(...)
+	{
+		if( _communication_link )
+		{
+			delete _communication_link;
+			_communication_link = 0;
+		}
+		return false;
+	}
 
   if (!_communication_link)
     return false;
 
-  //- configure tthe SCPI Keithley device
-  std::string cmd_to_send("");
-  //- Select reading only
-  cmd_to_send = "FORM:ELEM READ";
-	_communication_link->write(cmd_to_send);
-  //- Select control source : IMMediate
-  cmd_to_send = "ARM:SOUR IMM";
-	_communication_link->write(cmd_to_send);
-  //- Set measure count
-  cmd_to_send = "ARM:COUNT 1";
-	_communication_link->write(cmd_to_send);
+	try
+	{
+		//- configure tthe SCPI Keithley device
+		std::string cmd_to_send("");
+		//- Select reading only
+		cmd_to_send = "FORM:ELEM READ";
+		_communication_link->write(cmd_to_send);
+		//- Select control source : IMMediate
+		cmd_to_send = "ARM:SOUR IMM";
+		_communication_link->write(cmd_to_send);
+		//- Set measure count
+		cmd_to_send = "ARM:COUNT 1";
+		_communication_link->write(cmd_to_send);
+	}
+	catch(...)
+	{
+		if( _communication_link )
+		{
+			delete _communication_link;
+			_communication_link = 0;
+		}
+		return false;
+	}
 
   return true;
 }
@@ -86,6 +108,14 @@ void KeithleySCPIProtocol::set_range (std::string value)
 {
 std::string cmd_to_send("");
 std::string tmpMode;
+
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_range()");
+	}
 	
 	//- get electrometer mode
 	tmpMode = get_mode( );
@@ -105,6 +135,14 @@ void KeithleySCPIProtocol::zero_check_on (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_check_on()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCH ON" ;
 	_communication_link->write(cmd_to_send);
@@ -117,6 +155,14 @@ void KeithleySCPIProtocol::zero_check_off (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_check_off()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCH OFF";
 	_communication_link->write(cmd_to_send);
@@ -130,6 +176,14 @@ void KeithleySCPIProtocol::zero_correct_on (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_correct_on()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCOR ON" ;
 	_communication_link->write(cmd_to_send);
@@ -143,6 +197,14 @@ void KeithleySCPIProtocol::zero_correct_off (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_correct_off()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCOR OFF" ;
 	_communication_link->write(cmd_to_send);
@@ -156,6 +218,14 @@ void KeithleySCPIProtocol::zero_correct_state_on (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_correct_state_on()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCOR:STAT ON" ;
 	_communication_link->write(cmd_to_send);
@@ -169,6 +239,14 @@ void KeithleySCPIProtocol::zero_correct_state_off (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::zero_correct_state_off()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:ZCOR:STAT OFF" ;
 	_communication_link->write(cmd_to_send);
@@ -183,6 +261,14 @@ void KeithleySCPIProtocol::autoRange_on (void)
 std::string cmd_to_send("");
 std::string tmpMode;
 	
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::autoRange_ON()");
+	}
+	
 	//- get electrometer mode
 	tmpMode = get_mode( );
 
@@ -202,6 +288,14 @@ void KeithleySCPIProtocol::autoRange_off (void)
 std::string cmd_to_send("");
 std::string tmpMode;
 	
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::autoRange_off()");
+	}
+	
 	//- get electrometer mode
 	tmpMode = get_mode( );
 
@@ -221,6 +315,14 @@ void KeithleySCPIProtocol::auto_zero_on (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::auto_zero_on()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:AZER ON" ;
 	_communication_link->write(cmd_to_send);
@@ -233,6 +335,14 @@ void KeithleySCPIProtocol::auto_zero_off (void)
 {
 std::string cmd_to_send("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::auto_zero_off()");
+	}
+	
 	//- send command
 	cmd_to_send = "SYST:AZER OFF" ;
 	_communication_link->write(cmd_to_send);
@@ -247,13 +357,21 @@ std::string cmd_to_send("");
 void KeithleySCPIProtocol::setAmperMeterMode (void) 
 {
 std::stringstream cmd_to_send;
-std::string mode_ ("");
+std::string mode ("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setAmperMeterMode()");
+	}
+	
 	//- mode current (send CURR)
-	mode_ = "CURRent";
+	mode = "CURRent";
 
 	//- send command
-	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
+	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
 	_communication_link->write(cmd_to_send.str());
 
 }
@@ -264,13 +382,21 @@ std::string mode_ ("");
 void KeithleySCPIProtocol::setVoltMeterMode (void) 
 {
 std::stringstream cmd_to_send;
-std::string mode_ ("");
+std::string mode ("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setVoltMeterMode()");
+	}
+	
 	//- mode volt
-	mode_ = "VOLTage";
+	mode = "VOLTage";
 
 	//- send command
-	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
+	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
 	_communication_link->write(cmd_to_send.str());
 }
 
@@ -280,13 +406,21 @@ std::string mode_ ("");
 void KeithleySCPIProtocol::setOhmMeterMode (void) 
 {
 std::stringstream cmd_to_send;
-std::string mode_ ("");
+std::string mode ("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setOhmMeterMode()");
+	}
+	
 	//- mode ohm
-	mode_ = "RESistance";
+	mode = "RESistance";
 
 	//- send command
-	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
+	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
 	_communication_link->write(cmd_to_send.str());
 
 }
@@ -297,13 +431,21 @@ std::string mode_ ("");
 void KeithleySCPIProtocol::setCoulombMeterMode (void) 
 {
 std::stringstream cmd_to_send;
-std::string mode_ ("");
+std::string mode ("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setCoulombMeterMode()");
+	}
+	
 	//- mode coulomb
-	mode_ = "CHARge";
+	mode = "CHARge";
 
 	//- send command
-	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
+	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
 	_communication_link->write(cmd_to_send.str());
 
 }
@@ -313,11 +455,18 @@ std::string mode_ ("");
 // ============================================================================
 void KeithleySCPIProtocol::setVSourceOutputON (void) 
 {
-std::stringstream cmd_to_send;
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setVSourceOutputON()");
+	}
+	
+std::string cmd_to_send ("OUTP 1");
 
 	//- send command
-	cmd_to_send << "OUTP 1" << std::endl;
-	_communication_link->write(cmd_to_send.str());
+	_communication_link->write(cmd_to_send);
 }
 
 // ============================================================================
@@ -325,11 +474,17 @@ std::stringstream cmd_to_send;
 // ============================================================================
 void KeithleySCPIProtocol::setVSourceOutputOFF (void) 
 {
-std::stringstream cmd_to_send;
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setVSourceOutputOFF()");
+	}
+	
+std::string cmd_to_send ("OUTP 1");
 	//- send command
-	cmd_to_send << "OUTP 0" << std::endl;
-	_communication_link->write(cmd_to_send.str());
+	_communication_link->write(cmd_to_send);
 }
 
 // ============================================================================
@@ -337,8 +492,15 @@ std::stringstream cmd_to_send;
 // ============================================================================
 void KeithleySCPIProtocol::setVSourceValue (double voltsValue) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::setVSourceValue()");
+	}
+	
 std::stringstream cmd_to_send;
-
 	//- send command
   cmd_to_send << "SOUR:VOLT " << voltsValue << std::endl;
 	_communication_link->write(cmd_to_send.str());
@@ -349,8 +511,15 @@ std::stringstream cmd_to_send;
 // ============================================================================
 std::string KeithleySCPIProtocol::getVSourceValue (void) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::getVSourceValue()");
+	}
+	
 std::string cmd_to_send("SOUR:VOLT?");
-
 	//- send command
 	return _communication_link->write_read(cmd_to_send);
 }
@@ -360,8 +529,15 @@ std::string cmd_to_send("SOUR:VOLT?");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_mode (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_mode()");
+	}
 	
+std::string cmd_to_send("");
 	//- get electrometer mode
 	if(isDiffSuportedMode)
 	{
@@ -376,7 +552,6 @@ std::string cmd_to_send("");
 		_mode = "CURR\n";
 
 	return _mode;
-
 }
 
 // ============================================================================
@@ -384,11 +559,17 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_range (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode;
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_range()");
+	}
 	
+std::string cmd_to_send("");
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode( );
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
@@ -398,7 +579,6 @@ std::string tmpMode;
 	std::string _rangeStr = _communication_link->write_read(cmd_to_send);
 	
 	return _rangeStr;
-
 }
 
 // ============================================================================
@@ -409,6 +589,14 @@ std::string KeithleySCPIProtocol::get_value (void)
 std::string cmd_to_send("");
 std::string tmp("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_value()");
+	}
+	
 	////- This command performs a CONFIGURE and a READ?
 	//cmd_to_send = "MEAS?" ;
 	
@@ -429,6 +617,14 @@ std::vector<double> KeithleySCPIProtocol::get_integratedValue (void)
 std::string cmd_to_send("");
 std::string tmp("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_integratedValue()");
+	}
+	
 	//- This command performs an INIT and then query the bufferised values
 	cmd_to_send = "TRAC:DATA?" ;
 	tmp = _communication_link->write_read(cmd_to_send);
@@ -445,6 +641,14 @@ std::vector<double> KeithleySCPIProtocol::get_fetchValue (void)
 std::string cmd_to_send("");
 std::string tmp("");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_fetchValue()");
+	}
+	
 	//- This command queries the last value(s)
 	cmd_to_send = "FETCh?" ;
 	tmp = _communication_link->write_read(cmd_to_send);
@@ -513,7 +717,13 @@ std::cout << "\t*****::buildDataList -> FULL OF DATA : " << i << " -> $" << argo
 // ============================================================================
 void KeithleySCPIProtocol::init_keithley (void) 
 {
-std::string cmd_to_send("INIT");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::init_keithley()");
+	}
 
 #ifdef WIN32
   Sleep( 10 ); //- sleep just a few
@@ -521,6 +731,7 @@ std::string cmd_to_send("INIT");
   usleep(10000);
 #endif
 
+std::string cmd_to_send("INIT");
 	//- send command : INIT to trigg readings !
 	_communication_link->write(cmd_to_send);
 }
@@ -530,8 +741,15 @@ std::string cmd_to_send("INIT");
 // ============================================================================
 void KeithleySCPIProtocol::abort (void) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::abort()");
+	}
+	
 std::string cmd_to_send("ABORt");
-
 	//- send command : ABORt to cancel all operations
 	_communication_link->write(cmd_to_send);
 }
@@ -541,15 +759,21 @@ std::string cmd_to_send("ABORt");
 // ============================================================================
 void KeithleySCPIProtocol::set_knplc (std::string nbNPLC) 
 {
-std::string cmd_to_send("");
-std::string tmpMode;
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_knplc()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
 	
+std::string cmd_to_send("");
 	//- send command
 	cmd_to_send = tmpMode + ":NPLC " + nbNPLC ;
 	_communication_link->write(cmd_to_send);
@@ -560,15 +784,21 @@ std::string tmpMode;
 // ============================================================================
 std::string KeithleySCPIProtocol::get_knplc (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode;
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_knplc()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
-	tmpMode.erase(tmpMode.find("\n") );
+	tmpMode.erase( tmpMode.find("\n") );
 	
+std::string cmd_to_send("");
 	//- send command
 	cmd_to_send = tmpMode + ":NPLCycles?" ;
 	return _communication_link->write_read(cmd_to_send);
@@ -579,18 +809,21 @@ std::string tmpMode;
 // ============================================================================
 void KeithleySCPIProtocol::set_triggercount (std::string nbTrigCount) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_triggercount()");
+	}
+	
 std::string cmd_to_send("");
-
 	//- send command
 	cmd_to_send = "TRIG:COUN " + nbTrigCount ;
 	//- for internal use ( = keithley device buffer size)
 	trigCountStr = nbTrigCount;
 
 	_communication_link->write(cmd_to_send);
-
-	//- set buffer size ( = number of triggers )
-//	set_buffer_size(nbTrigCount);
-
 }
 
 // ============================================================================
@@ -598,12 +831,17 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_triggercount (void) 
 {
-std::string cmd_to_send("");
-std::string response("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_triggercount()");
+	}
+	
 	//- send command
-	cmd_to_send = "TRIG:COUNt?" ;
-	response  = _communication_link->write_read(cmd_to_send);
+	std::string cmd_to_send("TRIG:COUNt?");
+	std::string response  = _communication_link->write_read(cmd_to_send);
 
   return response;
 }
@@ -613,10 +851,16 @@ std::string response("");
 // ============================================================================
 void KeithleySCPIProtocol::set_triggerdelay (std::string trigDelay) 
 {
-std::string cmd_to_send("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_triggerdelay()");
+	}
+	
 	//- send command
-	cmd_to_send = "TRIG:DEL " + trigDelay ;
+	std::string cmd_to_send = "TRIG:DEL " + trigDelay ;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -625,10 +869,16 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_triggerdelay (void) 
 {
-std::string cmd_to_send("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_triggerdelay()");
+	}
+	
 	//- send command
-	cmd_to_send = "TRIG:DEL?" ;
+	std::string cmd_to_send = "TRIG:DEL?" ;
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -637,10 +887,16 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::set_triggerdelayAuto (std::string trigDelayAuto) 
 {
-std::string cmd_to_send("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_triggerdelayAuto()");
+	}
+	
 	//- send command
-	cmd_to_send = "TRIG:DEL:" + trigDelayAuto ;
+	std::string cmd_to_send = "TRIG:DEL:" + trigDelayAuto ;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -649,10 +905,16 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_triggerdelayAuto (void) 
 {
-std::string cmd_to_send("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_triggerdelayAuto()");
+	}
+	
 	//- send command
-	cmd_to_send = "TRIG:DEL:AUTO?" ;
+	std::string cmd_to_send = "TRIG:DEL:AUTO?" ;
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -661,10 +923,16 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::set_averagecount (std::string nbAverageCount) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_averagecount()");
+	}
 	
 	//- send command
-	cmd_to_send = "AVER:COUN " + nbAverageCount;
+	std::string cmd_to_send = "AVER:COUN " + nbAverageCount;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -673,16 +941,22 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::set_averagecount_K6517 (std::string cmd_to_send) 
 {
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_averagecount()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
-	tmpMode.erase(tmpMode.find("\n") );
+	tmpMode.erase( tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER:COUN " + cmd_to_send ;
+	std::string cmd_to_send = tmpMode + ":AVER:COUN " + cmd_to_send ;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -691,10 +965,16 @@ std::string tmpMode("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_averagecount (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_averagecount()");
+	}
 	
 	//- send command
-	cmd_to_send = "AVER:COUNt?" ;
+	std::string cmd_to_send("AVER:COUNt?");
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -703,17 +983,22 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_averagecount_K6517 (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode;
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_averagecount()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER:COUNt?" ;
+	std::string cmd_to_send = tmpMode + ":AVER:COUNt?" ;
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -722,14 +1007,16 @@ std::string tmpMode;
 // ============================================================================
 void KeithleySCPIProtocol::set_averagecontrol (std::string nbAverageControl) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_averagecontrol()");
+	}
 	
-	//- get electrometer mode
-//	tmpMode = get_mode( );
-
 	//- send command
-	cmd_to_send = "AVER:TCON " + nbAverageControl;
+	std::string cmd_to_send = "AVER:TCON " + nbAverageControl;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -738,17 +1025,22 @@ std::string tmpMode("");
 // ============================================================================
 void KeithleySCPIProtocol::set_averagecontrol_K6517 (std::string nbAverageControl) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_averagecontrol_K6517()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode( );
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER:TCON " + nbAverageControl;
+	std::string cmd_to_send = tmpMode + ":AVER:TCON " + nbAverageControl;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -757,14 +1049,16 @@ std::string tmpMode("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_averagecontrol (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_averagecontrol()");
+	}
 	
-	//- get electrometer mode
-//	tmpMode = get_mode( );
-
 	//- send command
-	cmd_to_send = "AVER:TCONtrol?" ;
+	std::string cmd_to_send = "AVER:TCONtrol?" ;
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -773,17 +1067,22 @@ std::string tmpMode("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_averagecontrol_K6517 (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_averagecontrol_K6517()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode( );
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER:TCONtrol?" ;
+	std::string cmd_to_send = tmpMode + ":AVER:TCONtrol?" ;
 	return _communication_link->write_read(cmd_to_send);
 }
 
@@ -792,12 +1091,17 @@ std::string tmpMode("");
 // ============================================================================
 void KeithleySCPIProtocol::clear_registers (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::clear_registers()");
+	}
 	
 	//- send command
-	cmd_to_send = "*CLS" ;
+	std::string cmd_to_send("*CLS");
 	_communication_link->write(cmd_to_send);
-
 }
 
 // ============================================================================
@@ -805,10 +1109,16 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::averageStateON (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::averageStateON()");
+	}
 	
 	//- send command
-	cmd_to_send = "AVER ON" ;
+	std::string cmd_to_send = "AVER ON" ;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -817,17 +1127,22 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::averageStateON_K6517 (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::averageStateON_K6517()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
-	tmpMode.erase(tmpMode.find("\n") );
+	tmpMode.erase( tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER ON" ;
+	std::string cmd_to_send = tmpMode + ":AVER ON";
 	_communication_link->write(cmd_to_send);
 }
 
@@ -836,10 +1151,16 @@ std::string tmpMode("");
 // ============================================================================
 void KeithleySCPIProtocol::averageStateOFF (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::averageStateOFF()");
+	}
 	
 	//- send command
-	cmd_to_send = "AVER OFF";
+	std::string cmd_to_send = "AVER OFF";
 	_communication_link->write(cmd_to_send);
 }
 
@@ -848,17 +1169,22 @@ std::string cmd_to_send("");
 // ============================================================================
 void KeithleySCPIProtocol::averageStateOFF_K6517 (void) 
 {
-std::string cmd_to_send("");
-std::string tmpMode("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::averageStateOFF_K6517()");
+	}
 	
 	//- get electrometer mode
-	tmpMode = get_mode( );
+	std::string tmpMode = get_mode();
 
 	//- erase bad caracters
 	tmpMode.erase(tmpMode.find("\n") );
 	
 	//- send command
-	cmd_to_send = tmpMode + ":AVER OFF" ;
+	std::string cmd_to_send = tmpMode + ":AVER OFF" ;
 	_communication_link->write(cmd_to_send);
 }
 
@@ -867,10 +1193,16 @@ std::string tmpMode("");
 // ============================================================================
 void KeithleySCPIProtocol::reset (void) 
 {
-std::string cmd_to_send("");
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::reset()");
+	}
 	
 	//- send command
-	cmd_to_send = "*RST" ;
+	std::string cmd_to_send = "*RST" ;
 	_communication_link->write(cmd_to_send);
 
   //- Select reading only
@@ -885,13 +1217,17 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_raw_status (void) 
 {
-std::string cmd_to_send("");
-std::string argout("no data");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_raw_status()");
+	}
+	
 	//- send command : read error queue only
-	cmd_to_send = "STAT:QUE?";
-	argout = _communication_link->write_read(cmd_to_send);
-
+	std::string cmd_to_send = "STAT:QUE?";
+	std::string argout = _communication_link->write_read(cmd_to_send);
 
 	return argout;
 }
@@ -901,12 +1237,17 @@ std::string argout("no data");
 // ============================================================================
 void KeithleySCPIProtocol::set_buffer_size (std::string size) 
 {
-std::string cmd_to_send("");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::set_buffer_size()");
+	}
+	
 	//- send command : size = number of triggers
-	cmd_to_send = "TRAC:POIN " + size;
+	std::string cmd_to_send = "TRAC:POIN " + size;
 	_communication_link->write(cmd_to_send);
-
 }
 
 // ============================================================================
@@ -914,11 +1255,17 @@ std::string cmd_to_send("");
 // ============================================================================
 std::string KeithleySCPIProtocol::get_buffer_size ( ) 
 {
-std::string cmd_to_send("TRAC:POIN:ACTual?");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::get_buffer_size()");
+	}
+	
 	//- send command :
+	std::string cmd_to_send("TRAC:POIN:ACTual?");
 	return _communication_link->write_read(cmd_to_send);
-
 }
 
 // ============================================================================
@@ -926,11 +1273,17 @@ std::string cmd_to_send("TRAC:POIN:ACTual?");
 // ============================================================================
 void KeithleySCPIProtocol::clear_buffer (void) 
 {
-std::string cmd_to_send("TRAC:CLEAR");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::clear_buffer()");
+	}
+	
 	//- send command : clear previous data
+	std::string cmd_to_send("TRAC:CLEAR");
 	_communication_link->write(cmd_to_send);
-
 }
 
 // ============================================================================
@@ -938,11 +1291,17 @@ std::string cmd_to_send("TRAC:CLEAR");
 // ============================================================================
 void KeithleySCPIProtocol::store_raw_input (void) 
 {
-std::string cmd_to_send("TRAC:FEED SENS");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::store_raw_input()");
+	}
+	
+	std::string cmd_to_send("TRAC:FEED SENS");
 	//- send command : Store raw input readings
 	_communication_link->write(cmd_to_send);
-
 }
 
 // ============================================================================
@@ -950,8 +1309,15 @@ std::string cmd_to_send("TRAC:FEED SENS");
 // ============================================================================
 void KeithleySCPIProtocol::start_storing (void) 
 {
-std::string cmd_to_send("TRAC:FEED:CONT NEXT");
-
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::start_storing()");
+	}
+	
+	std::string cmd_to_send("TRAC:FEED:CONT NEXT");
 	//- send command : Start storing readings
 	_communication_link->write(cmd_to_send);
 }
@@ -961,8 +1327,15 @@ std::string cmd_to_send("TRAC:FEED:CONT NEXT");
 // ============================================================================
 void KeithleySCPIProtocol::save_configuration (unsigned short memoryIdx) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::save_configuration()");
+	}
+	
 std::stringstream cmd_to_send;
-
 	//- send command
   cmd_to_send << "*SAV " << memoryIdx << std::endl;
 	_communication_link->write(cmd_to_send.str());
@@ -973,8 +1346,15 @@ std::stringstream cmd_to_send;
 // ============================================================================
 void KeithleySCPIProtocol::restore_configuration (unsigned short memoryIdx) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::restore_configuration()");
+	}
+	
 std::stringstream cmd_to_send;
-
 	//- send command
   cmd_to_send << "*RCL " << memoryIdx << std::endl;
 	_communication_link->write(cmd_to_send.str());
@@ -993,6 +1373,14 @@ void KeithleySCPIProtocol::enable_SRQBufferFull (void)
   
   std::string cmd_to_send("STAT:MEAS:ENAB 512");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::enable_SRQBufferFull()");
+	}
+	
 	//- send command : enable buffer full in the Measurement event enable register
 	_communication_link->write(cmd_to_send);
 
@@ -1010,6 +1398,14 @@ void KeithleySCPIProtocol::disable_SRQBufferFull (void)
 {
 std::string cmd_to_send("STAT:MEAS?");
 
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::disable_SRQBufferFull()");
+	}
+	
 	//- send command : disable buffer full event
 	_communication_link->write_read(cmd_to_send);
 
@@ -1024,6 +1420,14 @@ std::string cmd_to_send("STAT:MEAS?");
 // ============================================================================
 bool KeithleySCPIProtocol::SRQLineState (void) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::SRQLineState()");
+	}
+	
 	//- if asserted -> the programmed event occurs : the device can be asked !
 	return _communication_link->SRQLineState();
 
@@ -1036,6 +1440,14 @@ bool KeithleySCPIProtocol::SRQLineState (void)
 // ============================================================================
 short KeithleySCPIProtocol::readStatusByteRegister (void) 
 {
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::readStatusByteRegister()");
+	}
+	
 	//- if SRQ line UP -> the programmed event(s) occurs : the value is available !
 	return _communication_link->readStatusByteRegister();
 
@@ -1048,10 +1460,16 @@ short KeithleySCPIProtocol::readStatusByteRegister (void)
 // ============================================================================
 void KeithleySCPIProtocol::read_data_with_no_timestamp (void) 
 {
-std::stringstream cmd_to_send;
-
-		cmd_to_send << "FORM:ELEM READ" << std::endl;
-		_communication_link->write(cmd_to_send.str());
+	if( !this->_communication_link )
+	{
+		throw electrometer::ElectrometerException(
+												"INITIALIZATION_ERROR", 
+												"No communication protocol available.",
+												"KeithleySCPIProtocol::read_data_with_no_timestamp()");
+	}
+	
+	std::string cmd_to_send("FORM:ELEM READ");
+	_communication_link->write(cmd_to_send);
 }
 
 
diff --git a/src/TangoGpibLink.cpp b/src/TangoGpibLink.cpp
index faaab54..df0be07 100644
--- a/src/TangoGpibLink.cpp
+++ b/src/TangoGpibLink.cpp
@@ -64,13 +64,21 @@ void TangoGpibLink::create_gpib_proxy (void)  throw (Tango::DevFailed)
 	}
 	catch(Tango::DevFailed& df )
 	{
-		description = "Unable to create proxy on : " + _communication_Device_name;
+		description = "Unable to create proxy on : " + _communication_Device_name + ". Check GPIB device is up !";
 		
 		Tango::Except::re_throw_exception (df,
 			(const char*)"COMMUNICATION_ERROR",
 			description.c_str(),
 			(const char*)"TangoGpibLink::create_gpib_proxy");
-	}	
+	}
+	catch(...)
+	{
+		description = "Unable to create proxy on : " + _communication_Device_name + ". Check GPIB device is up !";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::create_gpib_proxy");
+	}
 }
 
 
@@ -120,16 +128,25 @@ void TangoGpibLink::write (std::string command_to_send)  throw (Tango::DevFailed
 	}
 	catch(Tango::DevFailed& df )
 	{
-		description = "Unable to write command : " + command_to_send;
 		if ( cmd )
 			delete [] cmd;
-		
+		description = "Unable to write command : " + command_to_send + ". Caught DevFailed." ;
 		Tango::Except::re_throw_exception (df,
 			(const char*)"COMMUNICATION_ERROR",
 			description.c_str(),
 			(const char*)"TangoGpibLink::write");
 		
 	}
+	catch(...)
+	{
+		if ( cmd )
+			delete [] cmd;
+		description = "Unable to write command : " + command_to_send + ". Caught [...]." ;
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::write");
+	}
 }
 
 
@@ -156,6 +173,13 @@ std::string TangoGpibLink::read (void) throw (Tango::DevFailed)
 			(const char*)"Unable to perform a read operation",
 			(const char*)"TangoGpibLink::read");
 	}
+	catch(...)
+	{
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			(const char*)"Unable to perform a read operation, caught [...].",
+			(const char*)"TangoGpibLink::read");
+	}
 	
 	return this->response;
 }
@@ -185,14 +209,25 @@ std::string TangoGpibLink::write_read (std::string command_to_send) throw (Tango
 	}
 	catch(Tango::DevFailed& df )
 	{
-		description = "Unable to write command : " + command_to_send + " and read device response.";
 		if ( argin )
 			delete [] argin;
+		description = "Unable to write/read command : " + command_to_send + " and read device response.";
 		Tango::Except::re_throw_exception (df,
 			(const char*)"COMMUNICATION_ERROR",
 			description.c_str(),
 			(const char*)"TangoGpibLink::write_read");		
 	}
+	catch(...)
+	{
+		if ( argin )
+			delete [] argin;
+		description = "Unable to write/read command : " + command_to_send + " and read device response.";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::write_read");
+	}
+
 	return this->response;
 }
 
@@ -224,6 +259,14 @@ bool TangoGpibLink::SRQLineState (void) throw (Tango::DevFailed)
 			(const char*)"TangoGpibLink::SRQLineState");
 		
 	}
+	catch(...)
+	{
+		description = "Unable to get Gpib SRQ line state.";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::SRQLineState");
+	}
 
 	return result;
 }
@@ -257,6 +300,15 @@ short TangoGpibLink::readStatusByteRegister (void) throw (Tango::DevFailed)
 			(const char*)"TangoGpibLink::readStatusByteRegister");
 		
 	}	
+	catch(...)
+	{
+		description = "Unable to get device status byte register.";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::readStatusByteRegister");
+	}
+
 	return result;
 }
 
@@ -278,12 +330,19 @@ void TangoGpibLink::clear (void) throw (Tango::DevFailed)
 	catch(Tango::DevFailed& df )
 	{
 		description = "Unable send Clear Device command.";
-		
 		Tango::Except::re_throw_exception (df,
 			(const char*)"COMMUNICATION_ERROR",
 			description.c_str(),
 			(const char*)"TangoGpibLink::clear");		
 	}	
+	catch(...)
+	{
+		description = "Unable send Clear Device command.";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::clear");
+	}
 }
 
 // ============================================================================
@@ -304,11 +363,18 @@ void TangoGpibLink::trigger (void) throw (Tango::DevFailed)
 	catch(Tango::DevFailed& df )
 	{
 		description = "Unable send Trigger command.";
-		
 		Tango::Except::re_throw_exception (df,
 			(const char*)"COMMUNICATION_ERROR",
 			description.c_str(),
-			(const char*)"TangoGpibLink::clear");
+			(const char*)"TangoGpibLink::trigger");
+	}
+	catch(...)
+	{
+		description = "Unable send Trigger command.";
+		Tango::Except::throw_exception (
+			(const char*)"COMMUNICATION_ERROR",
+			description.c_str(),
+			(const char*)"TangoGpibLink::trigger");
 	}
 }
 
diff --git a/src/TangoSerialLink.cpp b/src/TangoSerialLink.cpp
index 088a178..7cfc104 100644
--- a/src/TangoSerialLink.cpp
+++ b/src/TangoSerialLink.cpp
@@ -18,7 +18,7 @@
 #include <iostream>
 #include "TangoSerialLink.h"
 
-//- Read serial data in mode LINE (i.e SerialLine device wait until EOF is received from instrument
+//- Read serial data in mode LINE (i.e SerialLine device wait until EOF is received from instrument)
 
 static const long MODE_LINE = 2;
 //- init of the static instance
@@ -90,22 +90,39 @@ void TangoSerialLink::create_serial_proxy (void)  throw (Tango::DevFailed)
 	try
 	{
 		//- try
-		//this->_serial_proxy = new Tango::DeviceProxyHelper(_communication_Device_name);
 		this->_serial_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
 		//(*_serial_proxy)->ping();
 		_is_serial_proxy_created = true;
 	}
 	catch(Tango::DevFailed& df )
 	{
-		description = "Unable to create proxy on : " + _communication_Device_name;
+		if( this->_serial_proxy )
+		{
+			delete this->_serial_proxy;
+			this->_serial_proxy = 0;
+		}
 		_is_serial_proxy_created = false;
-		this->_serial_proxy = 0;
+		description = "Unable to create proxy on : " + _communication_Device_name;
 		Tango::Except::re_throw_exception (df,
-										(const char*)"COMMUNICATION_ERROR",
+										(const char*)"ALLOCATION_ERROR",
 										description.c_str(),
 										(const char*)"TangoSerialLink::create_serial_proxy");
 
 	}
+	catch(...)
+	{
+		if( this->_serial_proxy )
+		{
+			delete this->_serial_proxy;
+			this->_serial_proxy = 0;
+		}
+		_is_serial_proxy_created = false;
+		description = "Unable to write command : " + command_to_send + "\nmemory allocation failed.";
+		Tango::Except::throw_exception (
+										(const char*)"ALLOCATION_ERROR",
+										description.c_str(),
+										(const char*)"TangoSerialLink::write");
+	}
 }
 
 // ============================================================================
@@ -127,8 +144,12 @@ void TangoSerialLink::write (std::string command_to_send)  throw (Tango::DevFail
 	}
 	catch(Tango::DevFailed& df )
 	{
+		if( argin ) 
+		{
+			delete [] argin;
+			argin = 0;
+		}
 		description = "Unable to write command : " + command_to_send +  + "\nmemory allocation failed.";
-
 		Tango::Except::re_throw_exception (df,
 										(const char*)"ALLOCATION_ERROR",
 										description.c_str(),
@@ -137,7 +158,6 @@ void TangoSerialLink::write (std::string command_to_send)  throw (Tango::DevFail
 	catch(...)
 	{
 		description = "Unable to write command : " + command_to_send + "\nmemory allocation failed.";
-
 		Tango::Except::throw_exception (
 										(const char*)"ALLOCATION_ERROR",
 										description.c_str(),
@@ -149,18 +169,40 @@ void TangoSerialLink::write (std::string command_to_send)  throw (Tango::DevFail
 		//- try
 		dd_in << argin;
 		this->_serial_proxy->command_inout("DevSerWriteString", dd_in);
+		if( argin ) 
+		{
+			delete [] argin;
+			argin = 0;
+		}
 		//std::cout << "TangoSerialLink::write -> argin = *\"" << argin << "\"*" << std::endl;
 	}
 	catch(Tango::DevFailed& df )
 	{
+		if( argin ) 
+		{
+			delete [] argin;
+			argin = 0;
+		}
 		description = "Unable to write command : " + command_to_send;
-
 		Tango::Except::re_throw_exception (df,
 										(const char*)"COMMUNICATION_ERROR",
 										description.c_str(),
 										(const char*)"TangoSerialLink::write");
 
 	}
+	catch(...)
+	{
+		if( argin ) 
+		{
+			delete [] argin;
+			argin = 0;
+		}
+		description = "Unable to write command : " + command_to_send;
+		Tango::Except::throw_exception (
+										(const char*)"COMMUNICATION_ERROR",
+										description.c_str(),
+										(const char*)"TangoSerialLink::write");
+	}
 }
 
 
@@ -187,6 +229,13 @@ std::string TangoSerialLink::read (void) throw (Tango::DevFailed)
 										(const char*)"Unable to perform a read operation",
 										(const char*)"TangoSerialLink::read");
 	}
+	catch(...)
+	{
+		Tango::Except::throw_exception (
+										(const char*)"COMMUNICATION_ERROR",
+										(const char*)"Unable to perform a read operation",
+										(const char*)"TangoSerialLink::read");
+	}
 
 	return this->response ;
 }
-- 
GitLab