Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using RS232 serial port for payment transaction but not able check cable disconnected or not

What I have tried:

I tried with Data_Received, ErrorReceived and PinChanged event but no use
Posted
Updated 21-Feb-17 23:12pm
v2

There is no general solution to detect if a cable is connected.

If the used devices does not use the DTR and DTS lines, you can use a special cable that has a connection between DTR and DTS. Then you can set the DTR output and read the DSR input to check if that special cable is plugged in. But this will only check if the cable is plugged in and not if a device is connected.

If a connected device is using hardware flow control (DTR/DTS or RTS/CTS), the status lines can be used in a similar way. The device will then indicate it's presence via the DSR or CTS line (usually depening on the DTR / RTS line). But this will only work when the device is powered.

To set and read these status lines see the corresponding functions in the SerialPort Class (System.IO.Ports)[^].

To check if a device is present that does not use hardware flow control, the only solution is to send a command and wait for an answer for some time (time out detection).

Note that all these solutions are device dependant. There is no general solution.
 
Share this answer
 
 
Share this answer
 
Comments
Member 11318299 22-Feb-17 4:44am    
I already googled it but no use
Graeme_Grant 22-Feb-17 4:51am    
did you click on the link that I provided above?
Member 11318299 22-Feb-17 4:57am    
yes dude i already searched
Graeme_Grant 22-Feb-17 5:00am    
no, click on the link that I provided above - your answer is there...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900