tty.c

来自「44b0/linux环境基本实验源码,包括helloworld,线程,串口,AD」· C语言 代码 · 共 50 行

C
50
字号
#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <termios.h>int main(){    int fd,n;	char buf[256];    fd=open("/dev/ttyS1",O_NOCTTY|O_RDWR|O_NONBLOCK);    if( fd < 0)    {        perror("Unable open /dev/ttyS0\r ");		return 1;    }    n = write( fd, "hello\r", 6);    if ( n < 0 )		puts( "write() of 6 bytes failed!\r");    puts( "write() of 6 bytes ok!\r");    while(1)    {		read(fd,buf,256);		puts(buf);		if(strncmp(buf,"quit",4)==0)break;	    }return 0;}int set_port(int fd){	struct termios opt;		tcgetattr(fd,&opt);/*get current option setup*/	show_option(&opt);//	opt.c_cflags &= 	tcsetattr(fd,&opt);/*get current option setup*/	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?