Skip to content
Snippets Groups Projects
KeithleySCPIProtocol.cpp 48.1 KiB
Newer Older
LE's avatar
LE committed
// ============================================================================
//
// = CONTEXT
//    TANGO Project - SCPI KeithleySCPIProtocol Support Library
//
// = FILENAME
//    KeithleySCPIProtocol.cpp
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <Xstring.h>
ELATTAOUI's avatar
ELATTAOUI committed
#ifndef WIN32
# include <unistd.h>
#endif
LE's avatar
LE committed
#include "KeithleySCPIProtocol.h"
#include "TangoGpibLink.h"

// ============================================================================
// KeithleySCPIProtocol::KeithleySCPIProtocol
// ============================================================================
KeithleySCPIProtocol::KeithleySCPIProtocol (std::string& gpib_device_name)
:	ElectrometerProtocol(),
	isDiffSuportedMode(false),
ELATTAOUI's avatar
ELATTAOUI committed
	trigCountStr("")
LE's avatar
LE committed
{
	std::cout << "KeithleySCPIProtocol::KeithleySCPIProtocol <-" << std::endl;

ELATTAOUI's avatar
ELATTAOUI committed
  _commDevName = gpib_device_name;
LE's avatar
LE committed

	std::cout << "KeithleySCPIProtocol::KeithleySCPIProtocol ->" << std::endl;
}

// ============================================================================
// KeithleySCPIProtocol::~KeithleySCPIProtocol
// ============================================================================
KeithleySCPIProtocol::~KeithleySCPIProtocol (void)
{
	std::cout << "KeithleySCPIProtocol::~KeithleySCPIProtocol <-" << std::endl;

	std::cout << "KeithleySCPIProtocol::~KeithleySCPIProtocol ->" << std::endl;
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::build_communicationLink
// ============================================================================
bool KeithleySCPIProtocol::build_communicationLink()
{
  if (_commDevName.empty())
    return false;

ELATTAOUI's avatar
ELATTAOUI committed
	try
	{
		_communication_link = new TangoGpibLink (_commDevName);
	}
	catch(...)
	{
		if( _communication_link )
		{
			delete _communication_link;
			_communication_link = 0;
		}
		return false;
	}
ELATTAOUI's avatar
ELATTAOUI committed

  if (!_communication_link)
    return false;

ELATTAOUI's avatar
ELATTAOUI committed
	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;
	}
ELATTAOUI's avatar
ELATTAOUI committed

  return true;
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::set_range
// ============================================================================
void KeithleySCPIProtocol::set_range (std::string value) 
{
std::string cmd_to_send("");
std::string tmpMode;
ELATTAOUI's avatar
ELATTAOUI committed

	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_range()");
	}
LE's avatar
LE committed
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- send command to Keithley device
	cmd_to_send = tmpMode + ":RANGe " + value ;
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::zero_check_on
// ============================================================================
void KeithleySCPIProtocol::zero_check_on (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_check_on()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCH ON" ;
	_communication_link->write(cmd_to_send);

}
// ============================================================================
// KeithleySCPIProtocol::zero_check_off
// ============================================================================
void KeithleySCPIProtocol::zero_check_off (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_check_off()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCH OFF";
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::zero_correct_on
// ============================================================================
void KeithleySCPIProtocol::zero_correct_on (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_correct_on()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCOR ON" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::zero_correct_off
// ============================================================================
void KeithleySCPIProtocol::zero_correct_off (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_correct_off()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCOR OFF" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::zero_correct_state_on
// ============================================================================
void KeithleySCPIProtocol::zero_correct_state_on (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_correct_state_on()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCOR:STAT ON" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::zero_correct_state_off
// ============================================================================
void KeithleySCPIProtocol::zero_correct_state_off (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::zero_correct_state_off()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:ZCOR:STAT OFF" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::autoRange_ON
// ============================================================================
void KeithleySCPIProtocol::autoRange_on (void) 
{
std::string cmd_to_send("");
std::string tmpMode;
	
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::autoRange_ON()");
	}
	
LE's avatar
LE committed
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );

	cmd_to_send = tmpMode + ":RANGe:AUTO ON" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::autoRange_OFF
// ============================================================================
void KeithleySCPIProtocol::autoRange_off (void) 
{
std::string cmd_to_send("");
std::string tmpMode;
	
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::autoRange_off()");
	}
	
LE's avatar
LE committed
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );

	//- send command
	cmd_to_send = tmpMode + ":RANGe:AUTO OFF";
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::auto_zero_on
// ============================================================================
void KeithleySCPIProtocol::auto_zero_on (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::auto_zero_on()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:AZER ON" ;
	_communication_link->write(cmd_to_send);

}
// ============================================================================
// KeithleySCPIProtocol::auto_zero_off
// ============================================================================
void KeithleySCPIProtocol::auto_zero_off (void) 
{
std::string cmd_to_send("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::auto_zero_off()");
	}
	
LE's avatar
LE committed
	//- send command
	cmd_to_send = "SYST:AZER OFF" ;
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::MODE -> Ampere, Volt, Ohm, Coulomb and V on I meters
// ============================================================================
// ============================================================================
// KeithleySCPIProtocol::setAmperMeterMode
// ============================================================================
void KeithleySCPIProtocol::setAmperMeterMode (void) 
{
std::stringstream cmd_to_send;
ELATTAOUI's avatar
ELATTAOUI committed
std::string mode ("");
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setAmperMeterMode()");
	}
	
LE's avatar
LE committed
	//- mode current (send CURR)
ELATTAOUI's avatar
ELATTAOUI committed
	mode = "CURRent";
LE's avatar
LE committed

	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setVoltMeterMode
// ============================================================================
void KeithleySCPIProtocol::setVoltMeterMode (void) 
{
std::stringstream cmd_to_send;
ELATTAOUI's avatar
ELATTAOUI committed
std::string mode ("");
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setVoltMeterMode()");
	}
	
LE's avatar
LE committed
	//- mode volt
ELATTAOUI's avatar
ELATTAOUI committed
	mode = "VOLTage";
LE's avatar
LE committed

	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send.str());
}

// ============================================================================
// KeithleySCPIProtocol::setOhmMeterMode
// ============================================================================
void KeithleySCPIProtocol::setOhmMeterMode (void) 
{
std::stringstream cmd_to_send;
ELATTAOUI's avatar
ELATTAOUI committed
std::string mode ("");
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setOhmMeterMode()");
	}
	
LE's avatar
LE committed
	//- mode ohm
ELATTAOUI's avatar
ELATTAOUI committed
	mode = "RESistance";
LE's avatar
LE committed

	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setCoulombMeterMode
// ============================================================================
void KeithleySCPIProtocol::setCoulombMeterMode (void) 
{
std::stringstream cmd_to_send;
ELATTAOUI's avatar
ELATTAOUI committed
std::string mode ("");
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setCoulombMeterMode()");
	}
	
LE's avatar
LE committed
	//- mode coulomb
ELATTAOUI's avatar
ELATTAOUI committed
	mode = "CHARge";
LE's avatar
LE committed

	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << "FUNC \'" << mode << "\'" << std::endl;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setVSourceOutputON
// ============================================================================
void KeithleySCPIProtocol::setVSourceOutputON (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setVSourceOutputON()");
	}
	
std::string cmd_to_send ("OUTP 1");

	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::setVSourceOutputOFF
// ============================================================================
void KeithleySCPIProtocol::setVSourceOutputOFF (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setVSourceOutputOFF()");
	}
	
std::string cmd_to_send ("OUTP 1");
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	_communication_link->write(cmd_to_send);
ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::setVSourceValue
// ============================================================================
void KeithleySCPIProtocol::setVSourceValue (double voltsValue) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::setVSourceValue()");
	}
	
ELATTAOUI's avatar
ELATTAOUI committed
std::stringstream cmd_to_send;
	//- send command
  cmd_to_send << "SOUR:VOLT " << voltsValue << std::endl;
	_communication_link->write(cmd_to_send.str());
}

// ============================================================================
// KeithleySCPIProtocol::getVSourceValue
// ============================================================================
std::string KeithleySCPIProtocol::getVSourceValue (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::getVSourceValue()");
	}
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("SOUR:VOLT?");
	//- send command
	return _communication_link->write_read(cmd_to_send);
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::get_mode
// ============================================================================
std::string KeithleySCPIProtocol::get_mode (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_mode()");
	}
LE's avatar
LE committed
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("");
LE's avatar
LE committed
	//- get electrometer mode
	if(isDiffSuportedMode)
	{
		//- send command
		cmd_to_send = "FUNC?" ;
		_mode =  _communication_link->write_read(cmd_to_send);
		//- _mode returned is as this "RES" so, erase " caracters
		_mode.erase(_mode.find("\""), 1);
		_mode.erase(_mode.find("\""), 1);
	}
	else
		_mode = "CURR\n";

	return _mode;
}

// ============================================================================
// KeithleySCPIProtocol::get_range
// ============================================================================
std::string KeithleySCPIProtocol::get_range (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_range()");
	}
LE's avatar
LE committed
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("");
LE's avatar
LE committed
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	std::string tmpMode = get_mode( );
LE's avatar
LE committed

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- send command
	cmd_to_send = tmpMode + ":RANGe?" ;
	std::string _rangeStr = _communication_link->write_read(cmd_to_send);
	
	return _rangeStr;
}

// ============================================================================
// KeithleySCPIProtocol::get_value
// ============================================================================
std::string KeithleySCPIProtocol::get_value (void) 
{
std::string cmd_to_send("");
std::string tmp("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_value()");
	}
	
ELATTAOUI's avatar
ELATTAOUI committed
	////- This command performs a CONFIGURE and a READ?
	//cmd_to_send = "MEAS?" ;
	
LE's avatar
LE committed
	//- This command performs an INIT and then query the updated value
ELATTAOUI's avatar
ELATTAOUI committed
    cmd_to_send = "READ?" ;

LE's avatar
LE committed
	tmp = _communication_link->write_read(cmd_to_send);

  //- extract all data
  return tmp;
}

// ============================================================================
// KeithleySCPIProtocol::get_integratedValue
// ============================================================================
std::vector<double> KeithleySCPIProtocol::get_integratedValue (void) 
{
std::string cmd_to_send("");
std::string tmp("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_integratedValue()");
	}
	
LE's avatar
LE committed
	//- This command performs an INIT and then query the bufferised values
	cmd_to_send = "TRAC:DATA?" ;
	tmp = _communication_link->write_read(cmd_to_send);

  //- extract all data
  return buildDataList(tmp);
}

// ============================================================================
// KeithleySCPIProtocol::get_fetchValue
// ============================================================================
std::vector<double> KeithleySCPIProtocol::get_fetchValue (void) 
{
std::string cmd_to_send("");
std::string tmp("");

ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_fetchValue()");
	}
	
LE's avatar
LE committed
	//- This command queries the last value(s)
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send = "FETCh?" ;
LE's avatar
LE committed
	tmp = _communication_link->write_read(cmd_to_send);

  //- extract all data
  return buildDataList(tmp);

}

// ============================================================================
// KeithleySCPIProtocol::buildDataList
//
//  This method extract and convert data from the received string
// ============================================================================
std::vector<double> KeithleySCPIProtocol::buildDataList(std::string datalist)
{
std::string dataStr("");
std::vector<double> argout;
std::string::size_type posBeg;
std::string::size_type posEnd;
short numberOfData = 0;
	//- 
	posBeg = 0;
	posEnd = datalist.find(',', posBeg);

//-DEBUG 
std::cout << "\t*****::buildDataList -> argin :\n$" << datalist << "$" << std::endl;
  
	//- there is just one value
LE's avatar
LE committed
  if(posEnd == std::string::npos)
  {
		  argout.push_back( XString<double>::convertFromString(datalist) );
//-DEBUG 
std::cout << "\t*****::buildDataList -> JUST ONE DATA :$" << datalist << "$" << std::endl;
LE's avatar
LE committed
  }
  else
  {
	  int i = 0;
    //std::string tmp = get_triggercount();
    numberOfData =  XString<short>::convertFromString(get_triggercount());

    for(i=0; i < numberOfData; i++)
    {
		  dataStr = datalist.substr(posBeg,posEnd);
		  argout.push_back( XString<double>::convertFromString(dataStr) );
//-DEBUG 
std::cout << "\t*****::buildDataList -> FULL OF DATA : " << i << " -> $" << argout[i] << "$" << std::endl;
LE's avatar
LE committed
      posBeg = posEnd+1;
		  posEnd = datalist.find(',', posBeg);

      //- end of string reached so latest data is here
      if(posEnd == std::string::npos)
      {
        dataStr = datalist.substr(posBeg);
   		  argout.push_back( XString<double>::convertFromString(dataStr) );
        break;
      }
    }
  }

	return argout;
}

// ============================================================================
// KeithleySCPIProtocol::init_keithley to perform reading(s) data
// ============================================================================
void KeithleySCPIProtocol::init_keithley (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::init_keithley()");
	}
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
#ifdef WIN32
  Sleep( 10 ); //- sleep just a few
#else
  usleep(10000);
#endif

ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("INIT");
LE's avatar
LE committed
	//- send command : INIT to trigg readings !
	_communication_link->write(cmd_to_send);
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::abort -> cancel all operations started by INIT command
// ============================================================================
void KeithleySCPIProtocol::abort (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::abort()");
	}
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("ABORt");
	//- send command : ABORt to cancel all operations
	_communication_link->write(cmd_to_send);
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::set_knplc : specify the integration rate
// ============================================================================
void KeithleySCPIProtocol::set_knplc (std::string nbNPLC) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_knplc()");
	}
LE's avatar
LE committed
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	std::string tmpMode = get_mode();
LE's avatar
LE committed

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("");
LE's avatar
LE committed
	//- send command
	cmd_to_send = tmpMode + ":NPLC " + nbNPLC ;
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_knplc : get the integration rate
// ============================================================================
std::string KeithleySCPIProtocol::get_knplc (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_knplc()");
	}
LE's avatar
LE committed
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	std::string tmpMode = get_mode();
LE's avatar
LE committed

	//- erase bad caracters
ELATTAOUI's avatar
ELATTAOUI committed
	tmpMode.erase( tmpMode.find("\n") );
LE's avatar
LE committed
	
ELATTAOUI's avatar
ELATTAOUI committed
std::string cmd_to_send("");
LE's avatar
LE committed
	//- send command
	cmd_to_send = tmpMode + ":NPLCycles?" ;
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_triggercount
// ============================================================================
void KeithleySCPIProtocol::set_triggercount (std::string nbTrigCount) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_triggercount()");
	}
	
LE's avatar
LE committed
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);
}

// ============================================================================
// KeithleySCPIProtocol::get_triggercount
// ============================================================================
std::string KeithleySCPIProtocol::get_triggercount (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_triggercount()");
	}
	
LE's avatar
LE committed
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send("TRIG:COUNt?");
	std::string response  = _communication_link->write_read(cmd_to_send);
LE's avatar
LE committed

  return response;
}

// ============================================================================
// KeithleySCPIProtocol::set_triggerdelay
// ============================================================================
void KeithleySCPIProtocol::set_triggerdelay (std::string trigDelay) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_triggerdelay()");
	}
	
LE's avatar
LE committed
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = "TRIG:DEL " + trigDelay ;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_triggerdelay
// ============================================================================
std::string KeithleySCPIProtocol::get_triggerdelay (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_triggerdelay()");
	}
	
LE's avatar
LE committed
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = "TRIG:DEL?" ;
LE's avatar
LE committed
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_triggerdelayAuto
// ============================================================================
void KeithleySCPIProtocol::set_triggerdelayAuto (std::string trigDelayAuto) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_triggerdelayAuto()");
	}
	
LE's avatar
LE committed
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = "TRIG:DEL:" + trigDelayAuto ;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_triggerdelayAuto
// ============================================================================
std::string KeithleySCPIProtocol::get_triggerdelayAuto (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_triggerdelayAuto()");
	}
	
LE's avatar
LE committed
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = "TRIG:DEL:AUTO?" ;
LE's avatar
LE committed
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_averagecount
// ============================================================================
void KeithleySCPIProtocol::set_averagecount (std::string nbAverageCount) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_averagecount()");
	}
ELATTAOUI's avatar
ELATTAOUI committed
	
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = "AVER:COUN " + nbAverageCount;
ELATTAOUI's avatar
ELATTAOUI committed
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_averagecount
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void KeithleySCPIProtocol::set_averagecount_K6517 (std::string nbAverageCount) 
ELATTAOUI's avatar
ELATTAOUI committed
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::set_averagecount()");
	}
LE's avatar
LE committed
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	std::string tmpMode = get_mode();
LE's avatar
LE committed

	//- erase bad caracters
ELATTAOUI's avatar
ELATTAOUI committed
	tmpMode.erase( tmpMode.find("\n") );
LE's avatar
LE committed
	
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send = tmpMode + ":AVER:COUN " + nbAverageCount ;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_averagecount
// ============================================================================
std::string KeithleySCPIProtocol::get_averagecount (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_averagecount()");
	}
ELATTAOUI's avatar
ELATTAOUI committed
	
	//- send command
ELATTAOUI's avatar
ELATTAOUI committed
	std::string cmd_to_send("AVER:COUNt?");
ELATTAOUI's avatar
ELATTAOUI committed
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_averagecount
// ============================================================================
std::string KeithleySCPIProtocol::get_averagecount_K6517 (void) 
{
ELATTAOUI's avatar
ELATTAOUI committed
	if( !this->_communication_link )
	{
		throw electrometer::ElectrometerException(
												"INITIALIZATION_ERROR", 
												"No communication protocol available.",
												"KeithleySCPIProtocol::get_averagecount()");
	}
LE's avatar
LE committed
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	std::string tmpMode = get_mode();
LE's avatar
LE committed

	//- erase bad caracters
ELATTAOUI's avatar
ELATTAOUI committed
	tmpMode.erase(tmpMode.find("\n") );
LE's avatar
LE committed
	
	//- send command