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 |
相关文档:
复制以下内容,保存为 py 后缀的文件,拷贝到wallpaper文件夹,进入文件夹,以python运行,选取xml为壁纸
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
# Ubuntu 9.10 dynamic wallpaper maker_Can be used in all the distributions of linux
#
# Auto generate a configuration file which you can use ......
目录结构为:
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 ......
下面这个例子列出了所有系统定义的错误代码及错误描述
源代码是:
/************关于本文档********************************************
*filename: strerror.c
*purpose: 列出了系统定义的所有错误代码及描述
*wrote by: zhoulifa(zhoulifa@163.com) 周立发(http://zhoulifa.bokee.com)
Linux爱好者 Linux知识传播 ......
1、LINUX下TTY、CONSOLE、串口之间是怎样的层次关系?具体的函数接口是怎样的?串口是如何被调用的?
tty和console这些概念主要是一些虚拟设备的概念,而串口更多的是指一个真正的设备驱动。Tty实际是一类终端I/O设备的抽象,它实际上更多的是一个管理的概念,目的是向上层的VFS提供 ......
1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个library会找不到
2. 想往上面两个目录以外加东西的时候,一定要修改/etc/ld.so.conf,然后再调用ldconfig,不然也会找不到
比如安装了一个mysql到/usr/local/mysql,mysql有一大堆library在/usr/local/mysql/lib下面 ......