From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Override user interface upon inheritance

Solved!
Go to solution

Hello,

I am currently getting to know LabView and the ActorFramework and am trying to use it to remote control a power supply. This is working great and I currently have the user interface to set the current and voltage in the "Actor Core.vi". I store references to indicators as class attributes so I can update the user interface from within other class VIs that e.g. query the current power and voltage state of the power supply.

Now, I would like to inherit from this actor and make it an LED control. This means the new "Actor Core.vi" has only an On / Off button which uses the already existing messages to set the voltage to a specific value.

Of course, now the references to the indicators of the initial "Actor Core.vi" do not get populated anymore since in the inhertied class, the user interface looks differnetly which breaks the functionality of the VIs that used to update the UI. The question is, how do I handle such cases? I.e. how can I update the user interface in the actor core from another VI of the actor in a manner that the code won't brake when the user interface changes e.g. due to inheritance?

I was thinking about using notifiers but couldn't come up with a working code example. Any hints of what I could try or where this problem might have been discussed previously? Or how I should change my current design?

Thank you very much!

0 Kudos
Message 1 of 10
(6,174 Views)

Separate the GUI from the database. In other words, don't store references to the GUI indicators in your class, store current (double) and voltage (double). Have a VI "Update GUI" that updates these values in the user interface, and when changed from user interface put the values in the class (not the control references). Then when user interface changes, you only need to change "Update GUI" VI.

Hope this helps,

Danielle

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
Message 2 of 10
(4,321 Views)

Thank you for the input. But the "Update GUI" VI would also need access to the references of the GUI elements so I would have to store them anyway, right?

Another thing I thought about would be to just have an actor that controls the instrument and another one that shows the GUI. They then could communicate with messages and all GUI-actors would have to implement some default messages.

0 Kudos
Message 3 of 10
(4,321 Views)

The way I do it is this (not sure if it's that great but it does work):  I define all the functionality of the actor in a class with no UI, including all UI updates.  Each method that needs to update the UI does so through a user-defined event.  I create a VI in the parent class called Check Events which ensures all the events have been created.  That is the only thing called in the parent class Actor Core.  Children then simply subscribe to the events in the Actor Core and define UI update code in an event structure.  That way you don't have to pass control refs around, which will lock you in to a single UI.

CLAD
0 Kudos
Message 4 of 10
(4,321 Views)
Solution
Accepted by topic author ehrlich

Here's an example of the approach I use.  It's in LV2014.

CLAD
Message 5 of 10
(4,321 Views)

My advice is to use the "Model-View-Controller" approach here. The model is the power supply. It will send a data message to the view. The view is the user interface. Setpoints from the UI are sent to the controller which can input them into the model.

You separate the responsibility of calculating state (model) handling UI requests (controller) and displaying data and otherwise interacting with a human (view). Then you can change any of them independently.

Have fun!

Casey

Casey Lamers


Phoenix, LLC


casey.lamers@phoenixwi.com


CLA, LabVIEW Champion


Check Out the Software Engineering Processes, Architecture, and Design track at NIWeek. 2018 I guarantee you will learn things you can use daily! I will be presenting!

Message 6 of 10
(4,321 Views)

I like your approach! When inheriting, I just have to override the Actor Core and build a new VI but the event structure can be maintained. I implemented it in my controller and it works like a charm.

Thanks a lot for all the helpful answers.

0 Kudos
Message 7 of 10
(4,321 Views)

Great example!

I have a similar approach, just instead of generating an event I use a dynamic dispatch message (loosely coupled actors). In the parent I have a dynamic-dispatch VI "HandleUpdate" and generate a message for it; all children can override HandleUpdate and handle the  update differently.

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 8 of 10
(4,321 Views)

dsavir,  How do you pass data back to your UIs from the HandleUpdate vi?

CLAD
0 Kudos
Message 9 of 10
(4,321 Views)

I have GUI 1 and GUI 2 that inherit from GUI, Controller, and Measurement. GUI has a HandleUpdate VI and corresponding message, HandleUpdate VI is dynamic dispatch. GUI 1 and GUI 2 override HandleUpdate VI.

Measurement tells Controller to update the GUI with the given data. Controller calls the Handle Update Message on the current GUI (GUI 1 or 2), wich calls the handle update VI for the specific child GUI being used, because of dynamic dispatch.

I can work up an example for this by next week if you're interested (I've got lots of stuff this week unfortunately).

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 10 of 10
(4,321 Views)