Monday, March 23, 2009

How Do You Like Your Nuggets Served?

I've been receiving some requests lately regarding delivery of my weekly LabVIEW nuggets...some people want emails, some want RSS feeds, and some want a static document they can search. I hope the following solutions will satisfy all your varying nugget appetites:
  • Email - To receive an email notification when I post a new nugget, visit the Darren's weekly nugget thread on the NI Forums. Assuming you are logged in with your NI Forums ID, you can click the Thread Options button and choose Add this Thread to my Subscriptions. Note that other NI Forums users will occasionally post nuggetish links to this thread, but most of the time, it's me posting links to my weekly nuggets.
  • RSS - I created a weekly nugget blog on the NI Community website. The feed URL for this blog is here, so if you subscribe, you'll get notified in your favorite RSS reader whenever I post a new nugget.
  • Static Page - I also created a static document on the NI Community website that contains links to all my nuggets, and a short description of each nugget. You can use this page if you want to search to see what topics I've posted nuggets about throughout the years.
Is there another nugget distribution mechanism you would prefer? Let me know.

Thursday, March 19, 2009

Why Are You Still Using Loops in Your Functional Globals?

Are you still creating Functional Globals (a.k.a. LV2-style globals) that look like this?

If you're programming in LabVIEW 8.5 or later, do this instead!

In LabVIEW 8.5, Feedback Nodes gained the ability to live on the top level diagram of a VI... no loop required. This feature gives us the identical functionality of a single-iteration loop with an uninitialized shift register. And let's be honest here...the uninitialized shift register on a single-iteration loop is kind of a hack.

Not only does the Feedback Node clean up our diagrams, but it is slightly faster (sometimes by about 5-10%) than a loop with an uninitialized shift register. This is largely due to the removal of loop overhead.

So get over your Feedback Node (and backwards wire) hangups like I did and make your functional globals more efficient!

Friday, March 6, 2009

LabVIEW on a Netbook...It's Not That Bad!

In my last blog post, I mentioned I had an extra motive for writing the Bulk Controls and Indicators VI. I wanted to write a moderately-sized VI with my new Acer Aspire One netbook. I got the fully-loaded one: Windows XP, 160GB HDD, 6-cell battery (6+ hours!), and it was only $330 on (mine is the blue one, just like the picture). I've always loved small laptops (my previous was a Toshiba Satellite U205), and I originally bought this netbook for my wife. But she said it was too small, so she's getting my Toshiba and I'm taking the Acer. The reason for the new laptop, by the way, was that my wife's original Dell Inspiron b130 suffered catastrophic mechanical failure in the form of the screen becoming detached from the base.

I really, really love this thing. Its only drawback is inherent to its design...the maximum screen resolution for the 8.9" model I got is 1024x600. (There was another drawback regarding a slow network connection, but this link helped me solve it). As soon as I got it, I installed LabVIEW to try writing some VIs. I was worried at first about performance, but this laptop is really snappy...a non-initial launch of LabVIEW only takes 9 seconds (with Load Palettes at Launch enabled), and Quick Drop is instantaneous (that's been my editor benchmark of choice since 8.6 released). My next worry after performance was LabVIEW's usability on a small screen. Here's what I noticed:
  • The Getting Started Window doesn't fit on the screen (I hope somebody's Eyes are reading this). I wasn't too surprised by this, since our minimum screen resolution that we usually assume when designing UIs in LabVIEW R&D is 1024x768. Thankfully, the 'X' in the corner was still visible, so it wasn't too much of an inconvenience.
  • Apparently when you create a New VI, the size of the VI created is proportional to the screen size. I never really noticed this before until comparing the size of a new VI on the netbook to the size of a new VI on my 22" widescreen on my dev machine at work... :)
  • This isn't really peculiar to netbooks, but I quickly reminded myself how sloooow I am at programming LabVIEW with a touchpad. I'm planning on getting a nice wireless mouse, but for writing this VI, I used the free Acer mouse they sent me with the netbook.
  • Whenever you ctrl-drag in empty space to create diagram space, it's much more difficult to only drag in one direction (usually left-right for me), I guess because the lower resolution of the screen makes for larger relative mouse moves? I've filed a suggestion in the past that a ctrl-drag have a few pixels of slop on either side for growing only in one direction, but we haven't seen it yet...
So all in all, a pleasant experience. I don't think I'd be able to develop 8 hours a day on such a small screen. But for demonstrating something in LabVIEW during a discussion at work or NI Week, or for knocking out a quick VI for the NI Forums, LAVA, or my blog, I think it will be perfect.

Thursday, March 5, 2009

Bulk Creation of Controls and Indicators

In my previous blog post, Jason commented that it would be nice to have a utility that will create controls and indicators on diagram objects in bulk. I thought that was a good idea, and I decided to write a VI that gets us pretty darn's not quite a right-click option, but it's as close as I can get without getting a C-monkey to modify the LabVIEW source code for me, and without having plug-in VIs yet.

So put this VI in [LabVIEW 8.6]\project and restart LabVIEW. You'll now have a Tools > Create Controls and Indicators menu option. Select a few block diagram objects, then choose this menu option. It will create controls and indicators for any terminals of the selected object(s) that aren't already wired to something. This transaction is undoable/redoable as well.

I hope this VI is useful to people. I also had another motive for writing it, but you'll have to wait until my next blog post to find out what that was.

Tuesday, March 3, 2009

A Good Use for Block Diagram Cleanup

One of the big new features of LabVIEW 8.6 is Block Diagram Cleanup, a way to instantly rearrange block diagram contents to make them look "better". In fact, I demoed this feature briefly during my NI Week 2008 keynote appearance. In practice, however, I find that I don't really use the feature all that much. Keeping the diagram clean as I write code has been an integral part of the way I do my job for the past several years, and honestly, if I run Block Diagram Cleanup on my clean code, it makes it considerably less clean. I know many other advanced LabVIEW developers who feel the same way.

Lately though, I have discovered a perfectly valid niche use case for this feature. One of the great things about LabVIEW is how easy it is to write "throw away" know, that simple prototype VI that you write just to test an idea, or that debugging VI that helps you quickly unit test something you're working on...or even the VI where you just drop a single function and wire a few things in to double-check that it works the way you expect (I do this with Match Pattern about once every few months). Well, I tend to write throw away code very quickly, with no regard for "cleanliness". It's these throw away VIs that are the perfect candidates for Block Diagram Cleanup...with a single Ctrl-U, my code becomes considerably more clean than it was before, when I was slinging objects left and right with Quick Drop and reckless abandon. And even though it's throw away code, it's still easier to understand and modify (before I throw it away) if it's clean.

Here's an example "before and after" of one of these situations. In this case, I wanted a VI that displayed every single value in my LabVIEW Class this case, there were several subclasses that contained arrays, so a simple probe wouldn't let me see multiple array elements at I basically wrote a huge "probe" VI that displayed a bunch of these arrays, with several elements expanded. This VI was purely for debugging, and would be of limited utility once I got all my class data straightened other words, it was a "throw away" VI. So I slopped it together, then I cleaned it up. Although not perfect, the cleaned up version is much easier to understand (sorry for all the Wite-Out...these classes pertain to features that have yet to be released):



I understand that this might be a pretty limited use case, but who knows...maybe I should get my feet wet with the feature now, in the event that it gets a lot better in a future LabVIEW version?