[Boost-users] [ASIO] Windows native type for ASIO serial port?

95 views
Skip to first unread message

Jeff Diewald

unread,
Mar 30, 2009, 9:35:04 AM3/30/09
to boost...@lists.boost.org, Jeff Diewald
I have a boost::asio::serial_port object. What is the specific Windows
type returned by native()?

I'm having trouble with my serial communication across the serial
port, and want to get more diagnostic information by going to the
native level. The serial port hangs occasionally on a synchronous
read_some call, and I haven't been able to figure out why. Ideally,
I'd like to build a timeout into the synchronous call.

Any help is appreciated,
Jeff Diewald
JEOL USA
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christoph Gysin

unread,
Mar 30, 2009, 10:27:20 AM3/30/09
to boost...@lists.boost.org, Jeff Diewald
2009/3/30 Jeff Diewald <die...@jeol.com>:

> I have a boost::asio::serial_port object. What is the specific Windows type
> returned by native()?

See:
/usr/include/boost/asio/detail/win_iocp_serial_port_service.hpp

On Windows asio talks to the serial port by opening the special file
COM1. The native() call returns a HANDLE to that special file.

Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3

Christoph Gysin

unread,
Mar 30, 2009, 10:46:22 AM3/30/09
to boost...@lists.boost.org, Jeff Diewald
> I'm having trouble with my serial communication across the serial port, and
> want to get more diagnostic information by going to the native level. The
> serial port hangs occasionally on a synchronous read_some call, and I
> haven't been able to figure out why. Ideally, I'd like to build a timeout
> into the synchronous call.

AFAIK read_some() should only block if there is no data to read at
all. You could check for that with:

boost::asio::socket_base::bytes_readable command(true);
socket.io_control(command);
std::size_t bytes_readable = command.get();

Or you implement your own read() function with async_read() and
deadline_timer, like here:
http://lists.boost.org/Archives/boost/2007/04/120339.php

Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3

Jeff Diewald

unread,
Apr 3, 2009, 3:38:13 PM4/3/09
to Christoph Gysin, boost...@lists.boost.org, Jeff Diewald
Thanks. This is just what I needed to get to the serial port. I could
set the Windows timeouts using the SetCommTimeouts mechanism, which
worked just as I wanted.

Jeff

Reply all
Reply to author
Forward
0 new messages