10-02-2009 01:07 PM
I am trying to design a good error handling system for a project I am working on, but I have run into a "design" problem. I thought it would be good to ask for some guidance here before I sit down and start create the error handling system.
I have more than one subVI started from one mainVI, each subVI with an individual while loop running (they all stop when I press the same stop button from the mainVI). Each while loop continously retrievews information from various serial devices. Each VISA call etc. can thus of course generate errors. I only want one error dialog box in my mainVI front panel displaying any error that happens.
How would I design this in a good way? As I see it, I would have to use the error dialog box in the mainVI as a global/functional global. Each subVI would then write to this global error dialog box. This could however cause race conditions where only the latest error gets displayed even if earlier errors happened. Appreciate some good advice here.
Solved! Go to Solution.
10-02-2009 02:58 PM
10-02-2009 03:37 PM
Thanks for the reply Mark. Would this not still cause a problem in that only the latest message would be seen? If two of my subVIs' happen to get an error simultaneously (right next to eachother) and thus both post something to the queue, only the last one would be seen?
I just thought of something else that might actually prove that this won't be a problem. Let us say I place 5 subVIs in my mainVI (not connected by wires, thus running parallel). When I run the program, it would pick any of the 5 subVIs to enter first. Wouldn't it run through that whole subVIs while loop before even executing any of the other subVIs while loops? If I then at the start in every subVIs' while loop fetched the global error parameter, they would just not run (if I wire the error flag properly)?
10-02-2009 04:53 PM
No, if you parallel loops then each loop will run concurrently. If you have the same VI placed 5 times in your block diagram (assuming they are not wired together so they could run atthe same time) they can run simulatenaously if the subVI is configured as a reentrant subVI. If it is not then yes, only one of them will run at a time.
As for the errors you would have to do something to handle merging errors if that is what you want. Otherwise you would get an error dialog for each error messge. If you leave your queue unsized (meaning limitless) then your errors will simply get queued. You could implement some logic that once an error was received it would wait x amount of time for other errors so it could merge them before actually displaying the dialog box. Alternatetively you could simply have an error table on your front panel that would be a list of all of the errors that you received.
10-05-2009 08:14 AM
Mark, you are a stand-up guy! Thank you for the explanations. I did try to place 5 of the subVIs on the same mainVI and they could not run simultaneously. I knew VIs by default are non-reentrant, but somehow it never struck me there. You made it all much clearer. I tried placing 2 different subVIs (just for the sake of testing) on a mainVI and of course, as you say, they were both entered.
I also got some good ideas with the queue. Again, thank you.
10-05-2009 08:58 AM
10-05-2009 10:30 AM
Siniz wrote:
How would I handle the error from the queue itself?
It depends on what exactly you want to do. The simplest thing would to simply pull the error from the queue and display a dialog box with the error message. Another would be to have a table on your front panel that you would enter the error information into. You could also write the errors to a log file. You actually have a wide variety of options available to you and it really depends on what your requirements for error processing are.
Obviously this error handler would be in a loop itself and it would run continuously processing the errors. To exit this task at the end of teh application simply destroy the queue. That will cause the dequeue to exit with an error which you can then use to exit the error processing loop.
10-05-2009 03:42 PM
Thanks Mark. I do not think I made myself entirely clear there. I have understood that I can use queues to add all the errors around the application and later dequeue them in an error handling loop; this is what I am doing right now. What I meant was the actual error notification from the Dequeue Element in my error handler loop. That would never get accounted for. I do not think it matters anyway, so it is all good!
Here is how my VI looks (see attached). The 'Connect to COM ports and initialize...' section have several subVIs that can create errors and place on the queue. Since I am only 1,5 weeks old with LabVIEW, maybe could give me some other pointers on my layout? (if you find anything weird.)
10-05-2009 04:04 PM - edited 10-05-2009 04:05 PM
First and foremost I would avoid using the sequence structure. LabVIEW is a data flow language and you should take advantage of that rather than forcing it to be a sequenctial language. Take a look various examples that ship with LabVIEW. You will want to definitely check out the examples for state machines and the producer consumer architectures. Your current code will not meet your needs of continually monitoring for errors since your "Error" queue is not in a parallel loop task.
I have attached a very quik example of a producer consumer architecture with an error processing loop. There are no real code details but this is a simple example of an approach to take for an application. This along with the above examples should give you a decent starting point.
10-05-2009 04:37 PM
I have read before that you should avoid sequence structers, but I found no good way to do what I wanted without using them (especially in the case of the start-up and initialization of several devices). With more experience I will try to get further and further away from this. I will see if I can do something about it right now by looking at some examples. Appreciate it. I marked this thread as solved 🙂