locked
SerialPort.IsOpen - Speed up response RRS feed

  • Question

  • Hello,

    I am doing some communication with a bluetooth device, using the System.IO.Ports.SerialPort class.

    This is going ok, but I'm trying to handle disconnections gracefully and it's a bit slow.

    Currently I ping my device every five seconds, and expect a response within a few seconds. If this fails I check 

    SerialPort.IsOpen

    and if it's not I try SerialPort.Open. Using a timer I repeat IsOpen -> Open until IsOpen returns true.

    I can't think of anything better than pinging my device frequently, however SerialPort.IsOpen seems very slow (~10 seconds) before it decides that the port is closed.

    Does anyone have any ideas please? Far short of writing my own serial port class I'm a bit stuck. No amount of googling is helping either.

    Many thanks for your time,

    Russ
    Thursday, July 19, 2012 3:37 PM

Answers

  • Override WndProc and handle the  WM_DEVICECHANGE message.
    • Proposed as answer by Mike Feng Friday, July 20, 2012 9:49 AM
    • Marked as answer by Mike Feng Friday, July 27, 2012 9:59 AM
    Thursday, July 19, 2012 4:06 PM