From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

How to read private data in Actor Framework?

I am a new to actor frame work. I know how to change the private data in actor framework. But I can't find a way to read private data in Actor frame work. All messages are seemed to transferred to actor.

Could you help me about that?

Thanks.

0 Kudos
Message 1 of 9
(5,641 Views)

Duplicate Post?

You have posted a similiar question here: https://decibel.ni.com/content/thread/44295?tstart=0

The answers there might be helpful also for this question.

It is one of the fundamentals of object oriented programming, that the private data can only accessed by the class itself.

Inside the class the data can be acessed easily, since they are bundled to the class wire (between "actor in" and "actor out"). To access it, use the cluster bundle and unbundle or, if you want to access a property node of a parental class the property node vi.

People ofter try to access the date within actor core. This works only for initialization and only if you put the wire to the parent method call. This happens because every fork of an wire in LV creates a copy of the data. if you modify the data in that copy you do not modify the original data.

In AF you invoke methods of your actor class by sending messages to that actor. you can put parameters of the method you want to call and you can store output to your private data cluster (for internal evaluation) or send it to another actor (for external evaluation/probing).

0 Kudos
Message 2 of 9
(5,006 Views)

Thank you.

My question is how to read back private data for actor.

I have know the way of reading back data. I do it by "Reply message" class and "Send message and wait for reply.vi".

Do you have a more efficient way to do it? Thanks.

0 Kudos
Message 3 of 9
(5,006 Views)

mthimm1, one question regarding your answer (I am also new to AF): You said accessing of the data within the actor core generates copies of the data and thus editing the original data will not work.

Let's consider the following case: I have a nested actor for DAQ, which has a simple state machine in the actor core. I have put the actors in  wire as a shift register in the state machine and unbundle the device communication parameters every loop index for device communication. Does this mean it creates each loop intervall copy of the private data?

And if yes: how to prevent it? If i create a method for it, this method will be a VI which also has an unbundle function in the block diagram. So where is the difference of unbundling within the actor core and unbundling within the method, which i would use as a SubVI in my state machine?.

Actually, my DAQ works the way it should, but the application consumes a lot of CPU power. Thus i fear that i do exactly what you said, creating a lot of copies of copies.  

0 Kudos
Message 4 of 9
(5,006 Views)

I would say, that you should keep stuff that needs to deal with the private data out of actor core. You can define a method which reads processes and writes the data back to the private data cluster. Instead of doing this inside the actor core, you define a message, that calls your processing method. Be aware that while your method is running your actor does not process other messages. So do not use probably infinite loops.

There is an example in LV examples, that hast a loop in actor core, which sends periodically a message to itself that performs a single measurement. Like this, the actual data a held up to date. This is the way it was intended to be done.

Communication should be held asynchronous. I do not use replies at all, because I fear that someday my actor will wait forever.

Processing has its place in this model and the actor core is mainly for an event loop and to start the actors own priority queue.

0 Kudos
Message 5 of 9
(5,006 Views)

I do not think that you should wire the object to a shift register inside actor core.

I assume, that you have put the state machine in a fork of the wire, that is connected to the actor cores parent method. Unfortunately your actor wire is not that one, that  is used by methods which are called if you send a message to your actor.

Assume that you have a boolean "on/off" in your actor, standard "off" and a method that switches to "on". Inside your state machine the wire does not change even when the switch on method is executed, since the original switch is set to on instead the copy in your fork.

You can manipulate data in both forks simultanously by using data value references, but then you should probably not use AF at all. You can encounter horrible and dificult to find side effects.

0 Kudos
Message 6 of 9
(5,006 Views)

Thanks for the ideas. At the time of writing my last post, I actually had a producer/consumer principle within actor core and an own queue for communication between boths loops. The only difference between this producer/consumer principle compared to a "classic" producer/consumer principle was that the producer (=while loop with event structure) was able to be triggered from other actors using dynamical user events generated by methods.

Then after reading some more AF tutorials I figured out that this is probably not what AF is meant to be.

I am aware that processing messages should not take too much time, that's why I wanted to keep the hardware readout within the so-called helper loop within the actor core and not in the methods. What I have done now is attached to this post: Removed the second while loop and put the data polling in the timeout of the event structure. I also removed the actor object from the helper loop and just loop some of the private data (in this example: the serial settings). If now for whatever reasons the serial settings are changing (e.g. by user request) I can then call a method and rewrite the updated serial settings into the private data. Any comments on this idea?

0 Kudos
Message 7 of 9
(5,006 Views)

This looks good for me. It is an alternative way of implementing an poll actor.

If you send a poll once message instead a data send message and let the poll once message send the data you will be able to change the poll interval and the serial settuings without stopping the actor. That would be in my opinion more flexible.

0 Kudos
Message 8 of 9
(5,006 Views)

Hi, 

I am confused by your comment "send a poll once message instead a data send message and let the poll once message send the data you will be able to change the poll interval and the serial settings without stopping the actor". Can you please clarify ? 

0 Kudos
Message 9 of 9
(4,460 Views)