linux串口编程
linux串口编程(要点总结) 收藏
串口编程
查询硬件的方式:查询方式、中断方式、DMA方式。串口很多是使用中断方式,这种方式一般来讲对CPU比较有效。
UART的操作主要包括以下几个部分:
数据发送;数据接受;产生中断;产生波特率;Loopback模式;红外模式;自动流控模式;
串口参数的配置主要包括:波特率、数据位、停止位、流控协议。
在linux下操作串口与操作文件相同。
在使用串口之前必须设置相关配置,包括:波特率、数据位、校验位、停止位等。串口设置由下面结构体实现。
Struct termios{
tcflag_t c_iflag; /* input flags */
tcflag_t c_oflag; /* output flags */
tcflag_t c_cflag; /* control flags */
tcflag_t c_lflag; /* local flags */
cc_t c_cc[NCCS]; /* control character */
};
串口配置流程
1、保存原先串口配置,使用tcgetattr(fd,&oldtio)函数
struct termios newtio,oldtio;
tcgetattr(fd,&oldtio);
2、激活选项,有CLOCAL 和CREAD,用于本地连接和接收使能。
newtio.c_cflag |= CLOCAL | CREAD
3、设置波特率,使用函数cfsetispeed、cfsetospeed。
cfsetipeed(&newtio, B115200);
cfsetospeed(&newtio, B115
相关文档:
在linux下安装oracle是件繁琐的事情。具体来讲分为一下几大步:
1.修改系统版本
vi /etc/redhat-release
注释掉第一行,添加一行:redhat-4
2.安装软件包
rpm -Uvh setarch-2*
rpm -Uvh make-3*
rpm -Uvh glibc-2*
rpm -Uvh libaio-0*
rpm -Uvh compat-libstdc++-33-3*
rpm -Uvh compat-gcc-34-3*
rpm -Uvh comp ......
Name
hosts - The static table lookup for host names
Synopsis
/etc/hosts
Description
This manual page describes the format of the /etc/hosts
file. This file is a simple text file that
associates IP addresses with hostnames, one line per IP address. For
each host a single line should be presen ......
shell语法(五项)
1.命令格式
2.通配符
3.重定向
4.管道
5.shell中的引用
6.自动补齐命令行
系统管理维护
ls
pwd
cd
date
passwd
su
clear
man
who
w
uname
uptime
last
dmesg
free
ps
top
文件管理编辑
mkdir
more
cat
diff
grep
rm
touch
ln
file
cp
find
split
mv
压缩解压
zi ......
Linux获取毫秒级时间
Moakap
在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。
int gettimeofday(struct
timeval *tv, struct timezone *tz);
int settimeofday(const
struct timeval *tv , const struct timezone *tz);
struc ......
(1)exit()与_exit()区别: _exit()直接使进程停止运行,清除器使用的内存空间,销毁其在内核中的各种数据结构。
exit()函数在调用exit系统调用之前要检查文件的打开情况,把文件缓冲区中的内容写回文件,清理I/O缓冲(推荐使用这个函数)
(2)waitpid
#include <sys/ ......