05-08-2013 09:07 AM
How can I make a VI accept any data type?
In most languages I can define a method that will accpet object o, and then I can determine o's type later
as in
local int return tempConversion(object x){
if(x.type == array)
else if(x.type == int)
etc.
Is there a way to do this in labview?
05-08-2013 09:13 AM
Polymorphic VI's to make different vi's for different data, must be decided while coding.
Variants, can be messy but allows all types during runtime
Objects or DVR's.
/Y
05-08-2013 09:17 AM
So a variant input will allow for any data type to be wired to it as a subvi?
05-08-2013 09:19 AM
Yes, the issue arises when you need to extract the information and work with it somehow. What's the goal/plan?
(There's some useful Variant VI's in vi.lib that's not on the pallettes)
/Y
05-08-2013 09:23 AM - edited 05-08-2013 09:25 AM
Temperature conversion.
I'm pulling temperature from 9 devices in my current project.
On the display screen the temperature output is customizable (each devices output), the input temperatures (given over network will change based on engine parameters being simulated), and the output termpatures or the network will change.
On top of this I have 4 devices that feed me Kelvin temperatures, 2 that feed me F, and the rest feed me C.
So I want one function to handle all of these conversions (and future conversions).
Also safety inputs are undefined, so I'll need to handle some array's of temperature, compared to constants of unknown at this time units.
TL;DR Many unit conversions, some will be arrays others will be single units.
05-08-2013 09:28 AM
Sounds like the Read function should handle the conversion so you get all data in the same form (C). Either by internal logic or by OOP. OOP is fun. 🙂
/Y
05-08-2013 09:36 AM
The read dumps everything to Kelvin (which is my most generic output also). But since my outputs are variable, the write function also handles the writting. Which isn't much of a problem, the problem is (as anal as this will make me sound), It's sloppy coding.
I have 1 vi that can convert a C to an K
I have 1 vi that can convert a F to an K
I have 1 vi that can convert a K array to any (depending on input)
I have 1 vi that can convert a K to any (depending on input).
Which is bad (or I don't like it).
So I improved it and generatlized it
I have 1 VI that converts * to * (temperature type).
I have 1 VI that wraps an array, then places the above VI in a for loop, and itteratures though.
Which still bothers me, because it isn't an elegant solution.
In java for example (which I have more experience with).
I could just
def int[] convertTemperature(object x, String in, String out){
//clear white space and put strings to lower case
//determine input type
//convert to same input type
//itterate though input and convert from string in, to K
//itterate though that ouput convert from K to string out
//return
}
Then simply call that function where ever I needed to do a conversion.
05-08-2013 01:54 PM
I don't quite understand your Java pseudo-code - what data is carried by the object? Is it the actual temperature data, or just which conversion to use and the data itself is in the string? You can certainly create a LabVIEW object and then create children of it to handle different types of data, although that might be overkill here. You can also use a variant and get the type of data it contains at run-time; you are then trading compile-time type-checking for run-time type-checking, which means more risk of an error due to incorrect data.
05-08-2013 02:20 PM
05-08-2013 02:33 PM