Labvolution

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: LabVIEW Actor Framework Basics

GregPayne
Member

I have tried a number of times over the last year or so to get my head around the Actor Framework in LabVIEW. I started by reading the recommended starting point and went through all the examples, templates and hands-on. After trying a number of times, unsuccessfully, I put it to one side for another day.

My two main stumbling points, I felt, was not having a project to implement the framework in and not really knowing where to start. All the examples that I worked through started with a relatively large project and I could not find an example that starts with an empty project and builds up from there.

Last week a colleague explained the basics to me and over the last two weeks I have been working on a large project using the Actor Framework. I am finally getting an understanding of it and seeing the potential power in using the framework. Below is an example/tutorial on how to start from an empty project.

Recommended reading

Now for my example

Start off with an empty project and add three virtual folders named, Launcher, Parent Actor and Child Actor.

LabVIEW Actor Framework empty project

  • Launcher: Main vi which is used to start the program. Launches Parent Actor
  • Parent Actor: Main Actor which will launch Child Actor
  • Child Actor: Another Actor that can do things

The Parent Actor and Child(ren) Actor(s) will be created in a similar way. The main differences are the way in which they are started. I will explain how to create the Child Actor and then only show the differences in creating the Parent Actor.

You need to add Actor Framework.lvlib to your project. This is needed so that the classes we are going to create can inherit from Actor.lvclass. Actor Framework.lvlib can be found in C:\Program Files (x86)\National Instruments\LabVIEW 2013\vi.lib\ActorFramework\.

Child(ren) Actor

Create a new Class inside the Child Actor folder and save it.

LabVIEW Actor Framework Child Class

Create virtual folders called Messages and Framework Overrides.

LabVIEW Actor Framework Child Class 2

Change the inheritance of Child Actor.lvclass to inherit from Actor.lvclass.

LabVIEW Actor Framework Child Class Inheritance

Create three vi’s that override the Actor Core, Pre Launch Init and Stop Core. Pre Launch Init will be used to create a string notifier and Stop Core will be used to clean up the notifier. These vi’s are called before and after Actor Core is launched and stopped respectively. Actor Core will be the main vi that is run. This is where your Actor’s functionality happens. Save these vi’s and add them to the Framework Overrides folder in the project.

LabVIEW Actor Framework Override

Follow the following steps to be able to stop the Child Actor when Actor Core is closed.

Child Actor.lvclass:Pre Launch Init.vi

  • Create a notifier with an empty string for the data type
  • Use the notifier out terminal to create a control, rename it stop notifier and then move it into Child Actor.lvclass private data cluster.
  • Bundle the notifier out into the Child Actor object

LabVIEW Actor Framework Pre Launch Init

LabVIEW Actor Framework Private Data

Child Actor.lvclass:Stop Core.vi

  • Unbundle the stop notifier from the Child Actor object
  • Release the notifier

LabVIEW Actor Framework Child Class Stop Core

Child Actor.lvclass:Actor Core.vi

  • Create a while loop and an event structure inside with a 20ms timeout
  • On timeout, add a Get Notifier Status and wire the error cluster to the while loop stop terminal
  • Unbundle stop notifier from the Child Actor object and wire the notifier into the Get Notifier Status vi
  • This monitors the notifier every 20ms and when it is released in Stop Core, it will stop Actor Core. This is one of many ways that can be used to stop the Actor.
  • Add an event for Panel Close?
  • From the Actor Framework functions palette, place the Read Self Enqueuer outside the while loop and the Stop Actor inside the Panel Close? event.
  • Wire the Child Actor object to the Read Seld Enqueuer and the Self Enqueuer to the Stop Actor.

LabVIEW Actor Framework Child Class Actor Core

The Read Self Enqueuer vi gets the queue for itself. So what is happening here is the Stop Actor vi is being run on the Actors own queue which will call Stop Core, release the notifier and then stop the entire Actor.Next, create the Parent Actor using the same steps. Once complete, add the following modifications.

Parent Actor.lvclass:Actor Core.vi

The Parent Actor will be responsible for launching the Child Actor. To do this we need to:

  • Add the Launch Actor vi with the Read Self Enqueuer defining which queue to execute on.
  • Add a control of the Actor’s enqueuer to the Parent Actors private data and bundle it into the Parent Actor object.
  • Drag the Child Actor.lvclass from the project window onto the Parent Actor Core block diagram and wire it into the Launch Actor vi.

This will now launch the Child Actor before running the Parent Actor core. Make sure that if you want to show the front panel of the Actor being launched, you need to set the Open Actor Core front Panel? To TRUE as the default is false.

LabVIEW Actor Framework Parent Class Actor Core

Creating the Launcher to start the Parent Actor

  • Create a new vi in the Launcher folder and name it Launcher.vi
  • You first need to create a queue for the Actor Core to be launched on.
  • Then Launch the Actor by wiring in which class you want to launch. In this case we wire in the Parent Actor class
  • Then release the queue and close the front panel. You can make fancy launchers with splash screens, but this one is just a plain vi with an empty front panel

LabVIEW Actor Framework Launcher

You should now be able to run the launcher which will start the Parent Actor. The parent Actor will then start the Child Actor. When you close the two Actors, they should stop cleanly. If this works then we can carry on. If not, go back and make sure that you are releasing all the notifiers and queues.

LabVIEW Actor Framework Cores running

Communication between Actors

Add a Boolean control and indicator to the Parent and Child Actor Core. Setting the control in the one Actor will set the indicator in the other Actor. This will show the basics of sending messages between Actors.

Parent to Child Actor

You need to add references to both Actors for their respective indicators. We will use these references to get and update their state from other vi’s with the class. You also need to add a reference control to the Parent and Child class private data.

LabVIEW Actor Framework Parent Class Actor Core_2

LabVIEW Actor Framework Parent Class Actor Control

Make sure you add references to both the Parent and Child Classes.We now need to create a method (vi) in the Child Class that is going to change the Child indicator when told to do so. Create a new VI from Static Dispatch Template in the Child Class. Save it with the name Get state from Parent.vi.Add a Boolean control to the front panel and connect it to the connector pane. In the block diagram, unbundle the indicator reference, wire it into a property node and then write the Boolean state to the value property.

LabVIEW Actor Framework Child Class method

This vi is the method that does the work of changing the Child Actor front panel indicator. We now need a way to be able to run this vi from the Parent Actor. There are some tools that allow us to create these messages really easily.From the project window, select Tools and then Actor Framework Message Maker. This will open a window and allow you to create messages for methods that are in your project. Select the method that we just created and click Build Selected.A Get state from Parent Msg.lvclass is created with two vi’s. Close the vi’s and move the class to the Messages folder within the Child Actor.

LabVIEW Actor Framework Project with Child Actor message

The Send Get state from Parent vi is used to add the data to a queue and the Do vi calls the method that we created a step back. I am not going to go into the details of these vi’s but feel free to open them and see what is going on.Now that we have our Message and our method, we need to go back to the Parent Actor and to define when to execute this message.In the Parent Actor Core, add an event case to handle a value change from the Boolean control. This is where we will send the state to the Child Actor message. Add the Set Get state from Parent vi to the event case. This will put the Boolean control state onto the queue of the Child Actor. The Do vi will then be called which will then run the method from within the Child Actor Class. This will then update the front panel indicator of the Child Actor.

LabVIEW Actor Framework Parent Class Actor Core_3

Save your project and run the Launcher vi. Notice that changing the control on the Parent Actor, changes the indicator of the Child Actor.

LabVIEW Actor Framework Cores running_2

Child to Parent Actor

Now repeat the process to send the state from the Child Actor up to the Parent Actor.


  • Add a method to the Parent Actor Class writing the state to the indicator reference
  • Create the messages using the Actor Framework Message Maker tool
  • Add an event case to the Child Actor to handle the state change
  • Wire the control into the Send Get state from Child vi
  • Wire in the queue. You now need to get the caller enqueuer and wire that queue in.
  • Save the project and it should now work

LabVIEW Actor Framework Cores running_3

The final project should like something like this.

Actor Framework Final Project

You are now able to send states both ways between the Parent and Child Actor.I used these points to get a better understanding on how the Actor Framework works:

  • The main program of an Actor is the Actor Core that is overridden from the base class
  • Each Actor has its own queue
  • Use the Actor Framework Message Maker tool to create messages to communicate between Actors
  • Use the Read Self Enqueuer vi to get an Actors own queue
  • Use Read Callers Enqueuer vi to get the queue of the Actor that Launched it
  • Think of each Actor as its own process with a queue. To speak to a specific Actor, create a message and tell it which queue to execute on

It took me a week or so to get my head around what goes on. I still have a way to go but am getting there and the more I use it, the more confident I am getting. This is a very basic example but I feel it’s good to get going and to understand the framework without starting with a large project.

I have gone into detail with some of the above steps and breezed over others. I hope I have made the most important steps clear enough. If you are stuck with anything, please leave a comment and I will try help as much as I can. You can get a copy of the entire working project here. It has been written in LV2013 SP1.

Thanks for reading and I hope that I have been able to clear the fog over Actor Framework for some people.

Greg

(Originally found at http://www.labvolution.com/labview-actor-framework-basics/)

Comments
mirode
Member

Thanks! It was exactly what I was looking for to get started with the Actor Framework after having read/seen several documents and presentations.. It finally convinced me to utilize this interesting framework in my projects.

BTW, the Actor Framework Message Maker is accessible through the Tools Menu, not Options as you mentioned ("Options" does not exist).

GregPayne
Member

Thanks for the positive feedback. Glad you found it usefull.

I have also edited the post to point to the Tools menu.

Ludwig72
Member

Hi Greg,

thanks for the very useful tutorial. Just a little update: In LabVIEW 2014 the "Launch Actor.vi" is gone and now there are two different VIs: "Launch Root Actor.vi" and "Launch Nested Actor". They don't have an enqueuer input.

The Launcher.vi block diagram is very easy now:

Launcher.png

The Parent Actor Core.vi changes the following way:

Actor Core.png

Greetings Ludwig.

GregPayne
Member

Hi Ludwig,

I am glad you found the tutorial useful.

Thank you for pointing this out. I haven't worked with Actor Framework in LabVIEW 2014 yet so haven't noticed this until now. When I get some time I will look at updating the post/tutorial.

Cheers,

Greg

PeterFoerster
Active Participant

Hi Greg,

I'm not sure if I've missed something in your tutorial, but if I follow your instructions I get "not a refnum" from the Child Indicator Refnum in the Class, when calling the "Send get State from Parent.vi". This is of course, because a proper Refnum has never been passed to it, which I now do within the Child Actor>>Actor Core Method.

Did you pass the reference to it there, too?



Remember Cunningham's Law
G_Shellback
Member

Can you please expand on the following: "Create three vi’s that override the Actor Core, Pre Launch Init and Stop Core. Pre Launch Init will be used to create a string notifier and Stop Core will be used to clean up the notifier. These vi’s are called before and after Actor Core is launched and stopped respectively. Actor Core will be the main vi that is run. This is where your Actor’s functionality happens. Save these vi’s and add them to the Framework Overrides folder in the project."  You say three, but there only looks to be two.  Thank you.

GregPayne
Member

Hi J_T_L_ExonnMobil,

The three vi's that need to be overridden are the following:

  • Pre Launch Init.vi - This is run before the main actor vi
  • Actor Core.vi - This is the main vi
  • Stop Core.vi - This cleans up after the manin actor

Just as a note; In the latest version of LabVIEW, the actor framework vi's have been rewritten so the vi's used in this example might be old.

Regards,

Greg

GregPayne
Member

Hi Peter,

I'm sorry for only replying now. For some reason I didn't notice the notification of your comment.

What version of LabVIEW are you using? I know the actor framework has changed in 2014 and the old vi's are indicated with a red cross through them.

I passed the indicator reference in the Child Actor Core.

Untitled.png

And then I have a method that reads the reference from the object reference.

Regards,

Greg

winston.hensley
Member

Greg,

Thank you for this tutorial, I found it very useful in my attempts to understand the framework. Now if I practice better discipline in planning and organizing the file/library/class structure on my disk and in my labview projects this may be a great tool to use in my next development project!


Regards,
Winston    

GregPayne
Member

Hi Winston,

Thanks for the feedback. Glad you find it useful.

Greg

calimali
Member

Hi Greg,

Is there a cleaned up tutorial that works with LabVIEW 2014? I am quite confused about what changed or did not change between the different LabVIEW versions and the AF.

Thanks.

GregPayne
Member

Hi Calimali,

Unfortunately I have not had the time to get an updated blog with 2014.

Have you had a look at the JKI website, I think they have an Actor presentation. http://blog.jki.net/news/webinar-introduction-to-the-actor-model-getting-started-with-the-actor-fram...

I hope that help,

Greg

Wolleee
Active Participant

Hi Greg,
currently using LV2011. What is the parent class inheritence? When i try to create the override vi i get an error that object class is invalid?



-Matt
GregPayne
Member

Hi Matt,

The parent class inherits from Actor.

Untitled.png

Does that help? If you send a screen shot of the error I can maybe help.

Greg

adqwq
Member

Hi everybody,

I had the same trouble as many people here with respect to Labview 2014. I updated Greg's document and I included the source code in an example.You can find the following two documents for the version.

Document: https://decibel.ni.com/content/docs/DOC-44139

source code : https://decibel.ni.com/content/docs/DOC-44140

Hopefully someone will find it useful.

N.

GregPayne
Member

Hi adqwq,

Thank you for sharing your updated document. I haven't used Actor Framework in LV2014 yet so found it very useful to see the differences between 2013 and 2014.

I'll definitely be referring back to it when I need Actor again.

Regards,

Greg

adqwq
Member

You are welcome Greg.

thank you for the effort on original. I am trying to understand AF, and

your's has been the only complete starting point so far. I just had some

head scratching moments at some point, and seeing the comments I suspect

other people, so I thought I might as well do that.

N

GregPayne commented on

"LabVIEW Actor Framework Basics"

To view all comments on this blog post, visit:

https://decibel.ni.com/content/blogs/Labvolution/2014/07/23/labview-actor-framework-basics#comment-45215

antonioluppi
Member

Thank you adqwd and GregPayne for this!
I've been struggling to put this framework running, and this tutorial really helped me out.

Edit: It would be a great further improvement to include some sugestions or good practices on communicating complex data. I mean: How does somebody progress from simple booleans to more complex information? (rethorical question)

amitwadje
Member

Hi Greg,

Great tutorial about actor framework, Thank you.

one question though how it can be done only using the value messages ?

After finishing above tutorial, I try it to do it without using the references(using ONLY actual Boolean value).

I apperciate if you can advise me through.

Capture.JPG


Thank you.

Regards,

Amit

-
Amit
CLAD
matt.baker
Active Participant

Out of curiosity, how did you get the custom icon for the Messages virtual folder?

I can't see any option to change the icon on the right click menu etc.

Thanks



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
GregPayne
Member

Hi Matt,

To be honest, I'm not sure!!!

The only thing that it could be is that I had the GDS Toolkit installed and this might give you the icon overlays. Unfortunaltely I can't install it on the PC I'm currently working on to check.

matt.baker
Active Participant

Thanks Greg. I'll have a look at that toolkit.

Edit: Yep, it was the toolkit adding the icon.



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
hoffiz
NI Employee (retired)

Thanks for the post. I have been struggling for a while trying to, also, get my head around the AF. Between the webcast, you need to watch the webcast first, and following your steps; I feel like I can now at least defend myself.

I know this is an old post but I will try my luck, one of my struggles with AF is that it amplifies the need for documentation. A flow diagram or anything that helps understand the states. You loose the ctrl+wheel ability to quickly scrub through your states and can't easily read a VI anymore.

Jaime Hoffiz
National Instruments
Product Expert