linux debug串口改为普通串口
来源:互联网 发布:lorenz ectd注册软件 编辑:程序博客网 时间:2024/05/21 06:42
和我们的需求一样,我们是如果用户想把串口作为console的话,那么在系统启动的时候,输入回车来开启console,否则就作为普通的串口用。
1, 在内核驱动里,不要将串口初始化为console, 如我的:
uclinux-l200v40/linux-2.4.x/drivers/char/tty_io.c
// #ifdef CONFIG_SERIAL_WINBOND_CONSOLE
#if 0
winbond_console_init();
#endif
或者在make menuconfig的时候配置,不要将ttyS0设置为console;
2, 在内核启动,进入busybox时,在/etc/inittab中不要设置串口登录:
# Activate watchdog and logging
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 linux
3, 设置启动脚本/etc/init.d/S02Cmd.sh
#!/bin/sh
/usr/sbin/cmd -D 3
exit 0
其中/usr/sbin/cmd为我们从串口接收数据的C程序,这个程序在启动时监听串口,在1s内,如用户按了回车键,那么就作console,这个可以使用下面的方法来实现; 否则就做普通串口用了。
在cmd这个程序中,如果接收到回车键,可以使用system()执行脚本:/usr/sbin/cmd_getty.sh 来重新启用console,内容如下:
#!/bin/sh
/sbin/getty -L ttyS0 115200 linux &
exit 0
如果使用ssh登录上去,想开启console,也可以直接使用下面命令来开启:
/sbin/getty -L ttyS0 115200 linux &
如果有更好的方法,可以交流!
谢谢,dglwx,我从网上学习了一个方法。目前串口和终端都可以同时收到到数据,同时在终端中如果输入CTRL+C程序可以推出,哈哈,很好玩!
void CloseConsole(void)
{
int fp,err;
unsigned char buff[20];
unsigned char send_buff[20];
struct termios options;
printf("change1\n";
fp = open("/dev/console",O_RDONLY); // 改变console
ioctl(fp,TIOCCONS);
close(fp);
fp = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY|O_NONBLOCK); //打开串口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!\n12",15);
while(1)
{
sleep(11);
while(err=ReadComPort(fp,buff,20)/*read(fp,buff,1)*/>0)
{
WriteComPort(fp, send_buff, ;
}
}
close(fp); //关闭串口0
fp = open("/dev/console",O_RDONLY); //恢复console 到串口0
ioctl(fp,TIOCCONS);
close(fp);
printf("change2\n";
}
- linux debug串口改为普通串口
- wince去掉串口0的DEBUG模式,改为普通模式
- 把FL2440 的调试串口改为普通串口的方法
- 把FL2440 的调试串口改为普通串口的方法
- wince 6.0 如何把调试串口改为普通串口
- x210 debug口当普通串口使用
- linux 串口用户模式改为root模式
- arm+linux下调试串口切换成普通串口
- arm+linux下调试串口切换成普通串口
- 红外串口改普通串口
- debug 自定义, Linux下串口读写
- linux2.6.32.2内核把mini2440的UART2改为普通的串口驱动
- linux2.6.32.2内核把mini2440的UART2改为普通的串口驱动
- s3c2410调试串口改成普通串口
- OK6410 修改调试串口为普通串口
- real6410调试串口作为普通串口使用
- OK6410 调试串口 改 普通串口
- openwrt调试串口转为普通通信串口
- R语言系列4
- Java面试宝典
- Leetcode290. Word Pattern & 205. Isomorphic Strings
- Source model metarobots/product_attribute_source_unit not found for attribute
- C\C++中转义字符集锦
- linux debug串口改为普通串口
- x265-1.7版本-encoder/encoder.h注释
- ajax--xhr属性方法&post实例
- mysql中declare语句用法
- [leetcode]87. Scramble String @python
- 39. Combination Sum leetcode python 2016 new season
- android 改变输入法enter键文字 为搜索 下一个 以及前往
- VS2010+WDK VC\include\crtdefs.h(550): error C2143
- 设计模式知识点:细数JDK里的设计模式