RS-232 Communications (software) / RS-232通讯(软件)

Now that we understand the hardware part of the picture, let's dive right into the software part. We'll take a look at each part of the puzzle by defining a few of the common terms. Ever wondered what phrases like 9600-8-N-1 meant?

Do you use software-handshaking or hardware-handshaking at formal parties for a greeting? If you're not sure, read on!

现在我们已经了解了硬件部分,接下来让我们直接进入软件部分。我们将通过定义一些常见术语来了解这个迷题的每个部分。有没有想过像9600-8-N-1这样的一串字符是什么意思?

在正式的聚会上,你用软件握手还是硬件握手来表示问候?如果你不确定,请继续往下读!

三菱plc rs232编程(PLC基本知识--7.3)(1)

The picture below shows how data leaves the serial port for the character "E" (45h 100 0101b) and Even parity.

下面的图片显示了字符“E”(45h 100 0101b)这个数据和偶数校验位是如何离开串口的:

三菱plc rs232编程(PLC基本知识--7.3)(2)

Another important thing that is sometimes used is called software handshaking (flow control). Like the hardware handshaking we saw in the previous chapter, software handshaking is used to make sure both devices are ready to send/receive data. The most popular "character flow control" is called XON/XOFF. It's very simple to understand. Simply put, the receiver sends the XOFF character when it wants the transmitter to pause sending data. When it's ready to receive data again, it sends the transmitter the XON character. XOFF is sometimes referred to as the holdoff character and XON as the release character.

另一个重要的东西,有时被用来称为软件握手(流控制)。就像我们在前一章看到的硬件握手,软件握手是用来确保两个设备都准备好发送或者接收数据。最流行的“字符流控制”称为XON / XOFF,这很容易理解,简单地说,当接收方希望发送方暂停发送数据时,接收方发出XOFF字符,当它准备再次接收数据时,它向发送方发送XON字符。XOFF有时被称为拖延字符,XON被称为释放字符

The last thing we should know about is delimiters. A delimiter is simply added to the end of a message to tell the receiver to process the data it has received. The most common is the CR or the CR and LF pair. The CR (carriage return) is like the old typewriters. (remember them??) When you reached the end of a line while typing, a bell would sound. You would then grab the handle and move the carriage back to the start. In other words, you returned the carriage to the beginning. (This is the same as what a CR delimiter will do if you view it on a computer screen.) The plc/external device receives this and knows to take the data from its buffer. (where the data is stored temporarily before being processed) An LF (line feed) is also sometimes sent with the CR character. If viewed on a computer screen this would look like what happens on the typewriter when the carriage is returned and the page moves down a line so you don't type over what you just typed.

最后我们应该知道的是分隔符。只需要在消息的末尾添加一个分隔符,就可以告诉接收方可以处理它接收到的数据了,最常见的是CR或CR LF。CR(回车)就像老式的打字机(记得吗?),当你打字打到一行的末尾时,铃声会响起,然后,你可以抓住把手,把打字头移回起点。换句话说,你让马车回到了起点(这与在计算机屏幕上查看CR分隔符的作用相同)。PLC或外部设备接收这个分隔符,并知道从它的缓冲区取数据(数据在处理前暂时存储)。LF(换行)有时也与CR字符一起发送。如果在电脑屏幕上看,这看起来就像在打字机上发生的情况,当回车时,页面向下移动一行,这样您就不会在刚刚键入的内容上重叠打字了。

Sometimes an STX and ETX pair is used for transmission/reception as well. STX is "start of text" and ETX is "end of text". The STX is sent before the data and tells the external device that data is coming. After all the data has been sent, an ETX character is sent.

有时,STX和ETX也用于传输或接收。STX是“文本的开始”,ETX是“文本的结束”。STX在数据之前发送,并告诉外部设备数据即将到来。所有数据发送完毕后,将发送一个ETX字符。

Finally, we might also come across an ACK/NAK pair. This is rarely used but it should be noted as well. Essentially, the transmitter sends its data. If the receiver gets it without error, it sends back an ACK character. If there was an error, the receiver sends back a NAK character and the transmitter resends the data.

最后,我们可能还会遇到ACK / NAK。这很少使用,但也应该注意。本质上,发送器发送数据,如果接收方接收时没有发生错误,它将返回一个ACK字符;如果有一个错误,接收方发送回一个NAK字符并且发送方会重新发送数据。

RS-232 has a lot of information to absorb, so feel free to reread it. It's not so difficult if you take your time and think about each step. Other communication methods get easier!

关于RS-232有很多知识需要吸收,所以我们可以随时重读这些内容。如果你花时间思考每一步,这并不难,也可以更容易地理解其他的通讯方式!

,