diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8d14a0b49684f75da7001bedc6f54361d54f6689 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +NAME_SRV = aml-srv + +CXXFLAGS = +LDFLAGS = + + +include ../../../cs/ds/makefiles/Make-9.3.3.in diff --git a/src/Aml.cpp b/src/Aml.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e1549c0e3339007283e7039f031d8657a6cb7b4 --- /dev/null +++ b/src/Aml.cpp @@ -0,0 +1,1494 @@ +static const char *RcsId = "$Header: $"; +//+============================================================================= +// +// file : Aml.cpp +// +// description : C++ source for the Aml and its commands. +// The class is derived from Device. It represents the +// CORBA servant object which will be accessed from the +// network. All commands which can be executed on the +// Aml are implemented in this file. +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 +//============================================================================= + + + +//=================================================================== +// +// The following table gives the correspondence +// between commands and method name. +// +// Command name | Method name +// ---------------------------------------- +// State | dev_state() +// Status | dev_status() +// Axis1_MoveRelative | axis1__move_relative() +// Axis2_MoveRelative | axis2__move_relative() +// Axis1_MoveAbsolute | axis1__move_absolute() +// Axis2_MoveAbsolute | axis2__move_absolute() +// InitMotor | init_motor() +// Stop | stop() +// GetPosition | get_position() +// +//=================================================================== + + +#include <tango.h> +#include <Aml.h> +#include <AmlClass.h> + +namespace Aml_ns +{ + +//+---------------------------------------------------------------------------- +// +// method : Aml::Aml(string &s) +// +// description : constructor for simulated Aml +// +// in : - cl : Pointer to the DeviceClass object +// - s : Device name +// +//----------------------------------------------------------------------------- +Aml::Aml(Tango::DeviceClass *cl,string &s) +:Tango::Device_4Impl(cl,s.c_str()) +{ + device = 0; + init_device(); +} + +Aml::Aml(Tango::DeviceClass *cl,const char *s) +:Tango::Device_4Impl(cl,s) +{ + device = 0; + init_device(); +} + +Aml::Aml(Tango::DeviceClass *cl,const char *s,const char *d) +:Tango::Device_4Impl(cl,s,d) +{ + device = 0; + init_device(); +} +//+---------------------------------------------------------------------------- +// +// method : Aml::delete_device() +// +// description : will be called at device destruction or at init command. +// +//----------------------------------------------------------------------------- +void Aml::delete_device() +{ + // Delete device's allocated object + if (device > 0) + close(device); + device = 0; + +} + +//+---------------------------------------------------------------------------- +// +// method : Aml::init_device() +// +// description : will be called at device initialization. +// +//----------------------------------------------------------------------------- +void Aml::init_device() +{ + INFO_STREAM << "Aml::Aml() create device " << device_name << endl; + + // Initialise variables to default values + //-------------------------------------------- + get_device_property(); + + initSerialPort(); + init_motor(); + + Motor1Name = logicalName + axis1_Name; + Motor2Name = logicalName + axis2_Name; + + errorMessage=""; + errorNumber=0; + + logMessage=""; +} + + +//+---------------------------------------------------------------------------- +// +// method : Aml::get_device_property() +// +// description : Read the device properties from database. +// +//----------------------------------------------------------------------------- +void Aml::get_device_property() +{ + // Initialize your default values here (if not done with POGO). + //------------------------------------------------------------------ + + // Read device properties from database.(Automatic code generation) + //------------------------------------------------------------------ + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("LogicalName")); + dev_prop.push_back(Tango::DbDatum("SerialPort")); + dev_prop.push_back(Tango::DbDatum("ControllerVersion")); + dev_prop.push_back(Tango::DbDatum("Axis1_Name")); + dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate1")); + dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate2")); + dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate3")); + dev_prop.push_back(Tango::DbDatum("Axis1_PhaseCurrent")); + dev_prop.push_back(Tango::DbDatum("Axis1_Ramp")); + dev_prop.push_back(Tango::DbDatum("Axis1_StartStopSpeed")); + dev_prop.push_back(Tango::DbDatum("Axis1_SleewSpeed")); + dev_prop.push_back(Tango::DbDatum("Axis1_Range")); + dev_prop.push_back(Tango::DbDatum("Axis1_SetAccelerAndRetardPars")); + dev_prop.push_back(Tango::DbDatum("Axis2_Name")); + dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate1")); + dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate2")); + dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate3")); + dev_prop.push_back(Tango::DbDatum("Axis2_PhaseCurrent")); + dev_prop.push_back(Tango::DbDatum("Axis2_Ramp")); + dev_prop.push_back(Tango::DbDatum("Axis2_StartStopSpeed")); + dev_prop.push_back(Tango::DbDatum("Axis2_SleewSpeed")); + dev_prop.push_back(Tango::DbDatum("Axis2_Range")); + dev_prop.push_back(Tango::DbDatum("Axis2_SetAccelerAndRetardPars")); + + // Call database and extract values + //-------------------------------------------- + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + Tango::DbDatum def_prop, cl_prop; + AmlClass *ds_class = + (static_cast<AmlClass *>(get_device_class())); + int i = -1; + + // Try to initialize LogicalName from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> logicalName; + else { + // Try to initialize LogicalName from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> logicalName; + } + // And try to extract LogicalName value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> logicalName; + + // Try to initialize SerialPort from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> serialPort; + else { + // Try to initialize SerialPort from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> serialPort; + } + // And try to extract SerialPort value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialPort; + + // Try to initialize ControllerVersion from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> controllerVersion; + else { + // Try to initialize ControllerVersion from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> controllerVersion; + } + // And try to extract ControllerVersion value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> controllerVersion; + + // Try to initialize Axis1_Name from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_Name; + else { + // Try to initialize Axis1_Name from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_Name; + } + // And try to extract Axis1_Name value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Name; + + // Try to initialize Axis1_MinStepRate1 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate1; + else { + // Try to initialize Axis1_MinStepRate1 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate1; + } + // And try to extract Axis1_MinStepRate1 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate1; + + // Try to initialize Axis1_MinStepRate2 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate2; + else { + // Try to initialize Axis1_MinStepRate2 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate2; + } + // And try to extract Axis1_MinStepRate2 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate2; + + // Try to initialize Axis1_MinStepRate3 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate3; + else { + // Try to initialize Axis1_MinStepRate3 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate3; + } + // And try to extract Axis1_MinStepRate3 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate3; + + // Try to initialize Axis1_PhaseCurrent from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_PhaseCurrent; + else { + // Try to initialize Axis1_PhaseCurrent from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_PhaseCurrent; + } + // And try to extract Axis1_PhaseCurrent value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_PhaseCurrent; + + // Try to initialize Axis1_Ramp from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_Ramp; + else { + // Try to initialize Axis1_Ramp from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_Ramp; + } + // And try to extract Axis1_Ramp value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Ramp; + + // Try to initialize Axis1_StartStopSpeed from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_StartStopSpeed; + else { + // Try to initialize Axis1_StartStopSpeed from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_StartStopSpeed; + } + // And try to extract Axis1_StartStopSpeed value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_StartStopSpeed; + + // Try to initialize Axis1_SleewSpeed from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_SleewSpeed; + else { + // Try to initialize Axis1_SleewSpeed from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_SleewSpeed; + } + // And try to extract Axis1_SleewSpeed value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_SleewSpeed; + + // Try to initialize Axis1_Range from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_Range; + else { + // Try to initialize Axis1_Range from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_Range; + } + // And try to extract Axis1_Range value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Range; + + // Try to initialize Axis1_SetAccelerAndRetardPars from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis1_SetAccelerAndRetardPars; + else { + // Try to initialize Axis1_SetAccelerAndRetardPars from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis1_SetAccelerAndRetardPars; + } + // And try to extract Axis1_SetAccelerAndRetardPars value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_SetAccelerAndRetardPars; + + // Try to initialize Axis2_Name from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_Name; + else { + // Try to initialize Axis2_Name from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_Name; + } + // And try to extract Axis2_Name value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Name; + + // Try to initialize Axis2_MinStepRate1 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate1; + else { + // Try to initialize Axis2_MinStepRate1 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate1; + } + // And try to extract Axis2_MinStepRate1 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate1; + + // Try to initialize Axis2_MinStepRate2 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate2; + else { + // Try to initialize Axis2_MinStepRate2 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate2; + } + // And try to extract Axis2_MinStepRate2 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate2; + + // Try to initialize Axis2_MinStepRate3 from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate3; + else { + // Try to initialize Axis2_MinStepRate3 from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate3; + } + // And try to extract Axis2_MinStepRate3 value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate3; + + // Try to initialize Axis2_PhaseCurrent from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_PhaseCurrent; + else { + // Try to initialize Axis2_PhaseCurrent from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_PhaseCurrent; + } + // And try to extract Axis2_PhaseCurrent value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_PhaseCurrent; + + // Try to initialize Axis2_Ramp from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_Ramp; + else { + // Try to initialize Axis2_Ramp from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_Ramp; + } + // And try to extract Axis2_Ramp value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Ramp; + + // Try to initialize Axis2_StartStopSpeed from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_StartStopSpeed; + else { + // Try to initialize Axis2_StartStopSpeed from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_StartStopSpeed; + } + // And try to extract Axis2_StartStopSpeed value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_StartStopSpeed; + + // Try to initialize Axis2_SleewSpeed from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_SleewSpeed; + else { + // Try to initialize Axis2_SleewSpeed from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_SleewSpeed; + } + // And try to extract Axis2_SleewSpeed value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_SleewSpeed; + + // Try to initialize Axis2_Range from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_Range; + else { + // Try to initialize Axis2_Range from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_Range; + } + // And try to extract Axis2_Range value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Range; + + // Try to initialize Axis2_SetAccelerAndRetardPars from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> axis2_SetAccelerAndRetardPars; + else { + // Try to initialize Axis2_SetAccelerAndRetardPars from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> axis2_SetAccelerAndRetardPars; + } + // And try to extract Axis2_SetAccelerAndRetardPars value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_SetAccelerAndRetardPars; + + + + // End of Automatic code generation + //------------------------------------------------------------------ + +} +//+---------------------------------------------------------------------------- +// +// method : Aml::always_executed_hook() +// +// description : method always executed before any command is executed +// +//----------------------------------------------------------------------------- +void Aml::always_executed_hook() +{ + +} +//+---------------------------------------------------------------------------- +// +// method : Aml::read_attr_hardware +// +// description : Hardware acquisition for attributes. +// +//----------------------------------------------------------------------------- +void Aml::read_attr_hardware(vector<long> &attr_list) +{ + DEBUG_STREAM << "Aml::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; + // Add your own code here +} + +//+---------------------------------------------------------------------------- +// +// method : Aml::read_Axis1_Position +// +// description : Extract real attribute values for Axis1_Position acquisition result. +// +//----------------------------------------------------------------------------- +void Aml::read_Axis1_Position(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Aml::read_Axis1_Position(Tango::Attribute &attr) entering... "<< endl; + + attr_long_value=get_position(1); + currentPosAxis1=attr_long_value; + + attr.set_value(&attr_long_value); + +} + +//+---------------------------------------------------------------------------- +// +// method : Aml::read_Axis2_Position +// +// description : Extract real attribute values for Axis2_Position acquisition result. +// +//----------------------------------------------------------------------------- +void Aml::read_Axis2_Position(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Aml::read_Axis2_Position(Tango::Attribute &attr) entering... "<< endl; + + attr_long_value=get_position(2); + currentPosAxis2=attr_long_value; + + attr.set_value(&attr_long_value); +} + + +//+------------------------------------------------------------------ +/** + * method: Aml::init_motor + * + * description: method to execute "InitMotor" + * + * + */ +//+------------------------------------------------------------------ +void Aml::init_motor() +{ + DEBUG_STREAM << "Aml::init_motor(): entering... !" << endl; + + // Add your own code to control device here + char *answ; + string cmd; + string selMot; + char *char_cmd; + + actualSelectedMotor = -1; + //select 1st axis + selMot=string(AML_AXIS1); + selectMotor(selMot); + + + //set 1st axis parameters + if (device != 0) { + if (controllerVersion) + cmd=axis1_MinStepRate1; + else + cmd=string(AML_SET_MIN_STEP_RATE1) + "," + axis1_MinStepRate1; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting min step rate1 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_MIN_STEP_RATE2) + "," + axis1_MinStepRate2; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting min step rate2 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_MIN_STEP_RATE4) + "," + axis1_MinStepRate3; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting min step rate4 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_REMOVE_PHASE_CURRENT) + axis1_PhaseCurrent; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting phase current failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_RAMP) + axis1_Ramp; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting ramp failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_SMOOTH_STOP); + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting smooth stop failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_START_STOP_SPEED) + axis1_StartStopSpeed; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting start stop speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_SLEEW_SPEED) + axis1_SleewSpeed; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting sleew speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_SET_INIT_POS) ; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting init pos failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (controllerVersion)) { + cmd=axis1_SetAccelerAndRetardPars; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor1Name<<" init_motor: setting sleew speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + //select 2nd axis + selMot=string(AML_AXIS2); + selectMotor(selMot); + + //set 2nd axis parameters + if (device != 0) { + if (controllerVersion) + cmd=axis2_MinStepRate1; + else + cmd=string(AML_SET_MIN_STEP_RATE1) + "," + axis2_MinStepRate1; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting min step rate1 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_MIN_STEP_RATE2) + "," + axis2_MinStepRate2; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting min step rate2 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_MIN_STEP_RATE4) + "," + axis2_MinStepRate3; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting min step rate4 failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_REMOVE_PHASE_CURRENT) + axis2_PhaseCurrent; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting phase current failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_RAMP) + axis2_Ramp; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting ramp failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_SMOOTH_STOP); + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting smooth stop failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_START_STOP_SPEED) + axis2_StartStopSpeed; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting start stop speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (!controllerVersion)) { + cmd=string(AML_SET_SLEEW_SPEED) + axis2_SleewSpeed; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting sleew speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if (device != 0) { + cmd=string(AML_SET_INIT_POS) ; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting init pos failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + if ((device != 0) && (controllerVersion)) { + cmd=axis2_SetAccelerAndRetardPars; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< Motor2Name<<" init_motor: setting sleew speed failed"; + Tango::Except::throw_exception("Init Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + return; + +} + + + +//+------------------------------------------------------------------ +/** + * General methods + */ +//+------------------------------------------------------------------ +void Aml::initSerialPort() +{ + DEBUG_STREAM << "Aml::initSerialPort(): entering... !" << endl; + + // Add your own code to control device here + + struct termios tty_settings; + struct termios com_par; + char ttyport[128]; + + + // Initialise variables to default values + //-------------------------------------------- + sprintf(ttyport,"/dev/%s",serialPort.c_str()); + device = open (ttyport, O_RDWR | O_NONBLOCK); + if (device < 0) { + device = 0; + Tango::Except::throw_exception( + "Unable to open serial device", + "AML Init Error.", + "initSerialPort()", + Tango::ERR); + return; + } + + if(tcgetattr(device, &com_par) == -1) { + close(device); + device = 0; + Tango::Except::throw_exception( + "Unable to get serial device attributes", + "AML Init Error.", + "initSerialPort()", + Tango::ERR); + return; + } + + bzero(&tty_settings, sizeof(tty_settings)); + + tty_settings.c_oflag = 0; // raw output + tty_settings.c_iflag = IGNBRK | IGNPAR | ICRNL; + tty_settings.c_cflag = B19200 | CS7 | CSTOPB | PARODD | PARENB | CLOCAL | CREAD; + + //timeout della seriale + tty_settings.c_cc[VMIN]=1; /* blocking read until N character arrives */ + tty_settings.c_cc[VTIME]=0; /* inter-character timer */ + + cfsetospeed(&tty_settings,B19200); // input baud rate + cfsetispeed(&tty_settings,B19200); // output + + + if (tcflush(device,TCIOFLUSH)!=0) + { + close(device); + device = 0; + Tango::Except::throw_exception( + "Unable to flush serial device", + "AML int Error.", + "init_serialPort()", + Tango::ERR); + return; + } + + if(tcsetattr(device, TCSANOW, &tty_settings) == -1) { + close(device); + device = 0; + Tango::Except::throw_exception( + "tcsetattr of serial device failed!!!", + "AML int Error.", + "init_serialPort()", + Tango::ERR); + return; + } + + if (tcflush(device,TCIOFLUSH)!=0) + { + close(device); + device = 0; + Tango::Except::throw_exception( + "Unable to flush serial device after having set tty parameters", + "AML int Error.", + "init_serialPort()", + Tango::ERR); + return; + } + + tcsetattr(device, TCSANOW,&tty_settings);// changes made NOW + + //flusho la seriale + if (tcflush(device,TCIOFLUSH)!=0) + { + Tango::Except::throw_exception( + "Unable to flush serial device", + "AML int Error.", + "init_serialPort()", + Tango::ERR); + return; + } + +} + + +bool Aml:: checkRangeOk(string axis,Tango::DevLong distance) +{ + Tango::DevLong Range=0; + bool res=false; + if (strcmp(axis.c_str(), AML_AXIS1)== 0) + Range= atol(axis1_Range.c_str()); + else if (strcmp(axis.c_str(), AML_AXIS2)== 0) + Range= atol(axis2_Range.c_str()); + else + Tango::Except::throw_exception( + "NO AXIS SELECTED", + "AML setup error.", + "checkRangeOk()", + Tango::ERR); + res = ((distance> -Range) && (distance<Range)); + return res; +} + +void Aml::ClearError(void) { + errorMessage.clear(); + errorNumber = 0; +} + +void Aml::SetError(char *msg, int num = 0) { + ClearError(); + errorNumber = num; + errorMessage = string(msg); +} + + +void Aml::amlError(char *msg, char *answ) { + char buffer[AMLBUFFLEN]; + + sprintf(buffer,"%s: %s\n",logicalName.c_str(),msg); + + if (!(strcmp(answ,"E1"))) + sprintf(buffer+strlen(buffer),"Parity/Checksum error"); + if (!(strcmp(answ,"E2"))) + sprintf(buffer+strlen(buffer),"Command argument out of limit or not requested"); + if (!(strcmp(answ,"E3"))) + sprintf(buffer+strlen(buffer),"Error in downloaded program"); + if (!(strcmp(answ,"E4"))) + sprintf(buffer+strlen(buffer),"Command not executable"); + if (!(strcmp(answ,"E5"))) + sprintf(buffer+strlen(buffer),"Temperature exceeded 175 C"); + if (!(strcmp(answ,"E7"))) + sprintf(buffer+strlen(buffer),"End of travel input at \"low\""); + if (!(strcmp(answ,"E8"))) + sprintf(buffer+strlen(buffer),"Loop nesting too deep"); + if (!(strcmp(answ,"E9"))) + sprintf(buffer+strlen(buffer),"Program too large"); + + errorMessage=string(buffer); +} + + +char * Aml::talkListen(char *msg, const int retry) { + int readmask = 0; + fd_set readfds; + int nfound, nbytes, total_read_bytes,i; + char errbuffer[AMLBUFFLEN],logbuffer[AMLBUFFLEN]; + char *buffer; + char answ_buffer[AMLBUFFLEN]; + struct timeval timeout; + + tcflush(device,TCIOFLUSH); + DEBUG_STREAM << "Aml::talkListen(): Sending: " << msg << endl; + buffer = strdup(msg); + buffer[strlen(msg)] = '\r'; + if ( (nbytes = write(device, buffer, strlen(msg)+1)) < 0) { + sprintf(errbuffer,"%s: talk_listen: write failed: errno=%d",logicalName.c_str(), msg, errno); + SetError(errbuffer,errno); + return(0); + } + usleep(1000); + free(buffer); + readmask = 1 << device; + + bzero(answ_buffer,AMLBUFFLEN); + total_read_bytes = 0; + + for (i=0; i<retry; i++) { + +// changes required + + FD_ZERO(&readfds); + FD_SET(device, &readfds); + timeout.tv_sec = 1; + timeout.tv_usec = 0; + + if((nfound = select(32, &readfds, 0, 0, &timeout)) == -1) { + sprintf(errbuffer,"%s: talk_listen: select failed",logicalName.c_str(), msg); + SetError(errbuffer,nfound); + return(0); + } + else if (nfound > 0) { + if ( (nbytes = read(device, answ_buffer+total_read_bytes, AMLBUFFLEN)) < 0) { + sprintf(errbuffer,"%s: talk_listen: read failed: errno=%d",logicalName.c_str(), msg, errno); + SetError(errbuffer,errno); + return(0); + } + total_read_bytes += nbytes; + if (strchr(answ_buffer,'\n') == NULL) { + continue; + } + *(strchr(answ_buffer,'\n')) = 0; + DEBUG_STREAM << "Aml::talkListen(): Received: " << answ_buffer << endl; + if(!strncmp(answ_buffer,AMLOKY,1) || + !strncmp(answ_buffer,AMLOKV,1) || + !strncmp(answ_buffer,AMLOKQ,1) ) { + return(strdup(answ_buffer)); + } else + if (!strncmp(answ_buffer,AMLBUSY,1)) { + sprintf(logbuffer,"\n%s talk_listen: answer:|%s|: busy",logicalName.c_str(),answ_buffer); + logMessage=string(logbuffer); + } else + if (!strncmp(answ_buffer,AMLERROR,1)) { + sprintf(errbuffer,"%s talk_listen: answer:|%s|: error",logicalName.c_str(),answ_buffer); + amlError(errbuffer, answ_buffer); + return(0); + + } else { + sprintf(errbuffer,"%s talk_listen: answer:|%s|: unknown",logicalName.c_str(),answ_buffer); + SetError(errbuffer,1); + return(0); + } + } + usleep(1000); + } + sprintf(errbuffer,"%s talk_listen: answer:|%s|: select timeout",logicalName.c_str(),answ_buffer); + SetError(errbuffer,1); + return(0); +} + +int Aml:: checkStatus() +{ + char buffer[256]; + char *answ; + + if (device == 0) { + sprintf(buffer,"%s: getstatus: serial not initialized",logicalName.c_str()); + DEBUG_STREAM << buffer << endl; + return -1; + } + + answ=talkListen("F", AML_MAX_RETRY); + if (answ==0) { + return -1; + } + sprintf(buffer,"%s: getstatus: motor %s",logicalName.c_str(), answ); + DEBUG_STREAM << buffer << endl; + + while (answ[0] == 'B') { + sprintf(buffer,"%s: getstatus: motor %s",logicalName.c_str(), answ); + DEBUG_STREAM << buffer << endl; + free(answ); + answ=talkListen("F", AML_MAX_RETRY); + if (answ==0) { + return -1; + } + } + + sprintf(buffer,"%s: getstatus: motor %s",logicalName.c_str(), answ); + DEBUG_STREAM << buffer << endl; + if (answ[0] == 'Y') { + // motor is ready + free(answ); + return(0); + } else { + // motor in error + free(answ); + return -1; + } +} + +void Aml:: selectMotor(string selectedMotor) +{ + char *answ; + string cmd; + char *char_cmd; + int motnum = atoi(selectedMotor.c_str()); + + if ((device != 0) && ( actualSelectedMotor != motnum)){ + cmd=string(AML_SEL_MOTOR) + selectedMotor; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedMotor <<" selectMotor: selection of motor failed"; + Tango::Except::throw_exception("Select Motor Error", os.str(), __func__); + } else { + actualSelectedMotor = motnum; + // Sleep a little bit before next operation + usleep(1000); + } + free(answ); + delete []char_cmd; + } + return; +} + + +//+------------------------------------------------------------------ +/** + * method: Aml::get_position + * + * description: method to execute "GetPosition" + * + * @return + * + */ +//+------------------------------------------------------------------ +//Tango::DevFloat Aml::get_position() +//{ +// Tango::DevFloat argout ; +// DEBUG_STREAM << "Aml::get_position(): entering... !" << endl; +// +// selectMotor(); +// +// char *recbuffer; +// char logbuffer[256]; +// string cmd; +// char *char_cmd; +// +// if (device != 0) { +// cmd=string(AML_GET_POS) ; +// char_cmd=new char[cmd.length()+1]; +// strcpy(char_cmd, cmd.c_str()); +// +// recbuffer = talkListen(char_cmd, AML_MAX_RETRY);; +// if ( recbuffer== NULL) { +// TangoSys_OMemStream os; +// os << "Error->"<< logicalName<<" get_position: get pos failed"; +// Tango::Except::throw_exception("Aml::get_position(): Error", os.str(), __func__); +// } +// delete []char_cmd; +// } +// +// +// argout=atof(recbuffer+1); +// free(recbuffer); +// return argout; +//} + +//+------------------------------------------------------------------ +/** + * method: Aml::get_position + * + * description: method to execute "GetPosition" + * + * @param argin + * @return + * + */ +//+------------------------------------------------------------------ +Tango::DevLong Aml::get_position(Tango::DevShort argin) +{ + Tango::DevLong argout ; + DEBUG_STREAM << "Aml::get_position(): entering... !" << endl; + + // Add your own code to control device here + + string selectedMotor; + std::ostringstream oss; + oss<<argin; + + selectedMotor=oss.str(); + selectMotor(selectedMotor); + + char *recbuffer; + char logbuffer[256]; + string cmd; + char *char_cmd; + + if (device != 0) { + cmd=string(AML_GET_POS) ; + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + + recbuffer = talkListen(char_cmd, AML_MAX_RETRY);; + if ( recbuffer== NULL) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName<<" get_position: get pos failed"; + Tango::Except::throw_exception("Aml::get_position(): Error", os.str(), __func__); + } + delete []char_cmd; + } + + + argout=atol(recbuffer+1); + free(recbuffer); + return argout; + +} + + + + +//+------------------------------------------------------------------ +/** + * method: Aml::axis1__move_relative + * + * description: method to execute "Axis1_MoveRelative" + * + * @param argin + * + */ +//+------------------------------------------------------------------ +void Aml::axis1__move_relative(Tango::DevLong argin) +{ + DEBUG_STREAM << "Aml::axis1__move_relative(): entering... !" << endl; + + // Add your own code to control device here + string selectedAxis=string(AML_AXIS1); + selectMotor(selectedAxis); + + char *answ; + + if (checkStatus()<0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: motor NOT ready"; + Tango::Except::throw_exception("Motor Busy Error", os.str(), __func__); + return; + } + + currentPosAxis1=get_position(atol(selectedAxis.c_str())); + Tango::DevLong dist = currentPosAxis1 + argin; + + if (!checkRangeOk(selectedAxis, dist)) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: out of range"; + Tango::Except::throw_exception("Moving Error", os.str(), __func__); + return; + } + + if (device != 0) { + char cmd[AMLBUFFLEN]; + sprintf(cmd,"%s%d",AML_ABS_POS,(int)dist); + DEBUG_STREAM << dist << ","<< currentPosAxis1 << "," << argin << "," << AML_ABS_POS << "," << cmd << endl; + answ=talkListen(cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: movement failed"; + Tango::Except::throw_exception("Motor Error", os.str(), __func__); + } + free(answ); + } + return; + +} + +//+------------------------------------------------------------------ +/** + * method: Aml::axis2__move_relative + * + * description: method to execute "Axis2_MoveRelative" + * + * @param argin + * + */ +//+------------------------------------------------------------------ +void Aml::axis2__move_relative(Tango::DevLong argin) +{ + DEBUG_STREAM << "Aml::axis2__move_relative(): entering... !" << endl; + + // Add your own code to control device here + string selectedAxis=string(AML_AXIS2); + + selectMotor(selectedAxis); + + char *answ; + + if (checkStatus()<0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: motor NOT ready"; + Tango::Except::throw_exception("Motor Busy Error", os.str(), __func__); + return; + } + + currentPosAxis2=get_position(atol(selectedAxis.c_str())); + Tango::DevLong dist = currentPosAxis2 + argin; + if (!checkRangeOk(selectedAxis, dist)) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: out of range"; + Tango::Except::throw_exception("Moving Error", os.str(), __func__); + return; + } + + if (device != 0) { + char cmd[AMLBUFFLEN]; + sprintf(cmd,"%s%d",AML_ABS_POS,(int)dist); + answ=talkListen(cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_relative: movement failed"; + Tango::Except::throw_exception("Motor Error", os.str(), __func__); + } + free(answ); + } + return; + +} + +//+------------------------------------------------------------------ +/** + * method: Aml::axis1__move_absolute + * + * description: method to execute "Axis1_MoveAbsolute" + * + * @param argin + * + */ +//+------------------------------------------------------------------ +void Aml::axis1__move_absolute(Tango::DevLong argin) +{ + DEBUG_STREAM << "Aml::axis1__move_absolute(): entering... !" << endl; + + // Add your own code to control device here + + string selectedAxis=string(AML_AXIS1); + + selectMotor(selectedAxis); + + char buffer[256], logbuffer[256]; + char *answ; + + Tango::DevLong dist = argin; + + + if (!checkRangeOk(selectedAxis,argin)) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: out of range"; + Tango::Except::throw_exception("Moving Error", os.str(), __func__); + return; + } + + // control the motor state + if ( checkStatus() < 0) { // motor not ready (e.i. busy or in error) + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: motor NOT ready"; + Tango::Except::throw_exception("Motor Busy Error", os.str(), __func__); + return; + } + + if (device != 0) { + char cmd[AMLBUFFLEN]; + sprintf(cmd,"%s%d",AML_ABS_POS,(int)dist); + answ=talkListen(cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: movement failed"; + Tango::Except::throw_exception("Motor Error", os.str(), __func__); + } + free(answ); + } + + return; + + +} + +//+------------------------------------------------------------------ +/** + * method: Aml::axis2__move_absolute + * + * description: method to execute "Axis2_MoveAbsolute" + * + * @param argin + * + */ +//+------------------------------------------------------------------ +void Aml::axis2__move_absolute(Tango::DevLong argin) +{ + DEBUG_STREAM << "Aml::axis2__move_absolute(): entering... !" << endl; + + // Add your own code to control device here + string selectedAxis=string(AML_AXIS2); + selectMotor(selectedAxis); + + char buffer[256], logbuffer[256]; + char *answ; + + Tango::DevLong dist = argin; + + if (!checkRangeOk(selectedAxis,argin)) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: out of range"; + Tango::Except::throw_exception("Moving Error", os.str(), __func__); + return; + } + + // controll the motor state + if ( checkStatus() < 0) { // motor not ready (e.i. busy or in error) + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: motor NOT ready"; + Tango::Except::throw_exception("Motor Busy Error", os.str(), __func__); + return; + } + + if (device != 0) { + char cmd[AMLBUFFLEN]; + sprintf(cmd,"%s%d",AML_ABS_POS,(int)dist); + answ=talkListen(cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedAxis<<" move_absolute: movement failed"; + Tango::Except::throw_exception("Motor Error", os.str(), __func__); + } + free(answ); + } + + return; + +} + +//+------------------------------------------------------------------ +/** + * method: Aml::stop + * + * description: method to execute "Stop" + * + * @param argin + * + */ +//+------------------------------------------------------------------ +void Aml::stop(Tango::DevShort argin) +{ + DEBUG_STREAM << "Aml::stop(): entering... !" << endl; + + // Add your own code to control device here + + string selectedMotor; + std::ostringstream oss; + oss<<argin; + + selectedMotor=oss.str(); + selectMotor(selectedMotor); + + char *answ; + string cmd; + char *char_cmd; + + if (device != 0) { + cmd=string(AML_SMOOTH_STOP); + char_cmd=new char[cmd.length()+1]; + strcpy(char_cmd, cmd.c_str()); + answ=talkListen(char_cmd, AML_MAX_RETRY); + if (answ == 0) { + TangoSys_OMemStream os; + os << "Error->"<< logicalName + selectedMotor <<" stop: stopping of motor failed"; + Tango::Except::throw_exception("Stop Motor Error", os.str(), __func__); + } + free(answ); + delete []char_cmd; + } + + return; + +} + + + +} // namespace diff --git a/src/Aml.h b/src/Aml.h new file mode 100644 index 0000000000000000000000000000000000000000..555eb0d793e188d563f4b30e1c1cf6dbbd0b816d --- /dev/null +++ b/src/Aml.h @@ -0,0 +1,394 @@ +//============================================================================= +// +// file : Aml.h +// +// description : Include for the Aml class. +// +// project : +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 _AML_H +#define _AML_H + +//Including TANGO library +#include <tango.h> + +//Including libraries +#include <string.h> +#include <termio.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <termio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <math.h> +#include <fcntl.h> +#include <string.h> + +#define AMLBUFFLEN 256 +#define AMLOKY "Y" +#define AMLOKQ "Q" +#define AMLOKV "V" +#define AMLBUSY "B" +#define AMLERROR "E" +#define AML_MAX_RETRY 10 +#define AML_SEL_MOTOR "B" +#define AML_SET_MIN_STEP_RATE1 "M1" +#define AML_SET_MIN_STEP_RATE2 "M2" +#define AML_SET_MIN_STEP_RATE4 "M4" +#define AML_REMOVE_PHASE_CURRENT "h" +#define AML_SET_RAMP "R" +#define AML_SMOOTH_STOP "Z" +#define AML_START_STOP_SPEED "S" +#define AML_SET_SLEEW_SPEED "T" +#define AML_SET_INIT_POS "I1" +#define AML_ABS_POS "G" +#define AML_GET_POS "V1" +#define AML_AXIS1 "1" +#define AML_AXIS2 "2" + +//using namespace Tango; + +/** + * @author $Author: $ + * @version $Revision: $ + */ + + // Add your own constants definitions here. + //----------------------------------------------- + + +namespace Aml_ns +{ + +/** + * Class Description: + * + */ + +/* + * Device States Description: + */ + + +class Aml: public Tango::Device_4Impl +{ +public : + // Add your own data members here + //----------------------------------------- + void initSerialPort(); + bool checkRangeOk(string ,Tango::DevLong ); + void ClearError(void); + void SetError(char *msg, int num); + void amlError(char *, char *); + int checkStatus(); + char * talkListen(char *, const int ); + void selectMotor(string ); + + int device; + string curPos; + Tango::DevLong currentPosAxis1; + Tango::DevLong currentPosAxis2; + string errorMessage; + string logMessage; + int errorNumber; + string Motor1Name, Motor2Name; + + // Here is the Start of the automatic code generation part + //------------------------------------------------------------- +/** + * @name attributes + * Attributs member data. + */ +//@{ + Tango::DevLong *attr_Axis1_Position_read; + Tango::DevLong *attr_Axis2_Position_read; +//@} + +/** + * @name Device properties + * Device properties member data. + */ +//@{ +/** + * + */ + string logicalName; +/** + * Serial port device (ttyS0,ttyS1, ...) + */ + string serialPort; +/** + * + */ + Tango::DevShort controllerVersion; +/** + * + */ + string axis1_Name; +/** + * + */ + string axis1_MinStepRate1; +/** + * + */ + string axis1_MinStepRate2; +/** + * + */ + string axis1_MinStepRate3; +/** + * + */ + string axis1_PhaseCurrent; +/** + * + */ + string axis1_Ramp; +/** + * + */ + string axis1_StartStopSpeed; +/** + * + */ + string axis1_SleewSpeed; +/** + * + */ + string axis1_Range; +/** + * + */ + string axis1_SetAccelerAndRetardPars; +/** + * + */ + string axis2_Name; +/** + * + */ + string axis2_MinStepRate1; +/** + * + */ + string axis2_MinStepRate2; +/** + * + */ + string axis2_MinStepRate3; +/** + * + */ + string axis2_PhaseCurrent; +/** + * + */ + string axis2_Ramp; +/** + * + */ + string axis2_StartStopSpeed; +/** + * + */ + string axis2_SleewSpeed; +/** + * + */ + string axis2_Range; +/** + * + */ + string axis2_SetAccelerAndRetardPars; +//@} + +/**@name Constructors + * Miscellaneous constructors */ +//@{ +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + Aml(Tango::DeviceClass *cl,string &s); +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + Aml(Tango::DeviceClass *cl,const char *s); +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + Aml(Tango::DeviceClass *cl,const char *s,const char *d); +//@} + +/**@name Destructor + * Only one desctructor is defined for this class */ +//@{ +/** + * The object desctructor. + */ + ~Aml() {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 Aml methods prototypes + */ + +//@{ +/** + * Hardware acquisition for attributes. + */ + virtual void read_attr_hardware(vector<long> &attr_list); +/** + * Extract real attribute values for Axis1_Position acquisition result. + */ + virtual void read_Axis1_Position(Tango::Attribute &attr); +/** + * Extract real attribute values for Axis2_Position acquisition result. + */ + virtual void read_Axis2_Position(Tango::Attribute &attr); +/** + * Read/Write allowed for Axis1_Position attribute. + */ + virtual bool is_Axis1_Position_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Axis2_Position attribute. + */ + virtual bool is_Axis2_Position_allowed(Tango::AttReqType type); +/** + * Execution allowed for Axis1_MoveRelative command. + */ + virtual bool is_Axis1_MoveRelative_allowed(const CORBA::Any &any); +/** + * Execution allowed for Axis2_MoveRelative command. + */ + virtual bool is_Axis2_MoveRelative_allowed(const CORBA::Any &any); +/** + * Execution allowed for Axis1_MoveAbsolute command. + */ + virtual bool is_Axis1_MoveAbsolute_allowed(const CORBA::Any &any); +/** + * Execution allowed for Axis2_MoveAbsolute command. + */ + virtual bool is_Axis2_MoveAbsolute_allowed(const CORBA::Any &any); +/** + * Execution allowed for InitMotor command. + */ + virtual bool is_InitMotor_allowed(const CORBA::Any &any); +/** + * Execution allowed for Stop command. + */ + virtual bool is_Stop_allowed(const CORBA::Any &any); +/** + * Execution allowed for GetPosition command. + */ + virtual bool is_GetPosition_allowed(const CORBA::Any &any); +/** + * + * @param argin + * @exception DevFailed + */ + void axis1__move_relative(Tango::DevLong); +/** + * + * @param argin + * @exception DevFailed + */ + void axis2__move_relative(Tango::DevLong); +/** + * + * @param argin + * @exception DevFailed + */ + void axis1__move_absolute(Tango::DevLong); +/** + * + * @param argin + * @exception DevFailed + */ + void axis2__move_absolute(Tango::DevLong); +/** + * + * @exception DevFailed + */ + void init_motor(); +/** + * + * @param argin + * @exception DevFailed + */ + void stop(Tango::DevShort); +/** + * + * @param argin + * @return + * @exception DevFailed + */ + Tango::DevLong get_position(Tango::DevShort); + +/** + * 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 + //----------------------------------------- + Tango::DevLong attr_long_value; + int actualSelectedMotor; +}; + +} // namespace_ns + +#endif // _AML_H diff --git a/src/AmlClass.cpp b/src/AmlClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c040ba5b3d58cf8cbdcf472407e7892f0dcc4f3 --- /dev/null +++ b/src/AmlClass.cpp @@ -0,0 +1,941 @@ +static const char *RcsId = "$Header: $"; +static const char *TagName = "$Name: $"; +static const char *HttpServer= "http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/"; +//+============================================================================= +// +// file : AmlClass.cpp +// +// description : C++ source for the AmlClass. A singleton +// class derived from DeviceClass. It implements the +// command list and all properties and methods required +// by the Aml once per process. +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 +//============================================================================= + + +#include <tango.h> + +#include <Aml.h> +#include <AmlClass.h> + + +namespace Aml_ns +{ +//+---------------------------------------------------------------------------- +// +// method : StopCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *StopCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "StopCmd::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + + ((static_cast<Aml *>(device))->stop(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : Axis2_MoveAbsoluteCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *Axis2_MoveAbsoluteCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "Axis2_MoveAbsoluteCmd::execute(): arrived" << endl; + + Tango::DevLong argin; + extract(in_any, argin); + + ((static_cast<Aml *>(device))->axis2__move_absolute(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : Axis1_MoveAbsoluteCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *Axis1_MoveAbsoluteCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "Axis1_MoveAbsoluteCmd::execute(): arrived" << endl; + + Tango::DevLong argin; + extract(in_any, argin); + + ((static_cast<Aml *>(device))->axis1__move_absolute(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : Axis2_MoveRelativeCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *Axis2_MoveRelativeCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "Axis2_MoveRelativeCmd::execute(): arrived" << endl; + + Tango::DevLong argin; + extract(in_any, argin); + + ((static_cast<Aml *>(device))->axis2__move_relative(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : Axis1_MoveRelativeCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *Axis1_MoveRelativeCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "Axis1_MoveRelativeCmd::execute(): arrived" << endl; + + Tango::DevLong argin; + extract(in_any, argin); + + ((static_cast<Aml *>(device))->axis1__move_relative(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : GetPositionClass::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *GetPositionClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "GetPositionClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + + return insert((static_cast<Aml *>(device))->get_position(argin)); +} + + + + + + + +//+---------------------------------------------------------------------------- +// +// method : InitMotorCmd::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 excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *InitMotorCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout2 << "InitMotorCmd::execute(): arrived" << endl; + + ((static_cast<Aml *>(device))->init_motor()); + return new CORBA::Any(); +} + + + +// +//---------------------------------------------------------------- +// Initialize pointer for singleton pattern +//---------------------------------------------------------------- +// +AmlClass *AmlClass::_instance = NULL; + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::AmlClass(string &s) +// +// description : constructor for the AmlClass +// +// in : - s : The class name +// +//----------------------------------------------------------------------------- +AmlClass::AmlClass(string &s):DeviceClass(s) +{ + + cout2 << "Entering AmlClass constructor" << endl; + get_class_property(); + set_default_property(); + write_class_property(); + + cout2 << "Leaving AmlClass constructor" << endl; + +} +//+---------------------------------------------------------------------------- +// +// method : AmlClass::~AmlClass() +// +// description : destructor for the AmlClass +// +//----------------------------------------------------------------------------- +AmlClass::~AmlClass() +{ + _instance = NULL; +} + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::instance +// +// description : Create the object if not already done. Otherwise, just +// return a pointer to the object +// +// in : - name : The class name +// +//----------------------------------------------------------------------------- +AmlClass *AmlClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + string s(name); + _instance = new AmlClass(s); + } + catch (bad_alloc) + { + throw; + } + } + return _instance; +} + +AmlClass *AmlClass::instance() +{ + if (_instance == NULL) + { + cerr << "Class is not initialised !!" << endl; + exit(-1); + } + return _instance; +} + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::command_factory +// +// description : Create the command object(s) and store them in the +// command list +// +//----------------------------------------------------------------------------- +void AmlClass::command_factory() +{ + command_list.push_back(new Axis1_MoveRelativeCmd("Axis1_MoveRelative", + Tango::DEV_LONG, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new Axis2_MoveRelativeCmd("Axis2_MoveRelative", + Tango::DEV_LONG, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new Axis1_MoveAbsoluteCmd("Axis1_MoveAbsolute", + Tango::DEV_LONG, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new Axis2_MoveAbsoluteCmd("Axis2_MoveAbsolute", + Tango::DEV_LONG, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new InitMotorCmd("InitMotor", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new StopCmd("Stop", + Tango::DEV_SHORT, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new GetPositionClass("GetPosition", + Tango::DEV_SHORT, Tango::DEV_LONG, + "", + "", + Tango::OPERATOR)); + + // add polling if any + for (unsigned int i=0 ; i<command_list.size(); i++) + { + } +} + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::get_class_property +// +// description : Get the class property for specified name. +// +// in : string name : The property name +// +//+---------------------------------------------------------------------------- +Tango::DbDatum AmlClass::get_class_property(string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} +//+---------------------------------------------------------------------------- +// +// method : AmlClass::get_default_device_property() +// +// description : Return the default value for device property. +// +//----------------------------------------------------------------------------- +Tango::DbDatum AmlClass::get_default_device_property(string &prop_name) +{ + for (unsigned int i=0 ; i<dev_def_prop.size() ; i++) + if (dev_def_prop[i].name == prop_name) + return dev_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::get_default_class_property() +// +// description : Return the default value for class property. +// +//----------------------------------------------------------------------------- +Tango::DbDatum AmlClass::get_default_class_property(string &prop_name) +{ + for (unsigned int i=0 ; i<cl_def_prop.size() ; i++) + if (cl_def_prop[i].name == prop_name) + return cl_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} +//+---------------------------------------------------------------------------- +// +// method : AmlClass::device_factory +// +// description : Create the device object(s) and store them in the +// device list +// +// in : Tango::DevVarStringArray *devlist_ptr : The device name list +// +//----------------------------------------------------------------------------- +void AmlClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + + // Create all devices.(Automatic code generation) + //------------------------------------------------------------- + for (unsigned long i=0 ; i < devlist_ptr->length() ; i++) + { + cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl; + + // Create devices and add it into the device list + //---------------------------------------------------- + device_list.push_back(new Aml(this, (*devlist_ptr)[i])); + + // Export device to the outside world + // Check before if database used. + //--------------------------------------------- + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(device_list.back()); + else + export_device(device_list.back(), (*devlist_ptr)[i]); + } + // End of Automatic code generation + //------------------------------------------------------------- + +} +//+---------------------------------------------------------------------------- +// Method: AmlClass::attribute_factory(vector<Tango::Attr *> &att_list) +//----------------------------------------------------------------------------- +void AmlClass::attribute_factory(vector<Tango::Attr *> &att_list) +{ + // Attribute : Axis1_Position + Axis1_PositionAttrib *axis1__position = new Axis1_PositionAttrib(); + att_list.push_back(axis1__position); + + // Attribute : Axis2_Position + Axis2_PositionAttrib *axis2__position = new Axis2_PositionAttrib(); + att_list.push_back(axis2__position); + + // End of Automatic code generation + //------------------------------------------------------------- +} + + + + + + + + + + + + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::get_class_property() +// +// description : Read the class properties from database. +// +//----------------------------------------------------------------------------- +void AmlClass::get_class_property() +{ + // Initialize your default values here (if not done with POGO). + //------------------------------------------------------------------ + + // Read class properties from database.(Automatic code generation) + //------------------------------------------------------------------ + + // Call database and extract values + //-------------------------------------------- + if (Tango::Util::instance()->_UseDb==true) + get_db_class()->get_property(cl_prop); + Tango::DbDatum def_prop; + int i = -1; + + + // End of Automatic code generation + //------------------------------------------------------------------ + +} + +//+---------------------------------------------------------------------------- +// +// method : AmlClass::set_default_property +// +// description: Set default property (class and device) for wizard. +// For each property, add to wizard property name and description +// If default value has been set, add it to wizard property and +// store it in a DbDatum. +// +//----------------------------------------------------------------------------- +void AmlClass::set_default_property() +{ + string prop_name; + string prop_desc; + string prop_def; + + vector<string> vect_data; + // Set Default Class Properties + // Set Default Device Properties + prop_name = "LogicalName"; + prop_desc = ""; + prop_def = "MOTOR_"; + vect_data.clear(); + vect_data.push_back("MOTOR_"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "SerialPort"; + prop_desc = "Serial port device (ttyS0,ttyS1, ...)"; + prop_def = "ttyS0"; + vect_data.clear(); + vect_data.push_back("ttyS0"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "ControllerVersion"; + prop_desc = ""; + prop_def = "0"; + vect_data.clear(); + vect_data.push_back("0"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_Name"; + prop_desc = ""; + prop_def = ""; + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_MinStepRate1"; + prop_desc = ""; + prop_def = "100"; + vect_data.clear(); + vect_data.push_back("100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_MinStepRate2"; + prop_desc = ""; + prop_def = "70"; + vect_data.clear(); + vect_data.push_back("70"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_MinStepRate3"; + prop_desc = ""; + prop_def = "50"; + vect_data.clear(); + vect_data.push_back("50"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_PhaseCurrent"; + prop_desc = ""; + prop_def = "50"; + vect_data.clear(); + vect_data.push_back("50"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_Ramp"; + prop_desc = ""; + prop_def = "100"; + vect_data.clear(); + vect_data.push_back("100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_StartStopSpeed"; + prop_desc = ""; + prop_def = "400"; + vect_data.clear(); + vect_data.push_back("400"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_SleewSpeed"; + prop_desc = ""; + prop_def = "500"; + vect_data.clear(); + vect_data.push_back("500"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_Range"; + prop_desc = ""; + prop_def = "15000"; + vect_data.clear(); + vect_data.push_back("15000"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis1_SetAccelerAndRetardPars"; + prop_desc = ""; + prop_def = "X400,500,100"; + vect_data.clear(); + vect_data.push_back("X400,500,100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_Name"; + prop_desc = ""; + prop_def = ""; + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_MinStepRate1"; + prop_desc = ""; + prop_def = "100"; + vect_data.clear(); + vect_data.push_back("100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_MinStepRate2"; + prop_desc = ""; + prop_def = "70"; + vect_data.clear(); + vect_data.push_back("70"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_MinStepRate3"; + prop_desc = ""; + prop_def = "50"; + vect_data.clear(); + vect_data.push_back("50"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_PhaseCurrent"; + prop_desc = ""; + prop_def = "50"; + vect_data.clear(); + vect_data.push_back("50"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_Ramp"; + prop_desc = ""; + prop_def = "100"; + vect_data.clear(); + vect_data.push_back("100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_StartStopSpeed"; + prop_desc = ""; + prop_def = "400"; + vect_data.clear(); + vect_data.push_back("400"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_SleewSpeed"; + prop_desc = ""; + prop_def = "500"; + vect_data.clear(); + vect_data.push_back("500"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_Range"; + prop_desc = ""; + prop_def = "15000"; + vect_data.clear(); + vect_data.push_back("15000"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + + prop_name = "Axis2_SetAccelerAndRetardPars"; + prop_desc = ""; + prop_def = "X400,500,100"; + vect_data.clear(); + vect_data.push_back("X400,500,100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + +} +//+---------------------------------------------------------------------------- +// +// method : AmlClass::write_class_property +// +// description : Set class description as property in database +// +//----------------------------------------------------------------------------- +void AmlClass::write_class_property() +{ + // First time, check if database used + //-------------------------------------------- + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + string classname = get_name(); + string header; + string::size_type start, end; + + // Put title + Tango::DbDatum title("ProjectTitle"); + string str_title(""); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + vector<string> str_desc; + str_desc.push_back(" "); + description << str_desc; + data.push_back(description); + + // put cvs location + string rcsId(RcsId); + string filename(classname); + start = rcsId.find("/"); + if (start!=string::npos) + { + filename += "Class.cpp"; + end = rcsId.find(filename); + if (end>start) + { + string strloc = rcsId.substr(start, end-start); + // Check if specific repository + start = strloc.find("/cvsroot/"); + if (start!=string::npos && start>0) + { + string repository = strloc.substr(0, start); + if (repository.find("/segfs/")!=string::npos) + strloc = "ESRF:" + strloc.substr(start, strloc.length()-start); + } + Tango::DbDatum cvs_loc("cvs_location"); + cvs_loc << strloc; + data.push_back(cvs_loc); + } + } + + // Get CVS tag revision + string tagname(TagName); + header = "$Name: "; + start = header.length(); + string endstr(" $"); + end = tagname.find(endstr); + if (end!=string::npos && end>start) + { + string strtag = tagname.substr(start, end-start); + Tango::DbDatum cvs_tag("cvs_tag"); + cvs_tag << strtag; + data.push_back(cvs_tag); + } + + // Get URL location + string httpServ(HttpServer); + if (httpServ.length()>0) + { + Tango::DbDatum db_doc_url("doc_url"); + db_doc_url << httpServ; + data.push_back(db_doc_url); + } + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + vector<string> inheritance; + inheritance.push_back("Device_4Impl"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + //-------------------------------------------- + get_db_class()->put_property(data); +} + +} // namespace diff --git a/src/AmlClass.h b/src/AmlClass.h new file mode 100644 index 0000000000000000000000000000000000000000..89f190e608848d1a19bfce143ca795be03e7f58c --- /dev/null +++ b/src/AmlClass.h @@ -0,0 +1,283 @@ +//============================================================================= +// +// file : AmlClass.h +// +// description : Include for the AmlClass root class. +// This class is represents the singleton class for +// the Aml device class. +// It contains all properties and methods which the +// Aml requires only once e.g. the commands. +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 _AMLCLASS_H +#define _AMLCLASS_H + +#include <tango.h> +#include <Aml.h> + + +namespace Aml_ns +{ +//===================================== +// Define classes for attributes +//===================================== +class Axis2_PositionAttrib: public Tango::Attr +{ +public: + Axis2_PositionAttrib():Attr("Axis2_Position", Tango::DEV_LONG, Tango::READ) {}; + ~Axis2_PositionAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Aml *>(dev))->read_Axis2_Position(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Aml *>(dev))->is_Axis2_Position_allowed(ty);} +}; + +class Axis1_PositionAttrib: public Tango::Attr +{ +public: + Axis1_PositionAttrib():Attr("Axis1_Position", Tango::DEV_LONG, Tango::READ) {}; + ~Axis1_PositionAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Aml *>(dev))->read_Axis1_Position(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Aml *>(dev))->is_Axis1_Position_allowed(ty);} +}; + +//========================================= +// Define classes for commands +//========================================= +class GetPositionClass : public Tango::Command +{ +public: + GetPositionClass(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) {}; + + GetPositionClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetPositionClass() {}; + + 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<Aml *>(dev))->is_GetPosition_allowed(any);} +}; + + + +class StopCmd : public Tango::Command +{ +public: + StopCmd(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) {}; + + StopCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~StopCmd() {}; + + 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<Aml *>(dev))->is_Stop_allowed(any);} +}; + + + +class InitMotorCmd : public Tango::Command +{ +public: + InitMotorCmd(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) {}; + + InitMotorCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~InitMotorCmd() {}; + + 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<Aml *>(dev))->is_InitMotor_allowed(any);} +}; + + + +class Axis2_MoveAbsoluteCmd : public Tango::Command +{ +public: + Axis2_MoveAbsoluteCmd(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) {}; + + Axis2_MoveAbsoluteCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Axis2_MoveAbsoluteCmd() {}; + + 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<Aml *>(dev))->is_Axis2_MoveAbsolute_allowed(any);} +}; + + + +class Axis1_MoveAbsoluteCmd : public Tango::Command +{ +public: + Axis1_MoveAbsoluteCmd(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) {}; + + Axis1_MoveAbsoluteCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Axis1_MoveAbsoluteCmd() {}; + + 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<Aml *>(dev))->is_Axis1_MoveAbsolute_allowed(any);} +}; + + + +class Axis2_MoveRelativeCmd : public Tango::Command +{ +public: + Axis2_MoveRelativeCmd(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) {}; + + Axis2_MoveRelativeCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Axis2_MoveRelativeCmd() {}; + + 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<Aml *>(dev))->is_Axis2_MoveRelative_allowed(any);} +}; + + + +class Axis1_MoveRelativeCmd : public Tango::Command +{ +public: + Axis1_MoveRelativeCmd(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) {}; + + Axis1_MoveRelativeCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Axis1_MoveRelativeCmd() {}; + + 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<Aml *>(dev))->is_Axis1_MoveRelative_allowed(any);} +}; + + + +// +// The AmlClass singleton definition +// + +class +#ifdef WIN32 + __declspec(dllexport) +#endif + AmlClass : public Tango::DeviceClass +{ +public: +// properties member data + +// add your own data members here +//------------------------------------ + +public: + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + +// Method prototypes + static AmlClass *init(const char *); + static AmlClass *instance(); + ~AmlClass(); + Tango::DbDatum get_class_property(string &); + Tango::DbDatum get_default_device_property(string &); + Tango::DbDatum get_default_class_property(string &); + +protected: + AmlClass(string &); + static AmlClass *_instance; + void command_factory(); + void get_class_property(); + void attribute_factory(vector<Tango::Attr *> &); + void write_class_property(); + void set_default_property(); + +private: + void device_factory(const Tango::DevVarStringArray *); +}; + + +} // namespace Aml_ns + +#endif // _AMLCLASS_H diff --git a/src/AmlStateMachine.cpp b/src/AmlStateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd3b2d96c2ede4c7fda166f8ea65c5acb6796dc8 --- /dev/null +++ b/src/AmlStateMachine.cpp @@ -0,0 +1,183 @@ +static const char *RcsId = "$Header: $"; +//+============================================================================= +// +// file : AmlStateMachine.cpp +// +// description : C++ source for the Aml and its alowed. +// method for commands and attributes +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 +//============================================================================= + +#include <tango.h> +#include <Aml.h> +#include <AmlClass.h> + +/*==================================================================== + * This file contains the methods to allow commands and attributes + * read or write execution. + * + * If you wand to add your own code, add it between + * the "End/Re-Start of Generated Code" comments. + * + * If you want, you can also add your own methods. + *==================================================================== + */ + +namespace Aml_ns +{ + +//================================================= +// Attributes Allowed Methods +//================================================= + +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis1_Position_allowed +// +// description : Read/Write allowed for Axis1_Position attribute. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis1_Position_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis2_Position_allowed +// +// description : Read/Write allowed for Axis2_Position attribute. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis2_Position_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} + +//================================================= +// Commands Allowed Methods +//================================================= + +//+---------------------------------------------------------------------------- +// +// method : Aml::is_InitMotor_allowed +// +// description : Execution allowed for InitMotor command. +// +//----------------------------------------------------------------------------- +bool Aml::is_InitMotor_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Stop_allowed +// +// description : Execution allowed for Stop command. +// +//----------------------------------------------------------------------------- +bool Aml::is_Stop_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_GetPosition_allowed +// +// description : Execution allowed for GetPosition command. +// +//----------------------------------------------------------------------------- +bool Aml::is_GetPosition_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis1_MoveRelative_allowed +// +// description : Execution allowed for Axis1_MoveRelative command. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis1_MoveRelative_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis2_MoveRelative_allowed +// +// description : Execution allowed for Axis2_MoveRelative command. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis2_MoveRelative_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis1_MoveAbsolute_allowed +// +// description : Execution allowed for Axis1_MoveAbsolute command. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis1_MoveAbsolute_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : Aml::is_Axis2_MoveAbsolute_allowed +// +// description : Execution allowed for Axis2_MoveAbsolute command. +// +//----------------------------------------------------------------------------- +bool Aml::is_Axis2_MoveAbsolute_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} + +} // namespace Aml_ns diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bf31e4ec838a39df65269f51d399455ce0492cd --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,44 @@ +static const char *RcsId = "$Header: $"; +//+============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible to create +// all class singletin for a device server. It is called +// at device server startup +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ +// +// $Log: $ +// +// 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 +//============================================================================= + + +#include <tango.h> +#include <AmlClass.h> + +/** + * Create AmlClass singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + + add_class(Aml_ns::AmlClass::init("Aml")); + +} diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..615d29dafb83047835f9b29ece4f09a4dd16e33c --- /dev/null +++ b/src/Makefile @@ -0,0 +1,149 @@ +#PROTECTED REGION ID(NiMotionBoard::Makefile) ENABLED START# +#============================================================================= +# +# file : Makefile +# +# description : Makefile to generate a TANGO device server. +# +# project : Aml motors +# +# $Author: $ +# +# $Revision: $ +# +# $Log: $ +# +#============================================================================= +# This file is generated by POGO +# (Program Obviously used to Generate tango Object) +#============================================================================= +# +# +#============================================================================= +# MAKE_ENV is the path to find common environment to buil project +# +MAKE_ENV = /opt/tango-8.1.2c/share/pogo/preferences + +#============================================================================= +# PACKAGE_NAME is the name of the library/device/exe you want to build +# +PACKAGE_NAME = Aml +MAJOR_VERS = 1 +MINOR_VERS = 0 +RELEASE = Release_$(MAJOR_VERS)_$(MINOR_VERS) + +# #============================================================================= +# # RELEASE_TYPE +# # - DEBUG : debug symbols - no optimization +# # - OPTIMIZED : no debug symbols - optimization level set to O2 +# #----------------------------------------------------------------------------- +RELEASE_TYPE = DEBUG + +#============================================================================= +# OUTPUT_TYPE can be one of the following : +# - 'STATIC_LIB' for a static library (.a) +# - 'SHARED_LIB' for a dynamic library (.so) +# - 'DEVICE' for a device server (will automatically include and link +# with Tango dependencies) +# - 'SIMPLE_EXE' for an executable with no dependency (for exemple the test tool +# of a library with no Tango dependencies) +# +OUTPUT_TYPE = DEVICE + +#============================================================================= +# OUTPUT_DIR is the directory which contains the build result. +# if not set, the standard location is : +# - $HOME/DeviceServers if OUTPUT_TYPE is DEVICE +# - ../bin for others +# +OUTPUT_DIR = ./bin/$(BIN_DIR) + + + +#============================================================================= +# INC_DIR_USER is the list of all include path needed by your sources +# - for a device server, tango dependencies are automatically appended +# - '-I ../include' and '-I .' are automatically appended in all cases +# +# +INC_DIR_USER= -I . + + +#============================================================================= +# LIB_DIR_USER is the list of user library directories +# - for a device server, tango libraries directories are automatically appended +# - '-L ../lib' is automatically appended in all cases +# +LIB_DIR_USER= + +#============================================================================= +# LFLAGS_USR is the list of user link flags +# - for a device server, tango libraries directories are automatically appended +# - '-ldl -lpthread' is automatically appended in all cases +# +# !!! ATTENTION !!! +# Be aware that the order matters. +# For example if you must link with libA, and if libA depends itself on libB +# you must use '-lA -lB' in this order as link flags, otherwise you will get +# 'undefined reference' errors +# +#LFLAGS_USR+= + + +#============================================================================= +# CXXFLAGS_USR lists the compilation flags specific for your library/device/exe +# This is the place where to put your compile-time macros using '-Dmy_macro' +# +# -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ for ACE +# +#CXXFLAGS_USR+= -Wall + + +#============================================================================= +# TANGO_REQUIRED +# - TRUE : your project depends on TANGO +# - FALSE : your project does not depend on TANGO +#----------------------------------------------------------------------------- +# - NOTE : if PROJECT_TYPE is set to DEVICE, TANGO will be auto. added +#----------------------------------------------------------------------------- +TANGO_REQUIRED = TRUE + + + +#============================================================================= +# include Standard TANGO compilation options +# +include $(MAKE_ENV)/tango.opt + +#============================================================================= +# POST_PROCESSING: action to be done after normal make. +# e.g.: change executable file name, ..... +#POST_PROCESSING = \ +# mv bin/$(BIN_DIR)/$(PACKAGE_NAME) bin/$(BIN_DIR)/$(PACKAGE_NAME)_DS + +#============================================================================= +# SVC_OBJS is the list of all objects needed to make the output +# +SVC_INCL = $(PACKAGE_NAME).h $(PACKAGE_NAME)Class.h + + +SVC_OBJS = \ + $(OBJDIR)/$(PACKAGE_NAME).o \ + $(OBJDIR)/$(PACKAGE_NAME)Class.o \ + $(OBJDIR)/$(PACKAGE_NAME)StateMachine.o \ + $(OBJDIR)/ClassFactory.o \ + $(OBJDIR)/main.o \ + $(ADDITIONAL_OBJS) + + +#------------ Object files for additional files ------------ +ADDITIONAL_OBJS = + +#============================================================================= +# include common targets +# +include $(MAKE_ENV)/common_target.opt + + + +#PROTECTED REGION END# diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41f82bf8cd77edb63e7eb5fa87b3d35a4e7d1be0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,68 @@ +static const char *RcsId = "$Header: $"; +//+============================================================================= +// +// file : main.cpp +// +// description : C++ source for a TANGO device server main. +// The main rule is to initialise (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// project : TANGO Device Server +// +// $Author: $ +// +// $Revision: $ $ +// +// $Log: $ +// +// 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 +//============================================================================= + +#include <tango.h> + + +int main(int argc,char *argv[]) +{ + + Tango::Util *tg; + try + { + // Initialise the device server + //---------------------------------------- + tg = Tango::Util::init(argc,argv); + + // Create the device server singleton + // which will create everything + //---------------------------------------- + tg->server_init(false); + + // Run the endless loop + //---------------------------------------- + cout << "Ready to accept request" << endl; + tg->server_run(); + } + catch (bad_alloc) + { + cout << "Can't allocate memory to store device object !!!" << endl; + cout << "Exiting" << endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + cout << "Received a CORBA_Exception" << endl; + cout << "Exiting" << endl; + } + tg->server_cleanup(); + return(0); +}