arm板 釋放ttyS0作為通訊串口(關閉調試串口)

來源:互聯網
上載者:User

釋放ttyS0作為通訊串口

#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);

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.