Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the Self Adressed Message to return data from another actor

Solved!
Go to solution

Hi again AF folks,

Another simple/silly question, but how do I use the self-adressed message? I'm basically trying to retreive data from inside an actor (let us call it the nested actor).

In the root actor, I'm trying to get data from the nested actor, so I have made a method "get nested actor data". Then I provide the nested actor's queue to the destination of address message.vi, and onwards to the send self adressed message.vi.

For the message that I send, I'm confused - does that belong to the root actor or the nested actor messages? Who knows, and who should be responsible for that message? A simple example showing what message gets put in and who deals with the return would be great!

Of course, perhaps I should be doing the abstract message thing- still trying to wrap my head around that despite numerous examples.

Finally, any typical use cases of self-adressed messages might be useful (even if this is not one of them!)

Thanks

Rik

Message 1 of 10
(9,927 Views)

I recommend getting your head around Zero Coupling and using an abstract message that the nested actor owns.

In my opinion, you want the nested actor to send data to its caller without it knowing who the caller is.

I will attempt to give a simple example.

I have a counter that I want to use. It counts up at a regular interval. It reports the current "count" to its caller. It also reports if it has reached some threshold value at which point the count "needs to be reset".

Here is the project view:

Project View of Counter.png

Here is the private data of the class:

Counter Private Data.png

Notice the Counter Attributes cluster and the class right below it "Counter State Msg".

The Counter State Msg inherits from Message.lvclass. It has no "Do.vi" as that will be implemented by a child of the message.

Counter Message Inheritance.png

Now I want to use the counter. When I launch it I wire in the child class which will have a Do.vi.

Launch Counter.png

When the counter runs it regularly posts the data to the caller.

Post to Caller.png

The caller gets the data.

Child with Do.png

Child Do Method.png

The data is read out of the parent message class. The counter doesn't know which child is on the wire.

Now all you need to do is create another child of it's message and you can launch another counter that another actor can use.

Good luck!

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 2 of 10
(7,616 Views)

LV 2015 is going to help automate setting up the zero coupling, but we really need to go further with this. I wish we could get traction on building interfaces for LabVIEW.

*head bang*

0 Kudos
Message 3 of 10
(7,616 Views)

Yeah, that would be awesome. I have been running into issues such as 1403 errors when sending messages from PC to RT because class versions didn’t Match. In my implementation, I copied the message classes (keeping the names the same) to my host code base and rt code base and implemented the ‘Do’ or ‘Send’ depending on the direction of the message.

For abstract messages, this gets so much more difficult, not only do you need the abstract messages duplicated, but also the child of the abstract messages. I can’t wait for 2015 Beta (if I get accepted), to try this out.

Brian G. Shea

Sr. Systems Integrator / Engineer IV

Certified LabVIEW Architect

National Technical Systems, Inc

3801 Academy Parkway N NE

Albuquerque, NM 87124

Office: 505-821-4740 x3003

Direct: 505.222.5136

Brian G. Shea
Certified LabVIEW Architect
0 Kudos
Message 4 of 10
(7,616 Views)

So thanks for taking the time to try to explain that to me. The concept makes a lot more sense, but it still does not work for some little buggy reason.

I could post my code if you could take a look - I'm sure you'll see what I'm trying to do. Basically I see that the send abstract message is sent, but I do not see the do method being executed. The two things I have checked are that (1) the child class with Do override inherits from the abstract parent class and (2) the child class is input to the calling actor before it is launched. Perhaps also you could share ideas for how to debug this kind of problem in general. The only "technique" I have developed as of now is throwing message boxes in each VI to show that it is being executed.

Rik

0 Kudos
Message 5 of 10
(7,616 Views)

Brian,

Are you using the Linked Network Actor? I might have a solution for you regarding your messages and not needing to do any copying.

Give me a call.

Casey

608-577-7946

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!

0 Kudos
Message 6 of 10
(7,616 Views)

Post your code and I will take a look.

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!

0 Kudos
Message 7 of 10
(7,616 Views)

CaseyLamers1, would you be able to post your project so we can look closer. I'm still trying to figure out how to return data in a zero coupled fashion. I think looking closer at your example would help.

Thanks

Jason

0 Kudos
Message 8 of 10
(7,616 Views)

Hi Casey/anyone else,

Here is the example project I have been making. It is "trying" to unit test an actor, given that the effort would be fairly fundamental to anything else I try to achieve (if you believe in TDD). I was trying to do an abstract message, but do not see the Do that I think should get executed actually get executed. You should also notice that I'm just trying to pass data up the food chain, which is where this post originally came from - to me it's a weakness of AF that it's not so blindingly obvious how to do it that even an idiot such as myself succeeds!

Thanks for your help,

Rik

0 Kudos
Message 9 of 10
(7,616 Views)
Solution
Accepted by rik_aspinall

Rik,

I am looking at the project. It looks like you are missing the piece where you use the abstract message/concrete child. There should be something like this:

Post to Caller.png

There is a read of caller's enqueuer. There is putting the data in a message class (Counter State Msg) and then the enqueue of the message.

With regards to testing, we should have a talk. I use the JKI VI Tester and have 600+ unit tests. I think it is the perfect tool for unit testing actors.

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!

0 Kudos
Message 10 of 10
(7,616 Views)