LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Most efficient way (best practices) for checking each subVI executed without error

Highlighted

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:

Untitled.png

 

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:

Untitle3d.png

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?

 

 

 

0 Kudos
Message 1 of 6
(491 Views)

Hi Skoda,

 

add error IO to your subVIs. Set an error output when your DLL call does not return "zero"…

 

Then use the standard error wires!

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 2 of 6
(482 Views)

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 3 of 6
(457 Views)

Look into the state machine architecture. Here is a very basic version of what you need to do.

Tim
GHSP
Message 4 of 6
(443 Views)

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:

ErrCapture.PNG

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.

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
Message 5 of 6
(434 Views)

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.

 

ErrStateCapture.PNG

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
Message 6 of 6
(425 Views)