On Sat, Apr 25, 2015 at 02:38:54PM -0400, Cody P Schafer wrote:
> 
> But for serial devices, I've got min = 1 & time = 0.
> The idea here is to get _any_ data as soon as it is available (with
> grabbing more than one byte possible but not requested).
> 
> I'm not looking for any timeouts. I'm just trying to get bytes as soon
> as they are available in an efficient manner.

Ah OK, I was figuring it was VTIME rather than VMIN that you had set, to
cause read() to return early.

So we can drop the aspect of timeouts, there are indeed none involved
and your example with sp_wait() followed by a sp_nonblocking_read() call
is a direct equivalent.

What makes this code more efficient though? If you have VMIN=1, VTIME=0
then your code will be reading a byte at a time, because each read will
return as soon as there is one byte (VMIN=1), and the loop will execute
far quicker than the time it takes for a byte to come in on a serial line.

So you can just call sp_blocking_read(buf, 1, 0) in a loop to get
exactly the same result.

> 0.1 seconds doesn't appear common.
> Linux's default is VTIME=0, VMIN=1, which causes terminals to match
> the behavior of regular files.
> FreeBSD (from some source code grepping) appears to do the same.
> I don't have any other posix-like systems around, but I'd be impressed
> if they went with non-common behavior.

OK. I just knew there were some non-zero default values around as I'd
been caught out by them before. I thought that included VTIME=1 i.e. 0.1
seconds but apparently not.

> While it's unfortunate that windows doesn't have similarly sane
> defaults (as 
> https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx
> appears to imply, search for COMMTIMEOUTS), that isn't necessarily an
> excuse not to provide those sane defaults via a cross platform
> library.
> 
> The windows docs for COMMTIMEOUTS even imply it can get exactly the
> posix-like VTIME=0, VMIN=1 behavior (
> https://msdn.microsoft.com/en-us/library/windows/desktop/aa363190(v=vs.85).aspx
> , see the "Remarks" section).
> 
> Given all this, it still isn't clear why using events should be required.

I *think* you're correct that those mentioned Windows settings would
reproduce the special case of VTIME=0, VMIN=1 behaviour. It wouldn't
work for any other value of VMIN though, so you'd still be reading a
byte at a time.


Martin

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to