chuankoushou.c

来自「一个基于ARM和linux的终端服务器程序」· C语言 代码 · 共 59 行

C
59
字号
#include<stdio.h>#include<sys/ioctl.h>#include<termios.h>#include<stdlib.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>#include<unistd.h>#include<netdb.h>#include<sys/stat.h>#include<fcntl.h>#include<signal.h>#include<sys/time.h>#include<pthread.h>struct termios tio;int fd;char buff[100];int len;int i;void main(){	if((fd = open("/dev/ttyS0",O_RDWR |O_NDELAY |O_NOCTTY))<0)	{		printf("Couldn't open\n");		exit(1);	}	else	{		printf("comm open success!\n");	}	tio.c_cflag = B115200 |CS8 |CREAD | CLOCAL;	tio.c_cflag &=~HUPCL;	tio.c_lflag = 0;	tio.c_iflag = IGNPAR;	tio.c_oflag = 0;	tio.c_cc[VTIME] = 0;	tio.c_cc[VMIN] = 0;	tcflush(fd,TCIFLUSH);	tcsetattr(fd,TCSANOW,&tio);	fcntl(fd,F_SETFL,FNDELAY);	while(1)	{        len = read(fd,buff,8);	if(len > 0)	{	   for(i=0; i<len; i++)	      printf("%c",buff[i]);	   printf("\n");	}        sleep(1);}close(fd);}

⌨️ 快捷键说明

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