RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)

  前面转载的几篇文章重点介绍了UART及RS-232。在工控领域除了RS-232以外,常用的串行通信还有RS-485。本文转载的文章重点介绍了RS-232、RS-422和RS-485。

Overview

This article explains the general concepts of the serial communication protocols RS-232, RS-422, and RS-485, including basic concepts like baud rate, data bits, stop bits, parity, and handshaking.

Table of Contents

  1. What is Serial?
  2. What is RS-232?
  3. What is RS-422?
  4. What Is RS-485?
  5. How do RS-232, RS-422, and RS-485 Compare?
  6. What is Handshaking?
  7. Related Links

1. What is Serial?

The concept of serial communication is simple. The serial port sends and receives bytes of information one bit at a time. This is slower than parallel communication, which allows the transmission of an entire byte at once; however, it is simpler and can be used over longer distances. For example, the IEEE 488 specifications for parallel communication state that the cabling between equipment can be no more than 20 meters total, with no more than 2 meters between any two devices; serial can extend as much as 1200 meters.

Typically, serial is used to transmit ASCII data. Communication is completed using 3 transmission lines: (1) Ground, (2) Transmit, and (3) Receive. Since serial is asynchronous, the port is able to transmit data on one line while receiving data on another. This is referred to as Full-Duplex transmission. Other lines are available for handshaking, but are not required. The important serial characteristics are baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match:

  1. Baud rate is a speed measurement for communication. It indicates the number of bit transfers per second. For example, 300 baud is 300 bits per second. When we refer to a clock cycle, in the context of serial, we mean the baud rate. For example, if the protocol calls for a 4800 baud rate, then the clock is running at 4800Hz. This means that the serial port is sampling the data line at 4800Hz. Common baud rates for telephone lines are 14400, 28800, and 33600. Baud rates greater than these are possible, but these rates reduce the distance by which devices can be separated. These high baud rates are used for device communication where the devices are located near one another.
  2. Data bits are a measurement of the actual data bits in a transmission. When the computer sends a packet of information, the amount of actual data may not be a full 8 bits. Standard values for the data packets are 5, 7, and 8 bits. Which setting you choose depends on what information you are transferring. For example, standard ASCII has values from 0 to 127 (7 bits). Extended ASCII uses 0 to 255 (8 bits). If the data being transferred is simple text (standard ASCII), then sending 7 bits of data per packet is sufficient for communication. A packet refers to a single byte transfer, including start/stop bits, data bits, and parity. Since the number of actual bits depend on the protocol selected, the term packet is used to cover all instances.
  3. Stop bits are used to signal the end of communication for a single packet. Typical values are 1, 1.5, and 2 bits. Since the data is clocked across the lines and each device has its own clock, it is possible for the two devices to become slightly out of sync. Therefore, the stop bits not only indicate the end of transmission but also give the computers some room for error in the clock speeds. The more bits that are used for stop bits, the greater the lenience in synchronizing the different clocks, but the slower the data transmission rate.
  4. Parity is a simple form of error checking that is used in serial communication. There are four types of parity: even, odd, marked, and spaced. The option of using no parity is also available. For even and odd parity, the serial port will set the parity bit (the last bit after the data bits) to a value to ensure that the transmission has an even or odd number of logic high bits. For example, if the data was 011, then for even parity, the parity bit would be 0 to keep the number of logic high bits even. If the parity was odd, then the parity bit would be 1, resulting in 3 logic high bits. Marked and spaced parity does not actually check the data bits, but simply sets the parity bit high for marked parity or low for spaced parity. This allows the receiving device to know the state of a bit which enables the device to determine if noise is corrupting the data or if the transmitting and receiving devices' clocks are out of sync.

2. What is RS-232?

RS-232 (ANSI/EIA-232 Standard) is the serial connection historically found on IBM-compatible PCs. It is used for many purposes, such as connecting a mouse, printer, or modem, as well as industrial instrumentation. Because of improvements in line drivers and cables, applications often increase the performance of RS-232 beyond the distance and speed listed in the standard. RS-232 is limited to point-to-point connections between PC serial ports and devices. RS-232 hardware can be used for serial communication up to distances of 50 feet.

 


Data


TXD (pin 3)


Serial Data Output


RXD (pin 2)


Serial Data Input


Handshake


RTS (pin 7)


Request to Send


CTS (pin 8)


Clear to Send


DSR (pin 6)


Data Set Ready


DCD (pin 1)


Data Carrier Detect


DTR (pin 4)


Data Terminal Ready


Ground


GND (pin 5)


Ground


Other


RI (pin 9)


Ring Indicator

 Table 1: Pin Functions for RS-232

3. What is RS-422?

RS-422 (EIA RS-422-A Standard) is the serial connection historically used on Apple Macintosh computers. RS-422 uses a differential electrical signal, as opposed to unbalanced signals referenced to ground with the RS-232. Differential transmission uses two lines each for transmit and receive signals which results in greater noise immunity and longer distances as compared to the RS-232. These advantages make RS-422 a better fit for industrial applications.

4. What Is RS-485?

RS-485 (EIA-485 Standard) is an improvement over RS-422, because it increases the number of devices from 10 to 32 and defines the electrical characteristics necessary to ensure adequate signal voltages under maximum load. With this enhanced multi-drop capability, you can create networks of devices connected to a single RS-485 serial port. The noise immunity and multi-drop capability make RS-485 the serial connection of choice in industrial applications requiring many distributed devices networked to a PC or other controller for data collection, HMI, or other operations. RS-485 is a superset of RS-422; thus, all RS-422 devices may be controlled by RS-485. RS-485 hardware may be used for serial communication with up to 4000 feet of cable.

 


Data


TXD+ (pin 8)


Serial Data Output (differential)


TXD- (pin 9)


Serial Data Output(differential)


RXD+ (pin 4)


Serial Data Input(differential)


RXD- (pin 5)


Serial Data Input(differential)


Handshake


RTS+ (pin 3)


Request to Send (differential)


RTS- (pin 7)


Request to Send (differential)


CTS+ (pin 2)


Clear to Send (differential)


CTS- (pin 6)


Clear to Send (differential)


DSR (pin 6)


Data Set Ready


Ground


GND (pin 1)


Ground

   Table 2: Pin Functions for RS-485 and RS-422 

5. How do RS-232, RS-422, and RS-485 Compare?

RS-232 is the most common serial interface and used to ship as a standard component on most Windows-compatible desktop computers. Now it is more common to use RS-232 over USB using a converter. RS-232 only allows for one transmitter and one receiver on each line. RS-232 also uses a Full-Duplex transmission method. Some RS-232 boards sold by National Instruments support baud rates up to 1 Mbit/s, but most devices are limited to 115.2 kbits/s.

RS-422 (EIA RS-422-A Standard) is the serial connection used on legacy Apple computers. It provides a mechanism for transmitting data up to 10 Mbits/s. RS-422 sends each signal using two wires to increase the maximum baud rate and cable length. RS-422 is also specified for multi-drop applications where only one transmitter is connected to, and transmits on, a bus of up to 10 receivers.

RS-485 is a superset of RS-422 and expands on the capabilities. RS-485 was made to address the multi-drop limitation of RS-422, allowing up to 32 devices to communicate through the same data line. Any of the slave devices on a RS-485 bus can communicate with any other 32 slave devices without going through a master device. Since RS-422 is a subset of RS-485, all RS-422 devices may be controlled by RS-485.

Both RS-485 and RS-422 have multi-drop capability, but RS-485 allows up to 32 devices and RS-422 has a limit of 10. For both communication protocols, you should provide your own termination. All National Instruments RS-485 boards will work with RS-422 standards.

The following table compares mode of operation, total number of drivers and receivers, maximum cable length, and maximum data rate.   


Specifications


RS-232


RS-422


RS-485


Mode of Operation


Single-Ended


Differential


Differential


Number of Drivers / Receivers on One Line


1 Driver
1 Receiver


1 Driver
10 Receivers


32 Drivers*
32 Receivers


Maximum Cable Length


50 ft (2500 pF)


4000 ft


4000 ft


Maximum Data Rate (at max cable length)


160 kbits/s (can be up to 1Mbit/s)


10 Mbit/s


10 Mbit/s

Table 3: Specifications of RS-232, RS-422, and RS-485

*Only one driver is active at a time   

6. What is Handshaking?

The method used by RS-232 for communication allows for a simple connection of three lines: TX, RX, and ground.
For the data to be transmitted, both sides have to be clocking the data at the same baud rate. Although, this method is sufficient for most applications, it is limited in being able to respond to problems such as the receiver getting overloaded. This is where serial handshaking can help. In this section we will discuss three of the most popular forms of handshaking with RS-232: Software Handshaking, Hardware Handshaking, and Xmodem.

  1. Software Handshaking: The first form of handshaking we will discuss is software handshaking. This style uses actual data bytes as control characters, similar to the way GPIB uses command strings. The lines necessary are still the simple three line set of TX, RX, and round since the control characters are sent over the transmission line like regular data. The function SetXMode allows the user to enable or disable the use of two control characters, XON and XOFF. These characters are sent by the receiver of the data to pause the transmitter during communication.

    As an example, assume that the transmitter begins to transmit data at a high baud rate. During the transmission, the receiver finds that the input buffer is becoming full due to the CPU being busy with other duties. To temporarily pause the transmission, the receiver sends XOFF, typically decimal 19 or hex 13, until the input buffer has been emptied. Once the receiver is ready for more data it sends XON, typically decimal 17 or hex 11, to resume communication. LabWindows will send XOFF when its input buffer becomes half full. In addition, in case the XOFF transmission was corrupted, LabWindows will also transmit XOFF when the buffer has reached 75% and 90% capacity. Obviously, the transmitter must also be following this protocol for it to succeed.

    The biggest drawback to this method is also the most important fact to keep in mind: decimal 17 and 19 are now off limits for data values. In ASCII transmissions this typically does not matter since these values are non-character values; however, if the data is being transmitted via binary, it is very likely that these values could be transmitted as data and the transmission would fail.

  2. Hardware Handshaking: The second method of handshaking is to use actual hardware lines. Like the TX and RX lines, the RTS/CTS and DTR/DSR lines work together with one being the output and the other the input. The first set of lines are RTS (Request to Send) and CTS (Clear to Send). When a receiver is ready for data, it will assert the RTS line indicating it is ready to receive data. This is then read by the sender at the CTS input, indicating it is clear to send the data. The next set of lines are DTR (Data Terminal Ready) and DSR (Data Set Ready). These lines are used mainly for modem communication. They allow the serial port and the modem to communicate their status. For example, when the modem is ready for data to be sent from the PC, it will assert the DTR line indicating that a connection has been made across the phone line. This is read in through the DSR line and the PC can begin to send data. The general rule of thumb is that the DTR/DSR lines are used to indicate that the system is ready for communication where the RTS/CTS lines are used for individual packets of data.

    In LabWindows, the function SetCTSMode enables or disables the use of hardware handshaking. If the CTS mode is enabled, LabWindows employs the following rules:

    When the PC sends data:
    The RS-232 library must detect that its CTS line is high before sending data.

    When the PC receives data:
    If the port is opened and the input queue has room for data, the library raises RTS and DTR.
    If the port's input queue is 90% full, the library lowers RTS and leaves DTR high.
    If the port's input queue is nearly empty, the library raises RTS and leaves DTR high.
    If the port is closed, the library lowers RTS and DTR.

  3. XModem Handshaking: The last mode discussed here is the XModem file transfer protocol. This protocol is very common in modem communication. Although it is often used for modem communication, the XModem protocol can be used directly between other devices if they both follow the protocol. In LabWindows, the actual implementation of XModem is hidden from the user. As long as the PC is connected to another device using XModem protocol, the LabWindows' XModem functions can be used to transfer files from one site to another. The functions are XModemConfig, XModemSend, and XModemReceive.

    XModem uses a protocol based on the following parameters: start_of_data, end_of_trans, neg_ack, ack, wait_delay, start_delay, max_tries, packet_size. These parameters need to be agreed upon by both sides. Standard XModem has a standard definition of these; however, they can be modified through the XModemConfig function in LabWindows to meet any requirement. The way that these parameters are used in XModem is by having the neg_ack character sent by the receiver. This tells the sender that it is ready to receive data. It will try again with start_delay time in-between each try until either it reaches max_tries or receives start_of_data from the sender. If it reaches max_tries it will inform the user that it was unable to communicate with the sender. If it does receive start_of_data from the sender, it will read the packet of information that follows. This packet contains the packet number, the complement of the packet number as an error check, the actual data packet of packet_size bytes, and a checksum on the data for more error checking. After reading the data, the receiver will call wait_delay and then send ack back to the sender. If the sender does not receive ack, it will re-send the data packet max_tries or until it receives ack. If it never receives the ack, it informs the user that it has failed to transfer the file.

    Since the data must be sent in packets of packet_size bytes, when the last packet is sent, if there is not enough data to fill the packet, the data packet is padded with ASCII NUL (0) bytes. This can cause the received file to be larger than the original. It is also important to remember not to use XON/XOFF with the XModem protocol since the packet number from the XModem transfer is very likely to increment to the XON/OFF control character values, which would cause a breakdown in communication.

7. Related Links

White Paper: Serial Communication Starting Point

White Paper: Connecting RS-232 and RS-485 Over USB

Products and Services: NI Serial Interfaces for RS-232, RS-422, and RS-485

原文地址:http://www.ni.com/white-paper/11390/en/

时间: 2024-09-20 06:10:59

RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)的相关文章

RS-232 vs. TTL Serial Communication(转载)

RS-232串口一度像现在的USB接口一样,是PC的标准接口,用来连接打印机.Modem和其他一些外设.后来逐渐被USB接口所取代,现在PC上已经看不到它的身影了.开发调试时如果用到串口,一般都是用USB转串口头,如下图所示.左图为USB-to-RS-232,右图为USB-to-TTL.USB-to-RS-232和USB-to-TTL因电气特性不同,所以应用场合也不同,不能互换.本文所转载的文章,重点介绍了RS-232和TTL串口的异同. One of the tools we use most

Serial Communication Protocol Design Hints And Reference

前面转载的几篇文章详细介绍了UART.RS-232和RS-485的相关内容,可以知道,串口通信的双方在硬件层面需要约定如波特率.数据位.校验位和停止位等属性,才可以正常收发数据.实际项目中使用串口通信时,一般还需要设计一套通讯协议.那么设计串口通讯协议有什么需要注意的地方呢?本文以iPod.车载CAN解码盒及IoT设备EnOcean的串口通讯协议为例,对通讯协议数据帧的定义做一个简单的介绍和分析. 首先看Apple提供的文档<iPod_Accessory_Protocol_Interface_S

rs.open和conn.execute的关系与区别

问: Rs.open和Rs.execute() 有什么不一样(RS为RECORDSET 对象)?在有些页面用set Rs=conn.execute() 不能用,有些Rs.open不能用 问: Rs.open和Rs.execute()   有什么不一样(RS为RECORDSET   对象)?在有些页面用set   Rs=conn.execute()   不能用,有些Rs.open不能用 答: 第一个是可以有不同的打开游标     第二个只有一个向前的游标     而且你第二个写的好象不太正确应该是

rs的pagesize属性

在了解了Recordset对象的以上属性和方法后,我们来考虑一下,如何运用它们来达到我们分页显示的目的.首先,我们可以为PageSize属性设置一个值,从而指定从记录组中取出的构成一个页的行数:然后通过RecordCount属性来确定记录的总数:再用记录总数除以PageSize就可得到所显示的页面总数:最后通过AbsolutePage属性就能完成对指定页的访问.好象很并不复杂呀,下面让我们来看看程序该如何实现呢? 子的自动编号:"s我们建立这样一个简单的BBS应用程序,它的数据库中分别有以下五个

asp rs.open 参数1,2,3详解

读取数据都是用rs.open sql,conn,1,1 修改数据:rs.open sql,conn,1,3 删除数据:直接要conn.execute("delete * from new where id=1")这样的. rs.open语法如下:rs.open source,activeconnection,cursortype,locktype source为sql语句,activeconnection为数据库教程连接,cursortype是游标,locktype是数据锁定类型. c

论坛-rs=stmt.executeQuery 这里是调用的什么啊 ,急死我啦。各路大神,帮帮忙吧

问题描述 rs=stmt.executeQuery 这里是调用的什么啊 ,急死我啦.各路大神,帮帮忙吧 <%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" import="java.sql.*" import="java.util.*"%> <jsp:useBean i

jsp 应用程序 finally里的 rs pstmt conn出错

问题描述 jsp 应用程序 finally里的 rs pstmt conn出错 登录验证界面 <% try{ Connection conn =null; PreparedStatement pstmt =null; ResultSet rs=null; String driverName ="com.sql.jdbc.Driver"; String dbName="user"; String url1="jdbc:sql://localhost/&

我测试保存页的时候,老说 rs.addnew这行有错误,且提示:Microsoft JET Database Engine (0x80040E09)不能更新。数据库或对象为只读。?

问题描述 <%xuasmdb="yj.mdb"setconn=server.CreateObject("adodb.connection")DBPath=Server.MapPath(xuasmdb)conn.open"provider=microsoft.jet.oledb.4.0;datasource="&DBpath'ONERRORRESUMENEXT%><%setrs=server.CreateObject(&q

rs.open sql,conn,1,1与rs.open sql,conn,1.3还有rs.open sql,conn,3,2区别_应用技巧

经常开发asp但对于细致的说法,真实不太清楚,这里简单的介绍下.一般情况下读取数据都是用rs.open sql,conn,1,1修改数据:rs.open sql,conn,1,3删除数据:直接要conn.execute("delete * from new where id=1")这样的. Rs.Open语法如下:rs.Open Source,ActiveConnection,CursorType,LockType Source为sql语句,ActiveConnection为数据库连接