03-09-2010 06:47 PM
This one just bit me so I thought I should share. It looks like the Search 1D Array function behaves unexpectedly when used with an array of VI refnums. So far I have only reproduced it in LabVIEW 2009 SP1, but I ran some code in 8.6.1 that seemed to have the same symptoms.
When I run the code above, I always get a zero for the output "index of element". In the example shown I expect to get 3. In fact if you change that 3 on the array index to any number, you get zero on the output. My workaround is to typecast the refnum array to an array of I32 and also typecast the refnum that I'm searching for. That makes it work, but I'm still freaked out by the odd behavior.
Note that the VI you throw the snippet into must be reentrant. I believe the search is getting confused because the refnums all point to the same VI, albeit different instances of that VI. Of course, that is the whole point of using the search 1D array function. I am trying to identify a particular instance.
03-10-2010 09:57 AM
Photon Dan wrote:This one just bit me so I thought I should share. It looks like the Search 1D Array function behaves unexpectedly when used with an array of VI refnums. So far I have only reproduced it in LabVIEW 2009 SP1, but I ran some code in 8.6.1 that seemed to have the same symptoms.
When I run the code above, I always get a zero for the output "index of element".
I believe the search is getting confused because the refnums all point to the same VI, albeit different instances of that VI. Of course, that is the whole point of using the search 1D array function. I am trying to identify a particular instance.
Somewhat poor assumption.
"Different instances of the same vi" It Would be more correct to say the referances are all the same as they point to the same constant. Therefore since A [] are all the same you are returning the first match index 0.
Probe the array to confirm.
Turn on "Show constant folding" to see that the Loop doesn't really run
03-10-2010 10:17 AM - edited 03-10-2010 10:22 AM
Dan,
Yes, it seems that the search functions looks at what the references actually refer to, not what the actual value is...
But you can still use type-casting to find a particular reference you're looking for.
03-10-2010 10:49 AM
Jeff,
The elements in A[] are not all the same. A probe shows unique integer values for each element. Note that I said the snippet has to be run in a VI that is configured to be reentrant. A copy of the VI's dataspace must be made for each instance that gets created by the Open VI Ref function. I'm not sure why it looks like the For loop doesn't run since it does produce unique values on the array.
Others,
Thanks for verifying this!
- Dan
03-10-2010 11:24 AM
I can't speak to the specific of ths bug since I can't try it out where I am... but that will not stop me from throwing out some trivia.
The check that is going on in the Search may be the wrong type of "eqaulity check". It may be checking to see if it is the same VI rather than the same instance of a VI. I believe the check for "is this the same instance' is supported by the "equal" operator.
Done wtih the trivia,
Ben