XON/XOFF 流量控制实际上是做什么的? [英] What does XON/XOFF flow control actually do?

查看:338
本文介绍了XON/XOFF 流量控制实际上是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,XON 和 XOFF 只不过是用于两个串行设备之间握手的特殊 ASCII 字符.但是我不清楚当我使用这种类型的流量控制进行通信时实际上会发生什么.我的消息开头是否只有一个 XON 字符,而在结尾有一个 XOFF 字符?即,当我使用 PySerial 写一些东西时:

From what I have been able to discover, XON and XOFF are nothing but special ASCII characters used for handshaking between two serial devices. But it is not clear to me what actually happens when I use this type of flow control for communication. Is there just an XON character at the start of my message, and an XOFF character at the end? I.e., when I write something using PySerial like this:

import serial
ser = serial.Serial('COMx', 9600, xonxoff = True)
ser.write('Hi!\r\n')

设备是否真的收到了:

\x11Hi!\r\n\x13

(\x11\x13 是 XON 和 XOFF 字符 在 Python 中,分别.)或者还有其他事情发生吗?(遗憾的是,PortMon 的消亡 我没有一个简单的方法来测试这个.)

(\x11 and \x13 being the XON and XOFF characters in Python, respectively.) Or is there something else going on? (Sadly, with the demise of PortMon I don't have a simple way to test this myself.)

推荐答案

XON/XOFF 用于流量控制.如果您正在处理信息并且由于您的输入缓冲区已满而无法接收更多信息,那么您将发送 XOFF 以告诉对方停止发送.当您的输入缓冲区有一些空间时,您将发送一个 XON 以告诉另一方再次开始发送.我见过的应用程序(很多年前我做过很多这样的事情)只在需要时使用它们,而不是作为消息的标准部分.

XON/XOFF are used for flow control. If you are processing the information and can't receive any more because your input buffers are full, then you would send XOFF to tell the other party to stop sending. When your input buffers have some room, you would send an XON to tell the other party to start sending again. The applications I've seen (and I did a lot of this many years ago) only use them when needed, not as a standard part of a message.

XON/XOFF 的问题之一是在嘈杂的线路上,这些字符可能无法正确接收,因此接收方可能会在缓冲区已满 80% 时发送 XOFF,当缓冲区已满 90% 时可能再次发送,并且如果发送方不停止,则开始更频繁地发送它们.

One of the issues with XON/XOFF is that on a noisy line, these characters might not be received correctly, so the receiving party might send XOFF when the buffer is 80% full, and maybe again when 90% full, and then start sending them more frequently if the sending party doesn't stop.

同样,接收方可能会在准备好接收时发送 XON,但如果没有收到更多信息,则它可能会定期发送它以确保不会错过第一个.

Similarly, the receiving party might send XON when ready to receive, but if nothing more is received then it might send it periodically to make sure that the first one wasn't missed.

为了成功实现,消息的任何部分都不能出现任何字符.维基百科比我能更好地解释其中的一些.

To implement successfully, neither character can appear in any part of the messages. Wikipedia explains some of this better than I can.

在 PySerial 中,您不应该实际明确地发送它们.它会为您处理,或者您可以使用 API 发送.

In PySerial, you shouldn't have to actually send them explicitly. It will handle it for you or you can use the API to send it.

这篇关于XON/XOFF 流量控制实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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