LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Foolish mistake with Bundle by Name

Solved!
Go to solution

I recently spent too much time looking for an error in code "that used to work".  So I asked a student to look over my shoulder while I explained what was supposed to happen.  The bug is illustrated in this snippet:

Foolish Mistake.png

I'm doing a simple Bundle by Name, using a pre-defined TypeDef to define the cluster.  What I expected to get is shown on the left, and what I actually got is shown on the right.  The code looks the same, but the result is very different!

 

My student innocently asked if I was seeing, in fact, the Default value of my TypeDef (answer -- Yes).  He then asked if I had wired the TypeDef to the output terminal "by mistake".  This turns out to be almost right -- what I'd done was to wire the Indicator, not to the Output Terminal, but, in error, to the Input Terminal.

 

Notice the two beige rectangles at the right edge of the Bundle by Name.  The right-most is the Output, the left-most is the Input (which is where the TypeDef wire comes in).  What I'd carelessly done was to drag a wire from the Indicator "far enough" to make a connection, but, in fact, I dragged it too far so that it entered the Input rectangle.  Here are close-ups of the Correct and Wrong wires with highlighting -- it isn't easy to see, but the highlighting on the Wrong wire extends into the left-most beige rectangle.  If you bring your pointer in very carefully to the junction, you can sometimes see a Coercion dot on the edge of the Bundle function, but I couldn't capture it.

Correct Wire.png   Wrong Wire.png

Needless to say, this behavior, the ability to "mis-wire" a Bundle-by-Name function, was quite unexpected (by me) -- I spent most of my time suspecting subtle errors in my code and logic, not errors in wiring!

 

You can bet that I checked other places where Bundle by Name occurs in my code.  I'm posting this here in hopes that others do not fall into the same trap.

 

Bob (embarrassed) Schor

0 Kudos
Message 1 of 8
(3,320 Views)

I checked your snippets and they are both wired correctly. If you are daring, you can use autocleanup to make this sort of thing more obvious. There's also been some idea exchange ideas to make issues like these (hidden wires) into hard "break run arrow" errors optionally.

0 Kudos
Message 2 of 8
(3,304 Views)

Been there, done that.  I learned very early on to clean up my wires connected to the bundle by name just to make sure the wiring was correct for that reason.  (I'd then lay them out how I wanted them to look.)  Sometimes I can be a bit shaky with the mouse and wires get connected to the wrong place.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 8
(3,303 Views)

Son of a gun -- you are right, creating a Snippet either fixed the error, or when you paste the Snippet into LabVIEW, it "does what you mean", not "what you say".

 

If you try this "by hand" and deliberately bring the wire from the indicator to the left connector rectangle, you should duplicate my error.

 

BS

0 Kudos
Message 4 of 8
(3,287 Views)

I doubt the snippet auto-corrected the mistake. Most likely you accidentally snapped a correct version of the code.

 

In any case, I was wondering why it was that I never noticed this, so I had a look and now I'm going to guess that you have the auto-routing option unchecked. If it is checked, then LV automatically moves the wire to the top when you hover over the input terminal, thus not causing the issue you saw. I'm 99.9% sure that auto-routing is enabled by default, so the majority of people will never run into this.


___________________
Try to take over the world!
0 Kudos
Message 5 of 8
(3,222 Views)

You are absolutely correct -- I hate auto-routing of wires, as I think "my way is neater".  [Hmm, a little OCD here?].  Live and learn!

 

BS

0 Kudos
Message 6 of 8
(3,170 Views)
Solution
Accepted by topic author Bob_Schor

Sorry to beat a Dead Horse, but I wanted to bring some closure to this topic, and to comment on some of the helpful Replies.  A revised version of the Snippet is also included, below.

  • Oligarlicky and tst are correct -- I must have inadvertently "fixed" the original Snippet before posting, as the Snippet below does show the error (I tested it this time!).
  • tst is also correct that having the Option "Enable automatic wire routing" turned On (the Default behavior) would prevent this problem, resulting in the obviously-unintended diagram shown wired to Test 3.  I always turn this Option Off when I configure LabVIEW, as I like to control wire placement.
  • Many "mis-placed" (or mis-connected) wires seem to be "caught" by the VI Analyzer, so I "analyzed" this VI.  When I first read its findings, I said "Aha, it missed the error!".  But I was wrong -- there was an Unused Code notation that said "The function "Bundle By Name" has none of its outputs wired, and therefore performs no useful operation.  Consider removing this function from your diagram."  It really wasn't until I created the "Enable automatic wire routing" version shown as Test 3 that I realized it was (somewhat obscurely) talking about my mis-wire.
  • A colleague of mine said I should stop wiring "in Hebrew" (creating my wires from right-to-left) -- that would also have prevented this error, but I prefer the "ambidextrous" style of wiring, meaning I start from whichever connection I happen to be near and wire to wherever it has to go.

I hope I remember these lessons six months from now ...

 

Bob Schor

Wiring Error.png

 

 

0 Kudos
Message 7 of 8
(3,122 Views)

I expect that this won't make you change your habits, but it should probably be pointed out that the auto-routing behavior can be somewhat overridden -

  1. If you click on an empty point while wiring, it creates an anchor point for the wire which it has to go through.
  2. If you press the space key in mid-wiring, the algorithm toggles between different options.

As for "Hebrew wiring", it's the main language I grew up speaking and I use it every day (including in LV), but I almost always start wiring from the source, not from the sink, so I can say that at least that mindset is not a direct influence. Maybe it is the "ambidextrous" mindset.


___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(3,112 Views)