How to reconnect a serial port connection when connection is broken?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnnymarcelo
    New Member
    • Feb 2011
    • 1

    How to reconnect a serial port connection when connection is broken?

    Good morning everybody.

    First of all I would like to thanks for any answer or clue regarding this issue.

    I am working with a gas detector application, and the customer wants I control all possible problems with the hardware.

    For example, The gas detector application should be able to control if the hardware that send the signal is power off, or there is a problem with the cable.

    I am using serial port communication. To start the communication, I have to send a package then the hardware start sending data. This process is in a loop. So, the result of these readings is a graph. The problem occurs when I disconnect the cable to read the hardware, The java application does not produce any exception. I mean it keep working with out any output. The gas detector app keep stuck in a sentences like this: outputStream.wr ite(startReadin gPackage). It does not send back any response.

    I really appreciate if somebody gives me a help. I have to finish this part, it is rather urgent.

    Thanks.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    if you are using a 'normal' COM port builtin to the motherboard or on a PCI card I would exepect no problem if the cable was disconnected - data reception should resume when it is reconnected.
    On the other hand if you are using a something like a USB/RS232 converter, e.g.I use


    when the USB is disconnected you loose the serial port and have to restart the Java serial port software.
    In similar applications I send data regularly, e.g. every 10 seconds or 10 minutes depending on the application. You could have a timer in the Java application which if nothing is received within a set time you reinitialise the serial port and attempt reconnection.
    In practice I gave up using serial ports for this tye of application sometime ago. I now use 10/100baseT ethernet, WiFi, Zigbee, MiWi, etc. Many modern microcontroller s either have facilities onchip or as peripherals connected via SPI or I2C.

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      thinking about this a bit more, could noise be generated when you disconnect the cable which is interpreted by the serial ports as a faulty character, e.g. an overrun error? the serial port then goes into a error state which you have to clear. What type of microcontroller do you have managing the gas detector? read up on the UART interface error conditions and the action required to clear them.

      Comment

      Working...