如何使用C#检查RS232电缆是否断开? [英] How to check RS232 cable disconnected or not using C#?

查看:188
本文介绍了如何使用C#检查RS232电缆是否断开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RS232串口进行支付交易,但无法检查电缆是否断开



我尝试过:



我试过Data_Received,ErrorReceived和PinChanged事件但没有用

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

推荐答案

没有通用的解决方案来检测如果连接了电缆。



如果使用的设备不使用DTR和DTS线路,您可以使用在DTR和DTS之间连接的特殊电缆。然后你可以设置DTR输出并读取DSR输入以检查是否插入了特殊电缆。但这只会检查电缆是否已插入,而不是设备是否已连接。



如果连接的设备使用硬件流控制(DTR / DTS或RTS / CTS),则可以以类似的方式使用状态行。然后,设备将通过DSR或CTS线路指示它的存在(通常取决于DTR / RTS线路)。但这仅在设备通电时才有效。



要设置和读取这些状态行,请参阅 SerialPort类(System.IO.Ports) [ ^ ]。



要检查是否存在不使用硬件流控制的设备,唯一的解决方案是发送命令并等待一段时间的答案(超时)检测)。



请注意,所有这些解决方案都取决于设备。没有通用解决方案。
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.


Google搜索是您的朋友:如何使用C#检查RS232电缆是否断开连接[ ^ ]
Google Search is your friend: how to check RS232 cable disconnected or not using C#[^]


这篇关于如何使用C#检查RS232电缆是否断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆