From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

A more elegant solution, perhaps, to 64+ case structures?

Hello everyone!

Can I please get some recommendations on getting my block diagram a bit tidier? Referring to the VI, a user has a selection of 1-64 of channels to scan. For each channel, I've enlisted a case structure, and have wound up with, you guessed it, 64 case structures. Can I substitute the 64 case structures with something more elegant while maintaining the same layout in the Front Panel? An additional 64 channels is coming to the VI soon and, if possible, I want to avoid another 64 case structures! Any help is greatly appreciated!Smiley Very Happy

0 Kudos
Message 1 of 9
(3,491 Views)

I did not see 64 case structures, I assume you are talking about event structures. A few suggestions:

 

  1. Break your structure into two loops, producer & consumer. You will tie up your event structure with all of the loops you have processing.
  2. Make the block diagram smaller when uploading.
  3. I am not sure what you want to do with each channel, but they can all be combined into one event case, use the reference and label to differentiate. See inline picture.

mcduff

 

Snippet1.png

 

 

0 Kudos
Message 2 of 9
(3,468 Views)

Hi mcduff,

 

The case structures, I believe, are in the event structure "SCAN". Warning, it's really messy. Smiley Tongue

0 Kudos
Message 3 of 9
(3,465 Views)

I still am not seeing the case structures, maybe my monitor is too small. A few things for that case:

  1. You do not need to index explicity, see inline image.
  2. Use an array as an indicator, then you do not need index the array at all. When you have another 64 channels, use another array.

mcduff

 

Snippet2.png

Message 4 of 9
(3,461 Views)

I highly recommend you go and browse through the Rube Goldberg thread.  Your code has earned you a place in it.

Message 5 of 9
(3,441 Views)

Ouch.  Yeah the better way to handle the values, might be to use an array of booleans, and then you can index over each one.  You can do this through control references which seems to work alright and will scale with the number of buttons you add.  Of course this same technique could be used on an array of booleans, or a listbox with check boxes might be a more intuitive UI design as shown here.

 

Example_VI_BD.png

0 Kudos
Message 6 of 9
(3,416 Views)

Replace the 64 booleans with a single boolean and a channel control.  Select the desired channel, push the boolean.

CLA
Message 7 of 9
(3,413 Views)

If you really want all these buttons, use 2D array of booleans and numeric and the code will shrink to  few % of what you currently have. (Keep them 1D in the code and reshape from/to 2D for the front panel).

 

But, yes, this code is not maintainable, breaking all rules of plain common sense. There are tons of places where the code could get trapped inside inner loops e.g. if the right response is never received, for example. Event frames should complete quickly and not deal with lenghty code and inner loops.

 

Sorry, I cannot give more detailed advice, because my monitor is not wall sized and does not have 40 million pixels to efficiently navigate that mess.

 

If you keep working on this VI, you are just digging yourself deeper into a hole. Do a few simple LabVIEW tutorials, read the entire Rube Goldberg thread (all 1700+ messages!), then start from scratch with scalable code that fits on one screen.

0 Kudos
Message 8 of 9
(3,327 Views)

@altenbach wrote:

If you really want all these buttons, use 2D array of booleans and numeric and the code will shrink to  few % of what you currently have. (Keep them 1D in the code and reshape from/to 2D for the front panel).


Here's a quick draft of what I had in mind. The code basically fits on a postage stamp! 😄

The main control is a 2D array of clusters, where each element is a channel name string and a boolean. The string is disabled so it cannot be changed by the operator.

 

 

Download All
0 Kudos
Message 9 of 9
(3,320 Views)