From 29575e79fb432e6cf0c3dae2d34354f43fd94df3 Mon Sep 17 00:00:00 2001 From: Jade PHAM <jade.pham@synchrotron-soleil.fr> Date: Thu, 27 Feb 2025 18:08:03 +0100 Subject: [PATCH] fix CORBA::string_dup --- src/MCCE2Electrometers.cpp | 100 ++++++++++++-------------------- src/MCCE2Electrometers.h | 54 +++++++++-------- src/MCCE2Electrometers.xmi | 4 +- src/MCCE2ElectrometersClass.cpp | 2 +- 4 files changed, 69 insertions(+), 91 deletions(-) diff --git a/src/MCCE2Electrometers.cpp b/src/MCCE2Electrometers.cpp index 0ab9d97..63993d8 100644 --- a/src/MCCE2Electrometers.cpp +++ b/src/MCCE2Electrometers.cpp @@ -42,7 +42,7 @@ static const char *RcsId = "$Id: $"; #include <tango.h> #include <PogoHelper.h> -#include <Xstring.h> +#include <yat/utils/XString.h> #include <yat4tango/InnerAppender.h> #include <yat4tango/YatLogAdapter.h> #include <MCCE2Electrometers.h> @@ -179,9 +179,6 @@ void MCCE2Electrometers::delete_device() INFO_STREAM << "Remove the inner-appender." << endl; yat4tango::InnerAppender::release(this); - INFO_STREAM << "Remove the log-adapter." << endl; - yat4tango::YatLogAdapter::release(); - /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::delete_device } @@ -197,7 +194,6 @@ void MCCE2Electrometers::init_device() /*----- PROTECTED REGION ID(MCCE2Electrometers::init_device_before) ENABLED START -----*/ // Initialization before get_device_property() call - yat4tango::YatLogAdapter::initialize(this); // Initialize the inner appender. yat4tango::InnerAppender::initialize(this); @@ -211,6 +207,7 @@ void MCCE2Electrometers::init_device() this->_updateRange2FromHW = true; //- force update after init. this->_electroCH1StrType = "Not connected"; this->_electroCH2StrType = "Not connected"; + _notConnectedStr = "Not connected"; @@ -413,11 +410,10 @@ void MCCE2Electrometers::always_executed_hook() //-------------------------------------------------------- void MCCE2Electrometers::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list)) { - DEBUG_STREAM << "MCCE2Electrometers::read_attr_hardware(vector<long> &attr_list) entering... " << endl; + //DEBUG_STREAM << "MCCE2Electrometers::read_attr_hardware(vector<long> &attr_list) entering... " << endl; /*----- PROTECTED REGION ID(MCCE2Electrometers::read_attr_hardware) ENABLED START -----*/ // Add your own code - // Add your own code here /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::read_attr_hardware } @@ -439,10 +435,10 @@ void MCCE2Electrometers::read_electrometerChannel(Tango::Attribute &attr) if ( !this->_electrometer ) { - ERROR_STREAM << "Not enough memory to create the electrometer obj!" << std::endl; + ERROR_STREAM << "Failed to build the electrometer obj : error on connection or check_electrotype at init_device step?" << std::endl; Tango::Except::throw_exception( "MEMORY_ERROR", - "Failed to build the electrometer obj : not enough memory!?", + "Failed to build the electrometer obj : error on connection or check_electrotype at init_device step", "MCCE2Electrometers::read_electrometerChannel()" ); } @@ -516,12 +512,15 @@ void MCCE2Electrometers::write_electrometerChannel(Tango::WAttribute &attr) this->_electrometer = this->_electrometerCH1; //- now force update from HW this->_updateRange1FromHW = true; + + *attr_range1_read = get_range(); + } else { WARN_STREAM << "Cannot control electrometer on this channel : seems that nothing is connected on!" << std::endl; - //- warn nothing is connected on this channel - *attr_range1_read = CORBA::string_dup("Not connected"); + // nothing is connected on this channel + *attr_range1_read = &_notConnectedStr[0]; } } else if ( w_val == ELETRO_CHANNEL_TWO ) @@ -531,12 +530,15 @@ void MCCE2Electrometers::write_electrometerChannel(Tango::WAttribute &attr) this->_electrometer = this->_electrometerCH2; //- now force update from HW this->_updateRange2FromHW = true; + + *attr_range2_read = get_range(); + } else { WARN_STREAM << "Cannot control electrometer on this channel : seems that nothing is connected on!" << std::endl; //- warn nothing is connected on this channel - *attr_range2_read = CORBA::string_dup("Not connected"); + *attr_range2_read = &_notConnectedStr[0]; } } attr_electrometerChannel_write = w_val; @@ -549,8 +551,7 @@ void MCCE2Electrometers::write_electrometerChannel(Tango::WAttribute &attr) * Description: The channel one MCCE2 range. * * Data type: Tango::DevString - * Attr type: Scalar - */ + * Attr type: Scalar */ //-------------------------------------------------------- void MCCE2Electrometers::read_range1(Tango::Attribute &attr) { @@ -558,17 +559,17 @@ void MCCE2Electrometers::read_range1(Tango::Attribute &attr) /*----- PROTECTED REGION ID(MCCE2Electrometers::read_range1) ENABLED START -----*/ if ( !this->_electrometerCH1 ) { - *attr_range1_read = CORBA::string_dup("Not connected"); + *attr_range1_read = &_notConnectedStr[0]; } else { if ( this->_updateRange1FromHW && *attr_electrometerChannel_read == ELETRO_CHANNEL_ONE ) { *attr_range1_read = this->get_range(); + this->_updateRange1FromHW = false; } } - attr.set_value(attr_range1_read); /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::read_range1 @@ -588,17 +589,17 @@ void MCCE2Electrometers::read_range2(Tango::Attribute &attr) /*----- PROTECTED REGION ID(MCCE2Electrometers::read_range2) ENABLED START -----*/ if ( !this->_electrometerCH2 ) { - *attr_range2_read = CORBA::string_dup("Not connected"); + *attr_range2_read = &_notConnectedStr[0]; } else { if ( this->_updateRange2FromHW && *attr_electrometerChannel_read == ELETRO_CHANNEL_TWO ) { - *attr_range2_read = this->get_range(); + *attr_range2_read = get_range(); + this->_updateRange2FromHW = false; } } - attr.set_value(attr_range2_read); /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::read_range2 @@ -635,9 +636,7 @@ Tango::DevState MCCE2Electrometers::dev_state() Tango::DevState argout = Tango::UNKNOWN; // replace by your own algorithm // Add your own code - DEBUG_STREAM << "MCCE2Electrometers::dev_state(): entering... !" << endl; - // Add your own code to control device here try { //- check properties @@ -667,11 +666,9 @@ Tango::DevState MCCE2Electrometers::dev_state() else { //- update state - this->_electrometer->electrometer_status(); - //- get electrometer state - short tmpState = _electrometer->electrometer_state(); + _electrometer->electrometer_status(); - switch(tmpState) + switch(_electrometer->electrometer_state()) { case Tango::ON : argout = Tango::ON; @@ -725,8 +722,6 @@ Tango::DevState MCCE2Electrometers::dev_state() throw; } - set_state(argout); - /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::dev_state set_state(argout); // Give the state to Tango. if (argout!=Tango::ALARM) @@ -749,7 +744,7 @@ Tango::ConstDevString MCCE2Electrometers::dev_status() string status = "Device is OK"; // Add your own code //- clear previous status - this->_statusStr.clear(); + _statusStr.clear(); // Add your own code to control device here try @@ -758,6 +753,11 @@ Tango::ConstDevString MCCE2Electrometers::dev_status() { _statusStr = "Device cannot be up while its properties are not set!"; } + + else if ( !this->_electrometer ) + { + _statusStr = " Init device failed: communication error or something wrong on check_electrotype"; + } //- check device initialization else if ( !this->_electrometerCH1 && !_electrometerCH2 ) { @@ -818,8 +818,7 @@ Tango::ConstDevString MCCE2Electrometers::dev_status() set_status("Cannot perform electrometer_status() command : caugth [...] exception."); throw; } - set_status( _statusStr.c_str() ); - return _statusStr.c_str(); + status = _statusStr; /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::dev_status set_status(status); // Give the status to Tango. @@ -1707,16 +1706,6 @@ Tango::DevString MCCE2Electrometers::get_range() DEBUG_STREAM << "MCCE2Electrometers::GetRange() - " << device_name << endl; /*----- PROTECTED REGION ID(MCCE2Electrometers::get_range) ENABLED START -----*/ - // Add your own code - // 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) - //------------------------------------------------------------ - - // Add your own code to control device here - DEBUG_STREAM << "MCCE2Electrometers::get_range(): entering... !" << endl; - // Add your own code to control device here if ( !this->_electrometer ) { @@ -1743,7 +1732,7 @@ Tango::DevString MCCE2Electrometers::get_range() set_state(Tango::ALARM); set_status("Failed to read the range!"); - ERROR_STREAM << "Failed to set read the range : ElectrometerException EXCEPTION -> " << df << std::endl; + ERROR_STREAM << "Failed to read the range : ElectrometerException EXCEPTION -> " << df << std::endl; Tango::Except::re_throw_exception(df, "UNKNOWN_ERROR", "Failed to read the range.", @@ -2100,10 +2089,6 @@ Tango::DevShort MCCE2Electrometers::get_hz_filter() /*----- PROTECTED REGION ID(MCCE2Electrometers::get_hz_filter) ENABLED START -----*/ // Add your own code - - DEBUG_STREAM << "MCCE2Electrometers::get_hz_filter(): entering... !" << endl; - - // Add your own code to control device here std::string dataStr(""); if ( !this->_electrometer ) @@ -2119,7 +2104,7 @@ Tango::DevShort MCCE2Electrometers::get_hz_filter() try { dataStr = this->_electrometer->get_ElectroMeterFrequency(); - argout = XString<short>::convertFromString(dataStr); + argout = yat::XString<short>::to_num(dataStr); } catch(const electrometer::ElectrometerException& ke) { @@ -2189,7 +2174,7 @@ void MCCE2Electrometers::set_hz_filter(Tango::DevShort argin) try { - dataStr = XString<short>::convertToString(argin); + dataStr = yat::XString<short>::to_string(argin); this->_electrometer->set_ElectroMeterFrequency(dataStr); } catch(const electrometer::ElectrometerException& ke) @@ -2246,9 +2231,6 @@ Tango::DevShort MCCE2Electrometers::get_gain() // Add your own code - DEBUG_STREAM << "MCCE2Electrometers::get_gain(): entering... !" << endl; - - // Add your own code to control device here if ( !this->_electrometer ) { ERROR_STREAM << "Not enough memory to create the electrometer obj!" << std::endl; @@ -2263,7 +2245,7 @@ Tango::DevShort MCCE2Electrometers::get_gain() { std::string dataStr(""); dataStr = this->_electrometer->get_ElectroMeterGain(); - argout = XString<short>::convertFromString(dataStr); + argout = yat::XString<short>::to_num(dataStr); } catch(const electrometer::ElectrometerException& ke) { @@ -2331,7 +2313,7 @@ void MCCE2Electrometers::set_gain(Tango::DevUShort argin) try { std::string dataStr(""); - dataStr = XString<short>::convertToString(argin); + dataStr = yat::XString<short>::to_string(argin); this->_electrometer->set_ElectroMeterGain(dataStr); } catch(const electrometer::ElectrometerException& ke) @@ -2387,16 +2369,7 @@ Tango::DevString MCCE2Electrometers::get_electrometer_type_str(Tango::DevUShort DEBUG_STREAM << "MCCE2Electrometers::GetElectrometerTypeStr() - " << device_name << endl; /*----- PROTECTED REGION ID(MCCE2Electrometers::get_electrometer_type_str) ENABLED START -----*/ - // Add your own code - // 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) - //------------------------------------------------------------ - 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; @@ -2495,7 +2468,6 @@ void MCCE2Electrometers::create_electrometers_obj() { if(nMCCE1) { - DEBUG_STREAM<<"get_electrometer_type: " <<std::endl; //- get type as num type1 = nMCCE1->get_electrometer_type(); DEBUG_STREAM<<"get_electrometer_type type1= "<<type1 <<std::endl; @@ -2646,8 +2618,9 @@ void MCCE2Electrometers::create_electrometers_obj() //- read channel range this->_electrometer = this->_electrometerCH1; + *attr_range1_read = this->get_range(); - + INFO_STREAM << "this->_electrometer = this->_electrometerCH1!" << std::endl; } else @@ -2661,6 +2634,7 @@ void MCCE2Electrometers::create_electrometers_obj() //- read channel range this->_electrometer = this->_electrometerCH2; + *attr_range2_read = this->get_range(); INFO_STREAM << "this->_electrometer = this->_electrometerCH2!" << std::endl; diff --git a/src/MCCE2Electrometers.h b/src/MCCE2Electrometers.h index 293b104..34b23d2 100644 --- a/src/MCCE2Electrometers.h +++ b/src/MCCE2Electrometers.h @@ -78,7 +78,7 @@ public: // Device property data members public: - // ProxyName: The name of the device which manage the communication. + // ProxyName: The name of the device which manages the communication. string proxyName; // Electrometer1Address: The first electrometer address configured. <br /> // Note : if not connected, push 0 or let empty the property. @@ -121,7 +121,7 @@ public: MCCE2Electrometers(Tango::DeviceClass *cl,const char *s,const char *d); /** * The device object destructor. - */ + */ ~MCCE2Electrometers() {delete_device();}; @@ -213,98 +213,98 @@ public: virtual Tango::ConstDevString dev_status(); /** * Command RangeUP related method - * Description: + * Description: * */ virtual void range_up(); virtual bool is_RangeUP_allowed(const CORBA::Any &any); /** * Command RangeDOWN related method - * Description: + * Description: * */ virtual void range_down(); virtual bool is_RangeDOWN_allowed(const CORBA::Any &any); /** * Command SetZeroVFFunction related method - * Description: + * Description: * */ virtual void set_zero_vffunction(); virtual bool is_SetZeroVFFunction_allowed(const CORBA::Any &any); /** * Command SetOffsetZeroV1Function related method - * Description: + * Description: * */ virtual void set_offset_zero_v1_function(); virtual bool is_SetOffsetZeroV1Function_allowed(const CORBA::Any &any); /** * Command SetLeakageZeroV2Function related method - * Description: + * Description: * */ virtual void set_leakage_zero_v2_function(); virtual bool is_SetLeakageZeroV2Function_allowed(const CORBA::Any &any); /** * Command SetTestFunction related method - * Description: + * Description: * */ virtual void set_test_function(); virtual bool is_SetTestFunction_allowed(const CORBA::Any &any); /** * Command SetMeasureFunction related method - * Description: + * Description: * */ virtual void set_measure_function(); virtual bool is_SetMeasureFunction_allowed(const CORBA::Any &any); /** * Command MCCE2_ON related method - * Description: + * Description: * */ virtual void mcce2__on(); virtual bool is_MCCE2_ON_allowed(const CORBA::Any &any); /** * Command MCCE2_OFF related method - * Description: + * Description: * */ virtual void mcce2__off(); virtual bool is_MCCE2_OFF_allowed(const CORBA::Any &any); /** * Command Local related method - * Description: + * Description: * */ virtual void local(); virtual bool is_Local_allowed(const CORBA::Any &any); /** * Command Remote related method - * Description: + * Description: * */ virtual void remote(); virtual bool is_Remote_allowed(const CORBA::Any &any); /** * Command Reset related method - * Description: + * Description: * */ virtual void reset(); virtual bool is_Reset_allowed(const CORBA::Any &any); /** * Command ClearRegisters related method - * Description: + * Description: * */ virtual void clear_registers(); virtual bool is_ClearRegisters_allowed(const CORBA::Any &any); /** * Command GetRange related method - * Description: + * Description: * * @returns The actual electrometer range */ @@ -312,7 +312,7 @@ public: virtual bool is_GetRange_allowed(const CORBA::Any &any); /** * Command SetRange related method - * Description: + * Description: * * @param argin The range to apply on the electrometer */ @@ -320,7 +320,7 @@ public: virtual bool is_SetRange_allowed(const CORBA::Any &any); /** * Command GetMode related method - * Description: + * Description: * * @returns The electrometer mode (MEASURE, LEAKAGE ...) */ @@ -328,7 +328,7 @@ public: virtual bool is_GetMode_allowed(const CORBA::Any &any); /** * Command GetPolarity related method - * Description: + * Description: * * @returns The electrometer polarity */ @@ -336,7 +336,7 @@ public: virtual bool is_GetPolarity_allowed(const CORBA::Any &any); /** * Command SetPolarity related method - * Description: + * Description: * * @param argin POSITIVE or NEGATIVE */ @@ -344,7 +344,7 @@ public: virtual bool is_SetPolarity_allowed(const CORBA::Any &any); /** * Command GetHzFilter related method - * Description: + * Description: * * @returns The MCCE2 cut-off frequency in Hz */ @@ -352,7 +352,7 @@ public: virtual bool is_GetHzFilter_allowed(const CORBA::Any &any); /** * Command SetHzFilter related method - * Description: + * Description: * * @param argin The MCCE2 cut-off frequency in Hz */ @@ -360,7 +360,7 @@ public: virtual bool is_SetHzFilter_allowed(const CORBA::Any &any); /** * Command GetGain related method - * Description: + * Description: * * @returns The MCCE2 gain */ @@ -368,7 +368,7 @@ public: virtual bool is_GetGain_allowed(const CORBA::Any &any); /** * Command SetGain related method - * Description: + * Description: * * @param argin The new MCCE-2 gain */ @@ -376,7 +376,7 @@ public: virtual bool is_SetGain_allowed(const CORBA::Any &any); /** * Command GetElectrometerTypeStr related method - * Description: + * Description: * * @param argin channel number * @returns the electrometer type as string @@ -393,6 +393,8 @@ protected : std::string _statusStr; + std::string _notConnectedStr; + bool _init_done; //- used to allow device to start !! bool _missing_property; bool _updateRange1FromHW; @@ -410,8 +412,10 @@ private : AbstractElectrometerClass* _electrometerCH1; //- electrometer on channel 1 AbstractElectrometerClass* _electrometerCH2; //- electrometer on channel 2 Tango::DevUShort attr_electrometerChannel_write; + //- instanciate electrometer(s) obj void create_electrometers_obj(); + /*----- PROTECTED REGION END -----*/ // MCCE2Electrometers::Additional Method prototypes }; diff --git a/src/MCCE2Electrometers.xmi b/src/MCCE2Electrometers.xmi index 41165b4..3778935 100644 --- a/src/MCCE2Electrometers.xmi +++ b/src/MCCE2Electrometers.xmi @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ASCII"?> <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> <classes name="MCCE2Electrometers" pogoRevision="8.2"> - <description description="This class allows you to control all MCCE-2 Novelec electrometers
through a Serial bus.
<br> Supported types :
<br> Novelec Electrometers : MCCE2" title="Novelec MCCE-2 Electrometers" sourcePath="/home/informatique/ica/phamj/DEV/Serial/novelecelectrometer/src" language="Cpp" filestogenerate="XMI file,Code files,html Pages" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false" descriptionHtmlExists="true"> + <description description="This class allows you to control all MCCE-2 Novelec electrometers
through a Serial bus.
<br> Supported types :
<br> Novelec Electrometers : MCCE2" title="Novelec MCCE-2 Electrometers" sourcePath="/home/informatique/ica/phamj/DEV/Serial/mcce2electrometers/src" language="Cpp" filestogenerate="XMI file,Code files,html Pages" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false" descriptionHtmlExists="true"> <inheritances classname="Device_4Impl" sourcePath=""/> <identification contact="at synchrotron-soleil.fr - xavier.elattaoui" author="xavier.elattaoui" emailDomain="synchrotron-soleil.fr" classFamily="Acquisition" siteSpecific="" platform="All Platforms" bus="Serial Line" manufacturer="SAPHYMO" reference="MCCE-2"/> </description> - <deviceProperties name="ProxyName" description="The name of the device which manage the communication."> + <deviceProperties name="ProxyName" description="The name of the device which manages the communication."> <type xsi:type="pogoDsl:StringType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </deviceProperties> diff --git a/src/MCCE2ElectrometersClass.cpp b/src/MCCE2ElectrometersClass.cpp index 9fc061d..defcc8c 100644 --- a/src/MCCE2ElectrometersClass.cpp +++ b/src/MCCE2ElectrometersClass.cpp @@ -648,7 +648,7 @@ void MCCE2ElectrometersClass::set_default_property() // Set Default device Properties prop_name = "ProxyName"; - prop_desc = "The name of the device which manage the communication."; + prop_desc = "The name of the device which manages the communication."; prop_def = ""; vect_data.clear(); if (prop_def.length()>0) -- GitLab