Sonsivri

Electronics => General Electronics => Topic started by: xpress_embedo on April 11, 2014, 07:47:53 07:47



Title: How to detect whether RS232 cable is connected to PC or not?
Post by: xpress_embedo on April 11, 2014, 07:47:53 07:47
Hello Everyone.
how can i detect whether a RS232 cable is connected to PC.
Actually i had to send data to pc and receive data from pc with the help of micro-controller.
But when no cable is connected with PC then i have to glow an led indicating the link is not okay.
Please suggest me a way to implement this.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: pickit2 on April 11, 2014, 08:38:14 08:38
If you look at RS232 specs, you will see DTR and other Named Signal Paths, you just have to monitor one that suits.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: Sideshow Bob on April 11, 2014, 10:12:16 10:12
And if it is a true RS232 port. The signal level will be either in range minus 9 to 12 volt or plus 9 to 12 volt. That can be used to your advantage. Will this setup send data in a continuous stream or more sporadic. Which pins in the RS232 conector will be used besides GND, TXD and  RXD


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: xpress_embedo on April 11, 2014, 04:54:52 16:54
@Sideshow Bob
Quote
And if it is a true RS232 port. The signal level will be either in range minus 9 to 12 volt or plus 9 to 12 volt. That can be used to your advantage. Will this setup send data in a continuous stream or more sporadic. Which pins in the RS232 connector will be used besides GND, TXD and  RXD

I am planning just to use RXD, TXD and GND, but for detection purpose i need to use DTR i think, as i am getting around 9V on this pin (PIN 4 of DB-9 Connector), hope it will remain same always.


@pickit2
Quote
If you look at RS232 specs, you will see DTR and other Named Signal Paths, you just have to monitor one that suits.
Thanks pickit2, i will use DTR, is it okay to use this pin for sensing, i just want to confirm as i had seen some of the post on some forum, by which people uses RS232 to power there devices and they used DTR pin.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: mario2000 on April 11, 2014, 05:55:37 17:55
It is easy, you have to connect TXD with RXD, then sends a data vera and this is reflected in the reception of data as echo.

Pins: 2-3

(http://www.scourge.fr/mathdesc/lb/img/null_cable.png)



Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: xpress_embedo on April 11, 2014, 06:06:17 18:06
Let me clear exactly what i want to do.
My device is having two serial ports, both are connected to two different PC, only one pc will communicate with my device at a time, when the link betweeen the Firsr RS232 gets broke, i haveto use the second port.

And if i shrt my trans and receive line, then all gets echoed back to me whichis not my requirement.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: zuisti on April 11, 2014, 08:16:12 20:16
If the PC is connected, the PC-side TX  signal level will be in range minus 9 to 12 volt, ie definitely a non-positive voltage (else it will be floating, ie undetermined). Using a big pullup resistor (to VCC) for example, it can be sensed at uC side using an additional input pin, or - maybe - it will be the classic "break" condition which is also can be detected via SW.

Only an idea ...


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: pickit2 on April 11, 2014, 08:21:09 20:21
did you read the rs232 specs, in there is a part about handshaking...
FFS RTFM not what others tell you to do, by not reading specs you don't learn for the next time.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: ReefGuru on April 26, 2014, 07:54:28 19:54
Why not just use a simple keep-alive where you PC side client sends a heartbeat, or responds to a ping. If the heartbeat pong is not seen by the micro the port is down. This way you can still use 3 wire serial and not have to worry about sensing line voltages, etc.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: xpress_embedo on April 27, 2014, 02:42:43 02:42
In My Application, there is a Software on PC, which Sends and Receives Data from the device, in any case of communication failure, i have to switch.
What i am thinking is that, in PC Software i will set DTR or RTS to a known state, this will help detection in the device easy, as these two pins can be set to any level either high or low using PC Serial Port Programming.
And on Device side i will detect this signal, if signal is there then Connection is okay otherwise not.

I think this will solve my problem.
Hardware base methods are good as my Specification Given to me suggests not to use any Software based method to detect link failure as that will only slow down the speed of the whole setup.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: CocaCola on April 27, 2014, 03:05:48 03:05
I personally like the the ping/pong stay alive...  Depending on how fast it has to be able to detect the disconnect ping/pong works well and can be done with low overhead...  If either/or side misses a ping/pong responses within the given time period then the connection can be assumed dead or a second try made to confirm it wasn't simply a glitch before flagging the connection dead...


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: xpress_embedo on April 27, 2014, 06:45:54 06:45
Thanks for your help.

I will implement the ping pong method and the hardware detection method by sensing dtr pin, if it doesnt cause delay in my whole setup.


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: ReefGuru on May 15, 2014, 05:23:28 17:23
Any update on your solution?


Title: Re: How to detect whether RS232 cable is connected to PC or not?
Post by: DreamCat on May 19, 2014, 05:46:39 05:46
Good idea from ReeGuru.
if you learned some of TCP/IP, it is too easy about communication.
I often need write these kind of program for MCU, so I done various packe format for various application, include the CRC, auto answer, etc.