RS232串口无猫联机线指南
2010年2月<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
文章相当好,我趁春节的时间翻译的:
RS232 serial null modem cable wiring and tutorial
RS232串口无猫联机线指南
Null modem without handshaking
Null modem with loop back handshaking
Null modem with partial handshaking
Null modem with full handshaking
Null modem layout selection table
一、 Null modem, an introduction无猫,介绍
Serial communications with RS232. One of the oldest and most widely spread communication methods in computer world. The way this type of communication can be performed is pretty well defined in standards. I.e. with one exception. The standards show the use of DTE/DCE communication, the way a computer should communicate with a peripheral device like a modem. For your information, DTE means data terminal equipment (computers etc.) where DCE is the abbreviation of data communication equipment (modems). One of the main uses of serial communication today where no modem is involved—a serial null modem configuration with DTE/DTE communication—is not so well defined, especially when it comes to flow control. The terminology null modem for the situation where two computers communicate directly is so often used nowadays, that most people don't realize anymore the origin of the phrase and that a null modem connection is an exception, not the rule.
串口RS232通讯。在机算机上最老和最广泛的通讯方式之一。这种通讯方式在标准中详细定义过了,除了一个例外。 标准中描述了DTE/DCE的通讯,即电脑与一个外围设备如猫的通讯方式。DTE表示数据终端设备(如电脑等),DCE表示数据通讯设备(如猫等)。无猫介入是当今串口主要的通讯方式之一(即DTE和DTE之间的串口无猫通讯),它没有被很好地定义,特别是当涉及到流控时。二台电脑之间无猫直接通讯现在经常被使用,很多人不了解这个词语原始含义以外更多的东西,无猫连接是一个例外,而不是标准的规范。
In history, practical solutions were developed to let two computers talk with each other using a null modem serial communication line. In most situations, the original modem signal lines are reused to perform some sort of handshaking. Handshaking can increase the maximum allowed communication speed because it gives the computers the ability to control the flow of information. High amounts of incomming data is allowed if the computer is capable to handle it, but not if it is busy performing other tasks. If no flow control is implemented in the null modem connection, communication is only possible at speeds at which it is sure the receiving side can handle the amount information even under worst case conditions.
历史上,部分解决方案被开发来使二台电脑之间使用无猫串口通讯线互相通讯。多数情况下,原始的猫信号线路被重新使用来进行诸如握手等工作。握手可以增加最大通讯速度,因为它使电脑有能力控制信息的流量。大量的数据可以被允许从外面进来,只要电脑有能力处理它,但是当电脑忙时,就不允许进来。如果在无猫连接中没有流量控制,通讯只可能在保证接收端在最坏的情况下能处理多少的信息数量的速度下进行。
Original use of RS232 最初的RS232使用
When we look at the connector pinout of the RS232 port, we see two pins which are certainly used for flow control. These two pins are RTS, request to send and CTS, clear to send. With DTE/DCE communication (i.e. a computer communicating with a modem device), RTS is an output on the DTE and input on the DCE. CTS is the answering signal comming from the DCE.
当我们去看RS232的接口针脚,可以看出2个针脚一定用来做流量控制。即RTS请求发送和CTS允许发送。在DTE/DCE通讯(例如一台电脑与一个猫通讯),RTS是DTE的输出和DCE的输入。CTS是DCE发来的回答信号。
Before sending a character, the DTE asks permission by setting its RTS output. No information will be sent until the DCE grants permission by using the CTS line. If the DCE cannot handle new requests, the CTS signal will go low. A simple but useful mechanism allowing flow control in one direction. The assumption is, that the DTE can always handle incomming information faster than the DCE can send it. In the past, this was true. Modem speeds of 300 baud were common and 1200 baud was seen as a high speed connection.
在发送一个字符之前,DTE通过设置它的RTS输出来询问是否允许发送。没有数据被发送直到DCE使用CTS线路来确认允许发送。如果DCE无法处理新的请求,CTS信号将变低。一个简单但很好用的方法来允许一个方向的流量控制。这是假设DTE总是可以比DCE发送速度更快地处理进来的信息。以前,这是对的。猫速度在300波特率是常见的,1200波特率就被认为是高速连接了。
For further control of the information flow, both devices have the ability to signal their status to the other side. For this purpose, the DTR data terminal ready and DSR data set ready signals are present. The DTE uses the DTR signal to signal that it is ready to accept information, whereas the DCE uses the DSR signal for the same purpose. Using these signals involves not a small protocol of requesting and answering as with the RTS/CTS handshaking. These signals are in one direction only.
为了进一步地控制信息流,两边的设备都有能力给对方发出表示它的状态的信号。为了这个目的,DTR(数据终端准备好)和DSR(数据装置准备好)信号就存在了。DTE使用DTR信号来表示它已经准备好接收信息,而DCE使用DSR信号来达到相同目的。这些信号的使用包含不只是使用RTS/CTS握手信号的请求和回答的小协议。这些信号只是单方向的。
The last flow control signal present in DTE/DCE communication is the CD carrier detect. It is not used directly for flow control, but mainly an indication of the ability of the modem device to communicate with its counter part. This signal indicates the existence of a communication link between two modem devices.
存在于DTE/DCE通讯中的最后的流量控制信号是CD载波检测。它不是直接用来流控,而是主要是指示猫与对方通讯的能力。这个信号表明二台猫之间存在通讯链路。
1. Null modem without handshaking无握手的无猫电缆
How to use the handshaking lines in a null modem configuration? The simplest way is to don't use them at all. In that situation, only the data lines and signal ground are cross connected in the null modem communication cable. All other pins have no connection. An example of such a null modem cable without handshaking can be seen in the figure below.
在无猫配置中怎样使用握手线路?最简单的方法是根本不使用它们,在无猫通讯电缆中只有数据线和地线连接。其它针脚不连接。如下图:
Simple null modem without handshaking
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
Connector 1 | Connector 2 | Function | ||
2 | 3 | Rx | 《―― | Tx |
3 | 2 | Tx | ――》 | Rx |
5 | 5 | Signal ground |
Compatibility issues 兼容性说明
If you read about null modems, this three wire null modem cable is often talked about. Yes, it is simple but can we use it in all circumstances? There is a problem, if either of the two devices checks the DSR or CD inputs. These signals normaly define the ability of the other side to communicate. As they are not connected, their signal level will never go high. This might cause a problem.
如果你读过一些无猫通讯,这个三线电缆经常被谈论到。是的,它很简单但能在所有的场合使用它吗?这是个问题,如果二个设备中的任一个要检查DSR或CD信号。 这些信号通常定义了另外一方进行通讯的能力。 如果它们没有连接,它们的信号不会变高。这会产生问题。
The same holds for the RTS/CTS handshaking sequence. If the software on both sides is well structured, the RTS output is set high and then a waiting cycle is started until a ready signal is received on the CTS line. This causes the software to hang because no physical connection is present to either CTS line to make this possible. The only type of communication which is allowed on such a null modem line is data-only traffic on the cross connected Rx/Tx lines.
对于RTS/CTS握手序列也是个问题。如果双方的软件是基于良好的架构,RTS输出会先设置成高,然后等待直到CTS线路接收到准备好的信号。 这会造成软件当机因为没有物理连接存在于CTS线路。 这种通讯方式只允许存在于只有RX/TX线路上有数据交换的无猫线路上。
This does however not mean, that this null modem cable is useless. Communication links like present in the Norton Commander program can use this null modem cable. This null modem cable can also be used when communicating with devices which do not have modem control signals like electronic measuring equipment etc.
这并不意味着,这个无猫电缆没有用处。诺顿Commander程序中的通讯链路可以使用这个无猫电缆。 这个无猫电缆也可以被使用,当设备之间通讯不使用猫控制信号,比如电子测量设备等。
As you can imagine, with this simple null modem cable no hardware flow control can be implemented. The only way to perform flow control is with software flow control using the XOFF and XON characters.
你可以想像,使用这个简单的无猫电缆,不可以使用硬件流量控制。 使用流量控制的唯一办法是使用XOFF和XON字符的软件流量控制。
2. Null modem with loop back handshaking 带自反馈握手信号的无猫电缆
The simple null modem cable without handshaking shows incompatibilities with common software. The main problem with this cable is that there is a possibility for the software to hang if it checks the modem signal lines in a proper way. I.e. with this null modem cable, good written programs will perform worse than badly written programs.
没有握手的简单的无猫电缆在通常的软件中表现出不兼容性。这个电缆的主要的问题是它可能使软件当机,如果软件用正常的方式检查猫信号线路。也就是用这种无猫电缆,编写良好的软件将比编写差的软件运行得更坏。
To overcome this problem and still be able to use a cheap null modem communication cable with only three lines in it, a fake null modem cable layout has been defined. The null modem cable with loop back handshaking resulted from this.
为了克服这个问题并能够使用便宜的3线无猫电缆,一个欺骗无猫电缆就被定义了。这就产生了带自反馈握手信号的无猫电缆。
Null modem with loop back handshaking
Connector 1 | Connector 2 | Function | ||
2 | 3 | Rx | 《―― | Tx |
3 | 2 | Tx | ――》 | Rx |
5 | 5 | Signal ground | ||
1 + 4 + 6 | - | DTR | ――》 | CD + DSR |
- | 1 + 4 + 6 | DTR | ――》 | CD + DSR |
7 + 8 | - | RTS | ――》 | CTS |
- | 7 + 8 | RTS | ――》 | CTS |
The main purpose of this null modem cable is to let well defined software think there is handshaking available, with a null modem cable which has no provisions for it.
这个电缆的主要目的是让设计良好的软件认为握手正常。
Compatibility issues兼容性说明
Consider first the DSR signal (pin 6). This input indicates that the other side is ready to start communicating. In the layout, the line is linked back to the DTR output (pin 4). This means, that the software doesn't see the ready signal of the other device, but its own. The same holds for the CD input (pin 1). The assumption is, that if software has been written to check the DSR line to test communication availability, it will probably also set the DTR output to indicate its own state. This is true for at least 99% of all serial communication software. This implies that at least 99% of all serial communication software is capable of faking its own DSR check with this null modem cable.
先考虑DSR信号(6脚)。这个输入信号指示了另一方已经准备好开始通读了。这里,这条线路直接连接回到了DTR输出脚(4脚)。这意味着,软件不会看到另一方设备的准备信号,只是看到自已的。对于CD输入脚也是这样(1脚)。这里假设,如果软件需要检查DSR线路来测试通讯能力,它也将设置DTR输出来表明自已的状态。 对于至少99%的串口通讯软件来说这是真的。这意味着至少99%的串口通讯软件能够用这种无猫电缆来欺骗自已的DSR检查。
The same trick is used with the CTS input. In the original use, RTS is set, and then CTS is checked before starting the communication. By setting the RTS output (pin 7) the CTS input on the same connector (pin 8) is receiving clearance immediately. There is no possibility of a software hangup because of dangling RTS requests.
CTS用了同样的方式。在原始的使用中,RTS被设置,然后在开始通讯之前检查CTS。 通过设置RTS输出信号(7脚),连接在一起的CTS输入脚马上接收到授权信号。因为RTS请求,软件就不会当机了。
Other issues to consider其它考虑的问题
The null modem cable with loop back handshaking is often advised as the best low cost available null modem cable. But, is it really so good? The simple null modem cable without handshaking has the disadvantage that it does not permit proper written software to communicate with it. Software which is aware of the lack of handshaking signals can however use it without problems.
这种自反馈握手信号的无猫电缆经常被推荐成最好的低成本无猫电缆。它真的这么好?无握手的简单无猫电缆的不利之处是它不允许设计良好的软件用它来通讯。但是那些知道握手信号缺失的软件可以使用它而不出问题。
The null modem cable with loop back handshaking can be used with more software, but it has no functional enhancements over the simple cable! There is no way both devices can control data flow, other than by using XON/XOFF handshaking. If the software is designed for using hardware flow control it seems to work with this null modem cable, but on unpredictable moments, data loss may occur. This means that the null modem cable allows communication as long as no flow control is needed, but when data speeds reach the limit the receivers can handle, communication may stop immediately without an assignable reason. Therefore, although this null modem cable is cheap and easy to make, use it with care! Despite these warnings, this type of null modem cable has been used successfully between Windows 95/98/ME computers with a Direct Cable Connection.
自反馈握手信号无猫电缆可以使用于更多的软件,但它相对于简单电缆没有提供更强的功能。两个设备也无法控制流量,除非使用XON/XOFF握手信号。如果软件设计使用硬件流量控制,用这种无猫电缆似乎可以工作,但是在一些不可预知的时候,数据丢失可能会发生。 这意味着,只要不需要流控,无猫电缆就允许通讯,但是当数据速度达到接收设备能处理的限制值,通讯可能马上无指定原因地停止。因此,尽管这种无猫电缆便宜和简单,但是要小心用它!除了这些警告,这种类型的无猫电缆已经成功地在Windows 95/98/ME电脑之间通过Direct Cable Connection使用。
3. Null modem with partial handshaking带部分握手信号的无猫电缆
The simple null modem cable and the null modem cable with loop back handshaking are useful, but have no provisions for hardware flow control. If it is absolutely necessary that hardware flow control is used, the null modem with partial handshaking can be an alternative.
前面的二种电缆是有用的,但是无法提供硬件流控。如果必须需要使用硬流控,则带部分握手信号的无猫电缆可以作为一种选择。
Null modem with partial handshaking
Connector 1 | Connector 2 | Function | ||
1 | 7 + 8 | RTS2 | ――》 | CTS2 + CD1 |
2 | 3 | Rx | 《―― | Tx |
3 | 2 | Tx | ――》 | Rx |
4 | 6 | DTR | ――》 | DSR |
5 | 5 | Signal ground | ||
6 | 4 | DSR | 《―― | DTR |
7 + 8 | 1 | RTS1 | ――》 | CTS1 + CD2 |
Compatibility issues兼容性说明
This null modem cable is the best of two worlds. There is the possibility of hardware flow control without being incompatible with the original way flow control was used with DTE/DCE communication. Let us first consider the RTS/CTS flow control lines present on pins 7 and 8. As with the loop back null modem cable, these signals are not connected to the other device, but directly looped back on the same connector. This means, that RTS/CTS flow control is allowed to be used in the software, but it has no functional meaning. Only when the software at the other side checks the CD signal at pin 1, the RTS information will reach the other device. This would however be only the case in specifically developed software which uses the CD input for this purpose.
这种电缆是二个场合最好的。这是可以硬流控而不会不兼容最原始的使用于DTE/DCE通讯的流量控制方式。 我们先考虑存在于7脚 和8脚的RTS/CTS流量控制线。 就像自反馈的无猫电缆,这些信号没有连接到另一那台设备,而是从相同的接口直接反馈回去。这意味着,RTS/CTS流控允许在硬件中被使用,但是没有真正意义的功能。只有当另一方的软件检查1脚的CD信号,RTS信息才将到达另外那台设备。 这只有用于特别开发的使用CD输入信号用于这个目的的软件。
More important however is the cross connection of the DSR (pin 6) and DTR (pin 4) lines. By cross connecting these lines, their original function is simulated pretty well. The DTR output is used to signal the other device that communication is possible. This information is read on the DSR input, the same input used for this purpose with modem communication. Because of this cross connection, the DTR output line can be used for simple flow control. Incomming data is allowed when the output is set, and blocked if the output is not set.
更重要的是DSR(6脚)和DTR(4脚)线路的交叉连接。通过交叉连接这些线路,它们的原始功能被很好地模拟。 DTR输出信号用来发信号给另一台设备说通讯是可以的。 DSR输入口读入这个信息,在猫通讯中相同的输入口用于这个目的。 因为这种交叉连接,DTR输出线可以被用来简单的流量控制。 进来的数据是被允许的,当输出信号被设置;进来的数据不被允许,当输出信号没有被设置;
Software using only the RTS/CTS protocol for flow control cannot take advantage of the partial handshaking null modem cable. Most software however will also check the DSR line and in that case—when using the null modem cable with partial handshaking—the best possible hardware flow control can be achieved which is still compatible with the original use with modems.
那些只使用RTS/CTS协议来进行流量控制的软件就没有办法利用到带部分握手信号的无猫电缆的好处了。但是多数的软件也检查DSR线路,在这种情况下,当使用带部分握手信号的无猫电缆时,能得到最大可能的硬流量控制,而且也依旧兼容猫的原始使用。
4. Null modem with full handshaking带全握手信号的无猫电缆
The most expensive null modem cable is the null modem cable suitable for full handshaking. In this null modem cable, seven wires are present. Only the ring indicator RI and carrier detect CD signal are not linked. The cable is shown in the following figure.
最贵的无猫电缆是适用于全握手信号的无猫电缆。 在这种电缆中,存在7根线。只有RI和CD信号没有连接。如下图:
Null modem with full handshaking
Connector 1 | Connector 2 | Function | ||
2 | 3 | Rx | 《―― | Tx |
3 | 2 | Tx | ――》 | Rx |
4 | 6 | DTR | ――》 | DSR |
5 | 5 | Signal ground | ||
6 | 4 | DSR | 《―― | DTR |
7 | 8 | RTS | ――》 | CTS |
8 | 7 | CTS | 《―― | RTS |
Compatibility issues兼容性说明
The null modem cable with full handshaking does not permit the older way of flow control to take place. The main incompatibility is the cross connection of the RTS and CTS pins. Originally, these pins are used for a question/answer type of flow control. When the full handshaking null modem cable is used, there is no request anymore. The lines are purely used for telling the other side if communication is possible.
带全握手信号的电缆不允许使用老的流量控制方式。 主要的不兼容性是RTS和CTS针脚的交叉连接。最初原始地,这些针脚是用于请求/回答类型的流量控制。当使用带全握手信号的无猫电缆,就不再有“请求”了。这些线路只是单纯地用来告诉另外一方通讯是否可能。
The main advantage of this cable is, that there are two signalling lines in each direction. Both the RTS and DTR outputs can be used to send flow control information to the other device. This makes it possible to achieve very high communication speeds with this type of null modem cable, provided that the software has been designed for it. Because of the high possible connection speed, this null modem cable can be used with Interlink to connect two MS-DOS PC's.
这种电缆主要的好处是,在每个方向上有二个信号线路。RTS和DTR这二个输出信号都可以用来发出流量控制信息给另一方设备。这使得使用这种电缆达到很高的通讯速度成为可能,前提是软件按这种方式来设计。因为有可能达到高的连接速度,这种电缆可以用来连接二台MS-DOS电脑,使用Interlink软件。
This is the type of cable Microsoft recommends for the direct cable connection in their knowledge base article. For the DB9 connector they also added a connection of DTR to CD on each connector but they didn't define this connection for the DB25 connector version and they also didn't mention the CD input in the descriptive text, so it is safe to leave the CD input disconnected.
这是微软推荐用于直接电缆连接的电缆类型。对于DB9接头,他们还在每个接头上加上了DTR到CD的连接,但是他们没有定义在DB25接头上定义这个连接,并且他们也没有在文本中提到在CD输入信号,所以CD输入信号不连接是安全的。
二、Null modem layout selection table无猫电缆选择表
The right null modem cable to choose mainly depends on the application and the software that will be used. As a general guide line, I would advise the following.
选择正确的无猫电缆主要取决于应用和要使用的软件。作为一般的指导,我建议:
Choose your null modem cable | ||||
| Cable without handshaking 无握手 | <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Loop back handshaking 自反馈握手信号 | Partial handshaking 部分握手信号 | Full handshaking 全握手信号 |
Software flow control only只软件流控 | +++ | ++ | + | + |
DTE/DCE compatible hardware flow control at low speeds DTE/DCE兼容,硬流控,低速度 | - | +++ | ++ | - |
DTE/DCE compatible hardware flow control at high speeds DTE/DCE兼容,硬流控,高速度 | - | + | +++ | - |
High speed communication using special software 使用特殊软件的高速通讯 | - | - | ++ | +++ |
+++ ++ + - | Recommended cable推荐 Good alternative好用 Works, but not recommended可以用,但不推荐 Does not work无法工作 |
The null modem cable with partial handshaking works in most cases. If you are developing software which must work with all kinds of cables, it is best to use software flow control only and ignore all modem control inputs.
带部分握手信号的无猫电缆工作于大多数的场合。 如果你正在开发必须工作于所有类型电缆的软件,最好的方式是只使用软件流量控制并且忽略所有猫控制输入信号。
Software for file transfers用于文件传输的软件
The main use of null modem cables is file transfer between two computers. Several software is available for this task, but if you haven't made a choice yet, I would like to recommend the WinXFer program from Willies Computer Software Co. The software is capable to run in three modes. An easy Windows user interface can be used for interactive file transfer. There is also a command line version of the utility available which can be run in the background by batch files, schedulers etc. and the program is shipped with DLL's which can be linked to your own programs to make your own file transfer applications. The API can be used both by Visual C/C++ programs and Visual Basic. Beside transfer over a direct serial null modem line, the program is also capable of file transfer between computers which are connected using a telephone lines and Hayes compatible modems.
无猫电缆主要用途是二台之间文件传输。我推荐WinXFer软件。。。。。。
If you are interested you can buy this software on-line here. The product is available for immediate download!
文章评论(0条评论)
登录后参与讨论