LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simplify code?

Hi,
 
I have been working on a small problem in my application for some time now. It does work, but is there a smarter way to do this? I have attatched the part of my application that I had the with. It is explained in the block diagram.
 
-Christian
0 Kudos
Message 1 of 8
(4,211 Views)
Christian,

I suggest a state machine, probably queue driven. I modified your vi to show (crudely) how this can work.

Lynn
0 Kudos
Message 2 of 8
(4,191 Views)
...now I'll have a look at the first guy's reply.
 
My code looks to be a fair bit smaller in kbs. Smiley Wink
 
Mark.
Message 3 of 8
(4,188 Views)

I liked the last solution by Mark Smiley Happy  State machines are smart, but that code seemed alot more complicated.

-Christian

0 Kudos
Message 4 of 8
(4,161 Views)

Christian

It might be possible to dramatically simplify the code by adding an inner FOR loop that runs (1) once in the default behavior and (2) twice under reset condition. See attached sketch (LabVIEW 8.0)

(One side effect is the fact that the loop cannot be stopped between "reset" and "additional reset commands" because the stop button is not read during this sequence of events. This might actually be desired ;))

Message 5 of 8
(4,148 Views)

Nice!

But there is a problem, I need the string command outside the for-loop. (Because the command is supposed to be used another place.) If it is placed outside it only displays the final value, when the for-loop is finished, and then I miss the additional reset command. This might be the side-effect you explained...

-Christian

Message Edited by Christian_nor on 12-09-2005 03:06 AM

0 Kudos
Message 6 of 8
(4,146 Views)
Well, if you currently just need it outside the FOR loop(but inside the while loop), maybe you should place your other code also inside the FOR loop, right next to the string indicator. You could even add a case structure controlled by the string and place the approriate code for each of the three possible cases in it.
 
See attached sketch (LabVIEW 8.0).

Message Edited by altenbach on 12-09-2005 01:21 AM

0 Kudos
Message 7 of 8
(4,138 Views)
Here's another variation - it eliminates the case structure, which has the advantage of having all the values visible on the diagram at one time (code hidden in cases is a slight disadvantage of LabVIEW).
 
Of course, if you need to execute additional code per default/reset command, then you might be better off keeping the case structure.
 
Just thought you might be interested in seeing how you can use "array of clusters" constants, generally.
 
Mark.
Message 8 of 8
(4,132 Views)