Jump to content
Thang Nguyen

2 ways communication between 2 objects

Recommended Posts

Hi,

I need advice on how to exchange messages between 2 classes or 2 objects. So far I am using LVOOP mostly because of data encapsulation and inheritance feature.

Now I need communication between 2 objects A and B running parallel. Each object can send message to another. I can send message one way by using composition relationship. I put one class inside another class cluster, for example B inside A cluster. Then later from inside class A, I can use class B reference to send message to process of class B. But I don't know how to send message back from B to A. Is there any design pattern about this? Or is there any example? I can do this without using class by using name queue but I would like to learn how to do this with LVOOP.

I read about actor framework already but I don't want to use it now seam it's a little bit complicated for my project.

 

Thank you for your time reading and answering my question!

 

Thang Nguyen

Edited by Thang Nguyen

Share this post


Link to post
Share on other sites

I would use referenced objects, maybe even singleton objects with an active process in each.

That is basically an actor, but a bit easier/more flexible, but maybe more dangerous if you don’t know what you are doing.

Something like this:Objects.zip

  • Like 1

Share this post


Link to post
Share on other sites

User Events.

 

Create and register for the events int he top-level VI and pass them to the parallel processes.  Then you can also scale up to 3,4 or a thousand objects and they can inter-comminucate.

 

No LVOOP required for this aspect.

  • Like 1

Share this post


Link to post
Share on other sites

@Mikael: Basicly what you use is a name queue, am I correct? That's how you get the reference to another object. Thank you very much for your time building the example code :)

 

@Shoneill: Thanks for your advice. I will think a way to combine user event in LVOOP. There are some great feature I still want to use from LVOOP.

Share this post


Link to post
Share on other sites

@Mikael: Basicly what you use is a name queue, am I correct? That's how you get the reference to another object. Thank you very much for your time building the example code :)

Since I'm using the GDS toolkit, it generates >95% of the code, so it took me less than 5 minutes to create this :-)

 

The singleton is storing the Object Reference(DVR) in a 1 element named queue.

The Actor/Active Object Process is also using named queues (based on the DVR Reference number) to store the mechanism to send data to and from the process.

The steps to create this with the GDS tool is:

  1. Create the class: A as a DVR Singleton class
  2. Add Design Pattern Active Object to the class.
  3. Add a “Send Message To Process†method(RequestData.vi) to the class.
  4. Modify the newly created VI/method
  5. Modify the Process VI in the class to handle the message
  6. Clone Class A to B
  7. Modify the Process VI and RequestData.vi in the new class.
  8. Create the Top level Main VI

//Mike

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
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.