05-23-2009 08:11 PM - edited 05-23-2009 08:13 PM
Hello!
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?
Thanks
Solved! Go to Solution.
05-23-2009 09:30 PM
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"?
05-23-2009 09:39 PM - edited 05-23-2009 09:45 PM
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.
05-23-2009 09:44 PM
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.
05-23-2009 09:51 PM
05-24-2009 06:28 AM
Hi ACiDuser,
see the "Read From Spreadsheet File" function for an example. DAQmx read and write are also polymorphic.
Mike
05-24-2009 06:52 AM
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.
05-24-2009 12:24 PM
05-24-2009 01:03 PM
05-24-2009 01:09 PM