ttytest.c

来自「一个在arm2410下与pc机的串口调试程序」· C语言 代码 · 共 65 行

C
65
字号
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "rs232.h"//#define DEBUGint main(int argc, char *argv[]){        int ret1;	int ret,portno,nWritten,nRead;	char buf[256];	portno=0;	//while(1)	//{		  ret=OpenCom(portno,"/dev/ttyS0",115200);//open the com 1                portno=1;                 ret1=OpenCom(portno,"/dev/ttyS1",115200);//open the com 2 		if(ret==-1)		{			perror("The /dev/ttyS0 open error.");			exit(1);		}//------------------------------------------------------------               if(ret1==-1)                {                        perror("The /dev/ttyS1 open error.");                        exit(1);                }//------------------------------------------------------------	//	nWritten=ComWrt(portn1,"please input:",12);	//	printf("/dev/ttyS0 has send %d chars!\n",nWritten);		printf("\nRecieving data!**");		fflush(stdout);		nRead=ComRd(1,buf,256,30000);//receive the data from the com 2                printf("nread=%d\n",nRead);		if(nRead>0)		{			printf("ok*****OK\n");		}		else		{                   	printf("Timeout\n");                        ret=CloseCom(portno);//close the com 2                 }                ret=CloseCom(portno);		if((ret=CloseCom(portno)==-1))		{			perror("Close com");			exit(1);		}		ret=CloseCom(0);		if((ret=CloseCom(portno)==-1))		{			perror("Close com");			exit(1);		}		printf("ok*****************end\n");	//}//end while 1	printf("Exit now.\n");	return;}

⌨️ 快捷键说明

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