From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
05-04-2018 12:47 AM
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?
05-04-2018 01:32 AM
05-04-2018 06:59 AM
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.
05-04-2018 10:07 AM
Look into the state machine architecture. Here is a very basic version of what you need to do.
05-04-2018 11:00 AM - edited 05-04-2018 11:15 AM
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.
05-04-2018 11:32 AM - edited 05-04-2018 11:34 AM
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.