views:

63

answers:

3

I've written an application which reads from a serial device at a very fast rate. The serial port object however, fails to fire the DataReceieved event after about 20 min of continuous operation. Disconnecting and reconnecting the serial programmatically allows the event to work again but for only another 20 min.

I tried using DiscardInBuffer after every DataReceived event and this has appeared to have solved the problem. But the method consumes a lot of cpu time and is degrading the performance of the application. MSDN mentions that the method "Discards data from the serial driver's receive buffer.", but fails to suggest when it should be used.

When and how should DiscardInBuffer be used, and am I using it in the correct context for my particular problem ?

Edit:

After implementing the ErrorReceived event, the event data returned indicated the event type was an "RXOver".

A: 

Two ideas come to mind. The first (horrible) idea: call DiscardInBuffer every 15 to 20 minutes instead of after every DataReceived event. The second (somewhat better) idea: call DiscardInBuffer when you receive the ErrorReceived event, which you should be handling.

Matthew Ferreira
A: 

Hello,

I developed a serial port programming language. It really makes it easier to develop serial port applications. Would you please take a look and try it ? I think you will find it useful. It is freely available on sourceforge.

Download

Thank you,

Orhan

albay