From e4628b2ce1a10bc4fd2c89e3d12bf9ccfe7c11ef Mon Sep 17 00:00:00 2001 From: Xavier Elattaoui <xavier.elattaoui@synchrotron-soleil.fr> Date: Tue, 9 Feb 2016 09:27:30 +0000 Subject: [PATCH] Added command which returns the connected electrometer type as string. --- doc/doc_html/DevCommands.html | 16 +- doc/doc_html/DevCommandsList.html | 1 + doc/doc_html/DevCommandsTable.html | 3 + doc/doc_html/user_guide.html | 17 + pom.xml | 2 +- src/MCCE2Electrometers.cpp | 162 ++++- src/MCCE2Electrometers.h | 950 +++++++++++++------------ src/MCCE2ElectrometersClass.cpp | 29 + src/MCCE2ElectrometersClass.h | 24 + src/MCCE2ElectrometersStateMachine.cpp | 14 + 10 files changed, 721 insertions(+), 497 deletions(-) diff --git a/doc/doc_html/DevCommands.html b/doc/doc_html/DevCommands.html index e6d6821..529233c 100644 --- a/doc/doc_html/DevCommands.html +++ b/doc/doc_html/DevCommands.html @@ -230,7 +230,7 @@ Throw : <Li><Strong>Argout:<Br>DEV_VOID</Strong> : no argout<Br>  <Li><Strong>Command allowed for: </Strong><Ul> -<Li>Tango::ON<Li>Tango::ALARM<Li>Tango::FAULT</Ul> +<Li>Tango::ON<Li>Tango::ALARM</Ul> <Br>  </ul><Br> <Br> @@ -420,6 +420,20 @@ Value must be set in UPPER case !!!<Br>  <Br>  </ul><Br> <Br> +<A NAME="GetElectrometerTypeStr"><!-- --></A> +<A NAME="GetElectrometerTypeStr"><!-- --></A> +<h2>26 - GetElectrometerTypeStr</h2> +<ul> +<Li><Strong>Description: </Strong> This command returns the connected electrometer type as string for the specified channel.<Br>  +<Li><Strong>Argin:<Br>DEV_USHORT</Strong> + : channel number<Br>  +<Li><Strong>Argout:<Br>DEV_STRING</Strong> + : the electrometer type as string<Br>  +<Li><Strong>Command allowed for: </Strong><Ul> +<Li>Tango::ON<Li>Tango::ALARM<Li>Tango::FAULT<Li>Tango::DISABLE</Ul> +<Br>  +</ul><Br> +<Br> <!--- html Footer ---> diff --git a/doc/doc_html/DevCommandsList.html b/doc/doc_html/DevCommandsList.html index dc4d5af..cd83fb9 100644 --- a/doc/doc_html/DevCommandsList.html +++ b/doc/doc_html/DevCommandsList.html @@ -33,6 +33,7 @@ <A Href="DevCommands.html#SetHzFilter" TARGET="DevCommands"> SetHzFilter</a><Br> <A Href="DevCommands.html#GetGain" TARGET="DevCommands"> GetGain</a><Br> <A Href="DevCommands.html#SetGain" TARGET="DevCommands"> SetGain</a><Br> +<A Href="DevCommands.html#GetElectrometerTypeStr" TARGET="DevCommands"> GetElectrometerTypeStr</a><Br> </BODY> diff --git a/doc/doc_html/DevCommandsTable.html b/doc/doc_html/DevCommandsTable.html index aa7dbf6..bc7125a 100644 --- a/doc/doc_html/DevCommandsTable.html +++ b/doc/doc_html/DevCommandsTable.html @@ -94,6 +94,9 @@ Revision: - Author: xavela <Tr><Td><b>SetPolarity</b></Td> <Td><Font Size=-1>DEV_STRING</Font></Td> <Td><Font Size=-1>DEV_VOID</Font></Td> +<Tr><Td><b>GetElectrometerTypeStr</b></Td> +<Td><Font Size=-1>DEV_USHORT</Font></Td> +<Td><Font Size=-1>DEV_STRING</Font></Td> diff --git a/doc/doc_html/user_guide.html b/doc/doc_html/user_guide.html index a92f298..22c31f1 100644 --- a/doc/doc_html/user_guide.html +++ b/doc/doc_html/user_guide.html @@ -253,6 +253,9 @@ There is no Class properties.<Br><Br> <Tr><Td><b>SetPolarity</b></Td> <Td><Font Size=-1>DEV_STRING</Font></Td> <Td><Font Size=-1>DEV_VOID</Font></Td> +<Tr><Td><b>GetElectrometerTypeStr</b></Td> +<Td><Font Size=-1>DEV_USHORT</Font></Td> +<Td><Font Size=-1>DEV_STRING</Font></Td> @@ -686,6 +689,20 @@ Value must be set in UPPER case !!!<Br>  <Br>  </ul><Br> <Br> +<A NAME="GetElectrometerTypeStr"><!-- --></A> +<A NAME="GetElectrometerTypeStr"><!-- --></A> +<h2>26 - GetElectrometerTypeStr</h2> +<ul> +<Li><Strong>Description: </Strong> This command returns the connected electrometer type as string for the specified channel.<Br>  +<Li><Strong>Argin:<Br>DEV_USHORT</Strong> + : channel number<Br>  +<Li><Strong>Argout:<Br>DEV_STRING</Strong> + : the electrometer type as string<Br>  +<Li><Strong>Command allowed for: </Strong><Ul> +<Li>Tango::ON<Li>Tango::ALARM<Li>Tango::FAULT<Li>Tango::DISABLE</Ul> +<Br>  +</ul><Br> +<Br> </center> <Br> <Br><Br> <Br> diff --git a/pom.xml b/pom.xml index c5d24c7..6310ee1 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ </parent> <groupId>fr.soleil.device</groupId> <artifactId>MCCE2Electrometers-${aol}-${mode}</artifactId> - <version>2.2.6-SNAPSHOT</version> + <version>2.2.6</version> <packaging>nar</packaging> <name>MCCE2Electrometers</name> <!-- use for the name of executable --> diff --git a/src/MCCE2Electrometers.cpp b/src/MCCE2Electrometers.cpp index 3fc2ef9..2dd17cf 100644 --- a/src/MCCE2Electrometers.cpp +++ b/src/MCCE2Electrometers.cpp @@ -68,6 +68,7 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio // SetHzFilter | set_hz_filter() // GetGain | get_gain() // SetGain | set_gain() +// GetElectrometerTypeStr | get_electrometer_type_str() // //=================================================================== @@ -75,8 +76,8 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio #include <tango.h> #include <PogoHelper.h> #include <Xstring.h> -#include <yat4tango/InnerAppender.h> -#include <yat4tango/YatLogAdapter.h> +#include <yat4tango/InnerAppender.h> +#include <yat4tango/YatLogAdapter.h> #include <MCCE2Electrometers.h> #include <MCCE2ElectrometersClass.h> #include "N_PhotoVoltaique.h" @@ -143,12 +144,12 @@ void MCCE2Electrometers::delete_device() DELETE_DEVSTRING_ATTRIBUTE(attr_range2_read); DELETE_SCALAR_ATTRIBUTE(attr_electrometerChannel_read); - //- release the inner-appender - INFO_STREAM << "Remove the inner-appender." << endl; - yat4tango::InnerAppender::release(this); - - INFO_STREAM << "Remove the log-adapter." << endl; - yat4tango::YatLogAdapter::release(); + //- release the inner-appender + INFO_STREAM << "Remove the inner-appender." << endl; + yat4tango::InnerAppender::release(this); + + INFO_STREAM << "Remove the log-adapter." << endl; + yat4tango::YatLogAdapter::release(); } //+---------------------------------------------------------------------------- @@ -162,10 +163,10 @@ void MCCE2Electrometers::init_device() { INFO_STREAM << "MCCE2Electrometers::MCCE2Electrometers() create device " << device_name << endl; - yat4tango::YatLogAdapter::initialize(this); - - // Initialize the inner appender. - yat4tango::InnerAppender::initialize(this); + yat4tango::YatLogAdapter::initialize(this); + + // Initialize the inner appender. + yat4tango::InnerAppender::initialize(this); // Initialise variables to default values //-------------------------------------------- @@ -176,6 +177,8 @@ void MCCE2Electrometers::init_device() attr_electrometerChannel_write = ELETRO_CHANNEL_ONE; this->_updateRange1FromHW = true; //- force update after init. this->_updateRange2FromHW = true; //- force update after init. + this->_electroCH1StrType = "Not connected"; + this->_electroCH2StrType = "Not connected"; get_device_property(); @@ -196,6 +199,7 @@ void MCCE2Electrometers::init_device() INFO_STREAM << "init_device -> create_electrometers_obj : ... " << std::endl; try { + //- check connected electrometer(s) create_electrometers_obj(); } catch(...) @@ -481,9 +485,9 @@ void MCCE2Electrometers::write_electrometerChannel(Tango::WAttribute &attr) if ( attr_electrometerChannel_write == ELETRO_CHANNEL_ONE ) { - this->_electrometer = this->_electrometerCH1; if ( this->_electrometerCH1 ) { + this->_electrometer = this->_electrometerCH1; //- now force update from HW this->_updateRange1FromHW = true; } @@ -496,9 +500,9 @@ void MCCE2Electrometers::write_electrometerChannel(Tango::WAttribute &attr) } else if ( attr_electrometerChannel_write == ELETRO_CHANNEL_TWO ) { - this->_electrometer = this->_electrometerCH2; if ( this->_electrometerCH2 ) { + this->_electrometer = this->_electrometerCH2; //- now force update from HW this->_updateRange2FromHW = true; } @@ -2269,20 +2273,23 @@ void MCCE2Electrometers::create_electrometers_obj() try { if(nMCCE1) + { + //- get type as num type1 = nMCCE1->get_electrometer_type(); + //- get type as string + this->_electroCH1StrType = nMCCE1->get_electrometer_typeStr(); + } } catch(const electrometer::ElectrometerException& ke) { set_state(Tango::FAULT); - set_status("Failed to find which Novelec type is connected : communication caught[...]"); + set_status("Failed to find which Novelec type is connected on channel one : communication caught[...]"); Tango::DevFailed df = electrometer_to_tango_exception(ke); - - FATAL_STREAM << "Failed to find which Novelec type is connected : ElectrometerException EXCEPTION -> " << df << std::endl; - + FATAL_STREAM << "Failed to find which Novelec type is connected on channel one : ElectrometerException EXCEPTION -> " << df << std::endl; Tango::Except::re_throw_exception(df, "COMMUNICATION_ERROR", - "Failed to find which Novelec type is connected!", + "Failed to find which Novelec type is connected on channel one!", "MCCE2Electrometers::create_electrometers_obj()", Tango::ERR ); @@ -2290,13 +2297,13 @@ void MCCE2Electrometers::create_electrometers_obj() catch(Tango::DevFailed& df) { set_state(Tango::FAULT); - set_status("Failed to find which Novelec type is connected!"); + set_status("Failed to find which Novelec type is connected on channel one!"); FATAL_STREAM << "Failed to find which Novelec type is connected : DevFailed EXCEPTION -> " << df << std::endl; Tango::Except::re_throw_exception(df, "COMMUNICATION_ERROR", - "Failed to find which Novelec type is connected!", + "Failed to find which Novelec type is connected on channel one!", "MCCE2Electrometers::create_electrometers_obj()", Tango::ERR ); @@ -2304,13 +2311,13 @@ void MCCE2Electrometers::create_electrometers_obj() catch(...) { set_state(Tango::FAULT); - set_status("Failed to find which Novelec type is connected : communication caught[...]"); + set_status("Failed to find which Novelec type is connected on channel one : communication caught[...]"); - FATAL_STREAM << "Failed to find which Novelec type is connected : [...] EXCEPTION " << std::endl; + FATAL_STREAM << "Failed to find which Novelec type is connected on channel one : [...] EXCEPTION " << std::endl; Tango::Except::throw_exception( "UNKNOWN_ERROR", - "find which Novelec type is connected! [(...) exception]", + "find which Novelec type is connected on channel one! [(...) exception]", "MCCE2Electrometers::create_electrometers_obj()", Tango::ERR ); @@ -2350,8 +2357,58 @@ void MCCE2Electrometers::create_electrometers_obj() mcce2->init_protocol(); Novelec_MCCE2* nMCCE2 = dynamic_cast<Novelec_MCCE2*>(mcce2); short type2 = 0; - if(nMCCE2) - type2 = nMCCE2->get_electrometer_type(); + try + { + if(nMCCE2) + { + //- get type as num + type2 = nMCCE2->get_electrometer_type(); + //- get type as string + this->_electroCH2StrType = nMCCE2->get_electrometer_typeStr(); + } + } + catch(const electrometer::ElectrometerException& ke) + { + set_state(Tango::FAULT); + set_status("Failed to find which Novelec type is connected on channel two : communication caught[...]"); + + Tango::DevFailed df = electrometer_to_tango_exception(ke); + FATAL_STREAM << "Failed to find which Novelec type is connected on channel two : ElectrometerException EXCEPTION -> " << df << std::endl; + Tango::Except::re_throw_exception(df, + "COMMUNICATION_ERROR", + "Failed to find which Novelec type is connected on channel two!", + "MCCE2Electrometers::create_electrometers_obj()", + Tango::ERR + ); + } + catch(Tango::DevFailed& df) + { + set_state(Tango::FAULT); + set_status("Failed to find which Novelec type is connected on channel two!"); + + FATAL_STREAM << "Failed to find which Novelec type is connected on channel two : DevFailed EXCEPTION -> " << df << std::endl; + + Tango::Except::re_throw_exception(df, + "COMMUNICATION_ERROR", + "Failed to find which Novelec type is connected on channel two!", + "MCCE2Electrometers::create_electrometers_obj()", + Tango::ERR + ); + } + catch(...) + { + set_state(Tango::FAULT); + set_status("Failed to find which Novelec type is connected on channel two : communication caught[...]"); + + FATAL_STREAM << "Failed to find which Novelec type is connected on channel two : [...] EXCEPTION " << std::endl; + + Tango::Except::throw_exception( + "UNKNOWN_ERROR", + "find which Novelec type is connected on channel two! [(...) exception]", + "MCCE2Electrometers::create_electrometers_obj()", + Tango::ERR + ); + } switch(type2) { @@ -2381,10 +2438,10 @@ void MCCE2Electrometers::create_electrometers_obj() //- check if (!this->_electrometerCH1 && !this->_electrometerCH2) { - ERROR_STREAM << "Not enough memory to create the electrometer obj!" << std::endl; + ERROR_STREAM << "No connected electrometer(s) found!" << std::endl; Tango::Except::throw_exception( "MEMORY_ERROR", - "Cannot build device comm obj!", + "No connected electrometer(s) found!", "MCCE2Electrometers::create_electrometers_obj()"); } @@ -2539,4 +2596,53 @@ void MCCE2Electrometers::set_polarity(Tango::DevString argin) } } + +//+------------------------------------------------------------------ +/** + * method: MCCE2Electrometers::get_electrometer_type_str + * + * description: method to execute "GetElectrometerTypeStr" + * This command returns the connected electrometer type as string for the specified channel. + * + * @param argin channel number + * @return the electrometer type as string + * + */ +//+------------------------------------------------------------------ +Tango::DevString MCCE2Electrometers::get_electrometer_type_str(Tango::DevUShort argin) +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = 0; + DEBUG_STREAM << "MCCE2Electrometers::get_electrometer_type_str(): entering... !" << endl; + + // Add your own code to control device here + if ( !this->_electrometerCH1 && !_electrometerCH2 ) + { + ERROR_STREAM << "No electrometer connected on both channels!" << std::endl; + Tango::Except::throw_exception( + "MEMORY_ERROR", + "No electrometer connected on both channels!?", + "MCCE2Electrometers::get_electrometer_type_str()" + ); + } + + if ( *attr_electrometerChannel_read == ELETRO_CHANNEL_ONE ) + { + argout = new char[this->_electroCH1StrType.size()+1]; + ::strncpy(argout, _electroCH1StrType.c_str(), _electroCH1StrType.size()); + } + + if ( *attr_electrometerChannel_read == ELETRO_CHANNEL_TWO ) + { + argout = new char[this->_electroCH2StrType.size()+1]; + ::strncpy(argout, _electroCH2StrType.c_str(), _electroCH2StrType.size()); + } + + return argout; +} + } // namespace diff --git a/src/MCCE2Electrometers.h b/src/MCCE2Electrometers.h index 9ffdca4..9d81626 100644 --- a/src/MCCE2Electrometers.h +++ b/src/MCCE2Electrometers.h @@ -1,467 +1,483 @@ -//============================================================================= -// -// file : MCCE2Electrometers.h -// -// description : Include for the MCCE2Electrometers class. -// -// project : Novelec MCCE-2 Electrometers -// -// $Author: xavela $ -// -// $Revision: 1.16 $ -// -// $Log: not supported by cvs2svn $ -// Revision 1.14 2010/06/10 15:12:05 xavela -// TEST : control two channels with different MCCE2 -// -// -// copyleft : European Synchrotron Radiation Facility -// BP 220, Grenoble 38043 -// FRANCE -// -//============================================================================= -// -// This file is generated by POGO -// (Program Obviously used to Generate tango Object) -// -// (c) - Software Engineering Group - ESRF -//============================================================================= -#ifndef _MCCE2ELECTROMETERS_H -#define _MCCE2ELECTROMETERS_H - -#include <tango.h> -//using namespace Tango; -#include "AbstractElectrometerClass.h" -#include "ElectrometerException.h" - -/** - * @author $Author: xavela $ - * @version $Revision: 1.16 $ - */ - - // Add your own constants definitions here. - //----------------------------------------------- - - -namespace MCCE2Electrometers_ns -{ - -/** - * Class Description: - * This class allows you to control all MCCE-2 Novelec electrometers - * through a Serial bus. - * <br> Supported types : - * <br> Novelec Electrometers : MCCE2 - */ - -/* - * Device States Description: -* Tango::ON : Device up and ready -* Tango::ALARM : Device initialisation not complete or a bad channel number is set. -* Tango::FAULT : Internal electrometer interface is not built or a Serial communication error occurred. -* Tango::DISABLE : No electrometer conected! - */ - - -class MCCE2Electrometers: public Tango::Device_4Impl -{ -public : - // Add your own data members here - //----------------------------------------- - - - // Here is the Start of the automatic code generation part - //------------------------------------------------------------- -/** - * @name attributes - * Attributs member data. - */ -//@{ - Tango::DevUShort *attr_electrometerChannel_read; - Tango::DevUShort attr_electrometerChannel_write; - Tango::DevString *attr_range1_read; - Tango::DevString *attr_range2_read; -//@} - -/** - * @name Device properties - * Device properties member data. - */ -//@{ -/** - * The name of the device which manage the communication. - */ - string communicationLinkName; -/** - * The first electrometer address configured. <br /> - * Note : if not connected, push 0 or let empty the property. - */ - Tango::DevUShort electrometer1Address; -/** - * The second electrometer address configured. <br /> - * Note : if not connected, push 0 or let empty the property. - */ - Tango::DevUShort electrometer2Address; -//@} - -/**@name Constructors - * Miscellaneous constructors */ -//@{ -/** - * Constructs a newly allocated Command object. - * - * @param cl Class. - * @param s Device Name - */ - MCCE2Electrometers(Tango::DeviceClass *cl,string &s); -/** - * Constructs a newly allocated Command object. - * - * @param cl Class. - * @param s Device Name - */ - MCCE2Electrometers(Tango::DeviceClass *cl,const char *s); -/** - * Constructs a newly allocated Command object. - * - * @param cl Class. - * @param s Device name - * @param d Device description. - */ - MCCE2Electrometers(Tango::DeviceClass *cl,const char *s,const char *d); -//@} - -/**@name Destructor - * Only one desctructor is defined for this class */ -//@{ -/** - * The object desctructor. - */ - ~MCCE2Electrometers() {delete_device();}; -/** - * will be called at device destruction or at init command. - */ - void delete_device(); -//@} - - -/**@name Miscellaneous methods */ -//@{ -/** - * Initialize the device - */ - virtual void init_device(); -/** - * Always executed method befor execution command method. - */ - virtual void always_executed_hook(); - -//@} - -/** - * @name MCCE2Electrometers methods prototypes - */ - -//@{ -/** - * Hardware acquisition for attributes. - */ - virtual void read_attr_hardware(vector<long> &attr_list); -/** - * Extract real attribute values for electrometerChannel acquisition result. - */ - virtual void read_electrometerChannel(Tango::Attribute &attr); -/** - * Write electrometerChannel attribute values to hardware. - */ - virtual void write_electrometerChannel(Tango::WAttribute &attr); -/** - * Extract real attribute values for range1 acquisition result. - */ - virtual void read_range1(Tango::Attribute &attr); -/** - * Extract real attribute values for range2 acquisition result. - */ - virtual void read_range2(Tango::Attribute &attr); -/** - * Read/Write allowed for electrometerChannel attribute. - */ - virtual bool is_electrometerChannel_allowed(Tango::AttReqType type); -/** - * Read/Write allowed for range1 attribute. - */ - virtual bool is_range1_allowed(Tango::AttReqType type); -/** - * Read/Write allowed for range2 attribute. - */ - virtual bool is_range2_allowed(Tango::AttReqType type); -/** - * Execution allowed for RangeUP command. - */ - virtual bool is_RangeUP_allowed(const CORBA::Any &any); -/** - * Execution allowed for RangeDOWN command. - */ - virtual bool is_RangeDOWN_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetZeroVFFunction command. - */ - virtual bool is_SetZeroVFFunction_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetOffsetZeroV1Function command. - */ - virtual bool is_SetOffsetZeroV1Function_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetLeakageZeroV2Function command. - */ - virtual bool is_SetLeakageZeroV2Function_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetTestFunction command. - */ - virtual bool is_SetTestFunction_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetMeasureFunction command. - */ - virtual bool is_SetMeasureFunction_allowed(const CORBA::Any &any); -/** - * Execution allowed for MCCE2_ON command. - */ - virtual bool is_MCCE2_ON_allowed(const CORBA::Any &any); -/** - * Execution allowed for MCCE2_OFF command. - */ - virtual bool is_MCCE2_OFF_allowed(const CORBA::Any &any); -/** - * Execution allowed for Local command. - */ - virtual bool is_Local_allowed(const CORBA::Any &any); -/** - * Execution allowed for Remote command. - */ - virtual bool is_Remote_allowed(const CORBA::Any &any); -/** - * Execution allowed for Reset command. - */ - virtual bool is_Reset_allowed(const CORBA::Any &any); -/** - * Execution allowed for ClearRegisters command. - */ - virtual bool is_ClearRegisters_allowed(const CORBA::Any &any); -/** - * Execution allowed for GetRange command. - */ - virtual bool is_GetRange_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetRange command. - */ - virtual bool is_SetRange_allowed(const CORBA::Any &any); -/** - * Execution allowed for GetMode command. - */ - virtual bool is_GetMode_allowed(const CORBA::Any &any); -/** - * Execution allowed for GetPolarity command. - */ - virtual bool is_GetPolarity_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetPolarity command. - */ - virtual bool is_SetPolarity_allowed(const CORBA::Any &any); -/** - * Execution allowed for GetHzFilter command. - */ - virtual bool is_GetHzFilter_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetHzFilter command. - */ - virtual bool is_SetHzFilter_allowed(const CORBA::Any &any); -/** - * Execution allowed for GetGain command. - */ - virtual bool is_GetGain_allowed(const CORBA::Any &any); -/** - * Execution allowed for SetGain command. - */ - virtual bool is_SetGain_allowed(const CORBA::Any &any); -/** - * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller. - * @return State Code - * @exception DevFailed - */ - virtual Tango::DevState dev_state(); -/** - * This command gets the device status (stored in its <i>device_status</i> data member) and returns it to the caller. - * @return Status description - * @exception DevFailed - */ - virtual Tango::ConstDevString dev_status(); -/** - * Up the range of the electrometer. - * Throw : - * - electrometer::ElectrometerException if the range limit is reached - * - Tango::DevFailed if the command cannot be performed - * @exception DevFailed - */ - void range_up(); -/** - * Down the range of the electrometer. - * Throw : - * - electrometer::ElectrometerException if the range is negative - * - Tango::DevFailed if the command cannot be performed - * @exception DevFailed - */ - void range_down(); -/** - * Enable the Zero V/F MCCE2 mode. - * @exception DevFailed - */ - void set_zero_vffunction(); -/** - * Enable the Offset or Zero V1 MCCE2 mode. - * @exception DevFailed - */ - void set_offset_zero_v1_function(); -/** - * Enable the Leakage or Zero V2 MCCE2 mode. - * @exception DevFailed - */ - void set_leakage_zero_v2_function(); -/** - * Enable theTest MCCE2 mode. - * @exception DevFailed - */ - void set_test_function(); -/** - * Enable the Measure MCCE2 mode. - * @exception DevFailed - */ - void set_measure_function(); -/** - * Enables the function set. Parameters cannot be set (read only mode). - * @exception DevFailed - */ - void mcce2__on(); -/** - * Disables the function set. Parameters can be changed. - * @exception DevFailed - */ - void mcce2__off(); -/** - * Enable local keyboard and Key - * @exception DevFailed - */ - void local(); -/** - * Disable \"MODIFY\" and the \"ON-OFF\" keys - * @exception DevFailed - */ - void remote(); -/** - * Restart the MCCE-2 - * @exception DevFailed - */ - void reset(); -/** - * Clear error(s) - * @exception DevFailed - */ - void clear_registers(); -/** - * Returns the electrometer range. - * @return The actual electrometer range - * @exception DevFailed - */ - Tango::DevString get_range(); -/** - * Apply the specified argin range, on the electrometer, if well formatted. - * Else an exception is thrown. - * @param argin The range to apply on the electrometer - * @exception DevFailed - */ - void set_range(Tango::DevString); -/** - * Returns the electrometer mode which can be one of the following values : - * MEASURE, V/F Zero, OFFSET, LEAKAGE or TEST. - * @return The electrometer mode (MEASURE, LEAKAGE ...) - * @exception DevFailed - */ - Tango::DevString get_mode(); -/** - * Returns the electrometer polarity, which can be POSITIVE or NEGATIVE. - * @return The electrometer polarity - * @exception DevFailed - */ - Tango::DevString get_polarity(); -/** - * Sets the new electrometer polarity. <Br> - * NOTE : <Br> - * Value must be set in UPPER case !!! - * @param argin POSITIVE or NEGATIVE - * @exception DevFailed - */ - void set_polarity(Tango::DevString); -/** - * Returns the Cut-off frequency in Hz - * @return The MCCE2 cut-off frequency in Hz - * @exception DevFailed - */ - Tango::DevShort get_hz_filter(); -/** - * The Cut-off frequency in Hz - * @param argin The MCCE2 cut-off frequency in Hz - * @exception DevFailed - */ - void set_hz_filter(Tango::DevShort); -/** - * Returns the MCCE-2 gain - * @return The MCCE2 gain - * @exception DevFailed - */ - Tango::DevShort get_gain(); -/** - * Sets the new MCCE-2 gain value. - * @param argin The new MCCE-2 gain - * @exception DevFailed - */ - void set_gain(Tango::DevUShort); - -/** - * Read the device properties from database - */ - void get_device_property(); -//@} - - // Here is the end of the automatic code generation part - //------------------------------------------------------------- - - - -protected : - // Add your own data members here - //----------------------------------------- - AbstractElectrometerClass* _electrometer; - - std::string _statusStr; - - bool _init_done; //- used to allow device to start !! - bool _missing_property; - bool _updateRange1FromHW; - bool _updateRange2FromHW; - - std::string read_range_from_hw(); - - //- Method to convert all electrometer exceptions on Tango exception - Tango::DevFailed electrometer_to_tango_exception(const electrometer::ElectrometerException& de); - -private : - AbstractElectrometerClass* _electrometerCH1; //- electrometer on channel 1 - AbstractElectrometerClass* _electrometerCH2; //- electrometer on channel 2 - - //- instanciate electrometer(s) obj - void create_electrometers_obj(); - -}; - -} // namespace_ns - -#endif // _MCCE2ELECTROMETERS_H +//============================================================================= +// +// file : MCCE2Electrometers.h +// +// description : Include for the MCCE2Electrometers class. +// +// project : Novelec MCCE-2 Electrometers +// +// $Author: xavela $ +// +// $Revision: 1.16 $ +// +// $Log: not supported by cvs2svn $ +// Revision 1.14 2010/06/10 15:12:05 xavela +// TEST : control two channels with different MCCE2 +// +// +// copyleft : European Synchrotron Radiation Facility +// BP 220, Grenoble 38043 +// FRANCE +// +//============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= +#ifndef _MCCE2ELECTROMETERS_H +#define _MCCE2ELECTROMETERS_H + +#include <tango.h> +//using namespace Tango; +#include "AbstractElectrometerClass.h" +#include "ElectrometerException.h" + +/** + * @author $Author: xavela $ + * @version $Revision: 1.16 $ + */ + +// Add your own constants definitions here. +//----------------------------------------------- + + +namespace MCCE2Electrometers_ns +{ + +/** + * Class Description: + * This class allows you to control all MCCE-2 Novelec electrometers + * through a Serial bus. + * <br> Supported types : + * <br> Novelec Electrometers : MCCE2 + */ + +/* + * Device States Description: +* Tango::ON : Device up and ready +* Tango::ALARM : Device initialisation not complete or a bad channel number is set. +* Tango::FAULT : Internal electrometer interface is not built or a Serial communication error occurred. +* Tango::DISABLE : No electrometer conected! + */ + + +class MCCE2Electrometers: public Tango::Device_4Impl +{ +public : + // Add your own data members here + //----------------------------------------- + + + // Here is the Start of the automatic code generation part + //------------------------------------------------------------- + /** + * @name attributes + * Attributs member data. + */ +//@{ + Tango::DevUShort *attr_electrometerChannel_read; + Tango::DevUShort attr_electrometerChannel_write; + Tango::DevString *attr_range1_read; + Tango::DevString *attr_range2_read; +//@} + + /** + * @name Device properties + * Device properties member data. + */ +//@{ + /** + * The name of the device which manage the communication. + */ + string communicationLinkName; + /** + * The first electrometer address configured. <br /> + * Note : if not connected, push 0 or let empty the property. + */ + Tango::DevUShort electrometer1Address; + /** + * The second electrometer address configured. <br /> + * Note : if not connected, push 0 or let empty the property. + */ + Tango::DevUShort electrometer2Address; +//@} + + /**@name Constructors + * Miscellaneous constructors */ +//@{ + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + MCCE2Electrometers(Tango::DeviceClass *cl,string &s); + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + MCCE2Electrometers(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + MCCE2Electrometers(Tango::DeviceClass *cl,const char *s,const char *d); +//@} + + /**@name Destructor + * Only one desctructor is defined for this class */ +//@{ + /** + * The object desctructor. + */ + ~MCCE2Electrometers() { + delete_device(); + }; + /** + * will be called at device destruction or at init command. + */ + void delete_device(); +//@} + + + /**@name Miscellaneous methods */ +//@{ + /** + * Initialize the device + */ + virtual void init_device(); + /** + * Always executed method befor execution command method. + */ + virtual void always_executed_hook(); + +//@} + + /** + * @name MCCE2Electrometers methods prototypes + */ + +//@{ + /** + * Hardware acquisition for attributes. + */ + virtual void read_attr_hardware(vector<long> &attr_list); + /** + * Extract real attribute values for electrometerChannel acquisition result. + */ + virtual void read_electrometerChannel(Tango::Attribute &attr); + /** + * Write electrometerChannel attribute values to hardware. + */ + virtual void write_electrometerChannel(Tango::WAttribute &attr); + /** + * Extract real attribute values for range1 acquisition result. + */ + virtual void read_range1(Tango::Attribute &attr); + /** + * Extract real attribute values for range2 acquisition result. + */ + virtual void read_range2(Tango::Attribute &attr); + /** + * Read/Write allowed for electrometerChannel attribute. + */ + virtual bool is_electrometerChannel_allowed(Tango::AttReqType type); + /** + * Read/Write allowed for range1 attribute. + */ + virtual bool is_range1_allowed(Tango::AttReqType type); + /** + * Read/Write allowed for range2 attribute. + */ + virtual bool is_range2_allowed(Tango::AttReqType type); + /** + * Execution allowed for RangeUP command. + */ + virtual bool is_RangeUP_allowed(const CORBA::Any &any); + /** + * Execution allowed for RangeDOWN command. + */ + virtual bool is_RangeDOWN_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetZeroVFFunction command. + */ + virtual bool is_SetZeroVFFunction_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetOffsetZeroV1Function command. + */ + virtual bool is_SetOffsetZeroV1Function_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetLeakageZeroV2Function command. + */ + virtual bool is_SetLeakageZeroV2Function_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetTestFunction command. + */ + virtual bool is_SetTestFunction_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetMeasureFunction command. + */ + virtual bool is_SetMeasureFunction_allowed(const CORBA::Any &any); + /** + * Execution allowed for MCCE2_ON command. + */ + virtual bool is_MCCE2_ON_allowed(const CORBA::Any &any); + /** + * Execution allowed for MCCE2_OFF command. + */ + virtual bool is_MCCE2_OFF_allowed(const CORBA::Any &any); + /** + * Execution allowed for Local command. + */ + virtual bool is_Local_allowed(const CORBA::Any &any); + /** + * Execution allowed for Remote command. + */ + virtual bool is_Remote_allowed(const CORBA::Any &any); + /** + * Execution allowed for Reset command. + */ + virtual bool is_Reset_allowed(const CORBA::Any &any); + /** + * Execution allowed for ClearRegisters command. + */ + virtual bool is_ClearRegisters_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetRange command. + */ + virtual bool is_GetRange_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetRange command. + */ + virtual bool is_SetRange_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetMode command. + */ + virtual bool is_GetMode_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetPolarity command. + */ + virtual bool is_GetPolarity_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetPolarity command. + */ + virtual bool is_SetPolarity_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetHzFilter command. + */ + virtual bool is_GetHzFilter_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetHzFilter command. + */ + virtual bool is_SetHzFilter_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetGain command. + */ + virtual bool is_GetGain_allowed(const CORBA::Any &any); + /** + * Execution allowed for SetGain command. + */ + virtual bool is_SetGain_allowed(const CORBA::Any &any); + /** + * Execution allowed for GetElectrometerTypeStr command. + */ + virtual bool is_GetElectrometerTypeStr_allowed(const CORBA::Any &any); + /** + * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller. + * @return State Code + * @exception DevFailed + */ + virtual Tango::DevState dev_state(); + /** + * This command gets the device status (stored in its <i>device_status</i> data member) and returns it to the caller. + * @return Status description + * @exception DevFailed + */ + virtual Tango::ConstDevString dev_status(); + /** + * Up the range of the electrometer. + * Throw : + * - electrometer::ElectrometerException if the range limit is reached + * - Tango::DevFailed if the command cannot be performed + * @exception DevFailed + */ + void range_up(); + /** + * Down the range of the electrometer. + * Throw : + * - electrometer::ElectrometerException if the range is negative + * - Tango::DevFailed if the command cannot be performed + * @exception DevFailed + */ + void range_down(); + /** + * Enable the Zero V/F MCCE2 mode. + * @exception DevFailed + */ + void set_zero_vffunction(); + /** + * Enable the Offset or Zero V1 MCCE2 mode. + * @exception DevFailed + */ + void set_offset_zero_v1_function(); + /** + * Enable the Leakage or Zero V2 MCCE2 mode. + * @exception DevFailed + */ + void set_leakage_zero_v2_function(); + /** + * Enable theTest MCCE2 mode. + * @exception DevFailed + */ + void set_test_function(); + /** + * Enable the Measure MCCE2 mode. + * @exception DevFailed + */ + void set_measure_function(); + /** + * Enables the function set. Parameters cannot be set (read only mode). + * @exception DevFailed + */ + void mcce2__on(); + /** + * Disables the function set. Parameters can be changed. + * @exception DevFailed + */ + void mcce2__off(); + /** + * Enable local keyboard and Key + * @exception DevFailed + */ + void local(); + /** + * Disable \"MODIFY\" and the \"ON-OFF\" keys + * @exception DevFailed + */ + void remote(); + /** + * Restart the MCCE-2 + * @exception DevFailed + */ + void reset(); + /** + * Clear error(s) + * @exception DevFailed + */ + void clear_registers(); + /** + * Returns the electrometer range. + * @return The actual electrometer range + * @exception DevFailed + */ + Tango::DevString get_range(); + /** + * Apply the specified argin range, on the electrometer, if well formatted. + * Else an exception is thrown. + * @param argin The range to apply on the electrometer + * @exception DevFailed + */ + void set_range(Tango::DevString); + /** + * Returns the electrometer mode which can be one of the following values : + * MEASURE, V/F Zero, OFFSET, LEAKAGE or TEST. + * @return The electrometer mode (MEASURE, LEAKAGE ...) + * @exception DevFailed + */ + Tango::DevString get_mode(); + /** + * Returns the electrometer polarity, which can be POSITIVE or NEGATIVE. + * @return The electrometer polarity + * @exception DevFailed + */ + Tango::DevString get_polarity(); + /** + * Sets the new electrometer polarity. <Br> + * NOTE : <Br> + * Value must be set in UPPER case !!! + * @param argin POSITIVE or NEGATIVE + * @exception DevFailed + */ + void set_polarity(Tango::DevString); + /** + * Returns the Cut-off frequency in Hz + * @return The MCCE2 cut-off frequency in Hz + * @exception DevFailed + */ + Tango::DevShort get_hz_filter(); + /** + * The Cut-off frequency in Hz + * @param argin The MCCE2 cut-off frequency in Hz + * @exception DevFailed + */ + void set_hz_filter(Tango::DevShort); + /** + * Returns the MCCE-2 gain + * @return The MCCE2 gain + * @exception DevFailed + */ + Tango::DevShort get_gain(); + /** + * Sets the new MCCE-2 gain value. + * @param argin The new MCCE-2 gain + * @exception DevFailed + */ + void set_gain(Tango::DevUShort); + /** + * This command returns the connected electrometer type as string for the specified channel. + * @param argin channel number + * @return the electrometer type as string + * @exception DevFailed + */ + Tango::DevString get_electrometer_type_str(Tango::DevUShort); + + /** + * Read the device properties from database + */ + void get_device_property(); +//@} + + // Here is the end of the automatic code generation part + //------------------------------------------------------------- + + + +protected : + // Add your own data members here + //----------------------------------------- + AbstractElectrometerClass* _electrometer; + + std::string _statusStr; + + bool _init_done; //- used to allow device to start !! + bool _missing_property; + bool _updateRange1FromHW; + bool _updateRange2FromHW; + //- electrometer(s) type as string + std::string _electroCH1StrType; + std::string _electroCH2StrType; + + std::string read_range_from_hw(); + + //- Method to convert all electrometer exceptions on Tango exception + Tango::DevFailed electrometer_to_tango_exception(const electrometer::ElectrometerException& de); + +private : + AbstractElectrometerClass* _electrometerCH1; //- electrometer on channel 1 + AbstractElectrometerClass* _electrometerCH2; //- electrometer on channel 2 + + //- instanciate electrometer(s) obj + void create_electrometers_obj(); + +}; + +} // namespace_ns + +#endif // _MCCE2ELECTROMETERS_H diff --git a/src/MCCE2ElectrometersClass.cpp b/src/MCCE2ElectrometersClass.cpp index 9a409bb..8365586 100644 --- a/src/MCCE2ElectrometersClass.cpp +++ b/src/MCCE2ElectrometersClass.cpp @@ -64,6 +64,30 @@ __declspec(dllexport) namespace MCCE2Electrometers_ns { +//+---------------------------------------------------------------------------- +// +// method : GetElectrometerTypeStrClass::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *GetElectrometerTypeStrClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "GetElectrometerTypeStrClass::execute(): arrived" << endl; + + Tango::DevUShort argin; + extract(in_any, argin); + + return insert((static_cast<MCCE2Electrometers *>(device))->get_electrometer_type_str(argin)); +} + //+---------------------------------------------------------------------------- // // method : SetPolarityClass::execute() @@ -763,6 +787,11 @@ void MCCE2ElectrometersClass::command_factory() "The new MCCE-2 gain", "no argout", Tango::EXPERT)); + command_list.push_back(new GetElectrometerTypeStrClass("GetElectrometerTypeStr", + Tango::DEV_USHORT, Tango::DEV_STRING, + "channel number", + "the electrometer type as string", + Tango::OPERATOR)); // add polling if any for (unsigned int i=0 ; i<command_list.size(); i++) diff --git a/src/MCCE2ElectrometersClass.h b/src/MCCE2ElectrometersClass.h index bd4ac0b..f4e2d17 100644 --- a/src/MCCE2ElectrometersClass.h +++ b/src/MCCE2ElectrometersClass.h @@ -84,6 +84,30 @@ public: //========================================= // Define classes for commands //========================================= +class GetElectrometerTypeStrClass : public Tango::Command +{ +public: + GetElectrometerTypeStrClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + GetElectrometerTypeStrClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetElectrometerTypeStrClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<MCCE2Electrometers *>(dev))->is_GetElectrometerTypeStr_allowed(any);} +}; + + + class SetGainCmd : public Tango::Command { public: diff --git a/src/MCCE2ElectrometersStateMachine.cpp b/src/MCCE2ElectrometersStateMachine.cpp index 492861f..433d677 100644 --- a/src/MCCE2ElectrometersStateMachine.cpp +++ b/src/MCCE2ElectrometersStateMachine.cpp @@ -512,5 +512,19 @@ bool MCCE2Electrometers::is_SetPolarity_allowed(const CORBA::Any &any) } return true; } +//+---------------------------------------------------------------------------- +// +// method : MCCE2Electrometers::is_GetElectrometerTypeStr_allowed +// +// description : Execution allowed for GetElectrometerTypeStr command. +// +//----------------------------------------------------------------------------- +bool MCCE2Electrometers::is_GetElectrometerTypeStr_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} } // namespace MCCE2Electrometers_ns -- GitLab