beuleal Posted July 31, 2015 Report Share Posted July 31, 2015 Hi guys, Im creating a sub vi that manipulates an array, butttt the input doesnt work as any array function in the pallete. What should i do? Quote Link to comment
jcarmody Posted July 31, 2015 Report Share Posted July 31, 2015 Write your own function. Seriously, though, you need to share more information about what you're trying to do. Quote Link to comment
hooovahh Posted July 31, 2015 Report Share Posted July 31, 2015 You should ask for generic VIs, or XNodes . Okay but seriously the options today are to use polymorphic VIs, where you write your code to work on each type of array you expect, and have it auto pick the right one based on the type wired to it, or you work with variants and expect the user to convert the variant back into the array of their type that they put in. LabVIEW is a strictly typed language, and there is no easy way to do what you want in a scalable way. For examples look at OpenG. Their array tools work with multiple data types because of polymorphc VIs, but if you give it an array of a type def there isn't a VI for, it uses the array as a variant and you need to convert the variant back into the data type you gave it. A very experimental, not official technology is XNodes which NI uses to accomplish something like this. If NI ever officially releases XNodes I would recommend you use them, until then you're stuck with variants, and polymorphic VIs. Here is an example of taking the OpenG array tools and turning them into XNodes which accept any array data type. Again, not recommended yet. Quote Link to comment
beuleal Posted July 31, 2015 Author Report Share Posted July 31, 2015 Ok, let me explain again with more infos. My sub vi is attached. As you all can see, i just manipulate array, doesnt matter which type it is, like any array function in array pallete. Butttt, when I plug in the input one array of string, i get error, because the data type is different. This error doesnt appear when we use "index array", for example. Quote Link to comment
Norm Kirchner Posted July 31, 2015 Report Share Posted July 31, 2015 I heard a wise man say once, regarding your exact question. You should ask for generic VIs, or XNodes . Okay but seriously the options today are to use polymorphic VIs, where you write your code to work on each type of array you expect, and have it auto pick the right one based on the type wired to it, or you work with variants and expect the user to convert the variant back into the array of their type that they put in. LabVIEW is a strictly typed language, and there is no easy way to do what you want in a scalable way. For examples look at OpenG. Their array tools work with multiple data types because of polymorphc VIs, but if you give it an array of a type def there isn't a VI for, it uses the array as a variant and you need to convert the variant back into the data type you gave it. A very experimental, not official technology is XNodes which NI uses to accomplish something like this. If NI ever officially releases XNodes I would recommend you use them, until then you're stuck with variants, and polymorphic VIs. Here is an example of taking the OpenG array tools and turning them into XNodes which accept any array data type. Again, not recommended yet. In short, we as G developers can not make our own functions that act excatly like the array primitives in LabVIEW. This techniques listed above by Hoova are the ones to focus on if you want that same kind of behavior. I vaguely recall that someone once made a tool which would make the poly VI stack for you, for all available data types; this way you don't have to replicate your VI over and over and make the poly. But I can not recall where that would be. Maybe someone else could chime in Quote Link to comment
hooovahh Posted August 2, 2015 Report Share Posted August 2, 2015 Not sure if you were talking about me or not, but I had forgotten that I made such a tool, which I never got to finish here: https://lavag.org/topic/16003-another-create-polymorphic-vi/ If I were to write that again I would have done things differently, but the tool mostly works. Give it a template, tell it what controls to replace, with what other controls, and then a bunch of VIs were made for each control type you picked. Quote Link to comment
ThomasGutzler Posted August 3, 2015 Report Share Posted August 3, 2015 This will let you connect any 1D array if you really hate polymorphic VIs and xnodes 2 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.