Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel Firmware
serial
Commits
1b2d29f6
Commit
1b2d29f6
authored
14 years ago
by
William Woodall
Browse files
Options
Download
Email Patches
Plain Diff
Fixed nonblocking read problem.
parent
3d69d04c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
17 deletions
+15
-17
src/serial.cpp
src/serial.cpp
+15
-17
No files found.
src/serial.cpp
View file @
1b2d29f6
...
...
@@ -202,28 +202,26 @@ static const boost::posix_time::time_duration timeout_zero_comparison(boost::pos
const
int
Serial
::
read
(
char
*
buffer
,
int
size
)
{
this
->
reading
=
true
;
if
(
this
->
nonblocking
)
// Do not wait for data
boost
::
asio
::
async_read
(
*
this
->
serial_port
,
boost
::
asio
::
buffer
(
buffer
,
size
),
boost
::
bind
(
&
Serial
::
read_complete
,
this
,
boost
::
asio
::
placeholders
::
error
,
boost
::
asio
::
placeholders
::
bytes_transferred
));
else
// Wait for data until size is read or timeout occurs
if
(
this
->
nonblocking
)
{
// Do not wait for data
return
this
->
serial_port
->
read_some
(
boost
::
asio
::
buffer
(
buffer
,
size
));
}
else
{
// Wait for data until size is read or timeout occurs
boost
::
asio
::
async_read
(
*
this
->
serial_port
,
boost
::
asio
::
buffer
(
buffer
,
size
),
transfer_at_least_ignore_invalid_argument
(
size
),
boost
::
bind
(
&
Serial
::
read_complete
,
this
,
boost
::
asio
::
placeholders
::
error
,
boost
::
asio
::
placeholders
::
bytes_transferred
));
if
(
this
->
timeout
>
timeout_zero_comparison
)
{
// Only set a timeout_timer if there is a valid timeout
this
->
timeout_timer
.
expires_from_now
(
this
->
timeout
);
this
->
timeout_timer
.
async_wait
(
boost
::
bind
(
&
Serial
::
timeout_callback
,
this
,
boost
::
asio
::
placeholders
::
error
));
if
(
this
->
timeout
>
timeout_zero_comparison
)
{
// Only set a timeout_timer if there is a valid timeout
this
->
timeout_timer
.
expires_from_now
(
this
->
timeout
);
this
->
timeout_timer
.
async_wait
(
boost
::
bind
(
&
Serial
::
timeout_callback
,
this
,
boost
::
asio
::
placeholders
::
error
));
}
while
(
this
->
reading
)
this
->
io_service
.
run_one
();
this
->
bytes_to_read
=
size
;
return
this
->
bytes_read
;
}
while
(
this
->
reading
)
this
->
io_service
.
run_one
();
this
->
bytes_to_read
=
size
;
return
this
->
bytes_read
;
}
const
std
::
string
Serial
::
read
(
int
size
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment