没有合适的资源?快使用搜索试试~ 我知道了~
首页Serial Programming Guide for POSIX Operating Systems.
资源详情
资源评论
资源推荐
Serial Programming Guide for POSIX
Operating Systems
5th Edition
Michael R. Sweet
Copyright 1994-1999, All Rights Reserved.
Table of Contents
Serial Programming Guide for POSIX Operating Systems.................................................................1
Introduction..........................................................................................................................................2
Chapter 1, Basics of Serial Communications.......................................................................................3
What Are Serial Communications?..................................................................................................3
What Is RS-232?..............................................................................................................................3
Signal Definitions.......................................................................................................................4
GND - Logic Ground.............................................................................................................4
TXD - Transmitted Data.........................................................................................................4
RXD - Received Data.............................................................................................................4
DCD - Data Carrier Detect.....................................................................................................4
DTR - Data Terminal Ready...................................................................................................4
CTS - Clear To Send...............................................................................................................4
RTS - Request To Send...........................................................................................................4
Asynchronous Communications......................................................................................................5
What Are Full Duplex and Half Duplex?....................................................................................5
Flow Control...............................................................................................................................5
What Is a Break?.........................................................................................................................6
Synchronous Communications........................................................................................................6
Accessing Serial Ports.....................................................................................................................6
Serial Port Files...........................................................................................................................6
Opening a Serial Port..................................................................................................................7
Open Options..........................................................................................................................7
Writing Data to the Port..............................................................................................................8
Reading Data from the Port........................................................................................................8
Closing a Serial Port...................................................................................................................8
Chapter 2, Configuring the Serial Port.................................................................................................8
The POSIX Terminal Interface........................................................................................................8
Control Options...........................................................................................................................9
Setting the Baud Rate...........................................................................................................10
Setting the Character Size....................................................................................................11
Setting Parity Checking........................................................................................................11
Setting Hardware Flow Control...........................................................................................12
Local Options............................................................................................................................12
Choosing Canonical Input....................................................................................................12
Choosing Raw Input.............................................................................................................13
A Note About Input Echo.....................................................................................................13
Input Options.............................................................................................................................13
Setting Input Parity Options.................................................................................................13
Setting Software Flow Control.............................................................................................14
Output Options..........................................................................................................................14
Choosing Processed Output..................................................................................................15
Choosing Raw Output..........................................................................................................15
Control Characters....................................................................................................................15
Setting Software Flow Control Characters...........................................................................16
Setting Read Timeouts..........................................................................................................16
Chapter 3, MODEM Communications...............................................................................................16
What Is a MODEM?......................................................................................................................16
Communicating With a MODEM..................................................................................................16
Standard MODEM Commands.................................................................................................18
ATD - Dial A Number..........................................................................................................18
ATH - Hang Up....................................................................................................................18
ATZ - Reset MODEM..........................................................................................................18
Common MODEM Communication Problems.........................................................................18
Chapter 4, Advanced Serial Programming.........................................................................................18
Serial Port IOCTLs........................................................................................................................19
Getting the Control Signals.......................................................................................................19
Setting the Control Signals.......................................................................................................20
Getting the Number of Bytes Available....................................................................................20
Selecting Input from a Serial Port..................................................................................................21
The SELECT System Call........................................................................................................21
Using the SELECT System Call...............................................................................................21
Using SELECT with the X Intrinsics Library...........................................................................22
Appendix A, Pinouts...........................................................................................................................22
RS-232 Pinouts..............................................................................................................................23
RS-422 Pinouts..............................................................................................................................23
RS-574 (IBM PC/AT) Pinouts.......................................................................................................24
SGI Pinouts....................................................................................................................................24
Appendix B, ASCII Control Codes....................................................................................................25
Control Codes................................................................................................................................25
Introduction
The Serial Programming Guide for POSIX Operating Systems will teach you how to successfully,
efficiently, and portably program the serial ports on your UNIX® workstation or PC. Each chapter
provides programming examples that use the POSIX (Portable Standard for UNIX) terminal control
functions and should work with very few modifications under IRIX®, HP-UX, SunOS®, Solaris®,
Digital UNIX®, Linux®, and most other UNIX operating systems. The biggest difference between
operating systems that you will find is the filenames used for serial port device and lock files.
This guide is organized into the following chapters and appendices:
• Chapter 1, Basics of Serial Programming
• Chapter 2, Configuring the Serial Port
• Chapter 3, Talking to MODEMs
• Chapter 4, Advanced Serial Programming
• Appendix A, RS-232 Pinouts
• Appendix B, ASCII Control Codes|outline
Chapter 1, Basics of Serial Communications
This chapter introduces serial communications, RS-232 and other standards that are used on most
computers as well as how to access a serial port from a C program.
What Are Serial Communications?
Computers transfer information (data) one or more bits at a time. Serial refers to the transfer of data
one bit at a time. Serial communications include most network devices, keyboards, mice,
MODEMs, and terminals.
When doing serial communications each word (i.e. byte or character) of data you send or receive is
sent one bit at a time. Each bit is either on or off. The terms you'll hear sometimes are mark for the
on state and space for the off state.
The speed of the serial data is most often expressed as bits-per-second ("bps") or baudot rate
("baud"). This just represents the number of ones and zeroes that can be sent in one second. Back at
the dawn of the computer age, 300 baud was considered fast, but today computers can handle RS-
232 speeds as high as 430,800 baud! When the baud rate exceeds 1,000, you'll usually see the rate
shown in kilo baud, or kbps (e.g. 9.6k, 19.2k, etc). For rates above 1,000,000 that rate is shown in
megabaud, or Mbps (e.g. 1.5Mbps).
When referring to serial devices or ports, they are either labeled as Data Communications
Equipment ("DCE") or Data Terminal Equipment ("DTE"). The difference between these is simple -
every signal pair, like transmit and receive, is swapped. When connecting two DTE or two DCE
interfaces together, a serial null-MODEM cable or adapter is used that swaps the signal pairs.
What Is RS-232?
RS-232 is a standard electrical interface for serial communications defined by the Electronic
Industries Association ("EIA"). RS-232 actually comes in 3 different flavors (A, B, and C) with
each one defining a different voltage range for the on and off levels. The most commonly used
variety is RS-232C, which defines a mark (on) bit as a voltage between -3V and -12V and a space
(off) bit as a voltage between +3V and +12V. The RS-232C specification says these signals can go
about 25 feet (8m) before they become unusable. You can usually send signals a bit farther than this
as long as the baud is low enough.
Besides wires for incoming and outgoing data, there are others that provide timing, status, and
handshaking:
Table 1 - RS-232 Pin Assignments
Pin Description Pin Description Pin Description Pin Description Pin Description
1 Earth Ground 6
DSR - Data
Set Ready
11 Unassigned 16
Secondary
RXD
21
Signal
Quality
Detect
2
TXD -
Transmitted
Data
7
GND -
Logic
Ground
12
Secondary
DCD
17
Receiver
Clock
22 Ring Detect
3
RXD -
Received
Data
8
DCD - Data
Carrier
Detect
13
Secondary
CTS
18 Unassigned 23
Data Rate
Select
4
RTS -
Request To
9 Reserved 14
Secondary
TXD
19
Secondary
RTS
24
Transmit
Clock
Send
5
CTS - Clear
To Send
10 Reserved 15
Transmit
Clock
20
DTR - Data
Terminal
Ready
25 Unassigned
Two standards for serial interfaces you may also see are RS-422 and RS-574. RS-422 uses lower
voltages and differential signals to allow cable lengths up to about 1000ft (300m). RS-574 defines
the 9-pin PC serial connector and voltages.
Signal Definitions
The RS-232 standard defines some 18 different signals for serial communications. Of these, only
six are generally available in the UNIX environment.
GND - Logic Ground
Technically the logic ground is not a signal, but without it none of the other signals will operate.
Basically, the logic ground acts as a reference voltage so that the electronics know which voltages
are positive or negative.
TXD - Transmitted Data
The TXD signal carries data transmitted from your workstation to the computer or device on the
other end (like a MODEM). A mark voltage is interpreted as a value of 1, while a space voltage is
interpreted as a value of 0.
RXD - Received Data
The RXD signal carries data transmitted from the computer or device on the other end to your
workstation. Like TXD, mark and space voltages are interpreted as 1 and 0, respectively.
DCD - Data Carrier Detect
The DCD signal is received from the computer or device on the other end of your serial cable. A
space voltage on this signal line indicates that the computer or device is currently connected or on
line. DCD is not always used or available.
DTR - Data Terminal Ready
The DTR signal is generated by your workstation and tells the computer or device on the other end
that you are ready (a space voltage) or not-ready (a mark voltage). DTR is usually enabled
automatically whenever you open the serial interface on the workstation.
CTS - Clear To Send
The CTS signal is received from the other end of the serial cable. A space voltage indicates that is
alright to send more serial data from your workstation.
CTS is usually used to regulate the flow of serial data from your workstation to the other end.
RTS - Request To Send
The RTS signal is set to the space voltage by your workstation to indicate that more data is ready to
be sent.
Like CTS, RTS helps to regulate the flow of data between your workstation and the computer or
device on the other end of the serial cable. Most workstations leave this signal set to the space
voltage all the time.
Asynchronous Communications
For the computer to understand the serial data coming into it, it needs some way to determine where
one character ends and the next begins. This guide deals exclusively with asynchronous serial data.
In asynchronous mode the serial data line stays in the mark (1) state until a character is transmitted.
A start bit preceeds each character and is followed immediately by each bit in the character, an
optional parity bit, and one or more stop bits. The start bit is always a space (0) and tells the
computer that new serial data is available. Data can be sent or received at any time, thus the name
asynchronous.
Figure 1 - Asynchronous Data Transmission
The optional parity bit is a simple sum of the data bits indicating whether or not the data contains an
even or odd number of 1 bits. With even parity, the parity bit is 0 if there is an even number of 1's in
the character. With odd parity, the parity bit is 0 if there is an odd number of 1's in the data. You
may also hear the terms space parity, mark parity, and no parity. Space parity means that the parity
bit is always 0, while mark parity means the bit is always 1. No parity means that no parity bit is
present or transmitted.
The remaining bits are called stop bits. There can be 1, 1.5, or 2 stop bits between characters and
they always have a value of 1. Stop bits traditionally were used to give the computer time to process
the previous character, but now only serve to synchronize the receiving computer to the incoming
characters.
Asynchronous data formats are usually expressed as "8N1", "7E1", and so forth. These stand for "8
data bits, no parity, 1 stop bit" and "7 data bits, even parity, 1 stop bit" respectively.
What Are Full Duplex and Half Duplex?
Full duplex means that the computer can send and receive data simultaneously - there are two
separate data channels (one coming in, one going out).
Half duplex means that the computer cannot send or receive data at the same time. Usually this
means there is only a single data channel to talk over. This does not mean that any of the RS-232
signals are not used. Rather, it usually means that the communications link uses some standard other
than RS-232 that does not support full duplex operation.
Flow Control
It is often necessary to regulate the flow of data when transferring data between two serial
interfaces. This can be due to limitations in an intermediate serial communications link, one of the
serial interfaces, or some storage media. Two methods are commonly used for asynchronous data.
The first method is often called "software" flow control and uses special characters to start (XON or
DC1, 021 octal) or stop (XOFF or DC3, 023 octal) the flow of data. These characters are defined in
the American Standard Code for Information Interchange ("ASCII"). While these codes are useful
when transferring textual information, they cannot be used when transferring other types of
information without special programming.
剩余25页未读,继续阅读
般若程序蝉
- 粉丝: 46
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0