Newer
Older
// ============================================================================
//
// = CONTEXT
// TANGO Project - Keithley Electrometer Support Library
//
// = FILENAME
// TangoGpibLink.cpp
//
// = AUTHOR
// X. Elattaoui
//
// ============================================================================
// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <string>
#include <iostream>
#include "TangoGpibLink.h"
// ============================================================================
// TangoGpibLink::TangoGpibLink
// ============================================================================
TangoGpibLink::TangoGpibLink (std::string& gpib_device_name)
: CommunicationLink(gpib_device_name),
{
std::cout << "TangoGpibLink::TangoGpibLink <-" << std::endl;
response.erase();
std::cout << "TangoGpibLink::TangoGpibLink ->" << std::endl;
}
// ============================================================================
// TangoGpibLink::~TangoGpibLink
// ============================================================================
TangoGpibLink::~TangoGpibLink (void)
{
std::cout << "TangoGpibLink::~TangoGpibLink <-" << std::endl;
{
delete _gpib_proxy;
_gpib_proxy = 0;
}
std::cout << "TangoGpibLink::~TangoGpibLink ->" << std::endl;
}
// ============================================================================
// TangoGpibLink::create_gpib_proxy
// ============================================================================
void TangoGpibLink::create_gpib_proxy (void) throw (Tango::DevFailed)
{

ELATTAOUI
committed
this->_gpib_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
description = "Unable to create proxy on : " + _communication_Device_name + ". Check GPIB device is up !";
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
}
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");
}
}
// ============================================================================
// TangoGpibLink::write
// ============================================================================
void TangoGpibLink::write (std::string command_to_send) throw (Tango::DevFailed)
{

ELATTAOUI
committed
Tango::DeviceData dd_in;
Tango::DevString cmd = 0;

ELATTAOUI
committed
try
{
cmd = new char [command_to_send.size() + 1];
strcpy(cmd, command_to_send.c_str());
}
catch(Tango::DevFailed& df )
{
if ( cmd )
delete [] cmd;
description = "Failed to allocate memory for the command to write";
Tango::Except::re_throw_exception (df,
(const char*)"MEMORY_ALLOCATION",
description.c_str(),
(const char*)"TangoGpibLink::write");
}
catch(...)
{
if ( cmd )
delete [] cmd;
Tango::Except::throw_exception (
(const char*)"MEMORY_ALLOCATION",
(const char*)"Not enough memory.",
(const char*)"TangoGpibLink::write");
}

ELATTAOUI
committed
dd_in << cmd;
this->_gpib_proxy->command_inout("Write", dd_in);
if ( cmd )
delete [] cmd;

ELATTAOUI
committed
if ( cmd )
delete [] cmd;
description = "Unable to write command : " + command_to_send + ". Caught DevFailed." ;
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
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");
}
}
// ============================================================================
// TangoGpibLink::read
// ============================================================================
std::string TangoGpibLink::read (void) throw (Tango::DevFailed)
{

ELATTAOUI
committed
Tango::DeviceData dd_out;

ELATTAOUI
committed
dd_out = this->_gpib_proxy->command_inout("Read");
dd_out >> this->response;
}
catch(Tango::DevFailed& df )
{
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
(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");
}

ELATTAOUI
committed
return this->response;
}
// ============================================================================
// TangoGpibLink::write_read
// ============================================================================
std::string TangoGpibLink::write_read (std::string command_to_send) throw (Tango::DevFailed)
{

ELATTAOUI
committed
Tango::DeviceData dd_in, dd_out;
Tango::DevString argin = 0;

ELATTAOUI
committed
argin = new char [command_to_send.size() + 1];
strcpy(argin, command_to_send.c_str());
dd_in << argin;
dd_out = this->_gpib_proxy->command_inout("WriteRead", dd_in);
dd_out >> this->response;
if ( argin )
delete [] argin;

ELATTAOUI
committed
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",
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");
}
// ============================================================================
// ============================================================================

ELATTAOUI
committed
Tango::DeviceData dd_out;

ELATTAOUI
committed
dd_out = this->_gpib_proxy->command_inout("IsSRQLineUP");
dd_out >> result;
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
catch(...)
{
description = "Unable to get Gpib SRQ line state.";
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
description.c_str(),
(const char*)"TangoGpibLink::SRQLineState");
}
}
// ============================================================================
// TangoGpibLink::readStatusByteRegister
// ============================================================================
short TangoGpibLink::readStatusByteRegister (void) throw (Tango::DevFailed)
{

ELATTAOUI
committed
Tango::DeviceAttribute da_out;

ELATTAOUI
committed
da_out = this->_gpib_proxy->read_attribute("statusByteRegister");
da_out >> result;
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
catch(...)
{
description = "Unable to get device status byte register.";
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
description.c_str(),
(const char*)"TangoGpibLink::readStatusByteRegister");
}
// ============================================================================
// TangoGpibLink::clear
// ============================================================================
void TangoGpibLink::clear (void) throw (Tango::DevFailed)
{

ELATTAOUI
committed
this->_gpib_proxy->command_inout("Clear");
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
catch(...)
{
description = "Unable send Clear Device command.";
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
description.c_str(),
(const char*)"TangoGpibLink::clear");
}
}
// ============================================================================
// TangoGpibLink::trigger
// ============================================================================
void TangoGpibLink::trigger (void) throw (Tango::DevFailed)
{

ELATTAOUI
committed
this->_gpib_proxy->command_inout("Trigger");
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
(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");