LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

accept array or int data type

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?

 

0 Kudos
Message 1 of 18
(2,828 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 18
(2,826 Views)

So a variant input will allow for any data type to be wired to it as a subvi?

 

0 Kudos
Message 3 of 18
(2,823 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 18
(2,821 Views)

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. 

0 Kudos
Message 5 of 18
(2,813 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 18
(2,807 Views)

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. 

 

 

0 Kudos
Message 7 of 18
(2,804 Views)

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.

0 Kudos
Message 8 of 18
(2,777 Views)
The idea is I can define a method, the method's input is an object. It's type descriptor is object.

Therefore any data type is useable because I'm defining my input as an object (which all data types are objects in OOP's). You follow?

Is that possible in LV without using variants?
0 Kudos
Message 9 of 18
(2,768 Views)
The idea of data being carried by the object is this

In[] converTemp(Object x, inputUnits, outputUnits){

If(x.type == array){

For (int I = 0; i++; i< array.len()){

x[i] = TempConvert(x[i], inputTemp, outputTemp)
}}
Else if(x.type == int){
return TempConvert(x,inputUnits,outputUnits);
}
Elseif(x.type == double){
int int_x = x.floatToInt(x);
return TempteratureConvert(int_x, inputUnits,outputUnits);
}}


Example code ignore style mistakes done on smart phone
0 Kudos
Message 10 of 18
(2,765 Views)