Showing results for 
Search instead for 
Did you mean: 

How to detect which data type is passed in ?

Go to solution






 I've built a VI function. But I want to make it more secure - that function could detect which data type is wired to the inputs and allow wiring only certain data types. How can I do this?




Message Edited by ACiDuser on 05-23-2009 08:13 PM
0 Kudos
Message 1 of 22

I'm assuming you're talking about numeric datatypes. In this case that information is not available to you at the subVI level. The LabVIEW compiler will have already changed the datatype to match what your subVI expects if someone wires something of a different type.


You could use a variant as your input. Then in the subVI you can use the Variant to Flattened Data to get the type. The OpenG LabVIEW Data Tools VIs will be useful if returning an enum specifying the datatype. Specifically, using the "Get TDEnum From Data VI".


Now that we've gotten that out of the way, let's talk about the why. Why do you need to do this? What are you trying to "secure"?

0 Kudos
Message 2 of 22


Like many of built-in Labview function nodes - If you wire incorrect data type - the wire is indicating spotted with red cross - which means incorrect data type wired. I wand that my VI could distinguish if the wired data is type "Waveform" and allow it, and if it is array or any other data - not allow. Is is possible to implement?



It would be very useful if there were comparion nodes such as "Numeric Array ?" "String ?" "Waveform ?" "Cluster ?" and others. 


Message Edited by ACiDuser on 05-23-2009 09:45 PM
0 Kudos
Message 3 of 22
Accepted by topic author ACiDuser

You could look into polymorphic VI's.  They would allow you to connect different datatypes.  However, there really isn't an option to "not allow" it.


If anyone is creating their own VI's in LabVIEW, then they should be paying attention to the details such as coercion dots.  Other than providing good documentation describing the function, inputs and outputs of a subVI, it isn't really necessary for the creator of the subVI to prevent another programmer from using that subVI wrongly.

0 Kudos
Message 4 of 22
A Polymorphic VI could be a nice solution to my problem. Could point at an easy exaple of polymorphic VI ?
0 Kudos
Message 5 of 22

Hi ACiDuser,

see the "Read From Spreadsheet File" function for an example. DAQmx read and write are also polymorphic.



Message 6 of 22

ACiDuser wrote:
A Polymorphic VI could be a nice solution to my problem. Could point at an easy exaple of polymorphic VI ?

Have you checked the LabVIEW Help? It explains what polymorphic VIs are, and how to create them. You can also create one using the template (File -> New...). Note that you will not actually be creating one VI, but rather an instance for each datatype that you want to handle. How you do the inside is up to you. 

Message 7 of 22
Okey I will read this section. And the question is: Is there a way to detect that something is wired to specific VI output? If I could detect that for example 1 output is wired and the second is not wired then I could skip inside my vi processing for output2 - and VI will work faster.
0 Kudos
Message 8 of 22
This question also gets asked a lot. You have to set the default value of your control to something that would not be a valid input. For example, for floating point numerics you would set the default value to NaN. If a user does not wire a value, then your control have a value of NaN. Then, in your code you check to see if the value is NaN. If it is, it indicates the user did not wire to that input. Obviously, a user could wire NaN, but that's why you have documentation to explain how a VI is supposed to be used.
Message 9 of 22
smercurio…, and for checking if Output is wired - the same?
0 Kudos
Message 10 of 22