📄 ttytest.c
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "rs232.h"//#define DEBUG//int comchec(unsigned char *back)//{int main(int argc, char *argv[]){ int ret1,i,j,count=0,end=0; int ret,portno,nWritten,nRead; char buf[256]; unsigned char sendinit[14]={0x88,0xfb,0xfa,0x07,0x04,0x01,0x01,0x00,0x01,0x61,0x90,0xfc,0xfc}; portno=0; //while(1) //{ //ret=OpenCom(portno,"/dev/ttyS0",115200);//open the com 1 portno=1; ret1=OpenCom(portno,"/dev/ttyS1",19200);//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(portno,sendinit,13); printf("/dev/ttyS0 has send %d chars!\n",nWritten); printf("\nRecieving data!**\n"); fflush(stdout); //nRead=ComRd(1,buf,47,30000);//receive the data from the com 2 for(i=0;i<51;i++) { nRead=ComRd(1,&buf[i],1,500); if(nRead==1) { if(i==0&&buf[i]==0x88) j++; else if(i==1&&buf[i]==0xfb) j++; else j++; if((buf[i]==0xfc) {if(buf[i-1]==0xfc) {end=i;} //else if(buf[i+1]==0xfc) //{NULL;} } } else {j=0; break;} } if(j>0) {for(i=0;i<51;i++) {printf("%x ",buf[i]); if(i==25) printf("\n "); if(i==50) printf("\n "); }} else { printf("Timeout\n"); ret=CloseCom(portno);//close the com 2 } printf("nread=%d\n",nRead); ret=CloseCom(portno); 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -