In a console window type the following:
man -S 2 select
And that will give you info - but to use it is rather non-obvious. Here is an
example for a serial port:
int uartWaitForData(int milliseconds)
{
int maxfd = uartfd + 1; // create the
maximum FD to look for
fd_set readfs; // file
descriptor set
struct timeval timeout;
int result;
//----- set the timeout value
timeout.tv_sec = milliseconds / 1000;
timeout.tv_usec = milliseconds * 1000;
FD_ZERO(&readfs); //
clear the file selector set
FD_SET(uartfd, &readfs); // add
file descriptor to the file selector set
result = select(maxfd, &readfs, NULL, NULL, &timeout); // see if any
chars
if (result <= 0)
return (-1);
// if (FD_ISSET(fd, &readfs)) // see if ready
to be read
// return (1);
return (1);
}
I was merely looking to see if it timed out... and it MIGHT help you determine
if port closed (I don't know). YMMV as they say.
Good luck!
Cheers,
Lloyd
On Tuesday 19 February 2008 09:55, Kim Klaiman wrote:
> No, I haven't.
> Where can I find how to use it to get the status of device?
>
> -----Original Message-----
> From: Lloyd Sargent [mailto:[EMAIL PROTECTED]
> Sent: February 19, 2008 10:40 AM
> To: [email protected]
> Cc: Kim Klaiman
> Subject: Re: reading from usb serial gadget
>
> Hi,
>
> I have not tried this, but have you tried using the select() function?
>
> Cheers,
>
> Lloyd
>
> On Tuesday 12 February 2008 08:36, Kim Klaiman wrote:
> > Hi,
> >
> > Just wanted to follow up if anyone has any idea about this issue.
> >
> > Thanks in advance,
> > Kim Klaiman
> >
> > -----Original Message-----
> > From:
>
> [EMAIL PROTECTED]
>
> > idsp.com
>
> [mailto:[EMAIL PROTECTED]
>
> > x.davincidsp.com] On Behalf Of Kim Klaiman
> > Sent: February 4, 2008 10:26 AM
> > To: [email protected]
> > Subject: reading from usb serial gadget
> >
> > Hello all,
> >
> > I'm using USB serial gadget to read data from PC.
> >
> > At the beginning, I'm opening the device with open(/dev/ttygserial)
>
> and
>
> > then try to read data.
> >
> > If I launch the application and then connect the USB cable, everything
> > works fine. My problem is when the USB cable is disconnected and
> > reconnected while the application is running. Since read is blocking,
>
> I
>
> > cannot check if the device is opened, read does not return and I'm
> > stuck.
> >
> > How can I solve this situation?
> >
> > Thanks,
> > Kim
> >
> > _______________________________________________
> > Davinci-linux-open-source mailing list
> > [email protected]
> > http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
> > _______________________________________________
> > Davinci-linux-open-source mailing list
> > [email protected]
> > http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
--
Lloyd Sargent
Texas Digital Systems, Inc.
400 Technology Parkway
College Station, TX
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source