Linux下串口编程之二:读串口和写串口
1,打开串口
/**打开串口,dev 串口设备名, mode 打开方式,**/
int opendev(char *dev,mode_t mode)
{
int fd;
fd = open(dev, mode);
if (-1 == fd){
perror("Can't Open Serial Port");
return -1;
}
else{
fcntl(fd, F_SETFL, FNDELAY);
return fd;
}
}
2,写串口
#define FALSE -1
#define TRUE 0
#define NET_PORT 19988
#define MAX_BUF_SIZE 4096
struct net2net_buf{
int len;
char buf[MAX_BUF_SIZE];
};
#define RSDEV_NAME "/dev/ttyS1"
int main(void)
{
int rsfd = 0;
int nwrite;
char input_buf[64];
rsfd = opendev(RSDEV_NAME,O_RDWR | O_NOCTTY |
相关文档:
嵌入式系统与通用PC机不同,一般没有硬盘这样的存储设备而是使用Flash闪存芯片、小型闪存卡等专为嵌入式系统设计的存储装置,本文分析了嵌入式系统中常用的存储设备及其管理机制,介绍了常用的基于FLASH的文件系统类型。
1.嵌入式系统存储设备及其管理机制分析
构建适用于嵌入式系统的Li ......
目录结构为:
inc/hello.h
src/hello.c
main/main.c
Makefile
文件内容为:
hello.h:
void hello(char name[]);
hello.c:
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
main.c:
#include <stdio.h>
#include "hello.h"
// The second hello.h should ......
Unix中的函数select和poll用来,支持Unix中I/O复用的功能,在Unix中I/O模型可以分为以一几种:
(1)阻塞I/O
(2)非阻塞I/O
(3)I/O复用(select和poll)
(4)信号驱动I/O(SIGIO)
(5)异步I/O
其中,现在比较流行的I/O模型是阻塞I/O模型.阻塞I/O是当应用程序和内核交换数据时,由于内核还没有准备好 ......
下面这个例子列出了所有系统定义的错误代码及错误描述
源代码是:
/************关于本文档********************************************
*filename: strerror.c
*purpose: 列出了系统定义的所有错误代码及描述
*wrote by: zhoulifa(zhoulifa@163.com) 周立发(http://zhoulifa.bokee.com)
Linux爱好者 Linux知识传播 ......
安装程序所需要的共享库时需要注意的问题。
起因:安装libsqlite3.so.0 后,使用ldd test 时,却找不到该库文件。
在使用cpptest对原程序运行单元测试时,发现错误,即找不到库文件。
安装完libsqlite3.so.0后,其是存储在usr/local/lib的。所以问题在于,linux下的装载程序 ......