Is it possible to know the connection status of the RS232 port?

In a 9-pin cable, what signal / pin would you guys recommend to check the connection status?

So far I am using the DSR signal because in the hardware I am testing, if the cable is properly connected, the DSR signal is 1 , if it gets disconnected, the DSR goes to 0 . However, with other drivers and / or operating systems, the DSR changes during message transmission or is always 0. Therefore, I do not find this DSR signal reliable unless under controlled conditions at 25ºC on a sunny day.

So how can I know at a certain point in time if I am still connected, i.e. cable not disconnected?

Note that the connection may be lost and I still have my serial port present and open in the operating system's port list, so checking for the port does not solve anything. My only hope is to rely on one of the 9 contacts to verify this.

Also I don't want to send or receive bytes to check the connection status. There must be a better way ...

Thank!

+1


source to share


1 answer


There is no reliable way to determine the status of a serial connection at any given time.

The standard approach is for each side to turn the DTR high, so anyone you are connected to the DSR and thus knows something on the other end. You haven't specifically specified the exact type of connection, but since you have these problems, I'm going to assume for now that it is DTE / DTE and requires a null modem connection.

To make matters worse, the problem might be with the cable itself, not the software or operating system.

See this page for details , but there are multiple pins for null modem cables.

The minimum wiring required inside a null modem is as follows: No-Handshake Null Modem Cable

This is what is called a "No-handshake null modem cable". You can see that the DTR and DSR pins (pins 6 and 4) are not going anywhere. The state of the DSR pins will not change if something is connected to this cable.

Then this is:

Loop-Back handshake



This is the "Feedback confirmation key". You can see here that DTR and DSR (pins 6 and 4) are connected to each other on each connector and do not run along the length of the cable. This means that if you set the DTR high, you will see DSR - your own. This indicates that a serial cable is connected to your port, but the other end of that cable does not necessarily go anywhere. You can cut the cable in half and attach it to your nose, and you will still see the software telling you that it really is a connection.

The best solution is a cable that looks like this:

Partial handshake

or like this

Full handshake

This is a partial or complete confirmation cable. You can see that each side pin 4 fits into another pin 6. This way, each side can set the DTR high and watch the other side of the DSR. This is the only time you can tell if the cable is actually connected to the device; and even then, only if each party agrees to set the DTR. If you don't control both sides of the connection, this will be hit or miss.

This is the best you can do without sending data over the wires and waiting for a valid response.

+4


source







All Articles