LabVIEW Craft
  • Blog
  • About
  • Contact
  • Tools
  • Resources

Learning the MVA Framework - Tutorial 1: Start by Stopping

10/1/2019

4 Comments

 
- By Chris Cilino, Composed Systems Partner

I recently became a partner at Composed Systems in July 2019.  I hope you'll join me in my journey as I come up to speed on our tools set. One tool I want to highlight is the MVA Framework. The MVA Framework accelerates our development and give us flexibility to rapidly respond to changing requirements. And it can do the same for you since Composed Systems has made the framework open sourced.

I've found that I learn best when I first personally succeed at a task, and then share that knowledge with others. So I'm blogging about my journey to master the MVA Framework.
All of the tutorials are available at the  MVA-Tutorial Bitbucket Repository. Each tutorial is a LabVIEW project designed to present the smallest set of concepts possible to accomplish a meaningful task. And each tutorial builds on the concepts of the previous one. So DON'T SKIP!

To view any of the tutorials
1. Clone the repository using Sourcetree (or your favorite Git method).
​2. Install GPackage manager.
3. Open GPackage manager and navigate to the directory containing the LabVIEW project for a given tutorial.
4. Install the dependencies:
Picture
5. Use this blog in conjunction with the comments on the block diagrams to go on the journey with me.

The longest journey begins with a single step, so what better way to start than by learning to stop? Wait for it.... here's what I mean. Whenever I learn a new framework or look at someone's code, my very first question is "How does it stop?"  In learning how code stops, I find I learn the most fundamental notions of the code. So that's where I'll start with the MVA framework (hence the clever title "Start by Stopping").

In this first tutorial I'm sharing how I migrated the following application into an MVA application.
Picture
There's nothing terribly fantastic about this VI. It's designed to start, wait for the Boolean button value change, and then stop. The MVA framework allows us deconstruct the front panel and block diagram into more granular parts you can programmatically interact with. Deconstructed food is a good analogy here, mostly because I like food. You might be used to a hamburger that looks like
Picture
But the MVA Framework deconstructs it to look like
Picture
so you can eat any part independently of the other and in whatever order you'd like.  Let's deconstruct our VI into is separate parts. 

First we will split the front panel from the code by using subPanels, and we'll insert our UI into something designed to host UIs. I'm going to concentrate more on "What we are doing" and less on "Why" for the time being.
Picture
We'll make both the thing hosting the VI (aka the "hoster") and the hosted VI Actor Framework actors.
​WAIT! Actor Framework?! Ruuunnnn!!!! Deep breaths...before panic sets in, I'm a noob with the Actor Framework (AF), so I'm with ya. There isn't much AF stuff you'll need to know to use the MVA Framework. You'll see... just keep with me. 

To create the "hoster" MVA actor
  1. From a LabVIEW project right click on "My Project" and select "Actor"
  2. Inherit from \gpm_packages\@cs\mva-framework\Source\Framework\IViewModel\IViewModel\IViewModel.lvclass
To create the "hosted" MVA actor
  1. From a LabVIEW project right click on "My Project" and select "Actor"
  2. Inherit from gpm_packages\@cs\mva-framework\Source\Framework\IViewable\IViewable\IViewable.lvclass
​
So this is what we're putting together.

Picture
Next we cut up the block diagram and represent elements of the block diagram with VIs. The while loop becomes the actor core and, instead of the event handler, we introduce an API to Register For Control Events. The VI used to register for events is called "Register For Control Events.vi" and looks like 
Picture
 Path: gpm_packages\@cs\mva-framework\Source\Framework\ActorEvents\IEventAggregator\Register For Control Events.vi
We pass in an array of control references to dynamically register to an event handler (we'll get there). We also pass in an array of event types we want to handle. In this case we are saying "Something execute when the value of "stop" changes." In effect the code above is a programmatic version of:
Picture
Since we have two actors running (our hoster actor and hosted actor) we want our stop command to be handled by the hoster. The MVA framework propagates the "stop" to the hosted Actor. So we need to create an override in the hoster called "Catch Nested Value Update.vi". While each UI can (and often does) handle each value change event, stop is a little special because we want to close the hoster as well as the hosted VI. So in the hoster we create an override of "Catch Nested Value Update.vi". This VI is designed to handle messages sent from any sub actors or "nested" actors. The block diagram of the override looks like:
Picture
In the override we use an MVA function called "Unpack Nested Value Update" that outputs the label and value of the registered item (in this case the "stop" button). So in the "stop" case we stop the hoster actor which will in turn stop the hosted VI.

So now we'er almost done! We just need a "chef" to assemble our deconstructed hamburger on the serving plate. In every MVA application, the "Assembler" is responsible for inserting actors into actors. Let's take a look at the Assembler of our application. 
Picture
I've added pictures and comments in the code to explain what's going on here. The red class is the hoster and the purple class is getting hosted. We use the MVA framework function called "Construct MVA Application" to stitch everything together. The "IViewModel" is the hoster (red class) and, in this case, the startup view is our UI being hosted (IViewable, purple class). When the program starts the MVA starts the actors and stitches them together. 

What?! All that work for...??

Soooo what gives? This seems like a whole lot of complexity for not a whole lot of return. Here's the payoff:
  1. I can easily swap out the purple class for any other class instantly without changing anything else in the code. And at this point, all we assume is the hosted VI is sending a "stop" message. (actually, the hosting vi automatically handles the panel close event too!)
  2. Developers can work on separate sections of the UI without stomping on each other's work.
  3. UIs become more modular. It's almost like we are developing "widgits" of a UI instead of monolithic sets of code.

In the next tutorial I'll show how the MVA framework let's us have N widgets in a UI working together. We'll start with "A Community of Two". So stay tuned!
4 Comments
Matthew Nevels
11/27/2019 10:58:01 am

This looks very interesting to me. I've never dealt with G Package Manager so following our instructions I cloned the repository, installed G Package Manager (I had to install LV2017 Runtime first) but after the install I didn't see G Package Manager anywhere to launch. I finally found that it was called GPM Browser so launched it, selected the project folder, clicked Browse and Install Dev Packages. I got a popup window that said:
Executing Install
Install Complete!
Executing Import
Initializing Package Import
Import Failed
The status bar showed 100% complete and I had no option but to click the X to close that window. When I did I got an error 5600 at Package Manager.lvlib: Open LabVIEW App ref.vi with the possible reason of LabVIEW 2017 not installed.

Is LabVIEW 2017 a requirement for this? I'm using LV2019 x64.
I've been looking for some good reference projects to help me understand how I'd actually use Actor Framework in my applications and I really like the idea of dividing up all of the UI for a complex application into various subpanels but I've not seen a good way to do this. This MVA framework looks a lot like what I've been thinking of, but as LabVIEW application development is only part of my job I just don't have a lot of time to develop my own framework for this kind of thing. I actively use JKI State Machines in some projects and DQMH as modules in those and other applications but neither allow me to break the UI into separate modules. Anyway this could be made functional in LV2019 x64 would be great. Thanks!

Reply
Chris Cilino
12/23/2019 07:57:41 pm

Hey Matthew
Thanks for checking out the tutorial. I just so happen to also be using 2019 x64. There's a bug with G Package manager. I doesn't support LabVIEW 64 bit without a little arm twisting. But to get things up and running after you get the error you saw, just mass compile the directory where the project is located. That should get you squared away. You'll get a bunch of crossing linking warnings, but that's how G Package Manager works at the moment.

Reply
Matthew Nevels
12/26/2019 01:03:52 pm

Excellent! Mass compiling took care of my issue. I'm successfully walking through these tutorials now. Thanks for putting this together - I'm finding it tremendously informative!

Siva Shankar
11/29/2019 01:58:17 pm

Nice tutorial Chris. Waiting for the next one to understand other unexplained things.
This tutorial gives me an idea to get a big picture of mva framework and it showed me an starting point to see and understand this framework. Thank you!!👍

Reply



Leave a Reply.

    RSS Feed

    Tags

    All
    Abstract Messaging
    Actor Framework
    Agile
    AI
    Asynchronous Programming
    Best Practices
    C#
    Complexity
    Continuations
    Control Values By Index
    Craftsmanship
    Dependency Inversion
    Dependency Viewer
    Futures/Promises
    Genetic Algorithm
    Liskov Substitution
    Malleable VIs
    Mediator Pattern
    .NET
    Object Oriented
    Object-Oriented
    Packed Project Library
    Parallelism
    Polymorphism
    Pub/Sub
    RawCap
    Root Loop
    Scrum
    Task Parallel Library
    TCP/IP
    TDD
    Test Engineering
    UML
    Unit Test
    VI Scripting
    VI Server
    WireShark

    Archives

    October 2019
    April 2019
    July 2018
    October 2017
    March 2017
    February 2017
    January 2017
    December 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    August 2015
    February 2015
    January 2015

    LabVIEW Blogs

    Eyes on VIs
    LabVIEW Hacker
    VI Shots
    LabVIEW Artisan
    Software Engineering for LabVIEW
    ​Wiresmith Techology
Picture
Powered by the Panda Ant

  • Blog
  • About
  • Contact
  • Tools
  • Resources