08-10-2009 12:01 PM
I see this all of the time. It was brought up in the Rube Goldberg Code thread, but Altenbach suggested that I move it here.
My post:
I really don't like the idea of using any type of wait function in a while loop to control when operations are done. I see this over and over but what happens if someone wants to kill the program right away but they are taking data every 10 seconds with the way this is coded? The user hits stop and has to potentially wait 10 seconds for the program to actually stop! Try using a case structure and possibly a countdown timer to your advantage to fix this. I'm sure there are many other ways also, if anyone else wants to suggest something.
Altenbachs post:
Problems occur in poorly desinged code with deeply stacked while loops and excessive use of sequences, for example. A well designed state machine will never have such issues.
You are right, hard waits should typically not be used for anything longer than fractions of a second, and ther are plenty of alternatives (such as events with dynamic timeout recalculations (example) as discussed here). A program needs to be able to react to user input, including stop commands, at any time. If you get long stalls, you're definitely doing something wrong. I don't think there is any literature that suggest to use long waits.
What im talking about is ...
As I don't have LabVIEW on this computer it makes starting this thread a little difficult but I thought it would be good to start something where people could post examples of code where they take data or do operations at different intervals, but do it with efficient methods such as using a state machine, etc. This way new users of LabVIEW could see examples of how to program in a way that would, as altenbach said, react to user inputs efficiently, rather than having a crummy program that takes forever to stop, or take in a string, or change of control value etc due to a wait function being added to control when data is taken. I hope this turns into a useful thread!
08-22-2009 01:03 PM
Extremely basic, if not self-evident method, of taking data every 10 seconds, but responding to Stop within a fraction of one second...