LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error handling events

Hi Guys,

I think it's a simple question but i can't find the answer. I have an event structure that has about 6 cases. I have put my main code in the timeout case (BTW is that a bad move?) so that the main code executes if there are no events. One case is the stop for the while loop that the event structure resides in. The other cases call subVi's which make calls to a dll. What i want to know is what should i do if the subVi returns an error? How can i handle that within the Event structure? I want to either display the error or stop the program depending on the error code.

Any suggestions or comments gratefully recieved.

Phil
0 Kudos
Message 1 of 3
(2,812 Views)
You could pass the error of the SubVIs in a shift register of your main loop. In the timeout case you look at the error and handle it.
There could be a problem if you put  all the code in the timeout case. When the code takes some time the event structure is blocked and can't react to incoming events. I would create a parallel loop with a case structure in it. You could send queue commands from the event structure to the second loop. Use the event structure only to react to events and send the queue commands.
By doing so you could also handle the error in the other loop and for example display it in a popup window. The event structure can still react to incoming events then.

cheers, dave
Message 2 of 3
(2,797 Views)


@therealkilkenny wrote:
I have put my main code in the timeout case (BTW is that a bad move?) so that the main code executes if there are no events.

That really depends on what the main code does. As long as the timeout event does something useful (acquiring data, creating errors ;), etc) the solutions is fine. (If it just recalculates the same thing over and over again, it's a waste of CPU.)

Of course if the timeout case really does something useful and it needs to occur at regular intervals, the timeout case is not great, because any other event will mess with the timing. For example if you have a timeout of 1 second and press another button after 999ms, the spacing between timeout events will double for one iteration. This might not be acceptable. You can solve this partially by dynamically recalculating the timeout and feed it via a shift register.

In summary, I would not used the timeout case for anything that should happen very regularly.

Message 3 of 3
(2,782 Views)