1 / 51

TANGO training

TANGO training. How to develop a TANGO device. Preamble. Ambition Approaching different steps of a device development Handling the tools Collective approach Operating concepts of session I A C++ example Individual approach Read the documentation ! Tutorial C++ & Java

jenn
Download Presentation

TANGO training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TANGO training How to develop a TANGO device

  2. Preamble • Ambition • Approaching different steps of a device development • Handling the tools • Collective approach • Operating concepts of session I • A C++ example • Individual approach • Read the documentation ! • Tutorial C++ & Java • Many implementation details

  3. The example • Servers… • device BeamImage • Beam image (made in the plan of 1 screen) • Supposed to be linked to a camera (with on/off ctrl ) • Params : size (pixels) , scaling (mm/pixel) • device BeamDim • Profiles and size of beam • Logical device (SC service) • Analysis of the image produced by BeamImage • Params : image source (device) • The client(s)… • Matlab and/or Igor Pro and/or DeviceTree

  4. E1 : Definition of interfaces • Preliminary essential step • Led by the clients’ need • Functionalities and/or datas to «export» ? • Contract with the clients • Attractive choice • Strong link with non generic clients • Elementary choices • Commands, Attributes, Ownerships • Command or Attribute ? • command ~ action • attribute ~ physical size «monitorable»

  5. size pixels size pixels (size * scaling) mm (size * scaling) mm E1 : BeamImage : interface • 6 Commands • void SetImageSize(long) • long GetImageSize(void) • void SetImageScaling(double) • double GetImageScaling(void) • void SwitchOn (void) • void SwitchOff (void)

  6. size pixels size pixels (size * scaling) mm (size * scaling) mm E1 : BeamImage : interface • 3 Attributes • size • WRITE, SCALAR, LONG • scaling • READ_WRITE, SCALAR, DOUBLE • bimage • READ, IMAGE, LONG

  7. E1 : BeamImage : interface • 2 States • ON • Camera ON • All commands authorized except SwitchOn • Reading image authorized • OFF • Camera OFF • No authorized command except SwitchOn • Reading image forbidden • TANGO • State management -> command execution • No state management -> reading/writing attribute

  8. E1 : BeamDim : interface • 2 Commands • string GetImageSource(void) • void SetImageSource(string)

  9. E1 : BeamDim : interface • 4 Attributes • x_profil & y_profil • READ, SPECTRUM, LONG • x_dim & y_dim • READ, SCALAR, DOUBLE x_profil x_dim

  10. E2 : Code generation • POGO • TheProgramObviouslyused toGenerate TangoObjects • Java Application • Win32, Linux, Sun-Solaris • Code generator • C++ or Java • Devices skeleton • Commands, Attributes, Ownerships, States • To launch POGO under Windows… • %SOLEIL_ROOT%\tango\win32\script\start-pogo.bat

  11. E2 : POGO : Prog.Language

  12. E2 : POGO : New Project

  13. Classe du device E2 : POGO : New Project

  14. E2 : POGO : New Project

  15. E2 : POGO : States • class BeamImage interface : états • ON : Camera on • OFF : Camera off

  16. E2 : POGO : Commands • class BeamImage interface : commands • Tango::DEV_VOID SetImageSize(Tango::DEV_LONG) • - allowed for states: ON • Tango::DEV_LONG GetImageSize(Tango::DEV_VOID) • - allowed for states: ON • Tango::DEV_VOID SetImageScaling(Tango::DEV_DOUBLE) • - allowed for states: ON,OFF • Tango::DEV_DOUBLE GetImageScaling(Tango::DEV_VOID) • - allowed for states: ON,OFF • Tango::DEV_VOID SwitchOn(Tango::DEV_VOID) • allowed for states: OFF • Tango::DEV_VOID SwitchOff(Tango::DEV_VOID) • allowed for states: ON

  17. E2 : POGO : Attributes • class BeamImage interface : attributes • size • WRITE, SCALAR, LONG • Val_Min = 100, Val_Max = 500, Unit = pixels • Write allowed for states : ON • scaling • READ_WRITE, SCALAR, DOUBLE • Val_Min = 0.001, Val_Max = 10, Unit = mm/pixel • Read/Write allowed for states : ON, OFF • image • READ, IMAGE, LONG • Read allowed for states : ON

  18. E2 : POGO : Code generation

  19. E2 : POGO : Doc generation

  20. E3 : Compilation • Creating the working environment • Positioning the variables of environnement • %SOLEIL_ROOT%\env\win32\envSOLEIL.bat • executing this script in a console • Copying and modifying the Makefile • %SOLEIL_ROOT%\env\win32\Makefile.VC • copying to the directory of the device • editing : device_server = BeamImage • Compiler • nmake –f MakeFile.VC all • nmake –f MakeFile.VC clean

  21. E3 : Compilation • Where is the result of the compilation ? • Intermediate files • C:\TEMP\{USER NAME}\{DEVICE NAME} • Executable • C:\DeviceServers\ds_{DEVICE NAME}.exe

  22. E4 : Execution • Syntax • {EXEC NAME} {INSTANCE NAME} [-v{VERBOSE LEVEL}] • {EXEC NAME} = name of the binary • {INSTANCE NAME} = name of the device instance • C:\DeviceServers\ds_BeamImage 1 –v4

  23. E4 : Execution • Syntax • {EXEC NAME} {INSTANCE NAME} [-v {VERBOSE LEVEL}] • {EXEC NAME} = name of the binary • {INSTANCE NAME} = instance name of the device • C:\ds_BeamImage 1 –v4 • Oups! • The device server ds_BeamImage/1 is not defined in database. Exiting! • Save the server in the TANGO database • Jive : %SOLEIL_ROOT%\win32\script\start-jive.bat • Option –nodb (cf. TANGO programmer’s manual)

  24. E4 : Execution (recording)

  25. E4 : Execution (recording)

  26. E4 : Execution • Second attempt • {EXEC NAME} {INSTANCE NAME} [-v {VERBOSE LEVEL}] • {EXEC NAME} = name of the binary • {INSTANCE NAME} = instance name of the device • C:\ds_BeamImage 1 –v4

  27. E4 : Execution • Second attempt • {EXEC NAME} {INSTANCE NAME} [-v {VERBOSE LEVEL}] • {EXEC NAME} = name of the binary • {INSTANCE NAME} = instance name of the device • C:\ds_BeamImage 1 –v4 • This time … • Ready to accept request • Device waiting for external requests • Integrated into the control system • Appreciate what is done for you !

  28. E4 : Execution • Test • Generic client : DeviceTree, Igor Pro, Matlab • At this stage … • The device runs but does nothing • The interface remains to be implemented • Do what you declare doing !

  29. E5 : Implementation • What is POGO ? • Basic code of the device : 6 files • main.cpp • initialisation of the process and activation of the device • ClassFactory.cpp • Internal cooking of TANGO (extra load via linker) • {BeamImage}Class.h • {BeamImage}Class.cpp • header and impl. of the class (in the TANGO sense) of BeamImage devices. • Implement a « BeamImage factory » • Instanciation of devices , commands, attributes • States management (for the execution of commands only!) • Reading/writing of «class properties» in the TANGO database • {BeamImage}.h • {BeamImage}.cpp • «Implementation class» of BeamImage devices • Implementation of the interface : role of the developer ! Free ! Not expensive !

  30. E4 : Implementation • What is POGO generating (continuation) ? • The « glue» allowing to integrate the device to SC • An «empty» implementation of the device ! • Developer role • Implementing the specific code (acquisition, calculation, simulation, …) • Linking this code to the TANGO interface (generated by POGO)

  31. C S C SOLEIL Control system S S (applications network) client application. C C Server application. S S POGO TANGO Developer Application logic Material Supplier (driver, lib, …) E5 : Implementation

  32. E5 : Implementation • To do … • Implementing the commands • Implementing reading/writing of attributes • Managing the states • Taking into account the ownerships (stored in the database) • Where to intervene? • {DeviceClassName}.h et {DeviceClassName}.cpp • Here : BeamImage.h et BeamImage.cpp

  33. command_inout command_handler CORBA::Any always_executed_hook CORBA::Any is_allowed execute set_image_size CORBA::Any Tango::DevLong Tango::DevLong CORBA::Any CORBA::Any CORBA::Any E5 : Implementation : command • Execution command : • Tango::DEV_LONGSetImageSize(Tango::DEV_LONG) BeamImage (Device Impl.) BeamImage (CORBA Obj.) BeamImageClass (Device Class) SetImageSize (Command)

  34. E5 : Implementation : command BeamImage.h /** * Turns the camera on * @exception DevFailed */ void switch_on(); BeamImage.cpp //------------------------------------------------------------- // method: BeamImage::switch_on // description: method to execute "SwitchOn" // Turns the camera on //------------------------------------------------------------- void BeamImage::switch_on() { cout2 << "BeamImage::switch_on(): entering... !" << endl; // Add your own code to control device here }

  35. E5 : Implementation : command BeamImage.h /** * Turns the camera on * @exception DevFailed */ void switch_on(); BeamImage.cpp //------------------------------------------------------------- // method: BeamImage::switch_on // description: method to execute "SwitchOn" // Turns the camera on //------------------------------------------------------------- void BeamImage::switch_on() { cout2 << "BeamImage::switch_on(): entering... !" << endl; // Add your own code to control device here set_state(Tango::ON); set_status(‘Device up and ready (camera is on)’); } The TANGO command «SwitchOn» is implemented !

  36. E5 : Implementation : command • Main difficulties • Client/server exchange • Device client of a device (cf. BeamDim) • Rules of management of the memory in C++ • Allocation/De-allocation (Ownership) • CORBA (for certain types) • Strings, Sequences, Any (insertion/extraction) • Section 7.2 of the Tango programmer’s guide • Read this or die ! • An example (a model) • Device TangoTest • An ex. of command for each TANGO type

  37. E5 : Implementation : command • Management of errors • C++ Exceptions • spread towards the client (CORBA) • Generic exception • Tango: DevFailed • Reason, Description, Origin, Severity • Other exceptions (more semantic) • ConnectionFailed, CommunicationFailed, … • Section 7.2.4 of the programmer’s guide

  38. E5 : Implementation : command • Management of errors (example) // Allocate image buffer image_buffer = new Tango::DevLong[new_size]; // Check allocation if (image_buffer == 0) { TangoSys_OMemStream o; o << "Failed to allocate beam image buffer" << ends; LOG_ERROR((o.str())); Tango::Except::throw_exception( (const char *)"Out of memory error", o.str(), (const char *)"BeamImage::set_image_size"); }

  39. E5 : Implementation : command • Management of errors (example) Tango::DeviceProxy *isource = … try { Tango::DeviceData dd; dd = isource->command_inout(“GetImageScaling”); } cacth (Tango::DevFailed& ex) { TangoSys_OMemStream o; o << "Failed to execute GetImageScaling" << ends; LOG_ERROR((o.str())); Tango::Except::re_throw_exception( ex, (const char *)"Tango command failed", o.str(), (const char *)"BeamDim::read_attr_hardware"); }

  40. E5 : Implementation : command

  41. E5 : Implementation : attributes • Tricks to know… • The developer «handles» data associated to the attribute, not the attribute itself ! • Variables member of the implementation class with the type of the attribute (and not instances of the Tango class :Attribute) • For a READ attribute, the associated variable member represents the current value of the attribute (i.e. last value read on the hardware) • For a WRITE attribute, it represents the value of the instruction (i.e. value to «write» on the hardware) • Current implementation of TANGO • item being discussed • re-implementation considered

  42. E5 : Implementation : attributes • READ attribute • 1 variable member of the implementation class • name : attr_{ATTR NAME}_read • type : pointer on the attribute type • Ex : image attribute of a BeamImage device • BeamImage.h (header of the BeamImage class ) • POGO code : Tango::DevLong *attr_image_read; • BeamImage.cpp (impl. de la classe BeamImage) • POGO code : Nothing ! • Data associated to the attribute must be instanced • attr_image_read = new Tango::DevLong[size*size]; • Beware of memory leaks (init_device vs delete_device) !

  43. E5 : Implementation : attributes • Reading mecanism BeamImage (Device Impl.) BeamImage (CORBA Obj.) read_attributes(Attr1, Attr2) always_executed_hook read_attr_hardware (Attr1, Attr2) read_attr (Attr1) read_attr (Attr2)

  44. E5 : Implementation : attributes • Reading mecanism • About read_attribut_hardware… • 1 call for the n attributes to read • object : reading the hardware only once • update of variable members of the type <…_read> • About read_attr… • 1 call per attribute to read • object : affected a value to the attribute • associating the attribute and the variable member which represents it • attr.set_value(attr_image_read, size, size)

  45. E5 : Implementation : attributes • WRITE attribute • 1 variable member of the implementation class • name : attr_{ATTR NAME}_write • POGO 1.33 imperfection : also generates attr_{ATTR NAME}_read (do not take into account) • type : attribute type • Ex : attribute size of a BeamImage device • BeamImage.h (header of the BeamImage class ) • POGO code : Tango::DevLong attr_size_write; • BeamImage.cpp (impl. of the BeamImage class ) • POGO code : Nothing ! • attr_size_write = initialSize;

  46. E5 : Implementation : attributes • Writing mecanism BeamImage (Device Impl.) BeamImage (CORBA Obj.) write_attributes(Attr1, Attr2) always_executed_hook write_attr_hardware (Attr1, Attr2)

  47. E5 : Implementation : attributes • Writing mecanism • About write_attribut_hardware… • 1 call for n attributes to write • object : «writing» on the hardware (instruction) • update of variable members of type <…_write> • attr.get_write_value(attr_size_write) • exception removed beforehand (by TANGO) if … • val_min > valeur_utilisateur • or • Valeur_utilisateur > val_max • In that case … • no call to write_attribut_hardware ! • for no attribute !

  48. E5 : Implementation : attributes • READ_WRITE attribute • READ_WRITE = READ + WRITE • 2 variables member of the implementation class • instruction vs real value • <read part> • name : attr_{ATTR NAME}_read • type : pointer on the attribute type • <write part> • name : attr_{ATTR NAME}_write • type : attribute type • Ex : attribute scaling of a BeamImage device • BeamImage.h (header of the BeamImage class) • Tango::DevDouble *attr_scaling_read; • Tango::DevDouble attr_scaling_write; • BeamImage.cpp (impl. of the BeamImage class ) • POGO code : Nothing ! • attr_scaling_read = new Tango::DevDouble; • attr_scaling_write = initialScaling;

  49. E5 : Implementation : attributes

  50. E5 : Implementation : miscellaneous • About the init_device… • Method linked to the initialisation of a device • Contents • Everything in line with the device init • Instanciations and memory allocations • Reading of the properties from the TANGO database • A constraint … • The exec of the TANGO Init commands (on the DServer and/or the device) causes the one of <init_device> • Memory leaks ! • A reflex … • Overload delete_device • De-allott everyting (re)allotted by init_device

More Related