Linux下串口通信
1. 打开串口
与其他的关于设备编程的方法一样,在Linux下,操作、控制串口也是通过操作起设备文件进行的。在Linux下,串口的设备文件是/dev/ttyS0或/dev/ttyS1等。因此要读写串口,我们首先要打开串口:
char *dev = "/dev/ttyS0"; //串口1
int fd = open( dev, O_RDWR );
//| O_NOCTTY | O_NDELAY
if (-1 == fd)
{
perror("Can't Open Serial Port");
return -1;
}
else
return fd;
2. 设置串口速度
打开串口成功后,我们就可以对其进行读写了。首先要设置串口的波特率:
int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,
B38400, B19200, B9600, B4800, B2400, B1200, B300, };
int name_arr[] = {38400, 19200, 9600, 4800, 2400, 1200, 300, 38400,
&n
相关文档:
linux if命令
无论什么编程语言都离不开条件判断。SHELL也不例外。
if list then
do something here
elif list then
  ......
http://wiki.chinaunix.net/index.php/Linux
--------------------获得帮助 : man和info使用 --------------------
因为同一个命令可能属于几个section,如open:就既有命令的open,程序函数的open,等等。每一个section有一个section号。
man -aw <命令>&n ......
Securing your Linux server is important to protect your data, intellectual property, and time, from the hands of crackers (hackers). The system administrator is responsible for security Linux box. In this first part of a Linux server security series, I will provide 20 hardening tips for default inst ......
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
在我们国内,不少
Linux
的先行者都以失败而告终,现在,他们在哪里?怎么不出来说话了?但是,这些先行者想告诉我们什么呢?你想知道吗?
搞 ......
文章来源:http://www.diybl.com/course/6_system/linux/Linuxjs/2008826/137710.html
在Linux内核邮件列表中一个经常被问到的问题就是怎样为Linux内核打一个补丁,或者更具体一点说,存在这么多的主干/分支,一个补丁到底要打在哪个版本的基础内核上。希望这篇文档能够为你解释明白这一点。 除了解释怎样应用以及卸载补 ......