释放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..