LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial read/write design error handling

I was wondering if anybody could give me some advice on how to handle error in some code I'm working on.  My code basically reads and processes serial data, and occasionally writes responses.  To organize my code, I'm using the producer/consumer design for the read and processes parts and an an additional loop (consumer/provider?) for the write process.  The read loop enqueues data for the process loop and the process loop enqueues data for ther write loop.  I can't post my VI, but the attached image should pretty much capture what I've got. 

 

What I would really like to know is how do I connect the error wires so that I can ensure that if one loop errors and stops, the others error and stop as well? 

 

Also, if I'm approaching this problem in really messed up way, please let me know.  I'm somewhat new to LV, so there are a lot things I still don't know. 

0 Kudos
Message 1 of 2
(2,182 Views)

I have never been a fan of setting up a loop to stop on ANY error. That is what you have now and in my opinion, it's a bad practice. The problem is, multiple example VIs NI provides use this method, including the producer consumer architecture template. Instead, you should handle the error by sending your code into an error state. If it is an error you want to shutdown your application on, there are probably an infinite number of ways to do this, but these are two that come to mind 

 

1. Send messages via queues to other loops telling them to shut down, from the loop the error occured in.

2. You could have a parallel loop that is an error handler loop and has references to all the other loop's queues. Send all error messages to this error handler, and it can initialize the shutdown by broadcasting a message to ever parallel process.

 

Edit: Be careful when your error is in a shift register and wired into your dequeue. The dequeue will never execute if there is an error so you won't ever get the shutdown message. Make sure if your error is in a shift register, after it is handled, it is cleared so that the dequeue can execute.

0 Kudos
Message 2 of 2
(2,178 Views)