Thursday, February 9, 2012

Captions: More than You Ever Wanted to Know

Every once in a while, the subject of control/indicator captions comes up around here, and every time, confusion arises.  So here we go...everything I know about captions.

The Basics
Enabling a caption on a control or indicator is straightforward enough:










If you select this option, your control doesn't appear to change if you leave the caption as its default value:






But trust me, it has.  We have hidden the label of the control.  You are now viewing its caption (in the same location as the label).  If you give the caption a different value than the label, you will see both in the Context Help window:










Any control with its caption showing (assuming the caption is different than the label) will display the caption at the top, and the label in brackets underneath.  When hovering over the terminal of a subVI, you'll see the caption of the control/indicator in the tip strip instead of the label.

Use Cases
Now why would you ever want to show the caption in the first place?  I know of two possible reasons:
  1. Long caption, short label - If you want your control/indicator to have a long, meaningful description on the panel, but you don't want that long string getting in the way on the diagram, you could show its caption. Personally, I eschew this approach...instead of using a caption, I would opt for a free label on the panel positioned appropriately near the control with appropriately-justified text.
  2. Localization - This is the primary reason we use captions in LabVIEW R&D.  When we localize LabVIEW into other languages, we don't want to change the labels of controls and indicators...that could potentially break code that programmatically refers to controls and indicators by name.  So instead, we show localized captions (and hide the labels) for the controls and indicators in all user-facing VIs that ship with LabVIEW.

Deleting a Caption
In older LabVIEW versions, there was no easy way to delete the caption of a control/indicator.  Thankfully, in LabVIEW 8.2 and later, it is very easy.  All you need to do is select the caption with your selection tool and press the 'Delete' key on your keyboard.  Note that this is not the same as highlighting the text in the caption and pressing the 'Delete' key...if you do that, the control will still have a caption, but it will be an empty string.

Working with Captions Programmatically
This is where it gets a little tricky.  By default, controls and indicators do not have captions.  Let's say you try to read the Caption.Text property of a control like this:





Believe it or not, one of three different things can happen with this code:
  1. If the control already has a caption, you'll get the caption text.
  2. If the control doesn't already have a caption, and the VI that owns the control is in edit mode, then a caption will be created for you, with the same string as the label, and you'll get that text.
  3. If the control doesn't already have a caption, and the VI that owns the control is in run mode, then you'll get error 1320, which tells you that you can't read properties of control parts that haven't been created yet when the VI is in run mode.
Because of all this craziness, there is another helpful VI Server property that you can use:







The "HasCaption" property will tell you if a control even has a caption to begin with, before you start trying to do other caption-related stuff.

One other nifty tip for dealing with captions programmatically...if you want to delete a caption programmatically, this is the way to do it:




Summary
So there you have it...way more information than you ever wanted to know about a LabVIEW feature that you probably weren't even using in the first place. :P  But in the event that someone ever does need this information, here's hoping this blog post eventually bubbles up to the top of a "LabVIEW captions" google search.  ;)

Tuesday, August 2, 2011

How to Customize Edit > Create SubVI in LabVIEW 2011

LabVIEW 2011 was announced at the NI Week keynote today, and there are plenty of places you can learn about all the great new features. In this blog post, I'll describe how to customize one of the best new features...the improvements to the Edit > Create SubVI gesture in the LabVIEW IDE.

You may recall that last year, Stephen and I solicited the LabVIEW Community to vote up (or 'kudo' up, I guess) the Create a proper connector pane when doing Edit -> Create subVI idea posted by Yair on the Idea Exchange. You all responded in an impressive way, and we were able to add the feature in LabVIEW 2011.  Specifically, we now create a subVI with the proper connector pane, properly-named error terminals in the bottom corners, properly-named refnum/class terminals in the top corners, and an organized front panel.

But that's not all!  Thanks to Stephen, the code that modifies the created subVI is all VI-based.  So if you want to customize the created subVI in some way with your own scripting VIs, there are two ways to do it. Here's how:

Providing Additional Create SubVI Functionality
Do you like the way we create the subVI, but you want to perform additional actions on it?  If so, then follow these steps:
  1. Open this VI: [LabVIEW]\resource\plugins\CreateSubVI\Additional Actions Template.vi
  2. Save a copy of the VI here: [LabVIEW]\resource\plugins\CreateSubVI\CreateSubVI_AdditionalActions.vi
  3. Add scripting code to this copy of the VI to do whatever you want to the created subVI.  Some ideas I've had are:
    • Perform a Diagram Cleanup on the created subVI's diagram
    • Wrap the created subVI's diagram in an error case structure
    • Programmatically launch the Icon Editor on the created subVI
Completely Replacing Our Create SubVI Functionality
Would you rather define your own behavior for how the subVI is created?  If so, then follow these steps.
  1. Make a copy of  [LabVIEW]\resource\plugins\lv_modifyNewSubVI.vi and name it lv_modifyNewSubVI.bak.
  2. In the original lv_modifyNewSubVI.vi, you can remove the code on its diagram, and write your own scripting code to modify the new subVI.  Here is a description of the inputs/outputs of the VI:
    • VI Refnum - A VI reference to the newly created subVI.
    • Fail? - If true, LabVIEW assumes an error occurred during your scripting, does not commit any of your scripting changes, and instead creates the subVI in the same way it did in LabVIEW 2010 and previous...full conpane, weirdly-named controls, etc.
    • Caller Connections in/out - This is the most complicated part.  The input Caller Connections array defines numeric indices for the controls/indicators on the (full) subVI conpane as it is originally created.  For example, if you create a subVI with one input and one output, then the array might have the values [0,1].  You can then programmatically inspect the conpane to see which items are connected to which indices...let's say for this example, the control is index 0 and the indicator is index 1.  For the output Caller Connections array, you must specify which indices on the new conpane those same objects are now wired to.  So for example, if you change to a 4x2x2x4 conpane, and you place the indicator at index 0 and the control at index 11 (those are the top corners of 4x2x2x4), you would output [11,0] as the output Caller Connections.  If you want to learn more about how this works, check out [LabVIEW]\resource\plugins\CreateSubVI\Calculate New Conpane Array.vi, which is the VI that figures this out for the current shipping Create SubVI technique.
  3. If you ever want to revert to the shipping functionality, restore the .bak copy of the VI.
I should also point out that these VIs are not kept in memory after a Create SubVI operation...so it's very easy to debug (via breakpoints, etc.) any plugins you write, as you can easily modify your plugin code and test it by performing the Edit > Create SubVI  gesture again.

I would like to eventually post some plugins of both types to the NI Community.  In the meantime, please let me know if you've written some plugins to augment (or replace) the Create SubVI functionality...I'd love to see what y'all can come up with!

Wednesday, March 16, 2011

My Interview on VI Shots

Last week, Michael posted his first interview with me on VI Shots. So far, I've been impressed with the content on this blog. Additionally, with the twitter account @vishots, he retweets relevant LabVIEW-related topics posted by other twitter users.

In our interview, we talk a bit about my background in LabVIEW, along with some of my tips for programming in LabVIEW at breakneck speed.  Check out our interview here.  And from what I understand, Michael has lots more great LabVIEW content in the works for future podcasts and articles.

Wednesday, February 16, 2011

Code Madness: The LabVIEW Example Program Challenge 2011

(What a funny coincidence that my last two LabVIEW blog posts had a college basketball-themed title. And I'm not even into college basketball. Although I guess as good as the Longhorns are doing this season, I probably should be...)

The latest LabVIEW coding contest on the NI Community has begun. Enter the LabVIEW Example Program Challenge 2011 today for your chance to win an XBox, Amazon gift cards, and other prizes. In this contest, example submissions will initially compete with one another in a qualifying round (taking place now until March 6th), with downloads, "likes", and ratings all contributing to each submissions's ranking. The top 16 submissions will then move on to a tournament-style coding competition (taking place from March 8th to April 4th), with a bracket system being used to match up winners for the rounds of 16, 8, 4, and 2, until the winner is decided in the final round.

To learn more about the Code Madness Program Challenge, visit http://www.ni.com/codechallenge. Begin submitting code today!

Thursday, October 7, 2010

The Sweet 16: Idea Exchange Entries That Need More Support

I've really been enjoying all the fantastic LabVIEW 2010 features that originated in the Idea Exchange, and I'm also excited about the ones we have planned for LabVIEW 2011.  Last night, I went through the Idea Exchange and read through all the ideas that have more than 10, but less than 100 kudos.  I found 16 that I think would really benefit the LabVIEW environment and increase my productivity, but aren't currently on our roadmap of features because they haven't bubbled up high enough in the rankings.  So if you haven't already, please consider kudoing some or all of the following ideas, so we can push to get them included in LabVIEW 2012:
By the way, I got the idea for this blog post from Aristos Queue, who has already posted his own list of Idea Exchange entries that he'd like to see implemented in a future LabVIEW version.

Tuesday, July 20, 2010

Changes to the CLA Exam

The Preparing for the CLA post is one of the most highly visited links on my blog, so I figured I should post some updates that I just learned about (thanks to JG's post on LAVA) to the way the CLA exam is now done. Much of the advice I gave in the aforementioned post is no longer valid, so I'd like to highlight some of the new features of the CLA Exam as described on the NI CLA prep website:
  • No more written portion - When I took the CLA exam, it contained a written portion that was 40% of my score. This part of the exam has been removed, which now makes the CLA a 100% practical exam.
  • Customize LabVIEW settings prior to exam start - When I took the exam, I had to spend the first few minutes after the clock started customizing LabVIEW (adding Quick Drop shortcuts, turning off auto wire routing, etc. etc.) before I even read the first question. But now, it seems you can ask your proctor to allow you to customize LabVIEW *before* starting the exam. The following is a direct quote from the new CLA Exam Preparation Guide (page 2) on ni.com: "Please note that you will not receive extra exam time to compensate for non-familiarity with the LabVIEW environment. If you need time to customize the environment, please make arrangements with your proctor to hold off on giving you the exam packet until you are ready to start the exam."
  • Sample Exam Available - There is now a CLA Practice Exam available...this is a great asset in CLA preparation that I highly recommend taking very seriously. There is also an exam solution available.
  • Requirements tracking - 30% of your CLA score is now determined by requirements tracking, the details of which are described in the practice exam and prep guide documents linked above. The exam graders will be using NI Requirements Gateway to verify requirement tracking in your VIs, so make sure you adhere to the [Covers: ] syntax described in the prep guide and sample exam. Note that knowledge of NI Requirements Gateway is *not* a requirement for the CLA.
Looking at the changes, I think they're probably for the best. I personally found the written portion of the CLA when I took it to be relatively easy and straightforward. But I know that written exams are notoriously hard to grade, and there might potentially be language barriers for some test takers. It looks like the test writers are expecting the additional requirements tracking to take roughly the same amount of time as the written portion of the exam, since the sample exam is very similar to the actual exam I took for my CLA, with the addition of the requirements tracking information.

Friday, July 16, 2010

Conclusions - The Diagram Cleanup Experiment

It's been just about a year since I embarked on The Diagram Cleanup Experiment. I attempted to use block diagram cleanup on just about every VI I wrote in LabVIEW 2009 this year. With such heavy use of the feature, I have come to the following conclusions:
  • Use it on moderately-sized diagrams - The majority of the VIs I write fit on one screen, and have relatively low levels of nesting. For these kinds of VIs, it is *way* faster to quickly write the VI, then press Ctrl-U to clean it up. The cleanup results in these cases, although not perfect, are acceptable. The diagrams are readable enough to avoid maintenance headaches down the road.
  • Don't use it on large diagrams - Diagram cleanup still has trouble with large diagrams. For top-level state machines, or similar architecture-level VIs, cleanup does not respect the arrangement of the diagram, which, for these VIs, is crucial to the understanding of the VI. I have decided that it is still best for me to arrange these diagrams myself.
  • Don't use it on heavily-nested diagrams - As I mentioned in my progress report, diagram cleanup completely explodes the diagram if there is heavy structure nesting. It simply can't figure out how to condense space in multiple frames simultaneously. Until it does, I will continue to arrange heavily-nested diagrams myself.
  • Mixed results with Tools > Options settings - I tried several times to tweak the settings in Tools > Options > Block Diagram > Block Diagram Cleanup to see if that would improve the cleanup arrangement, but I couldn't figure out a definitive collection of settings that always worked better. If anyone has any specific suggestions for settings that seem to improve the cleanup layout, let me know.
So what's next? I just posted the following idea on the LabVIEW Idea Exchange:

Tell Block Diagram Cleanup what "Clean" Looks Like

I think the easiest way to get diagram cleanup to arrange VIs to my liking is to show it VIs that I like. :) Please kudo the idea if you agree.

So that's pretty much it. In short--I like the feature, I will continue to use it because it helps me program faster, but it definitely has room for improvement.