08-15-2013 05:14 PM
No, simply selecting code and turning it into a subVI is not cleaning up code. When writing code you should start with some design of what needs to be accomplished. Try to think of tasks that need to be perform. These tasks can be a basis for what subVIs you need to create. They also allow you to reuse code. Organize your code into libraries and projects. Projects will contain your applications and the libraries will be groups of code that are related. For example, you could have a library for you code which controls on piece type of scope or DAQ. (You can also use LVOOP but we will leave that for a later discussion). In addition, subVIs should never be large entities. They should be defined to do one, or very few things, and nothing else. More complex subVIs will be comprised of these smaller VIs and build upon them. Don't be afraid of creating subVIs as long as they are well defined. Just selecting a bunch of unrelated code and turning it into a subVI is not code design. Creating subVIs with very specific purposes is a good coding practice.
I also try to keep my code fairly clean to start with. Sloppy code will generally remain sloppy because you are rarely given time to go back and clean it up. You can use diagram cleanup on small VIs which helps, but on large block diagrams it can often make it worse. Therefore try to get in the habit of using good coding techniques from the start.
With the exception of the top level UI and application framework VIs below is a very typical block diagram of the type of code we write.
08-17-2013 01:29 PM
Not sure what you mean by linked input tunnels. I get a cursor with a square when I click create. Not sure what I'm supposed to do with this or how I can use the cursor.
Quite new to labview so sorry if this sounds pretty basic
08-17-2013 01:39 PM
Ok it seems to be working now! What I did was simply wire all the remaining cases across the loop. What does this do though? Let's say I'm running a case where I don't need to send any queues to the consumer - what values are sent there?
08-17-2013 01:59 PM
Ok, first you need to understand that the queue is a reference to a location in memory. This reference does not need to be maintained in a shift register. Simply wire directly into the queue from outside the loop once. Then in cases where you don't need to use the queue just ignore it. The problem you had is that by not wiring the queue from the left tunnel to the right tunnel, you were telling LabVIEW to set the queue back to "not a reference", this was being shifted around by the shift register so that the queue reference to the queue was lost. You should check out the Queued message handler template that ships with LabVIEW 2012, those template projects will give you a really good starting point.
As far as your comment regarding a linked input tunnel, Right-click the output tunnel (usually on the right side of the case structure), then navigate to "Linked Input Tunnel". For your case choose "Create and wire unused cases". This will link the queue in on the left to the queue out on the right. All new created cases will be automatically wired. Also on that same right-click menu, uncheck "Use Default If Unwired", that option will cause you more pain than it will save you.