How to detect the serial cable been unplugged

Hi all,

I wrote a small application using the javax.comm api to talk to an external device. I would like to know how to detect if the cable is unplugged. Right now, if I run the application with cable not connected, if i start communicate with the device, the program will hang.

The program works fine with connection is there.

Please help me.

[368 byte] By [ngo4lifea] at [2007-11-27 4:28:46]
# 1
You'd have to put in some sort of ping method to wait for a response and cancel it if no response is received within a certain amount of time - I'd be surprised if there was a way to detect it physically.
DavidKNa at 2007-7-12 9:37:37 > top of Java-index,Java Essentials,New To Java...
# 2

there are ways that do what he wants to do (though not what he says he wants to do), but they need to be implemented in hardware.

You could monitor the voltage on some of the pins on the serial connection for example, which tells you whether there's a signal on the line.

That of course would not detect whether the cable is there, as it has preconditions. It detects whether there's a signal on the cable, which requires that the systems on both ends of the cable are powered up and that the cable itself is not faulty.

jwentinga at 2007-7-12 9:37:37 > top of Java-index,Java Essentials,New To Java...