Dave I appreciate the info.

Unfortunately still no joy.  I used 

int qsb = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK);
fcntl(qsb, F_SETFL, fcntl(qsb, F_GETFL ) & ~O_NONBLOCK);

fcntl after my open() but the only result is that the process hangs 
indefinately and there is no output.  If I run then kill "screen" before 
executing the code change works albeit much slower.

Did I put the call in the wrong location?


On Monday, December 2, 2013 4:55:55 PM UTC-5, Dave Hylands wrote:
>
> Hi Mike,
>
>
> On Mon, Dec 2, 2013 at 1:45 PM, Mikester <[email protected] <javascript:>> 
> wrote:
> >
> > Im using a TTYL encoder/decoder counter device that translates the 
> encoder pulses to a USB serial port.
> >
> > the call being used is
> > int qsb = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK);
> > ...
> > ioResult = read(qsb, response, responseSize); //EAGAIN error in here
>
> Exactly. This happens because the serial port was opened using O_NONBLOCK.
>
> Opening with O_NONBLOCK is desirable, so you need to add
>
>     fcntl(gsb, F_SETFL, fcntl(gsb, F_GETFL ) & ~O_NONBLOCK);
>
> to turn off non-blocking mode once you've done the open.
>
> Then the read command will block and wait for the data, rather than 
> returning EAGAIN if the data isn't ready yet.
>
> Also - In general I highly recommend that you put the port in raw mode. 
> Otherwise if you're sending binary data you'll get a bunch of weird 
> translations happening and your data will get corrupted. In canonical mode, 
> it interprets things like backspaces, and may massage your CRs
>
> I use VMIN = 1 and VTIME = 0 which means that read will return as soon as 
> a single byte is available, but it will return more if its available.
> So you may get less data that you asked for, but on the other hand if you 
> ask for 6 bytes, it won't actually wait for 6 bytes to arrive.
>
> It kind of boils down to the type of error handling that you want to do. 
> Here's a site that explains the VMIN/VTIME configuration:
> http://www.unixwiz.net/techtips/termios-vmin-vtime.html
>
>
> --
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to