08-15-2013 06:27 PM
Hi all,
My project involves testing SubVIs. I`m doing this by writing a test VI that calls SubVis. Many of these SubVis take queues as inputs. Therefore, my test VI obtains a reference to a queue, fills the queue from an array, passes this reference into the SubVi being tested, then destroys the queue.
I'm finding that I need to copy and paste this "obtain a queue, fill the queue, pass the queue into a SubVI, destroy the queue" logic a lot. The only difference in each copy & paste is the queue data type. Is there a way to avoid copying and pasting this VI all over the place? I'd love to have only one VI that does "obtain a queue, fill the queue, pass the queue into a SubVI, destroy the queue" and have many seperate VIs that define different queue data types. Is this possible in LabView? All this copy and pasting I'm doing will be difficult to maintain.
I've attached the VI that does "obtain a queue, fill the queue, pass the queue into a SubVI, destroy the queue".
Thank you!
Solved! Go to Solution.
08-15-2013 08:06 PM
To start, you could save that function as a VI Template (File->Save As, change the file type drop down to be a VI Template).
08-16-2013 09:37 AM
If I do that but later I find a problem in the template I need to go back and correct all VIs that used that template though, right?
Thank you.
08-16-2013 10:31 AM
Yes, that would be the case. Another option you investigate would be VI scripting. You could write a VI that would create your new VI and programming select the data type for the queue.
08-16-2013 10:33 AM
@Jared7 wrote:
If I do that but later I find a problem in the template I need to go back and correct all VIs that used that template though, right?
Thank you.
yes, the bug will just be copied to each instance you create from the template.
Thinking about this more, you might want to make a polymorphic VI to hold all of the instances you have used. That way you can just drop down the polymorphic VI and have it auto select which instance to use based on the input data.
08-16-2013 10:38 AM
Cant you generalize the testing sub-vi with a vi ref or path in and open the vi that way, thus only using 1 VI for all tests? If all VI's uses "Queue in" you can set it through e.g. invoke ctrl.set, or if all uses the same connector pane you can use the Call by reference.
/Y
08-16-2013 10:55 AM
Thank you for so many quick and good suggestions! I'll give these a try and let you know how they work for me.
08-16-2013 11:13 AM
This is one reason why the cluster of string,varient, QMH is so popular. What it lacks in readability (Compared to the type def enum driven, QMH) it makes up in testability. The major difference being that you must handle the "Typo" case since some developer somewhere will type a string wrong. (If we could all type perfectly LabVIEW itself might not exist)
08-16-2013 12:34 PM
Another option is to use a variant data type in the queue. This requires, however, that each subvi reads in variant data and converts it to the data type it needs. This method allows you to send any data you wish so long as the subvi converts variant data to the appropriate type.
While it may be too much work right now to modify these subvi's, you would only need one section of code in your main "test" vi.
08-16-2013 01:44 PM
Hey all again. I'm looking at implementing the various solutions suggested and have come up with the following:
- Polymorphic VI - The problem I see with this is I will still need to copy and paste VIs to include in a single polymorphic VI. Each copied and pasted VI will have a slightly different connector pane. Again, if I find a bug in one VI I will have to go into each cloned VI and correct the problem.
- Use a single VI - This seems like a good idea. All VI's do have a "Queue in". I'm not sure how to populate the queue with data that has an unknown type at run-time though. I might need something like a Generic Array as input. I'm somewhat new to LabView.
- Using variants - Yes, this also would only require 1 test VI. Unfortunately I would need to modify a lot of VIs to convert the variant to required data types.
Since this VI is pretty small I may go with the copy & paste approach. Since I'm somewhat new to LabView I wanted to ensure I'm not missing something obvious before doing this. I'm more familiar with C# where this problem could be solved with a single parent class containing the "obtain a queue, fill the queue, pass the queue into a SubVI, destroy the queue" logic, and several child subclasses that call different subVIs and handle the different data types.
Thank you!