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

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2328 更新时间:2009/4/22 20:45:36
The original author thanked Mr. Strudthoff, Michael Carter, Peter Waltenberg, Antonino Ianella, Greg Hankins, Dave Pfaltzgraff, Sean Lincolne, Michael Wiedmann, and Adrey Bonar.

原作者感谢 Strudthoff, Michael Carter, Peter Waltenberg, Antonino Ianella, Greg Hankins, Dave Pfaltzgraff, Sean Lincolne, Michael Wiedmann, and Adrey Bonar 诸位先生。

1.5.   Feedback  意见反馈

Feedback is most certainly welcome for this document. Without your submissions and input, this document wouldn''''t exist. Please send your additions, comments and criticisms to the following email address : <gary@frerking.org>.

非常欢迎对此文档提出反馈意见。有任何补充,评论,批评请发信到: gary@frerking.org

2.    Getting started  入门

2.1. Debugging  调试

The best way to debug your code is to set up another Linux box, and connect the two computers via a null-modem cable. Use miniterm (available from the LDP programmers guide (ftp://sunsite.unc.edu/pub/Linux/docs/LDP/programmers-guide/lpg-0.4.tar.gz in the examples directory) to transmit characters to your Linux box. Miniterm can be compiled very easily and will transmit all keyboard input raw over the serial port. Only the define statement #define MODEMDEVICE "/dev/ttyS0" has to be checked. Set it to ttyS0 for COM1, ttyS1 for COM2, etc.. It is essential for testing, that all characters are transmitted raw (without output processing) over the line. To test your connection, start miniterm on both computers and just type away. The characters input on one computer should appear on the other computer and vice versa. The input will not be echoed to the attached screen.

调试代码最好的方法,是另外建立一台Linux主机(Linux box),采用非调制解调器的串口线(null-modem)连接两台机器。还可以使用minicom (可以从 LDP 编程指南上获得:ftp://sunsite.unc.edu/pub/Linux/docs/LDP/programmers-guide/lpg-0.4.tar.gz 里的examples 目录)来传输字符到你的 Linux 主机。Miniterm 很容易编译而且会直接把键盘的输入不做处理(raw 方式)地传到串口。只需要把 定义申明 #define MODEMDIVICE “/dev/ttyS0” 改一下。 COM1 口就设置成 ttyS0, COM2 口就是 ttyS1, 以此类推测试是必需的,所有的字符直接通过缆线传输,不进行任何输出处理。为了测试你的连接,在你的两台机器上开启minicom,然后随意输入一些字符。从一台电脑中输入的字符应该能显示在另一台设备上,反之亦然。输入的字符不会回显(echo) 在本地的屏幕上.

To make a null-modem cable you have to cross the TxD (transmit) and RxD (receive) lines. For a description of a cable see sect. 7 of the Serial-HOWTO.

 

自制非调制解调器的串口连接线(null-modem cable)时,你需要将一端的传送端(TxD)与另一端的接收端(RxD)连接,一端的接收端与另外一端的传送端连接,详情见Serial-HOWTO第七节。

It is also possible to perform this testing with only one computer, if you have two unused serial ports. You can then run two miniterms off two virtual consoles. If you free a serial port by disconnecting the mouse, remember to redirect /dev/mouse if it exists. If you use a multiport serial card, be sure to configure it correctly. I had mine configured wrong and everything worked fine as long as I was testing only on my computer. When I connected to another computer, the port started loosing characters. Executing two programs on one computer just isn''''t fully asynchronous.

如果你的电脑有两个空闲的串口端口的话,那么只要使用一台机器就可以做这些试验了,你可以在两个虚拟控制台上各运行一个miniterm,分别用来发送和接收结果。如果你使用串口鼠标,记得在试验前将 /dev/mouse 重定向。如果你使用多端口的串口卡(multiport serial card,一定要确保此设备配置正确,我的电脑就曾因为配置错误,而出现这样的问题:当我在自己的机器上测试的时候一切正常,而连接到其他电脑上的时候,端口开始丢失数据。注意,在一台机器上运行两个串口应用程序,并不是完全异步的。

2.2. Port Settings  端口设置

The devices /dev/ttyS* are intended to hook up terminals to your Linux box, and are configured for this use after startup. This has to be kept in mind when programming communication with a raw device. E.g. the ports are configured to echo characters sent from the device back to it, which normally has to be changed for data transmission.

设备 /dev/ttyS* 会被当作连接到你的 Linux 机器的终端设备,而且在系统启动后就已经配置好了。這一点是在你寫 raw 设备的串口通信程式時必需牢記的. 举例来说,這個串口被設定為回显(echo)所有自此设备送出的字符, 通常在做数据传输时,需要改變這種工作模式。

All parameters can be easily configured from within a program. The configuration is stored in a structure struct termios, which is defined in <asm/termbits.h>:

#define NCCS 19
        struct termios {
                tcflag_t c_iflag;         /* input mode flags */
                tcflag_t c_oflag;        /* output mode flags */
                tcflag_t c_cflag;        /* control mode flags */
                tcflag_t c_lflag;        /* local mode flags */
                cc_t c_line;             /* line discipline */
                cc_t c_cc[NCCS];         /* control characters */
}

所有的参数都可以在程序中轻松配置。配置保存在结构体 struct termios 中,这个结构是在 <asm/termbits.h> 中定义的

#define NCCS 19
        struct termios {
                tcflag_t c_iflag;         /* 输入模式标志 */
               tcflag_t c_oflag;        /* 输出模式标志 */
                tcflag_t c_cflag;        /* 控制模式标志 */

上一页  [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……
    咸宁网络警察报警平台