10-10-2012 07:29 AM
I am sure it has been discussed here in the past but I can't find it. I am writing a VI for the manipulation of some array data. I really don't care if it comes to me as a string or as a number array. How does Labview handle this? Basically I want to create an array tool much like the ones in the existing toolbox except I can't see the source code behind those. So how do I create a tool that looks at the incoming data and if it is dbl treats it as so, but if string treates it as string?
The first issue is on the front panel VI I have to establish what the linked arrays are. How do I allow for the input of both? Next do I need case structure for dbl vs. string or is there a way to set up a constant that is either or?
I hope I am explaining this correctly but I want everything to work like one of Labview's existing array tools. Namely the incoming data comes in in one format and then the paths adjust to handle it automatically.
Solved! Go to Solution.
10-10-2012 07:39 AM
Sounds like what you want is a Polymorphic VI. It's not quite the same as the primitives, but it will do the job.
10-10-2012 07:42 AM
Take a look at creating a polymorphic VI. You'll have to create one VI for handling a DBL array and one VI for handling a string array, then create the polymorphic 'shell'. The type of wire you connect to the input will determine which actual VI gets called.
10-10-2012 08:47 AM
OR.
This sounds a lot like a call for a "Class" with dynamic dispatch of two override methods.
The choice between the LVOOP and Polymorphic approaches depends on the question....
"Will the datatype be known during development or must the vi dynamically chose the vi to run at runtime?"
10-26-2012 07:10 AM
It has been a little while since I was working on this but now I am coming back to it. Here's a great example. See my code below for "Is in array".
This will be a little subarray, so right now the operator selects the mode and it goes from there. However I know there must be a way to get the data stream to automatically configure based on what it is being sourced. Basically I want my inputs to "Is in array" to change just like the acctual array vi's inside the program do.
Any ideas?
10-26-2012 07:38 AM - edited 10-26-2012 07:40 AM
Without using LVOOP, a variant data type is the only type of wire that can pass more than one type of value.
In your code;
Try using a type-def'd enum for you cases. It will help you keep the states straight.
Experiment with code like this
And while I am at it.
If you enable indexing on an input array the "N" for the loop is determined by the array size and there is not need to explicitly index array elements.
Ben
10-26-2012 07:41 AM - edited 10-26-2012 07:42 AM
Well, your code could be simplified quite a bit.
Again, look into the polymorphic VI. That and classes are the only real options at this point.
10-26-2012 08:09 AM
Short comment re: The appraoch by crossrulz vs my version.
My version is a near one-to-one translation of the orignal code.
Crossrulz version is more efficient and will out perfrom my version particularly with large arrays because;
Mine cheks all for equality, his stop when it finds a match.
Mine creates an intermediary array, his does not.
Done with the compare.
Ben