/**************ttytest.c*******************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rs232.h"
main(int argc, char *argv[])
{
int ret,portno,nWritten,nRead;
char buf[256];
portno=0;
while(1)
{
ret=OpenCom(portno,"/dev/ttyS1",115200);
if(ret==-1)
{
perror("The /dev/ttyS1 open error.");
exit(1);
}
nWritten=ComWrt(portno,"abc",3);
printf("\n/dev/ttyS1 has send %d chars!\n",nWritten);
printf("\nRecieving data!***\n");
fflush(stdout);
nRead=ComRd(0,buf,256,3000);
if(nRead>0)
{
printf("*****OK\n");
}
else
printf("Timeout\n");
if((ret=CloseCom(portno)==-1))
{
perror("Close com");
exit(1);
}
printf("\n\n");
}
printf("Exit now.\n");
return;
}
/******************************rs232********************************/
int ComRd(int portNo, char buf[], int maxCnt,int Timeout)
{
int actualRead = 0;
fd_set rfds;
struct timeval tv;
int retval;
if (!ports[portNo].busy)
{
assert(0);
}
/* camp on the port until data appears or 5 seconds have passed */
FD_ZERO(&rfds);
FD_SET(ports[portNo].handle, &rfds);
tv.tv_sec = Timeout/1000;
tv.tv_usec = (Timeout%1000)*1000;
retval = select(16, &rfds, NULL, NULL, &tv);
if (retval)
{
actualRead = read(ports[portNo].handle, buf, maxCnt);
}
rs232.c贴了一部分 我查了retval是0 ,超时 ,我是用串口调试助手发的 会是什么原因呢
疯掉了~~~~