I have to write a program for production testing that uses functions from dll.
Functions from dll return 0 if no error accurs in their execution, like this:
In my program I have to call a lot of functions and for each call of every function I have to check if function returned 0. And if function does NOT return 0, the next function from the program must NOT be executed and the
program should jump to "cleanup" VI (close handles etc.)
My Idea was to implemet "zero checking" by using case structure like this:
Each function is connected to case selector terminal (?) and I check if function returned 0. If function does NOT return 0, the other case for "cleanup the program" is executed.
The problem is that there are a lot of function and there are a lot of nested Case Structures. That leeds to very ugly and hard to read program.
My Question is:
What would be more elegant, efficient way of implement "zero (error) checking" in each of subVI?
add error IO to your subVIs. Set an error output when your DLL call does not return "zero"…
Then use the standard error wires!
I second the use of error clusters. With the error clusters, you can also store what the error was and which VI caused it. In fact, you should look at using the Error Ring.
Then you just have a case structure around all of the code in each subVI with the error in wired to the case selector. The green case (no error) will contain the normal code and the red case (error) can just pass the current error on and any default data. This would eliminate the "pyramid" of case structures you are starting to do since you can then just chain each of your subVIs together and let their individual error handling do the rest.
Look into the state machine architecture. Here is a very basic version of what you need to do.
As everyone said add the error cluster to your vi's and use a State Machine architecture with each function call being its own "state" in the machine.
Then do something like this:
Now if any state exits with an error your program will override the next state and goto the error state
Using the error cluster instead of just a boolean allows you to setup custom error messages in each function's sub-vi so you will know exactly what function failed.
Just to avoid any confusion I thought I would explain further. As you can see in the post above I also have a boolean going to the OR on the error detection. This comes from my Stop button and rather than having both an Error state and a Stop state that do exactly the same thing, (close files safe shutdown) pressing the Stop button also sends it to the Error state but I only run through the Error Handler and pop-up an error message if there is an error.