Skip to content
Snippets Groups Projects
Commit 2d753550 authored by Jade PHAM's avatar Jade PHAM
Browse files

add TCP comm mode for Novelec protocol

parent 24e01b1a
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ from conan import ConanFile
class electrometersRecipe(ConanFile):
name = "electrometers"
version = "2.7.1"
version = "2.8.0"
package_type = "library"
user = "soleil"
python_requires = "base/[>=1.0]@soleil/stable"
......
......@@ -36,7 +36,7 @@ public:
* \brief Initialization.
*/
// N_PhotoConducteur (std::string& comLink_device_name, short channel_address, short electroType);
N_PhotoConducteur (std::string& comLink_device_name, short channel_address);
N_PhotoConducteur (std::string& comLink_device_name, short channel_address, std::string comProtocol);
/**
* \brief Release resources.
......
......@@ -36,7 +36,7 @@ public:
* \brief Initialization.
*/
// N_PhotoVoltaique (std::string comLink_device_name, short channel_address, short electroType);
N_PhotoVoltaique (std::string comLink_device_name, short channel_address);
N_PhotoVoltaique (std::string comLink_device_name, short channel_address, std::string comProtocol);
/**
* \brief Release resources.
......
......@@ -17,6 +17,7 @@
#include "ElectrometerProtocol.h"
#include "ElectrometerException.h"
#include "TangoSerialLink.h"
#include "TangoEthernetLink.h"
/**
* \addtogroup Standard Commands Protocol
......@@ -38,7 +39,7 @@ public:
* \brief Initialization.
*/
//NovelecProtocol (std::string& communication_device_name, unsigned short channel_address, unsigned short electroTypeNumber);
NovelecProtocol (std::string& communication_device_name, unsigned short channel_address);
NovelecProtocol (std::string& communication_device_name, unsigned short channel_address, std::string comProtocol);
/**
* \brief Release resources.
......@@ -129,11 +130,15 @@ private :
void is_allowed();
CommunicationLink* _communication_link;
//communication protocol ETHERNET/SERIAL
std::string _comProtocol;
//- if true, parameters cannot be changed !
bool _is_measure_mode_on;
//- if true, explicite response mode is enabled
bool _is_explicite_resp_enabled;
//- the specific new line character
string END_OF_LINE ;
};
......
......@@ -36,7 +36,7 @@ public:
* \brief Initialization.
*/
// Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address, unsigned short electroType);
Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address);
Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address, std::string comProtocol);
/**
* \brief Release resources.
......@@ -100,6 +100,8 @@ protected :
* \brief Checks the new range value
*/
short check_range_value(const std::string& rgToCheck, const std::vector<std::string> electroRangeList);
private:
std::string _comProtocol;
};
......
// ============================================================================
//
// = CONTEXT
// TANGO Project - Keithley Electrometer Support Library
//
// = FILENAME
// TangoEthernetLink.h
//
// = AUTHOR
// X. Elattaoui
//
// ============================================================================
#ifndef _TANGO_ETHERNET_LINK_H_
#define _TANGO_ETHERNET_LINK_H_
// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <tango.h>
#include "CommunicationLink.h"
/**
* \addtogroup Communication Management
* @{
*/
/**
* \brief This class manage the ETHERNET communication bus
*
* \author
* \date
*/
class TangoEthernetLink : public CommunicationLink
{
public :
/**
* \brief Initialization.
*/
TangoEthernetLink (std::string& serial_device_name);
/**
* \brief Release resources.
*/
~TangoEthernetLink ();
/**
* \brief Send command (data) as string to hardware.
*
* \throws Tango::DevFailed
*/
void write(std::string cmd) throw (Tango::DevFailed);
std::string read(void) throw (Tango::DevFailed);
/**
* \brief Performs a write read operation as string. (read nb char)
*
* \throws Tango::DevFailed
*/
std::string write_read(std::string cmd, size_t nbChar) throw (Tango::DevFailed);
private :
/**
* Creates a proxy on the specified Serial Device.
*/
void check_proxy(void) throw (Tango::DevFailed);
Tango::DeviceProxy* _ethernet_proxy;
bool _is_ethernet_proxy_ok;
};
/** @} */ //- end addtogroup
#endif // _TANGO_ETHERNET_LINK_H_
......@@ -4,7 +4,7 @@
// TANGO Project - Keithley Electrometer Support Library
//
// = FILENAME
// TangoSerialLink.h
// TangoSerialLink.h.h
//
// = AUTHOR
// X. Elattaoui
......@@ -79,12 +79,11 @@ private :
/**
* Creates a proxy on the specified Serial Device.
*/
void create_serial_proxy(void) throw (Tango::DevFailed);
void check_proxy(void) throw (Tango::DevFailed);
//Tango::DeviceProxyHelper* _serial_proxy;
Tango::DeviceProxy* _serial_proxy;
bool _is_serial_proxy_created;
bool _is_serial_proxy_ok;
};
......
......@@ -8,7 +8,7 @@
</parent>
<groupId>fr.soleil.lib</groupId>
<artifactId>Electrometers-${aol}-${library}-${mode}</artifactId>
<version>2.7.1</version>
<version>2.8.0</version>
<packaging>nar</packaging>
<name>Electrometers library</name>
<description>Electrometers library</description>
......
......@@ -31,8 +31,8 @@ static const std::vector<std::string> NType5_rangeValue {"1000","300","100","30"
// ============================================================================
// N_PhotoConducteur::N_PhotoConducteur
// ============================================================================
N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short address)
: Novelec_MCCE2(comLink_device_name, address)
N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short address, std::string comProtocol)
: Novelec_MCCE2(comLink_device_name, address, comProtocol)
{
//std::cout << "N_PhotoConducteur::N_PhotoConducteur <-" << std::endl;
......@@ -46,7 +46,7 @@ N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short ad
// ============================================================================
N_PhotoConducteur::~N_PhotoConducteur (void)
{
//std::cout << "N_PhotoConducteur::~N_PhotoConducteur <-" << std::endl;
std::cout << "N_PhotoConducteur::~N_PhotoConducteur <-" << std::endl;
//std::cout << "N_PhotoConducteur::~N_PhotoConducteur ->" << std::endl;
}
......
......@@ -32,10 +32,10 @@ static const std::vector<std::string> NType3_rangeValue {"1E-08AcC","3E-08AcC","
// ============================================================================
// N_PhotoVoltaique::N_PhotoVoltaique
// ============================================================================
N_PhotoVoltaique::N_PhotoVoltaique (std::string comLink_device_name, short address)
: Novelec_MCCE2(comLink_device_name, address)
N_PhotoVoltaique::N_PhotoVoltaique (std::string comLink_device_name, short address, std::string comProtocol)
: Novelec_MCCE2(comLink_device_name, address, comProtocol)
{
//std::cout << "N_PhotoVoltaique::N_PhotoVoltaique <-" << std::endl;
std::cout << "N_PhotoVoltaique::N_PhotoVoltaique <-" << std::endl;
//std::cout << "N_PhotoVoltaique::N_PhotoVoltaique ->" << std::endl;
}
......
......@@ -40,8 +40,7 @@ static const short RESPONSE_LGTH_CMD_NUM = 17;
static const short CLEAR_ERRORS_CMD_NUM = 18;
static const long PILOTAGE_AND_PROG_RESP_LGTH = 10;
static const long READ_DATA_RESP_LGTH = 24;
//- the specific new line character
static const char END_OF_LINE[] = "\r\n";
//- modes allowed
static const std::string mode_str[] = {"ERR : UNKNOWN MODE","ZERO V/F","OFFSET","LEAKAGE","TEST","MEASURE"};
static const std::string range_str[5][8] = {
......@@ -54,36 +53,21 @@ static const std::string range_str[5][8] = {
static const std::string frequency_str[]= {"3 Hz","10 Hz","100 Hz","1000 Hz"};
static const std::string gain_str[] = {"1","10","100"};
/*
// ============================================================================
// NovelecProtocol::NovelecProtocol
// ============================================================================
NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress, unsigned short novelecType)
: ElectrometerProtocol(),
_devAdd(devAddress),
_novType(novelecType),
_rangeParameterNum(0),
_communication_link(0),
_is_measure_mode_on(false),
_is_explicite_resp_enabled(false)
{
_commDevName = serial_device_name;
_function = "Not updated";
}
*/
// ============================================================================
// NovelecProtocol::NovelecProtocol
// ============================================================================
NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress)
NovelecProtocol::NovelecProtocol (std::string& communication_device_name, unsigned short devAddress, std::string comProtocol)
: ElectrometerProtocol(),
_devAdd(devAddress),
_novType(0),
_rangeParameterNum(0),
_communication_link(0),
_comProtocol(comProtocol),
_is_measure_mode_on(false),
_is_explicite_resp_enabled(false)
{
_commDevName = serial_device_name;
_commDevName = communication_device_name;
_function = "Not updated";
}
......@@ -108,8 +92,17 @@ bool NovelecProtocol::build_communicationLink()
{
if (_commDevName.empty())
return false;
std::cout<<"NovelecProtocol::build_communicationLink "<<_comProtocol<<std::endl;
if (_comProtocol=="SERIAL")
{
_communication_link = new TangoSerialLink(_commDevName);
END_OF_LINE = "\r\n";
}
else if (_comProtocol=="ETHERNET")
{
_communication_link = new TangoEthernetLink(_commDevName);
END_OF_LINE ="";
}
if (!_communication_link)
return false;
......@@ -804,8 +797,6 @@ std::string NovelecProtocol::check_and_extract_data (std::string response, short
pos = data.find(" ");
}
/*data.erase(data.find_first_of(" "),1);
data.erase(data.find_last_of(" ")); */
}
else
throw electrometer::ElectrometerException("SYNCHRONISATION_LOST",
......
......@@ -39,16 +39,17 @@
// ============================================================================
// Novelec_MCCE2::Novelec_MCCE2
// ============================================================================
Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address)
Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address, std::string comProtocol)
: AbstractElectrometerClass(comLink_device_name),
_rangeLimit(0),
_address(address),
_MCCE2electroTypeNumber(0),
_MCCE2electroTypeStr("Unknown type")
_MCCE2electroTypeStr("Unknown type"),
_comProtocol(comProtocol)
{
std::cout << "\t\tNovelec_MCCE2::Novelec_MCCE2 <-" << std::endl;
std::cout << "\t\tNovelec_MCCE2::Novelec_MCCE2 <-" <<comProtocol<< std::endl;
std::cout << "\t\tNovelec_MCCE2::Novelec_MCCE2 ->" << std::endl;
}
// ============================================================================
......@@ -58,7 +59,6 @@ Novelec_MCCE2::~Novelec_MCCE2 (void)
{
//std::cout << "Novelec_MCCE2::~Novelec_MCCE2 <-" << std::endl;
//std::cout << "Novelec_MCCE2::~Novelec_MCCE2 ->" << std::endl;
}
// ============================================================================
......@@ -71,7 +71,7 @@ bool Novelec_MCCE2::init_protocol (void)
try
{
//- build the keithley Electrometer protocol obj
_electrometerProtocol = new NovelecProtocol(_device_proxy_name, _address);
_electrometerProtocol = new NovelecProtocol(_device_proxy_name, _address,_comProtocol);
if(_electrometerProtocol)
success = _electrometerProtocol->build_communicationLink();
......
// ============================================================================
//
// = CONTEXT
// TANGO Project - Keithley Electrometer Support Library
//
// = FILENAME
// TangoEthernetLink.cpp
//
// = AUTHOR
// X. Elattaoui
//
// ============================================================================
// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <string>
#include <iostream>
#include "TangoEthernetLink.h"
// ============================================================================
// TangoEthernetLink::TangoEthernetLink
// ============================================================================
TangoEthernetLink::TangoEthernetLink (std::string& serial_device_name)
: CommunicationLink(serial_device_name),
_ethernet_proxy (0),
_is_ethernet_proxy_ok (false)
{
}
// ============================================================================
// TangoEthernetLink::~TangoEthernetLink
// ============================================================================
TangoEthernetLink::~TangoEthernetLink (void)
{
if(_ethernet_proxy)
{
delete _ethernet_proxy;
_ethernet_proxy = 0;
_is_ethernet_proxy_ok = false;
}
}
// ============================================================================
// TangoEthernetLink::create_ethernet_proxy
// ============================================================================
void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed)
{
std::string description("");
try
{
//- try
this->_ethernet_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
_ethernet_proxy->ping();
_is_ethernet_proxy_ok = true;
}
catch(Tango::DevFailed& df )
{
if( this->_ethernet_proxy )
{
delete this->_ethernet_proxy;
this->_ethernet_proxy = 0;
}
_is_ethernet_proxy_ok = false;
description = "Unable to create proxy on : " + _communication_Device_name;
Tango::Except::re_throw_exception (df,
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoEthernetLink::create_ethernet_proxy");
}
catch(...)
{
if( this->_ethernet_proxy )
{
delete this->_ethernet_proxy;
this->_ethernet_proxy = 0;
}
_is_ethernet_proxy_ok = false;
description = "Unable to create proxy on : " + _communication_Device_name + "\nmemory allocation failed.";
Tango::Except::throw_exception (
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoEthernetLink::write");
}
}
// ============================================================================
// TangoEthernetLink::write
// ============================================================================
void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFailed)
{
std::string description("");
check_proxy();
if (!_is_ethernet_proxy_ok)
return;
Tango::DeviceData dd_in;
Tango::DevString argin = 0;
try
{
argin = new char [command_to_send.size() + 1];
strcpy(argin, command_to_send.c_str());
}
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(),
(const char*)"TangoEthernetLink::write");
}
catch(...)
{
description = "Unable to write command : " + command_to_send + "\nmemory allocation failed.";
Tango::Except::throw_exception (
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoEthernetLink::write");
}
try
{
//- try
dd_in << argin;
_ethernet_proxy->command_inout("Write", dd_in);
if( argin )
{
delete [] argin;
argin = 0;
}
//std::cout << "TangoEthernetLink::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*)"TangoEthernetLink::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*)"TangoEthernetLink::write");
}
}
// ============================================================================
// TangoEthernetLink::read
// ============================================================================
std::string TangoEthernetLink::read (void) throw (Tango::DevFailed)
{
check_proxy();
if(!_is_ethernet_proxy_ok)
return "";
Tango::DeviceData dd_out;
std::string response("");
try
{
dd_out = _ethernet_proxy->command_inout("Read");
dd_out >> 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*)"TangoEthernetLink::read");
}
catch(...)
{
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
(const char*)"Unable to perform a read operation",
(const char*)"TangoEthernetLink::read");
}
return response ;
}
// ============================================================================
// TangoEthernetLink::write_read : read N char
// ============================================================================
std::string TangoEthernetLink::write_read (std::string command_to_send, size_t nbChar) throw (Tango::DevFailed)
{
std::string resp;
check_proxy();
if(!_is_ethernet_proxy_ok)
return "";
Tango::DeviceData dd_in;
Tango::DevString argin = 0;
Tango::DeviceData dd_out;
std::string response("");
try
{
argin = new char [command_to_send.size() + 1];
strcpy(argin, command_to_send.c_str());
dd_in << argin;
dd_out = _ethernet_proxy->command_inout("WriteRead", dd_in);
dd_out >> 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*)"TangoEthernetLink::read");
}
catch(...)
{
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
(const char*)"Unable to perform a read operation",
(const char*)"TangoEthernetLink::read");
}
return response ;
}
......@@ -28,11 +28,10 @@ static const long MODE_LINE = 2;
TangoSerialLink::TangoSerialLink (std::string& serial_device_name)
: CommunicationLink(serial_device_name),
_serial_proxy (0),
_is_serial_proxy_created (false)
_is_serial_proxy_ok (false)
{
// //std::cout << "TangoSerialLink::TangoSerialLink <-" << std::endl;
//std::cout << "TangoSerialLink::TangoSerialLink <-" << std::endl;
// //std::cout << "TangoSerialLink::TangoSerialLink ->" << std::endl;
}
// ============================================================================
......@@ -46,7 +45,7 @@ TangoSerialLink::~TangoSerialLink (void)
{
delete _serial_proxy;
_serial_proxy = 0;
_is_serial_proxy_created = false;
_is_serial_proxy_ok = false;
}
std::cout << "TangoSerialLink::~TangoSerialLink ->" << std::endl;
......@@ -56,16 +55,19 @@ TangoSerialLink::~TangoSerialLink (void)
// ============================================================================
// TangoSerialLink::create_serial_proxy
// ============================================================================
void TangoSerialLink::create_serial_proxy (void) throw (Tango::DevFailed)
void TangoSerialLink::check_proxy (void) throw (Tango::DevFailed)
{
std::string description("");
try
{
//- try
this->_serial_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
//(*_serial_proxy)->ping();
_is_serial_proxy_created = true;
if (_serial_proxy==0)
{
_serial_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
}
_serial_proxy->ping();
_is_serial_proxy_ok = true;
}
catch(Tango::DevFailed& df )
{
......@@ -74,13 +76,12 @@ void TangoSerialLink::create_serial_proxy (void) throw (Tango::DevFailed)
delete this->_serial_proxy;
this->_serial_proxy = 0;
}
_is_serial_proxy_created = false;
description = "Unable to create proxy on : " + _communication_Device_name;
_is_serial_proxy_ok = false;
description = "Cannot connect to : " + _communication_Device_name;
Tango::Except::re_throw_exception (df,
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoSerialLink::create_serial_proxy");
(const char*)"TangoSerialLink::check_proxy");
}
catch(...)
{
......@@ -89,12 +90,12 @@ void TangoSerialLink::create_serial_proxy (void) throw (Tango::DevFailed)
delete this->_serial_proxy;
this->_serial_proxy = 0;
}
_is_serial_proxy_created = false;
_is_serial_proxy_ok = false;
description = "Unable to create proxy on : " + _communication_Device_name + "\nmemory allocation failed.";
Tango::Except::throw_exception (
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoSerialLink::write");
(const char*)"TangoSerialLink::check_proxy");
}
}
......@@ -105,8 +106,9 @@ void TangoSerialLink::write (std::string command_to_send) throw (Tango::DevFail
{
std::string description("");
check_proxy();
if(!_serial_proxy)
create_serial_proxy();
return ;
Tango::DeviceData dd_in;
Tango::DevString argin = 0;
......@@ -185,8 +187,9 @@ void TangoSerialLink::write (std::string command_to_send) throw (Tango::DevFail
std::string TangoSerialLink::read (void) throw (Tango::DevFailed)
{
check_proxy();
if(!_serial_proxy)
create_serial_proxy();
return "";
Tango::DeviceData dd_out;
std::string response("");
......@@ -220,8 +223,10 @@ std::string TangoSerialLink::read (void) throw (Tango::DevFailed)
std::string TangoSerialLink::read (long nbCharToRead) throw (Tango::DevFailed)
{
check_proxy();
if(!_serial_proxy)
create_serial_proxy();
return "";
Tango::DeviceData dd_in;
Tango::DeviceData dd_out;
std::string response("");
......@@ -253,8 +258,9 @@ std::string TangoSerialLink::write_read (std::string command_to_send, size_t nbC
Tango::DeviceData dd_in;
Tango::DeviceData dd_out;
check_proxy();
if(!_serial_proxy)
create_serial_proxy();
return "";
long flush_in_out = 2;
dd_in << flush_in_out;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment