Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1119990
  • 博文数量: 91
  • 博客积分: 10053
  • 博客等级: 上将
  • 技术积分: 1335
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-01 12:46
文章分类
文章存档

2011年(4)

2010年(22)

2009年(22)

2008年(43)

分类: LINUX

2010-07-02 10:26:56

释放ttyS0作为通信串口

#include
#include
#include
#include
#include
#include
void CloseConsole(void) {

int fp;
struct termios options;
printf("change1\n");
fp = open("/dev/tty1",O_RDONLY); // 改变console
ioctl(fp,TIOCCONS);
close(fp);

fp = open("/dev/tts/0",O_RDWR|O_NOCTTY|O_NDELAY); //打开串口0读写
if(fp == -1) exit(0);
tcgetattr(fp,&options);
cfsetispeed(&options,B115200);
cfsetospeed(&options,B115200);
options.c_cflag |= (CLOCAL|CREAD);
tcsetattr(fp,TCSANOW,&options);
write(fp,"hello world!\n123",15);
close(fp);                       //关闭串口0

fp = open("/dev/tty0",O_RDONLY); //恢复console 到串口0
ioctl(fp,TIOCCONS);
close(fp);
printf("change2\n");
}

关于关闭SHELL对串口的占用,使之能做普通的串口通信和拨号

1、步骤:
在内核编译过程中执行make menuconfig
Character devices --->
Serial drivers --->

S3C2410 serial port support
[ ] Console on S3C2410 serial port 【注】去掉这项即可,不必修改busybox/init.c了
< > 8250/16550 and compatible serial support (EXPERIMENTAL)
2、备注:
这样就不能用ttyS0口来登录ARM开发板了,你可以选择用TELNET的方式来登录。
做法:telnet 192.168.0.12(你的开发板的IP地址)
         输入:“root”用户名就可以进入你的开发板了
3、OK..

阅读(5883) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~