是否可以知道 RS232 端口的连接状态? [英] Is it possible to know the connection status of a RS232 port?

查看:127
本文介绍了是否可以知道 RS232 端口的连接状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 9 针电缆中,你们建议使用哪个信号/针来检查连接状态?

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

到目前为止,我使用的是 DSR 信号,因为在我测试的硬件中,如果电缆连接正确,则 DSR 信号为 1断开连接的 DSR 变为 0.但是,对于其他驱动程序和/或操作系统,DSR 在消息传输过程中会发生变化或始终为 0.因此,除非在晴天 25ºC 的受控条件下,否则我认为此 DSR 信号并不可靠.

So far I'm using the DSR signal because, in the hardware I'm testing, if the cable is properly connected the DSR signal is 1 if it gets disconnected DSR goes to 0. However with another drivers and/or operating systems DSR varies during message transmission or is always 0. So I don't find this DSR signal that reliable unless in controlled conditions at 25ºC in a sunny day.

那么我如何知道在给定的时间点我是否仍然连接,即电缆没有断开连接?

So how can I know at a given point in time if I'm still connected, i.e. the cable didn't got disconnected?

请注意,连接可能会丢失,而且我的串行端口仍然存在并在操作系统的端口列表中打开,因此检查端口存在并不能解决任何问题.我唯一的希望是依靠 9 个引脚之一来检查它.

Note that the connection can be lost and I still have my serial port present and opened in my operating system's ports list, so checking for port presence solves nothing. My only hope is to rely on one of the 9 pins to check it.

我也不想发送或接收字节来检查连接状态.应该有更好的方法...

Also I do not want to send or receive bytes to check the connection status. There should be a better way...

谢谢!

推荐答案

在任何给定时间没有确定串行连接状态的可靠方法.

There is no reliable way of determining Serial Connection status at any given time.

标准方法是让每一方都将 DTR 调高,这样你所连接的任何人都会看到 DSR,从而知道另一端有什么东西.您没有具体说明连接的确切类型,但由于您遇到了这些问题,我暂时假设它是 DTE/DTE 并且需要空调制解调器连接.

The standard approach is for each side to turn DTR to high, so whoever you're connected to sees DSR and thus knows something is on the other end. You haven't specifically stated the exact type of connection, but since you're having these issues, I'm going to assume for the moment that it is DTE/DTE and requires a null modem connection.

更糟糕的是,问题可能出在电缆本身而不是软件或操作系统上.

What makes this worse is that the problem may be with the cable itself and not with the software or the OS.

查看此页面了解更多信息,但还有更多一个空调制解调器电缆的引脚.

See this page for more info, but there is more than one pinout for a null modem cables.

零调制解调器电缆内部所需的最少布线如下所示:

The minimum wiring required inside the null modem cable looks like this:

这就是所谓的无握手零调制解调器电缆".您可以看到 DTR 和 DSR 引脚(引脚 6 和 4)无处可去.当使用此电缆插入某些东西时,DSR 引脚状态不会改变.

This is what's called a "No-Handshake null modem cable". You can see that the DTR and DSR pins (pin 6 and 4) go nowhere. DSR pin states will not change when something is plugged in using this cable.

然后是这个:

这是一条环回握手电缆".您可以在此处看到 DTR 和 DSR(引脚 6 和 4)在每个连接器处相互桥接,并且不沿电缆长度方向延伸.这意味着,如果您将 DTR 设置得较高,您将看到一个 DSR - 您自己的.这告诉您有一条串行电缆连接到您的端口,但该电缆的另一端不一定连接到任何地方.您可以将电缆切成两半并将其插入鼻子,您仍然会看到软件告诉您的是有效连接.

This is a "Loop-Back handshake cable". You can see here that DTR and DSR (pins 6 and 4) are bridged to eachother at each connector and don't go along the length of the cable. This means that if you set your DTR high, you will see a DSR - your own. This tells you that there is a serial cable connected to your port, but the other end of that cable doesn't necessarily go anywhere. You could chop the cable in half and stick it up your nose and you'd still see what the software is telling you is a valid connection.

更好的解决方案是使用如下所示的电缆:

The better solution is a cable that looks like this:

或者像这样

这是部分或完整的握手电缆.您可以看到每一侧的引脚 4 进入另一侧的引脚 6.所以每一方都可以将DTR设置为高,并查看对方的DSR.这是您可以准确确定电缆是否实际连接到设备的唯一情况;即便如此,只有在每一方都同意设置 DTR 的情况下.除非你控制沟通的双方,否则这将是命中注定的.

This is a partial or full handshake cable. You can see that each side's pin 4 goes into the other's pin6. So each side can set DTR high, and see the other party's DSR. This is the only case where you can accurately determine if the cable is actually connected to a device; and even then only if each side agrees set DTR. Unless you control both sides of the communication, this is going to be hit or miss.

这是最好的做法,无需通过网络发送数据并等待有效回复.

That's the best you can do without sending data down the wire and waiting for a valid reply.

这篇关于是否可以知道 RS232 端口的连接状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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