locked
window form refresh and serial communication RRS feed

  • Question

  • hi there,

    i have a device that communicates with the pc via a serial to usb cable.
    so i have made windows form with a serial communication to speak with it.

    the communication is every 125ms so every time it checks if the
    com port is open and sends the new message.

    the problem is that if the usb is not connected the program tries every 125 ms
    to connect to the serial port and the busy cursor appears always and the form
    is not responding to any action (for example enter into the menu or refresh a listbox).

    any ideas?

    i have also an other problem that perhaps it is not for this forum but i will mension it in
    case somebody knows.

    i have tried multiple times to connect and disconnect the usb while the program is running.
    thats mean that the serial connection stopped and started all over again several time.
    The problem is that occationaly it shows an error "unable to open com port"

    any ideas?

    thanks in advance

    Wednesday, June 24, 2009 5:42 AM

Answers

  • Serial ports date back to the stone-age of computing.  Back when the only kind of plug-and-play was a screwdriver with the power off.  Accordingly, it has no way to deal with the hardware disappearing while it is in use, nor does it have a way to signal that the hardware suddenly appeared.  The SerialPort class will in fact crash your program when you pop the USB cable.  You cannot make this work unless you can resist the urge to disconnect the device while it is in use.

    Contact the manufacturer of your device for a native USB driver interface that leverages the abilities of the USB bus.  Don't get your hopes up.

    Hans Passant.
    • Marked as answer by Kira Qian Tuesday, June 30, 2009 6:29 AM
    Wednesday, June 24, 2009 12:14 PM

All replies

  • anyone any idea?
    Wednesday, June 24, 2009 9:09 AM
  • Serial ports date back to the stone-age of computing.  Back when the only kind of plug-and-play was a screwdriver with the power off.  Accordingly, it has no way to deal with the hardware disappearing while it is in use, nor does it have a way to signal that the hardware suddenly appeared.  The SerialPort class will in fact crash your program when you pop the USB cable.  You cannot make this work unless you can resist the urge to disconnect the device while it is in use.

    Contact the manufacturer of your device for a native USB driver interface that leverages the abilities of the USB bus.  Don't get your hopes up.

    Hans Passant.
    • Marked as answer by Kira Qian Tuesday, June 30, 2009 6:29 AM
    Wednesday, June 24, 2009 12:14 PM