i m using Select() sys cal on XBee rf module which is on /dev/ttyUSB0.but this syscal just doesnt return(returns only on timeout),but if i use read() in a WHILE loop on this port i can see the data comming
/*code to open the port*/
system("stty -F /dev/ttyUSB0 5:0:8bd:0:3:1c:7f:15:1:64:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0");
fd = open("/dev/ttyUSB0", O_RDWR );
printf("fd is %d",fd);
if(fd == -1)
return ERR_PORT;
select returns only when TIMEOUT not when port is ready for reading
FD_ZERO (&set);
FD_SET (fd, &set);//fd is an opened file des. for /dev/ttyUSB0
struct timeval timeout;
timeout.tv_sec = 50;
timeout.tv_usec = 0;
if(select(FD_SETSIZE,&set, NULL,NULL,&timeout)==1)
Do_stuff();
else
return TIMEOUT;
but if i use following i can see the data being printed
char ch;
while(1)
{
read(fd,&ch,1);
printf("\n0x%X",ch);
}
Please note: about command in system()
function,i got it by issuing stty -F /dev/USB0 -g
after having GTKterm opened on /dev/ttyUSB0
.(thats when i was able to talk to my modem from my program) so made a guess that GTKterm configured the port,and i used the exact same configuration.