Skip to content
Snippets Groups Projects
KeithleySCPIProtocol.cpp 34.8 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
//# include 
//#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;

	_communication_link = new TangoGpibLink (_commDevName);

  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);

  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;
	
	//- 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("");

	//- 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("");

	//- 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("");

	//- 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("");

	//- 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("");

	//- 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("");

	//- 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;
	
	//- 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;
	
	//- 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("");

	//- 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("");

	//- 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;
std::string mode_ ("");

	//- mode current (send CURR)
	mode_ = "CURRent";

	//- send command
	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setVoltMeterMode
// ============================================================================
void KeithleySCPIProtocol::setVoltMeterMode (void) 
{
std::stringstream cmd_to_send;
std::string mode_ ("");

	//- mode volt
	mode_ = "VOLTage";

	//- send command
	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
	_communication_link->write(cmd_to_send.str());
}

// ============================================================================
// KeithleySCPIProtocol::setOhmMeterMode
// ============================================================================
void KeithleySCPIProtocol::setOhmMeterMode (void) 
{
std::stringstream cmd_to_send;
std::string mode_ ("");

	//- mode ohm
	mode_ = "RESistance";

	//- send command
	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setCoulombMeterMode
// ============================================================================
void KeithleySCPIProtocol::setCoulombMeterMode (void) 
{
std::stringstream cmd_to_send;
std::string mode_ ("");

	//- mode coulomb
	mode_ = "CHARge";

	//- send command
	cmd_to_send << "FUNC \'" << mode_ << "\'" << std::endl;
	_communication_link->write(cmd_to_send.str());

}

// ============================================================================
// KeithleySCPIProtocol::setVSourceOutputON
// ============================================================================
void KeithleySCPIProtocol::setVSourceOutputON (void) 
{
std::stringstream cmd_to_send;

	//- send command
	cmd_to_send << "OUTP 1" << std::endl;
	_communication_link->write(cmd_to_send.str());
}

// ============================================================================
// KeithleySCPIProtocol::setVSourceOutputOFF
// ============================================================================
void KeithleySCPIProtocol::setVSourceOutputOFF (void) 
{
std::stringstream cmd_to_send;

	//- send command
	cmd_to_send << "OUTP 0" << std::endl;
	_communication_link->write(cmd_to_send.str());
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::setVSourceValue
// ============================================================================
void KeithleySCPIProtocol::setVSourceValue (double voltsValue) 
{
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) 
{
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) 
{
std::string cmd_to_send("");
	
	//- 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) 
{
std::string cmd_to_send("");
std::string tmpMode;
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- 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
	////- 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("");

	//- 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("");

	//- 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) 
{
std::string cmd_to_send("INIT");

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

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) 
{
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) 
{
std::string cmd_to_send("");
std::string tmpMode;
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- 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) 
{
std::string cmd_to_send("");
std::string tmpMode;
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- 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) 
{
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 )
ELATTAOUI's avatar
ELATTAOUI committed
//	set_buffer_size(nbTrigCount);
LE's avatar
LE committed

}

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

	//- send command
	cmd_to_send = "TRIG:COUNt?" ;
	response  = _communication_link->write_read(cmd_to_send);

  return response;
}

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

	//- send command
	cmd_to_send = "TRIG:DEL " + trigDelay ;
	_communication_link->write(cmd_to_send);
}

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

	//- send command
	cmd_to_send = "TRIG:DEL?" ;
	return _communication_link->write_read(cmd_to_send);
}

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

	//- send command
	cmd_to_send = "TRIG:DEL:" + trigDelayAuto ;
	_communication_link->write(cmd_to_send);
}

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

	//- send command
	cmd_to_send = "TRIG:DEL:AUTO?" ;
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_averagecount
// ============================================================================
void KeithleySCPIProtocol::set_averagecount (std::string nbAverageCount) 
{
std::string cmd_to_send("");
ELATTAOUI's avatar
ELATTAOUI committed
	
	//- send command
	cmd_to_send = "AVER:COUN " + nbAverageCount;
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_averagecount
// ============================================================================
void KeithleySCPIProtocol::set_averagecount_K6517 (std::string cmd_to_send) 
{
std::string tmpMode("");
LE's avatar
LE committed
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	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
	cmd_to_send = tmpMode + ":AVER:COUN " + cmd_to_send ;
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
std::string cmd_to_send("");
	
	//- send command
	cmd_to_send = "AVER:COUNt?" ;
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_averagecount
// ============================================================================
std::string KeithleySCPIProtocol::get_averagecount_K6517 (void) 
{
LE's avatar
LE committed
std::string cmd_to_send("");
std::string tmpMode;
	
	//- get electrometer mode
ELATTAOUI's avatar
ELATTAOUI committed
	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
	cmd_to_send = tmpMode + ":AVER:COUNt?" ;
LE's avatar
LE committed
	return _communication_link->write_read(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::set_averagecontrol
// ============================================================================
void KeithleySCPIProtocol::set_averagecontrol (std::string nbAverageControl) 
{
std::string cmd_to_send("");
ELATTAOUI's avatar
ELATTAOUI committed
std::string tmpMode("");
LE's avatar
LE committed
	
	//- get electrometer mode
//	tmpMode = get_mode( );

	//- send command
	cmd_to_send = "AVER:TCON " + nbAverageControl;
	_communication_link->write(cmd_to_send);
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::set_averagecontrol
// ============================================================================
void KeithleySCPIProtocol::set_averagecontrol_K6517 (std::string nbAverageControl) 
{
std::string cmd_to_send("");
std::string tmpMode("");
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- send command
	cmd_to_send = tmpMode + ":AVER:TCON " + nbAverageControl;
	_communication_link->write(cmd_to_send);
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::get_averagecontrol
// ============================================================================
std::string KeithleySCPIProtocol::get_averagecontrol (void) 
{
std::string cmd_to_send("");
ELATTAOUI's avatar
ELATTAOUI committed
std::string tmpMode("");
LE's avatar
LE committed
	
	//- get electrometer mode
//	tmpMode = get_mode( );

	//- send command
	cmd_to_send = "AVER:TCONtrol?" ;
	return _communication_link->write_read(cmd_to_send);
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::get_averagecount
// ============================================================================
std::string KeithleySCPIProtocol::get_averagecontrol_K6517 (void) 
{
std::string cmd_to_send("");
std::string tmpMode("");
	
	//- get electrometer mode
	tmpMode = get_mode( );

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

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::clear_registers
// ============================================================================
void KeithleySCPIProtocol::clear_registers (void) 
{
std::string cmd_to_send("");
	
	//- send command
	cmd_to_send = "*CLS" ;
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::averageStateON
// ============================================================================
void KeithleySCPIProtocol::averageStateON (void) 
{
std::string cmd_to_send("");
	
	//- send command
	cmd_to_send = "AVER ON" ;
	_communication_link->write(cmd_to_send);
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::averageStateON_K6517
// ============================================================================
void KeithleySCPIProtocol::averageStateON_K6517 (void) 
{
std::string cmd_to_send("");
std::string tmpMode("");
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- send command
	cmd_to_send = tmpMode + ":AVER ON" ;
	_communication_link->write(cmd_to_send);
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::averageStateOFF
// ============================================================================
void KeithleySCPIProtocol::averageStateOFF (void) 
{
std::string cmd_to_send("");
	
	//- send command
	cmd_to_send = "AVER OFF";
	_communication_link->write(cmd_to_send);
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::averageStateOFF_K6517
// ============================================================================
void KeithleySCPIProtocol::averageStateOFF_K6517 (void) 
{
std::string cmd_to_send("");
std::string tmpMode("");
	
	//- get electrometer mode
	tmpMode = get_mode( );

	//- erase bad caracters
	tmpMode.erase(tmpMode.find("\n") );
	
	//- send command
	cmd_to_send = tmpMode + ":AVER OFF" ;
	_communication_link->write(cmd_to_send);
}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::reset
// ============================================================================
void KeithleySCPIProtocol::reset (void) 
{
std::string cmd_to_send("");
	
	//- send command
	cmd_to_send = "*RST" ;
	_communication_link->write(cmd_to_send);

  //- Select reading only
  cmd_to_send = "FORM:ELEM READ";

	//- send command
	_communication_link->write(cmd_to_send);
}

// ============================================================================
// KeithleySCPIProtocol::get_raw_status
// ============================================================================
std::string KeithleySCPIProtocol::get_raw_status (void) 
{
std::string cmd_to_send("");
std::string argout("no data");

	//- send command : read error queue only
	cmd_to_send = "STAT:QUE?";
	argout = _communication_link->write_read(cmd_to_send);


	return argout;
}

// ============================================================================
// KeithleySCPIProtocol::set_buffer_size()
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void KeithleySCPIProtocol::set_buffer_size (std::string size) 
LE's avatar
LE committed
{
std::string cmd_to_send("");

	//- send command : size = number of triggers
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send = "TRAC:POIN " + size;
LE's avatar
LE committed
	_communication_link->write(cmd_to_send);

}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// KeithleySCPIProtocol::get_buffer_size()
// ============================================================================
std::string KeithleySCPIProtocol::get_buffer_size ( ) 
{
std::string cmd_to_send("TRAC:POIN:ACTual?");

	//- send command :
	return _communication_link->write_read(cmd_to_send);

}

LE's avatar
LE committed
// ============================================================================
// KeithleySCPIProtocol::clear_buffer()
// ============================================================================
void KeithleySCPIProtocol::clear_buffer (void) 
{
std::string cmd_to_send("TRAC:CLEAR");

	//- send command : clear previous data
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::store_raw_input()
// ============================================================================
void KeithleySCPIProtocol::store_raw_input (void) 
{
std::string cmd_to_send("TRAC:FEED SENS");

	//- send command : Store raw input readings
	_communication_link->write(cmd_to_send);

}

// ============================================================================
// KeithleySCPIProtocol::start_storing()
// ============================================================================
void KeithleySCPIProtocol::start_storing (void) 
{
std::string cmd_to_send("TRAC:FEED:CONT NEXT");

	//- send command : Start storing readings
	_communication_link->write(cmd_to_send);
LE's avatar
LE committed

// ============================================================================
// KeithleySCPIProtocol::save_configuration
// ============================================================================
void KeithleySCPIProtocol::save_configuration (unsigned short memoryIdx) 
{
std::stringstream cmd_to_send;

	//- send command
  cmd_to_send << "*SAV " << memoryIdx << std::endl;
	_communication_link->write(cmd_to_send.str());
}

// ============================================================================
// KeithleySCPIProtocol::restore_configuration
// ============================================================================
void KeithleySCPIProtocol::restore_configuration (unsigned short memoryIdx) 
{
std::stringstream cmd_to_send;

	//- send command
  cmd_to_send << "*RCL " << memoryIdx << std::endl;
	_communication_link->write(cmd_to_send.str());
LE's avatar
LE committed
}

// ============================================================================
// KeithleySCPIProtocol::enable_SRQBufferFull()
// ============================================================================
void KeithleySCPIProtocol::enable_SRQBufferFull (void) 
{
/**********************************************************/
/*  NOTE :                                                */
/* 512 is the 10th bit in the MESUREMENT EVENT REGISTERS  */
/* which the BUFFER FULL bit that can be enabled          */
/**********************************************************/
  
  std::string cmd_to_send("STAT:MEAS:ENAB 512");

	//- send command : enable buffer full in the Measurement event enable register
	_communication_link->write(cmd_to_send);

  //- Program the service request enable register: to send SRQ on Buffer Full !
  cmd_to_send = "*SRE 1";