06-05-2018 01:12 PM
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:
This does not seem possible, but I cannot think of another way to handle this situation.
06-05-2018 01:43 PM
@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.
06-05-2018 01:52 PM
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?
06-06-2018 07:11 AM
@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.