yjcomtest.c

来自「linux 多串口测试程序」· C语言 代码 · 共 72 行

C
72
字号
#include "cfg_com.h"int main(int argc,char* argv[]){	int ncomport,fd,fd1,nSpeed,nBits,nEvent,nStop,ncount;	int nret;	unsigned char cRecvBuf[100];	fd = -1;	nSpeed =-1;	nBits = 8;	nEvent ='N';	nStop =1;	ncomport = -1;	ncount = 0;	ncomport = 1;		fd = OpenCom(1);	if(fd == -1)	{		perror("Open Com is error");			return -1;	}#if 1	{					nSpeed = 115200;		if( nSpeed <300 || nSpeed >115200)		{			perror("BandRate range 300<=bps<=115200\n");			return -1;		}							SetComOpt(fd1,nSpeed,nBits,nEvent,nStop);			 int sendSize = 0;			 unsigned char sendBuf1[] = {0xFF,0x02,0x01};			 unsigned char sendBuf2[] = {0xFF,0x0A,0x01};			 printf("send fd=%d\n",fd);			 SetComOpt(fd,nSpeed,nBits,nEvent,nStop);			 while(1)			 {				//sendSize = ComSend (fd,SENDSTR,sizeof(SENDSTR)/sizeof(unsigned char), 50);				sendSize = ComSend (fd,sendBuf1,3, 50);				usleep(100);				sendSize = ComSend (fd,sendBuf2,3, 50);						     	//printf("sendSize2 = %d\n",sendSize); 			     	sleep(5);			//	usleep(100);		 		     	nret = ComRecv(fd,&cRecvBuf,3,100);		     	printf("recv is %d\n",nret);		     	if(nret  > 0)			 	{				 		int i;			 		for(i=0;i<nret;i++)			 		 		printf("%02x ",cRecvBuf[i]);			 	}			 	printf("\n");		 				 }		}	#endif		if(fd != -1)		CloseCom(fd);				return 0;}

⌨️ 快捷键说明

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