07-12-2012 08:49 AM
I'm relatively new to LabVIEW and I keep getting into this situation:
when the tasks at hand get a little more complicated, my programs use a lot of nested structures like loop, case, and sequence structures. Now, how does one exit nested structures quickly and cleanly? In a programming language like Java you could throw an exception, but in LabVIEW I'm apparently condemned to use even more case structures to check for error conditions so I can skip and get out immediately when an error has occurred or the abort button was pressed.
I feel I'm doing something terribly wrong. Any input on how I can structure my programs better to avoid this?
Thanks in advance.
Solved! Go to Solution.
07-12-2012 08:51 AM - edited 07-12-2012 08:52 AM
Hi someguy,
ever heard of "state machines" or "producer-consumer pattern"?
You will find a lot of information here in the forum...
When you are new to LabVIEW: you will also find a lot of free resources on NI's website for learning LabVIEW!
07-12-2012 08:54 AM
Hi,
An example would be good in this case, can you post one?
Generally speaking, if you are using a lot of case structures and nested loops, from a software development point of view, I would say the program is not being planned out. Maybe
Again, in general terms, you should use a state machine with lots of cases that are not nested, so that when you do a specific piece of work you leave the case and are back in the main loop. If there are a lot of cases, and it sounds like it, then you should try a queue driven state machine, that way you have more control over what case comes next.
Also, you could try a producer consumer, which is queue driven, to more cleanly program the code.
07-12-2012 09:07 AM - edited 07-12-2012 09:08 AM
Throwing exceptions is generally not something you should be doing anyways. But to reiterate what has already been said, learn to use state machines. There are examples all over the place.
07-12-2012 11:44 AM - edited 07-12-2012 11:52 AM
what i like to use is the "notifier operatons". whats neat about it is you can use it for clocking your loops using the timout node and use the timeout bool to stop the loop when you send the notification messege...just make sure you create a control terminal for the "notifier" at low level inorder to recieve the messege from the top level VI.
07-17-2012 08:07 AM
Thanks for all your input! It's greatly appreciated.
I've switched to a state machine now. Everything works fine. Code is much cleaner.
The "notifier operations" thing also look interesting. I'll study that later.