Jump to content

Newbie Question about Actor Framework


Recommended Posts

Hey guys,

I have been teaching myself labview for the past 2 to 3 years. I know other programming languages like java and PHP so OOP is not entirely new to me.

I am running into an issue with actor framework, specifically writing/reading private data of actor instances. I have created a simple project that encapsulate my issue.

Basically, I have a main vi called "test" that starts an actor called "Prime". Prime immediately starts another actor called "Secondary". Secondary has a string in its private data member, with proper read/write accessors. I created a message to be able to write to the string in the private data.

Prime has a message dequeuer in its private data so that it can communicate with secondary.

My whole goal is to have both prime and secondary running simultaneously and have you, with the click of a button, update that string in secondary and have the new string show on the front panel.

I have been struggling with this for a few days now. I have posted the zip file for the project below. Please help.

Actor Message Learning.zip

Link to comment

Hi Jean,

You've hit into one of the things that also puzzled me at first with the AF :) Attached, you'll find a "fixed" version of your project. Let me explain what's going on here.

What's crucially important in your understanding of the Actor Framework, is that LabVIEW objects are by-value, not by-reference (see the NI Whitepaper on LVOOP). So every class wire in your Block Diagrams has class private data clusters flowing through them, following the same data-flow rules that would apply to other wires.

Let's have a look at the Actor Core.vi of your Secondary actor:

post-18573-0-44942300-1355477842.png

The private data cluster of Secondary.lvclass comes in at the "Secondary in" terminal (top-left), but the wire splits in two branches. The branch labeled [1] goes off into the base class' Actor core, which contains an 'infinite' while loop that processes all incoming messages, and calls the "Do.vi" methods of your message classes. The branch labeled [2] goes into your parallel While loop.

So, effectively, the above VI looks like this:

post-18573-0-85110000-1355479717.png

What happens if your Secondary actor receives the Write my String message? Well, all this message processing takes place in the bottom While loop! Whatever happens to Secondary's private data cluster there, will stay within that bottom While loop, due to the way data flow works. The "my String" update will never reach the upper loop.

All this means that getting data updates from your messages to your Actor Core's front panel is a very fundemantal 'problem' in the Actor Framework. The only way to solve this problem, is to somehow work with references to data, instead. There's two ways to do this:

  1. Use a Data Value Reference (DVR). Add a DVR to your actor's private data cluster, and use this DVR to communicate data between the upper while loop and the message processing VIs. (As a sidenote, you should be aware, if not already, that continuously updating your Front Panel like you did in your example project, is not very efficient).
  2. Use control refnums to your Front Panel controls and indicators, and store those refnums in the actor's private data cluster before the class wire branches off into [1] and [2]. You can then update Front Panel controls elsewhere in the code, whenever necessary.

Strategy 2 is the one I've chosen in the attached sample, and also the one I've been using in my real-world AF project. It's a bit cumbersome, but works very well.

I hope this clears a few things up!

Best,

Onno

(Actor Message Learning_fixed.zip)

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.