天嵌 ARM开发社区

 找回密码
 注册
查看: 4227|回复: 1

求解释:释放ttyS0作为通信串口

[复制链接]
rqmini 发表于 2010-12-25 11:41:18 | 显示全部楼层 |阅读模式
代码转自网上:
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
void CloseConsole(void) {

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

//打开串口0读写,/dev/tts/0相当于串口tq2440_serial0第二步
fp = open("/dev/tts/0",O_RDWR|O_NOCTTY|O_NDELAY);
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");
}

其中不明白的地方:
1)第一步和第三步open的设备为什么不一样,有其他类似程序这2步都是/dev/console。
查了下资料/dev/console是到/dev/tty0当前虚拟终端的链接,那第一步为什么是/dev/tty1虚拟终端

2)就是这个程序运行的时候,/etc/inittab中的tq2440_serial0::askfirst:-/bin/sh需要改吗?当然这里内核配置console是转向串口的。
fjpmbb 发表于 2011-4-21 09:31:39 | 显示全部楼层
友情帮顶 我现在也遇到这个问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-3 00:21 , Processed in 1.026302 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表