1 / 45

Elijah Kerry, Certified LabVIEW Architect (CLA)

Developing Scalable Applications with Object-Oriented Architectures. Elijah Kerry, Certified LabVIEW Architect (CLA) Senior Product Manager for LabVIEW, National Instruments. Does this sound familiar?. Adding or changing support for hardware requires significant effort and time.

Télécharger la présentation

Elijah Kerry, Certified LabVIEW Architect (CLA)

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. Developing Scalable Applications with Object-Oriented Architectures Elijah Kerry, Certified LabVIEW Architect (CLA) Senior Product Manager for LabVIEW, National Instruments

  2. Does this sound familiar? • Adding or changing support for hardware requires significant effort and time. • You’re constantly copying and duplicating code to add similar, but different functionality. • Adding new functionality breaks code due to brittle design. Scalable Modular Reusable Extensible Simple

  3. Agenda • Multi-Process System Design • Actor Framework Overview • Abstraction Layers • Designing Plugins • Distributing Templates ni.com/largeapps

  4. Why is Coupling Bad? User Interface Event Handler DAQ DAQ Acquisition Execution: The user interface cannot respond to other input while acquiring data Development: Modifying one process requires modifying the other, introducing added risk Extensibility: How do you add a data logging process?

  5. Cohesion: Understanding Data Scope • Shifter defines scope of process • Processes should be very cohesive • Independent processes should be separate loops While Loop DAQ TDMS User Interface State Information Multiple shift registers for one process indicate over-coupling

  6. De-Coupling Independent Processes Best Practices • Identify data scope • Delegate actions to appropriate process • Do not poll or use timeouts* *except for code that communicates with hardware Considerations • How do you send commands? • How do you send data? • Which processes can communicate with each other? • How do you update the UI? Event-Driven Loop DAQ Application

  7. Anatomy of a Producer Process Process Action or Event Stop Condition Met? Information Send Information Data Sends message to other process, program, or target

  8. Anatomy of a Message Producer Process Process Action or Event Stop Condition Met? Command Inter-Process Communication Data Message comprised of a command and optional data Sends message to other process, program, or target

  9. Constructing a Message Examples Data Variant allows data-type to vary. Different messages may require different data Command Enumerated constants listall of the options

  10. Queued Message Handler Process After command is executed, data cluster may be updated Case structure has a case for every command FIRST STATE Data cluster for all states Defines the scope of operationsthis consumer can handle Command Execution State Specific Data-type Definition Stop Condition Met? Queue Reference Next Steps Dequeue Action & Data ? Variant To Data Next steps could enqueue new action for any other loop, including this one

  11. New Framework for Multi-Process Systems The Actor Framework designed for large multi-process applications Includes utility for generating messages and invoking actor methods For more information: ni.com/actorframework Makes heavy use of object-oriented programming in order to eliminate duplication of code and improve system scalability

  12. Scaling Multiple Consumer Systems • Scenario Two: Multiple Instances of Same Process Queue References • Traditional Solution: Dynamically load VI or duplicate code

  13. Scaling Multiple Consumer Systems • Scenario One: Customize existing behavior Measurement B Measurement A • Messages • Configure • Acquire • Measure • Close • Exit • Messages • Configure • Acquire • Measure • Close • Exit • Messages • Configure • Acquire • Measure • Close • Exit • Traditional Solution: Maintain two separate copies

  14. Scaling Multiple Consumer Systems • Scenario Two: Add Additional Capability Measurement B Measurement A • Messages • Configure • Acquire • Measure • Close • Exit • Messages • Configure • Acquire • Log • Measure • Close • Exit • Messages • Configure • Acquire • Measure • Close • Exit • Traditional Solution: Maintain two separate copies

  15. Queues Exist for the Lifetime of the Creator Everyone STOP! When the creator of a queue leaves memory, the reference is destroyed. Any items remaining in the buffer will not be read, including ‘Stop’

  16. Class: Four Door Sedan Examples of Objects of this Class • These items can.. • Start • Drive • Change gear • Deploy airbags • Properties of these items: • Miles per gallon • Crash safety rating • Manual / Automatic • Engine size • Horse power Data Methods

  17. What Is a LabVIEW Class? Class: A collection of data and the methods that interact with that data. Object: A specific instance of a class • A LabVIEW Class is… • A glorified cluster • A user-defined data type • A type of Project Library

  18. Anatomy of a Class • Private data control • Accessors • Methods • Static • Dynamic • Access Scope • Public • Protected • Private • Community • Class Property Menu • Define Inheritance • Define Rules • Define Iconage

  19. Private Data ControlThe reason some people call classes a ‘glorified cluster’ Only VIs belonging to the class can access or modify this data

  20. Streamlining Member VI Creation Right click on the lvclass file in the Project and select ‘New’ Scripts the creation of member VIs to get and set data in the private data control Scripts the creation of member VIs with pre-populated connector panes Right-click an item in the private data control and select ‘Create Acessor’

  21. What Is Inheritance? • Example methods: • Initialize • Get Cargo Capacity A car is a type of vehicle. A truck is a type of vehicle.

  22. Dynamic Dispatch Dynamic dispatch can be thought of as ‘polymorphism at run-time.’ The Class you pass in to the dynamic dispatch terminal determines the specific method that gets executed at run-time. 10 6 2 Vehicle.lvclass Get Cargo Capacity.vi Truck.lvclass Get Cargo Capacity.vi Car.lvclass Get Cargo Capacity.vi

  23. What is an Actor? = An actor is conceptually the same as a queued message handler (QMH) or queued state machine (QSM).

  24. Methods of an Actor are run when a message is received Log Status Update Update Data Launch Results UI Initialize Hardware Scan Measurement Done = Measurement Scan Start Measurement Receive Results Object Methods of an Actor define the messages it can consume

  25. Messages Can Be Changed or Added by Children Log Status Update Update Data Launch Results UI Initialize Hardware Scan Measurement Done = Measurement Scan Start Measurement Receive Results Object Receive Results Object Overridden Receive Request for Compatible Hardware Types Receive Request for Hardware Device Names Receive Request to Load New Measurement from Disk

  26. Launching Actors and Managing Queues • Actor.lvclass has two queues in the private data • Queue for sending messages to the calling actor • Queue for receiving messages • These are stored in the actor’s private data when launched • Actors that launch another actor should store the new actor’s queue in its own private data

  27. Understanding ‘Actor Core.vi’ • This is a queued message handler • Launching an Actor starts the ‘actor core.vi’ method.

  28. When Do You Need to Override ‘Actor Core.vi’ ? • To maintain an additional loop within the Actor • To guarantee certain actions are performed before any messages are handled • To create a unique user interface for a specific Actor

  29. Actor Framework Template Demonstration

  30. Relationship between Messages and Actors • Messages call a method of an Actor • Messages encapsulate data for that method in the private data control • Messages are therefore coupled to that Actor, but not the children of that Actor • Children may have unique messages, but they are then coupled to those messages • File View • Items Tree

  31. When Do you Need to Override Actor Core.vi ? • To maintain an additional loop within the Actor • To guarantee certain actions are performed before any messages are handled • To create a unique user interface for a specific Actor Do.vi Do.vi Do.vi Event Driven Message Handler Free Running

  32. Actor core.vi of Operator UI.lvclassOperator User Interface Block Diagram

  33. Measurement Abstraction Layer Application

  34. Measurement System Sample Project Class hierarchy view Actor How do we communicate between all of these different ‘things’ ? Measurement Controller User Interface Headless Controller Operator Admin Test Step Controller Diode I-V Strain Resistance

  35. Test Step Task Tree Task Tree Controller Actor User Interface Measurement Result

  36. Launch UI Actor Launch UI Msg.lvclass Initialize Msg.lvclass Initialize.vi Hardware Scan.vi Launch UI.vi Test Step User Interface HW Scan.lvclass Initialize.vi MsmtScan.lvclass Msmt Scan.vi Disp Msmt.vi Request HW Msg.lvclass Available HW Msg.lvclass Msmt Selected Get HW Info.vi Initialize Msg.lvclass Matching HW.vi Display Hardware.vi HW Selected Check Validty.vi Validate Selection.vi

  37. Launch UI Actor Launch UI Msg.lvclass Initialize Msg.lvclass Initialize.vi Hardware Scan.vi Launch UI.vi Test Step User Interface HW Scan.lvclass Initialize.vi MsmtScan.lvclass Msmt Scan.vi Disp Msmt.vi Request HW Msg.lvclass Available HW Msg.lvclass Msmt Selected Get HW Info.vi Initialize Msg.lvclass Matching HW.vi Display Hardware.vi HW Selected Check Validty.vi Validate Selection.vi

  38. Run Pressed Send Run Rqst.lvclass Send Run Request HW Selected Check Validty.vi Validate Selection.vi Launch Measurement Display Results.vi Start Msmt.vi Close.vi Measurement Checkout HW.vi Initialize.vi ConfigMsmtMsg.lvclass Configure.vi Acquire Msg.lvclass Stop MsmtMsg.lvclass Launch MsmtMsg.lvclass Display Results Msg.lvclass Acquire.vi Measure Msg.lvclass Measure.vi Receive Results.vi Send Results Msg.lvclass Checkin HW.vi

  39. Creating a New Measurement

  40. Measurement QSM Configure Acquire Measure Close = We are going to override Acquire and Measure

  41. LabVIEW Templates and Sample Projects • Recommended starting points for common LabVIEW applications • Clearly indicates where to add or change functionality • Shows best practices for code design, documentation, and organization • Add custom templates and sample projects

  42. Checklist for Creating a Plugin • Project Name: Advanced Sample Project Session • Measurement: NIWeek Demo • Methods: • Acquire • Measure • Hardware • Digital Multimeter (DMM) • Power Supply (PSU)

  43. Creating a New Template • Required • Create the source code for template • Create the XML document for template • Optional: Scripting on Copied Code • Create a custom scripting method to modify template • Optional: Custom Create Project Dialog • Override the MetaData object (resources folder) • Create a new ‘Spec Page’ (must have required inputs) Information Available Here

  44. The Basics of an Object Factory A B Objects Loaded Into Memory C Generic Measurement  Parent Location on Disk Where Measurements are Stored A B C  Children

  45. More Information on Architectures and ProcessDedicated to LabVIEW Development and Software Engineering Practices • Getting Started with the Actor Framework • ni.com/actorframework • Online Community Dedicated to Development Best Practices • ni.com/community/largeapps • Follow My Blog on Software Engineering with LabVIEW • ekerry.wordpress.com • Follow me on Twitter • elijah286

More Related