转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> MySql >> 正文
Linux 串口编程HOWTO 中英文简体对照 beta 版         ★★★★

Linux 串口编程HOWTO 中英文简体对照 beta 版

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3078 更新时间:2009/4/22 20:45:36
                tcflag_t c_lflag;        /* 本地模式标志 */
                cc_t c_line;             /* 行控制 line discipline */
                cc_t c_cc[NCCS];         /* 控制字符 control characters */
        }

This file also includes all flag definitions. The input mode flags in c_iflag handle all input processing, which means that the characters sent from the device can be processed before they are read with read. Similarly c_oflag handles the output processing. c_cflag contains the settings for the port, as the baudrate, bits per character, stop bits, etc.. The local mode flags stored in c_lflag determine if characters are echoed, signals are sent to your program, etc.. Finally the array c_cc defines the control characters for end of file, stop, etc.. Default values for the control characters are defined in <asm/termios.h>. The flags are described in the manual page termios(3). The structure termios contains the c_line (line discipline) element, which is not used in POSIX compliant systems.

这个文件也包括了所有标志 (flag) 的定义。c_iflag 中的输入模式标志,进行所有的输入处理,也就是说从其他设备传来的字符,在被read函数读入之前,会先按照标志进行预处理。同样的,c_oflag 定义了所有的输出处理。c_cflag 包括了对端口的设置,比如波特率,停止符号等等。c_lflag 包括了,决定了字符是否回显,信号是否发送到你的程序,等等所有的本地工作方式。c_cc 定义了所有的控制符号,例如文件结束符和停止符等等,所有的这些参数的默认值都定义在<asm/termios.h>中,man手册页termios(3)中有这些参数的具体描述。termio结构体中还包括在不能在 POSIX 系统中使用的c_line参数(行控制)

2.3. Input Concepts for Serial Devices  串口设备的输入概念

Here three different input concepts will be presented. The appropriate concept has to be chosen for the intended application. Whenever possible, do not loop reading single characters to get a complete string. When I did this, I lost characters, whereas a read for the whole string did not show any errors.

这里将介绍串行设备三种不同的输入方式,你需要为你的程序选择合适的工作方式。任何可能的情况下,不要采用循环读取单字符的方式来获取一个字符串。我以前这样做的时候,就丢失了字符,而读取整个字符串的 read 方法,则没有这种错误。

2.3.1. Canonical Input Processing 标准输入模式

This is the normal processing mode for terminals, but can also be useful for communicating with other dl input is processed in units of lines, which means that a read will only return a full line of input. A line is by default terminated by a NL (ASCII LF), an end of file, or an end of line character. A CR (the DOS/Windows default end-of-line) will not terminate a line with the default settings.

Canonical input processing can also handle the erase, delete word, and reprint characters, translate CR to NL, etc..

这是终端设备的标准处理模式, 在与其它 dl 的以行为单位的输入通讯中也很有用。这种方式中, read 会传回一整行完整的输入. 一行的结束,默认是以 NL (ASCII值 LF), 文件结束符, 或是一个行结束字符。默认设置中, CR ( DOS/Windows 里的默认行结束符) 并不是行结束标志。

标准的输入处理还可以处理 清除, 删除字, 重画字符, 转换 CRNL 等等功能。

2.3.2. Non-Canonical Input Processing 非标准输入模式

Non-Canonical Input Processing will handle a fixed amount of characters per read, and allows for a character timer. This mode should be used if your application will always read a fixed number of characters, or if the connected device sends bursts of characters.

非标准输入处理可以用于需要每次读取固定数量字符的情况下, 并允许使用字符接收时间的定时器。这种模式可以用在每次读取固定长度字符串的程序中, 或者所连接的设备会突然送出大量字符的情况下。

2.3.3. Asynchronous Input 异步输入模式

The two modes described above can be used in synchronous and asynchronous mode. Synchronous is the default, where a read statement will block, until the read is satisfied. In asynchronous mode the read statement will return immediatly and send a signal to the calling program upon completion. This signal can be received by a signal handler.

前面敘述的兩種模式都可以用在同步與异步的傳輸模式。默认是在同步的模式下工作的, 也就是在尚未讀完数据之前, read 的狀態會被阻塞(block)。而在异步模式下,read 的狀態會立即返回並送出一个信号到所调用的程式直到完成工作。這個信号可以由信号处理程式 handler來接收。

2.3.4. Waiting for Input from Multiple Sources 等待来自多信号源的输入

This is not a different input mode, but might be useful, if you are handling multiple devices. In my application I was handling input over a TCP/IP socket and input over a serial connection from another computer quasi-simultaneously. The program example given below will wait for input from two different input sources. If input from one source becomes available, it will be processed, and the program will then wait for new input.

The approach presented below seems rather complex, but it is important to keep in mind that Linux is a multi-processing operating system. The select system call will not load the CPU while waiting for input, whereas looping until input becomes available would slow down other processes executing at the same time.

本节介绍的不是另一个输入模式,不过如果你要处理来自多个设备的数据的话,可能会很有用。在我的应用程序中,我需要同时通过一个 TCP/IP socket 和一个串口来处理其它计算机传来的输入。下面给出的示例程序将等待来自两个不同输入源的输入。如果其中一个信号源出现, 程序就会进行相应处理, 同时程序会继续等待新的输入。

后面提出的方法看起来相当覆杂, 但请记住 Linux 是一个多进程的操作系统。 系统调用 select 并不会在等待输入信号时增加 CPU 的负担,而如果使用轮询方式来等待输入信号的话,则将拖慢其它正在执行的进程。

 

上一页  [1] [2] [3] 


[C语言系列]C# 和 Linux 时间戳转换  [Web开发]PHP flock文件锁介绍
[Web开发]flock() Linux下的文件锁  [电脑应用]Linux下的六个免费的虚拟主机管理系统介绍
[互联动态]Windows Server 2008 Beta 3官方ISO下载  [电脑应用]Linux数据库大比拚
[操作系统]在Windows中玩转Linux操作系统  [办公软件]在RedHat Linux 9里安装gaim0.80
[办公软件]掌握 Linux 调试技术  [办公软件]理解 Linux 配置文件
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台