LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

type parameters and generic programming

Hi

 

I come from the world of C# and something I miss is type parameters which enables a lot of code re-use.

 

For example in an application i am developing I need to sort some data and make it searchable. I need to do this several times on different data types so I am casting the input data into a variant and then casting back to the data type i need. I do this using a lab view class which stores the data (key value pairs) and includes functions for querying the data.

 

This works to an extent but the casting to/from the variant data type has a lot of overhead and the casting needs to be performed outside the VI doing the work. Additionaly I encounter error code 91 which does not help. 

 

In C# there is a better way, we can write functions which allow the caller to specify the type of the parameters during run time. A feature which would be ideal for the above situation.

I found an article online which states that labview does not include such functionality.

the article is

http://expressionflow.com/2009/10/23/introduction-to-type-parameters/

 

 Is there some way to achieve this level of functionality with lab view? or is it only available to the NI R&D department?

 

 

0 Kudos
Message 1 of 6
(2,449 Views)

Well, you could go for the Java approach. Create a class method that can sort items, using a compare method using the larger or smaller than. Then in your class you have to implement the Comparable method, see http://www.javapractices.com/topic/TopicAction.do?Id=10

This way you can keep things generic, yet scalable for different data types.

0 Kudos
Message 2 of 6
(2,445 Views)

@JacobM123 wrote:

 

 Is there some way to achieve this level of functionality with lab view?


Short answer - no.

 

Longer answer - NI has been looking into this for a long time (including some working experiments which are in LV, but which aren't officially exposed), but LV still doesn't have a proper mechanism for this. You can see here for some more details - http://forums.ni.com/t5/LabVIEW-Developers-Feature/Now-available-for-download-quot-Randomize-1D-Arra...

 

Also, read this idea and vote for it - http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Provide-a-better-way-to-implement-a-polymorphic-VI/idi...


___________________
Try to take over the world!
0 Kudos
Message 3 of 6
(2,434 Views)

ok thanks, its a shame that NI feels that they must password protect that vi which was posted.

Shouldn't this sort thing be available to the people trying to use lab view?

 

Failing that is there some way to query the data type stored on a variant wire?

0 Kudos
Message 4 of 6
(2,425 Views)

@JacobM123 wrote:

ok thanks, its a shame that NI feels that they must password protect that vi which was posted.

Shouldn't this sort thing be available to the people trying to use lab view?


It was password proctected because it contains confidential code.  How it did it was proprietary to LV R&D.  But then it turned out that the experiment was a bust.  NI knows it is something that needs done.  They are just having trouble getting it to work in a usable way.  There are many things to concider with it.  They'll figure it out one of these days.  They are some really smart people in R&D.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(2,419 Views)

@JacobM123 wrote:

 

Failing that is there some way to query the data type stored on a variant wire?


There are some relevant VIs in <vi.lib>\utility\variantdatatype, but I don't see how those would help you for something like this.

 

One thing you could do is create polymorphic VIs, which would give you automatic adaptation at edit time, but they require a lot of duplication of code and there is no official tool for automating their creation (although I believe you can download some from the OpenG repository).

 


___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(2,405 Views)