09-30-2023 01:01 PM
I'm finding the LabVIEW help a little obtuse sometimes and I've searched but can't find an answer to these two questions (bad search terms maybe??). Anyway, I have a VI which is used to remove a specific entry from an array and pass the new array out:
In this VI CommandDirector has an Array of Commands and I want to remove an entry and store the updated array back in the CommandDirector. So I'm extracting the array and auto-indexing the input to a For loop. For each Command I read it's ID (the icon in the For loop) and compare it to a passed Command ID and if equal, remove it from the array. This should terminate the loop early because it has been found (there is only ever one potential match). The array is passed out of the for Case and For loop and used to store back into CommandDirector. The False condition for the Case just passes the array of Commands straight through. My questions:
1) The Tunnel Mode for the For Loop is "Last Value". Given that the array either never changes (no match found) or has one entry removed and then the loop terminated, it feels like this is the right setting?
2) I want to stop the loop early when a match is found OR an error occurs. Have I done this correctly? I'm not clear on whether the error input when NO error has occurred is treating an empty Error cluster as False or not.
Solved! Go to Solution.
09-30-2023 02:07 PM
To answer (1) myself:
Yes it is the right setting.
09-30-2023 02:23 PM
I am not familiar with your tools and what the possible errors are.
Since the loop exits on error, you don't really need the shift register for the error wire.
Is the "removed command"indicator connected to the connector pane? It would be better to have it on the top level diagram after the loop. It is never a good idea to bury indicators deep inside structures, it might even show stale values if the case never occurs. Same for the "removed" Boolean. It should be connected to the wire going to the stop terminal via a last value tunnel.
Sorry posting by phone. I can look at it later once you post the actual vi. Pictures are ambiguous (we cannot see what's in other cases, we cannot tell what's on the connector pane, we cannot see vi settings, etc etc)
09-30-2023 03:08 PM
I hate working with "pictures of LabVIEW code", as that's all I can see (and not always clearly). So I see elements that "look like" DAQmx Read or Write functions, but that's probably just a "misleading icon" ...
But getting back to the Question at hand, I'd suggest the following:
Bob Schor
09-30-2023 03:39 PM
I only posted an image because it really is as simple as it looks: The CommandDirector is a class which has a property which is an array of Commands. The icons for reading/writing might be a bit confusing, I'm just picking glyphs that make sense to me: they just return/store an array into that property.
I'll take on board what you guys say and have a look at restructuring, thanks.
I'd still be interested in understanding how the Error Cluster is interpreted by the OR comparison though.
09-30-2023 05:25 PM - edited 09-30-2023 05:28 PM
When you feed an error cluster to any native boolean terminal that accepts it, it will evaluate according to the boolean element of the error cluster. In other words, True when there IS an error, False when there is not (and that includes "warnings", where the boolean is False but there may be a descriptor string and a non-zero numeric code).
-Kevin P
10-01-2023 04:23 AM
Thanks Kevin. I've been used to anything that isn't zero or null being True and I know that LabVIEW is different.
10-01-2023 09:49 AM
@andrewDJ wrote:
Thanks Kevin. I've been used to anything that isn't zero or null being True and I know that LabVIEW is different.
If the code is nonzero and the boolean is FALSE, it's a warning, not an error! For this reason, you cannot use a nonzero error code for your purpose. As has been said, LabVIEW tests the boolean.
Being able to wire an error code directly to a logical function is a more recent code shortcut. In the distant past, we had to unbundle the boolean.
Of course the bottom code is useful if you also want to stop the loop on warnings.... 😄
10-01-2023 12:59 PM
I don't remember exactly when this happened, but about 15 years ago (so around LabVIEW 8.6 or 2009, perhaps), NI changed the "Stop" control of For Loops to be able to accept an Error Line as a valid input (so "Stop on Error"). Previously, we all did an Unbundle by Name and wired the "Error" boolean indicator to the Stop, so this was a great improvement in speed and "ease of reading the code". At the same time, NI made the Boolean functions (such as "And" and "Or") also treat the Error Line as though it was just the "Error" Boolean, so you could easily program "Stop OR Error" to end a While Loop.
Note that you can not simply wire the Error Line to any old Boolean Indicator (such as an LED) -- they are different "Types". The limited specific exception that NI made 15 years ago for the Error Line is specific for that Data Type (if you look at the Error In on a Front Panel, note that the Status symbol is "special", not available on the Boolean Palette) -- NI does some "magic behind the scenes" to provide this additional functionality to LabVIEW users.
Bob Schor
10-01-2023 02:00 PM
Thanks both for the useful information.