// ============================================================================ // // = 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), _gpib_proxy (0), _is_gpib_proxy_created (false) { 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; if(_is_gpib_proxy_created) { delete _gpib_proxy; _gpib_proxy = 0; _is_gpib_proxy_created = false; } std::cout << "TangoGpibLink::~TangoGpibLink ->" << std::endl; } // ============================================================================ // TangoGpibLink::create_gpib_proxy // ============================================================================ void TangoGpibLink::create_gpib_proxy (void) throw (Tango::DevFailed) { TangoSys_OMemStream description; try { //- try this->_gpib_proxy = new Tango::DeviceProxyHelper(_communication_Device_name); _is_gpib_proxy_created = true; } catch(Tango::DevFailed& df ) { description << "Unable to create proxy on : " << _communication_Device_name << ends; _is_gpib_proxy_created = false; Tango::Except::re_throw_exception (df, (const char*)"COMMUNICATION_ERROR", description.str(), (const char*)"TangoGpibLink::create_gpib_proxy"); } } // ============================================================================ // TangoGpibLink::write // ============================================================================ void TangoGpibLink::write (std::string command_to_send) throw (Tango::DevFailed) { TangoSys_OMemStream description; if(!_is_gpib_proxy_created) create_gpib_proxy(); try { //- try this->_gpib_proxy->command_in("Write", command_to_send); } catch(Tango::DevFailed& df ) { description << "Unable to write command : " << command_to_send << ends; Tango::Except::re_throw_exception (df, (const char*)"COMMUNICATION_ERROR", description.str(), (const char*)"TangoGpibLink::write"); } } // ============================================================================ // TangoGpibLink::read // ============================================================================ std::string TangoGpibLink::read (void) throw (Tango::DevFailed) { if(!_is_gpib_proxy_created) create_gpib_proxy(); try { //- try this->_gpib_proxy->command_out("Read", 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"); } return this->response ; } // ============================================================================ // TangoGpibLink::write_read // ============================================================================ std::string TangoGpibLink::write_read (std::string command_to_send) throw (Tango::DevFailed) { TangoSys_OMemStream description; if(!_is_gpib_proxy_created) create_gpib_proxy(); try { //- try this->_gpib_proxy->command_inout("WriteRead", command_to_send, response); return this->response; } catch(Tango::DevFailed& df ) { description << "Unable to write command : " << command_to_send << " and read device response." << ends; Tango::Except::re_throw_exception (df, (const char*)"COMMUNICATION_ERROR", description.str(), (const char*)"TangoGpibLink::write_read"); } } // ============================================================================ // TangoGpibLink::isSRQLineUp // ============================================================================ bool TangoGpibLink::isSRQLineUp (void) throw (Tango::DevFailed) { TangoSys_OMemStream description; bool result = false; if(!_is_gpib_proxy_created) create_gpib_proxy(); try { //- try this->_gpib_proxy->read_attribute("isSRQLineAsserted", result); return result; } catch(Tango::DevFailed& df ) { description << "Unable to get Gpib SRQ line state." << ends; Tango::Except::re_throw_exception (df, (const char*)"COMMUNICATION_ERROR", description.str(), (const char*)"TangoGpibLink::isSRQLineUp"); } }