LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Polymorphic" class method with array of objects as an input

Dear Community,

 

I have been using LV OOP for a few months now, and I am today facing a new challenge.

Let's imagine that I created a class that will serve as a driver for a device (a temperature sensor for example).

In this class I will have a few attributes, for example a sensitivity coefficient, a correction factor, etc.

I will also have methods for communicating with the device, say WriteRegister.vi, ReadRegister.vi, CalculateCorrectionFactor.vi, etc.

 

Now, I want to use several devices, and we will assume that I can communicate with all the devices with a communication bus either individually (send message to device 1) or in a broadcast mode (send message to all devices).

I will create several instances of my class, and each will have its own separate attributes (for example, correction factor will vary from one device to another).

There will be some cases where I want to send a message at the same time to all devices (for example, Write a register to configure the internal clock) and some cases where I want to write to each device separately (for example set the correction factor).

For this case I would like to have a WriteRegister method that would accept:

  • An array/cluster of objects as an input (Object Ref In) and use the broadcast communication
  • A single object as an input (Object Ref In) and use the individual communication

This does not seem possible, but I cannot think of another way to handle this situation.

0 Kudos
Message 1 of 4
(2,275 Views)

@seb_bd wrote:
  • An array/cluster of objects as an input (Object Ref In) and use the broadcast communication

You are going to have to use a FOR loop.  If you need to really have these methods parallel, you could try to parallelize the FOR loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 4
(2,265 Views)

Thanks for your answer, crossrulz. Actually, it's not so much a matter of parallelism: In the case I described, I could have either an individual communication or a broadcast, no such thing as parallel communication (otherwise there would be conflict on the bus, assuming that it would actually be possible to send multiple message in parallel [different from my idea of broadcast, one message to all]).

 

I am currently looking at polymorphic VIs and OOP, more particularly dynamic dispatch VIs. I found out that there is an official hack to wrap a dynamic dispatch in a static dispatch and then use this in the polymorphic VI. Maybe I could create a polymorphic WriteRegister.vi and use either a single object or an array of objects as input of this VI (I insist on a general input, not Object Ref Input in the upper left corner as in member VIs). Does that sound like a good workaround?

0 Kudos
Message 3 of 4
(2,263 Views)

@seb_bd wrote:

I am currently looking at polymorphic VIs and OOP, more particularly dynamic dispatch VIs. I found out that there is an official hack to wrap a dynamic dispatch in a static dispatch and then use this in the polymorphic VI. Maybe I could create a polymorphic WriteRegister.vi and use either a single object or an array of objects as input of this VI (I insist on a general input, not Object Ref Input in the upper left corner as in member VIs). Does that sound like a good workaround?


I have not done that with objects, but I think it should work.  Just have your array version be nothing but a FOR loop (autoindex) around the Dynamic Dispatch version.  My only real concern is that the polymorphic VI could complain about the Dynamic Dispatch.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 4
(2,211 Views)