in reply to Serial I/O and time question
What we did (for this exact same application :-) was write our own routine to get a line of data one character at a time using select. Here's the relevant bit of code (modified slightly from the actual code we use):
sub Gets { my($fh, $timeout) = @_; my($str, $c, $rin, $rout, $found, $timeleft); $rin = ''; vec($rin, fileno($fh), 1) = 1; $timeout ||= 1; while (1) { ($found, $timeleft) = select($rout=$rin, undef, undef, $timeout) +; last unless $found; sysread($fh, $c, 1); $str .= $c if ($c ne "\0"); last if ($c eq "\n"); } return $str; }
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Serial I/O and time question
by shepner (Initiate) on Feb 20, 2004 at 22:03 UTC | |
by duff (Parson) on Feb 24, 2004 at 20:34 UTC | |
|
Re: Re: Serial I/O and time question
by eyepopslikeamosquito (Archbishop) on Feb 21, 2004 at 04:04 UTC | |
by shepner (Initiate) on Feb 21, 2004 at 21:12 UTC | |
by duff (Parson) on Feb 24, 2004 at 22:28 UTC |