LabVIEW Object Oriented Programming (LVOOP)

Click here to load reader

  • date post

    19-Mar-2016
  • Category

    Documents

  • view

    104
  • download

    8

Embed Size (px)

description

LabVIEW Object Oriented Programming (LVOOP). Introduction of the HGF Base Class Library ( H elmholtz, G SI, F AIR) NI Big Physics Round Table February 2nd 2009 Holger Brand. Introduction to LVOOP What is LabVIEW? Why Object Oriented Programming? Why should use LVOOP? - PowerPoint PPT Presentation

Transcript of LabVIEW Object Oriented Programming (LVOOP)

  • LabVIEW Object Oriented Programming (LVOOP)Introduction of theHGF Base Class Library(Helmholtz, GSI, FAIR)

    NI Big Physics Round Table February 2nd 2009Holger Brand

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • ContentsIntroduction to LVOOPWhat is LabVIEW?Why Object Oriented Programming?Why should use LVOOP?Differences to conventional OO languagesSome remarks on constructors, destructors and dataflowVI & Object MemorySimple classes, inheritance, examplesLVOOP Design PatternsFocus of HGF Base Class LibraryFactory & HGF_BaseReference & Object ManagerFunctional Global Variable & VisitorEvents & Thread PoolNetwork Communication

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • What is LabVIEW?LabVIEW is a development environmentFor development of Measurement- , Automation-, Test- and Control Systems.It includes an advanced math and analysis library.Provides interfaces to DAQ, many field busses, network communication, ActiveX, .Net, DLL, etc.LabVIEW is a graphical programming languageInherent multithreaded with easy to use synchronization methodsVI: Virtual Instrument consists of frontpanel and blockdiagramsubVI: VI to be used as functionExpress VI: configurable subVILabVIEW Modules and Add-Ons extend the base functionalityRefer to http://www.ni.com/labview

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • LabVIEW 8.5

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • Dataflow ParadigmLabVIEW is a data flow language.Data flows from data source to sink.It does not normally have variables. Wires are not variables. Front panel controls are not variables.Even local or global variables are not scoped or allocated the way variables are in other languages. Variables are part of a model that conflicts with data flow.Without variables and a scope defining the lifetime of those variables, construction and destruction are meaningless concepts, and therefore they are left out of the language design. Therefore: LabVIEW forbid LabVIEW classes in the interface of LV-built DLLs (shared libraries).

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • Scope and Live timeWhat is the scope of the C++ integer? It exists from the point it is declared until the closing brace.What is the scope of the LabVIEW integer? Unknown. Until the wire ends? Until the VI stops executing?Until probe is closed?Until front panel closes? LabVIEW does not have space scope. LabVIEW has temporal scope. A piece of data exists as long as it is needed. If it is copied into front panel control, it stays there, even after execution finishes.Copies on the wires exist until the next execution of that wire.Another copy will be made for any probe on the wire.

    In a pure theoretical data flow language, there would be a separate copy on every individual wire, because every wire is an independent computation unit. Of course, that would be inefficient to actually implement, so LabVIEW's compiler optimizes the number of copies. But the principle is the same: data lives for a long time, sometimes outliving the program that generated that data.

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • Why Object Oriented Programming?ClassesAttribute data encapsulationMethods operating on attribute dataAccess scope(Multiple-) InheritanceRecipe, how to create objectsAdvantagesWell defined public interfaceWell define responsibilities (class and developer)Easier to debugBetter scalabilityBetter maintenance

    Each object can be viewed as an independent little machine or actor with a distinct role or responsibility (object by reference).

    Leads to better software design and architecture (hopefully!)// C++ class example #include

    using namespace std;

    class CRectangle { private: int x, y; public: void set_values (int,int); int area () {return (x*y);} };

    void CRectangle::set_values (int a, int b) { x = a; y = b; }

    int main () { CRectangle rect; rect.set_values (3,4); cout

  • Differences between C++ and LVOOP OO for LV means strict encapsulation, simple inheritance and dynamic dispatching (virtual methods)Refer to http://zone.ni.com/devzone/cda/tut/p/id/3574

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • Some remarksLVOOP NamingA Class is Cluster of private data (C:struct) and Member VIs operating on that dataAccess scope: public, protected and private VIsClass attribute is always private!Inheritance: Parent (ancestor) and child classLabVIEW Object is THE ultimate ancestor classNo multiple inheritanceStatic member VIs can not be overloadedDynamic dispatch and overwrite VIs (C++: virtual functions)No overloading! All dynamic VIs with the same name in one inheritance line must have the same connector pane. No friends in this versionDefault constructor onlyDefault class attribute values in case of frontpanel control or blockdiagram constantCurrent attribute data from callerNo destructor LVOOP FAQ: http://zone.ni.com/devzone/cda/tut/p/id/3573

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • VI & Object Memory LabVIEW allocates a dataspace for all the data needed to exectute a VI. Therefore it is thread safe. There is no need for mutex locking. A LV class attribute is a cluster of clusters. LabVIEW Object has an empty cluster that will be filled with child class attribute clusters. The VI data space has a pointer to object info which refers to Object data and Class information

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • A Simple ClassA simple example VI demonstrates: A LV object is just encapsulated structured data.

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • ContentsIntroduction to LVOOPWhat is LabVIEW?Why Object Oriented Programming?Why should use LVOOP?Differences to conventional OO languagesSome remarks on constructors, destructors and dataflowVI & Object MemorySimple classes, inheritance, examplesLVOOP Design PatternsFocus of HGF Base Class LibraryFactory & HGF_BaseReference & Object ManagerFunctional Global Variable & VisitorEvents & Thread PoolNetwork Communication

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • LVOOP Design Patternshttp://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems.

    Since LabVIEW objects follow the dataflow paradigm, many design pattern must be reinvented with respect to dataflow.

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • Focus of HGF Base Class LibraryHow to deal with LabVIEW objects as entities?FactoryNamed and initialized objectsConstructor and destructorHow to prevent unintended copying of objects at wire forks?Reference, SingletonObject ManagerFunctional Global Variable & VisitorHow to deal with Agents?Separation of passive object data and active threads > Thread PoolEvent handlingBehaviour -> State ChartHow to overcome some technical restrictions?Missing class information -> vi.lib\Utility\LVClassMissing overloading -> VariantMissing Multiple Inheritance -> AggregationMissing Interfaces -> Delegation

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • HGF Class Hierarchy

    Blue:HGF Base Class libraryRed:Example classes

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • ContentsLVOOP Design PatternsFocus of HGF Base Class LibraryFactory & HGF_BaseReference & Object ManagerFunctional Global Variable & VisitorEvents & Thread PoolNetwork Communication

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • HGF_Factory & HGF_BaseHow to create initialized, named objects?(LabVIEW provides objects with default attribute values only!)HGF_Factory is a base class for EntitiesIt creates initialized objects that remember their class and object names and whether it was created and initialized by a Factory.It defines two dynamic dispatch VIs (virtual methods)classesVI that returns a default object of a desired class.To be overwritten by child factories.initializeVI that uses variant attributes to initialize the default object.To be overwritten by child classes.HGF_Base is the base classOverwrites the initialize method.More common attributes could be added

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • H.Brand@gsi.de, NI Big Physics Round Table 2009

  • HGF_Factory Implementation

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • ContentsLVOOP Design PatternsFocus of HGF Base Class LibraryHGF_Factory & HGF_BaseReference & Object ManagerFunctional Global Variable & VisitorEvents & Thread PoolNetwork Communication

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • HGF_ReferenceHow to create References to objects?Reference object should follow dataflow paradigm! (That means such reference objects become cloned at wire forks.)Reference? Idea Queue!Single element size queueQueues can be referenced in LVSize=1 Object is in the queue or not Mutual exclusion

    H.Brand@gsi.de, NI Big Physics Round Table 2009

  • HGF_Reference ExampleReference object becomes cloned at wire fork, but not the object itself!savepublic subVI

    H.Brand@gsi.de, NI Big Physics R