LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Challenge: Optimize my Code!

Yesterday I spent quite a bit of time trying to build this vi.  Essentially, it takes an array of ten booleans and searches for which values are true.  It then takes the indexes of all the true elements and builds an array of those indexes.  Those indexes then are used to index an array that stores serial commands for an RS232 instrument.  Is there a simpler way to send a sequence of commands from a user interface that has individual buttons for each command?  The user needs to see all command buttons at once. make his/her choice(es), and execute the sequence.  I can see a way to do this with queues, but you still would have to 'translate' button pushes into indexes.  I hate doing more work than I have to, and I plan on implementing this user interface several times.  Any input to improve it would be appreciated.
 
Grub
 
 
Hell, there are no rules here...we're trying to accomplish something!!! - Thomas Edison
0 Kudos
Message 1 of 10
(3,820 Views)
"Optimize my Code!"

"I hate doing more work than I have to"

Nah, pull the other one.

I can't open your VI as I've only got 6.1, but it sounds like it's something which souldn't be too hard to do.

Why don't you have the booleans in an array and use a for-loop to send the apprporiate commands.  Sounds to me like you've a level of processing too many.

Check out my example

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 2 of 10
(3,803 Views)

Ahhh, I forgot to mention that I'm doing this in RT...so no build arrays allowed.

 

Grub

Hell, there are no rules here...we're trying to accomplish something!!! - Thomas Edison
0 Kudos
Message 3 of 10
(3,797 Views)
I'm not familiar with RT.  No arrays allowed at all or just no dynamic allocation of arrays....?

If the latter, instead of building an array, stick your instrument communication VI inside the case structure of the while loop and that should do it really.

Again, no RT experience..

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 10
(3,780 Views)
I like the boolean array to load steps into a queue. Then use the queue elements to determine the states to execute in a state machine architecture.
0 Kudos
Message 5 of 10
(3,779 Views)

Nice Uncle Bump!

I like the way you used the booleans in the array to set the true or false case.  I had never thought of using it like that.  I think I'll use your solution in my upcoming modules.  Thanks....

 

Grub

Hell, there are no rules here...we're trying to accomplish something!!! - Thomas Edison
0 Kudos
Message 6 of 10
(3,776 Views)

Here is my original implementation...the subVI is the one I posted earlier....

 

Grub

Hell, there are no rules here...we're trying to accomplish something!!! - Thomas Edison
0 Kudos
Message 7 of 10
(3,774 Views)
Why are you jumping through so many hoopsloops 😉 for this simple task? A much simpler version is show in the attached modification. There are many ways to do this.

Message Edited by altenbach on 08-30-2005 08:55 AM

0 Kudos
Message 8 of 10
(3,755 Views)

Thank you altenbach,

I see that in your implementation you also used the booleans from the array to control the case structure.  I have never used the reshape array command, but can se how it would be useful (especially in this example).  Thank you for your input.

 

Grub

Hell, there are no rules here...we're trying to accomplish something!!! - Thomas Edison
0 Kudos
Message 9 of 10
(3,742 Views)
Reshape arrray is one of the more useful, but often overlooked array tools. Even on simple 1D arrays, it can be used to either trim or pad (with zeroes) an existing array to a new lenght. One of the advantages is its efficiency because it does not move data in memory. It is thus very fast. 🙂
 
Check the online help for more details.
Message 10 of 10
(3,735 Views)