LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I suppress (or catch) a serial port read timeout exception?

Hi,
 
I wish to be able to read a serial port by polling it in a loop where I allow the timeout to occur without causing an exception.  The default operation is that the timeout causes a popup to appear with a NON-FATAL RUN-TIME ERROR message.  How do I suppress or catch this exception so I can continue to poll the port?
 
Thanks,
Brian
0 Kudos
Message 1 of 5
(7,260 Views)
Hi Brian,

This popup only comes up if you are running your application in debug mode, so changing to release mode will avoid the popup.  If you need to avoid it in debug mode as well, you can temporarily disable breaking on library errors with the SetBOLE function as follows:

SetBOLE(0);
status = ComRd(...);
SetBOLE(1);
/* handle status yourself */

It is still a good idea to check the return value and handle any errors yourself, if you are not already doing so.

I hope this helps.

Mert A.
National Instruments
0 Kudos
Message 2 of 5
(7,255 Views)

Thanks!  I'll try the SetBOLE and see if it works.

 

I guess I still have to wonder why the application would shut down (when compiled in 'release' mode) just because the call to the hardware has timed out.  I'm a programmer and I *never* count on the hardware to do what I want!  I'd already put in code to handle the status message by retrying the command and displaying an error message, but the code couldn't run because the application had already quit.  Worse, it was one of those errors that only shows up after the application's been running for 45 minutes or so, so you hate to lose all the other work.

 

But thanks again for your help.

0 Kudos
Message 3 of 5
(6,988 Views)

It sounds like your release executable is crashing, and unfortunately in your case, crashing sporadically (i.e. after 45 minutes of normal operation). From what you said, it sounds like the debug build does not crash. The crash may or may not have anything to do with the read timeout. I would advise debugging the problem by putting in some logging code to try to pinpoint the code that causes the crash. Also, if you haven't already, you might try setting the initialized on the "Uninitialized local variables detection" under Options>>Build to Aggressive and recompiling. Sometimes errors that occur in release builds don't show up in the debug builds because of automatic zero-initialization.

 

Mert A.

National Instruments

0 Kudos
Message 4 of 5
(6,935 Views)

Hi Brian,

 

If you do not disable "break on library errors" (BOLE) option, the code will stop in the debugger as if it hits a breakpoint.

However, you do not have to quit if it is not a "fatal run time error". The serial read time-out is a non-fatal error.

When the debugger stops, simply click the green "Go" button.

 

If you disable BOLE and run in release mode you will not get an error popup for the serial read timeout.

But you have to check the ComRd return value to catch the problem.

Probably your hardware causes a read timeout after that 45 minutes, that's why you only encounter it then.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 5
(6,904 Views)