| Author |
Is there STL equivalent of CreateFile for comms
|
|
| Ian Semmel 2005-08-12, 10:35 pm |
| In windows I would use CreateFile and overlapped I/O to read/write to the comms
port in threads.
Is there an equivalent mechanism in STL or do I use <fcntl.h > etc ?
| |
| red floyd 2005-08-12, 10:35 pm |
| Ian Semmel wrote:
> In windows I would use CreateFile and overlapped I/O to read/write to
> the comms port in threads.
>
> Is there an equivalent mechanism in STL or do I use <fcntl.h > etc ?
What, specifically, are you looking for. I'm assuming you're writing in
VC, given the newgroup. STL is generic/portable across platforms,
including those with no concept of files, threads, or overlapped I/O.
Without a better handle on it, I'd just stick with CreateFile. Or are
you going to Unix?
| |
| Ian Semmel 2005-08-12, 10:35 pm |
| Well, I use stl for writing code that will hopefully work on windows and linux.
red floyd wrote:
> Ian Semmel wrote:
>
>
>
> What, specifically, are you looking for. I'm assuming you're writing in
> VC, given the newgroup. STL is generic/portable across platforms,
> including those with no concept of files, threads, or overlapped I/O.
> Without a better handle on it, I'd just stick with CreateFile. Or are
> you going to Unix?
| |
| red floyd 2005-08-12, 10:35 pm |
| Ian Semmel wrote:[color=darkred]
> Well, I use stl for writing code that will hopefully work on windows and
> linux.
>
> red floyd wrote:
>
I'm afraid you're out of luck with the STL for this. As mentioned
earlier, the Standard Library has no concept of serial ports, etc...
You'll need to use <fcntl.h>, <termio.h> (or <termios.h> ), possibly
<sys/select.h>, and <pthread.h>.
Good luck.
| |
| Stephen Howe 2005-08-12, 10:35 pm |
| > Is there an equivalent mechanism in STL...
No. The STL comprises 3 things (and that is all):
- containers
- iterator categories for iterating through containers
- algorithms
Given that, files or devices are not supported. There is file support in
C++, streams, but, strictly speaking is not part of the STL (although you
can use them together).
Stephen Howe
| |
| Ian Semmel 2005-08-13, 5:02 pm |
| Thanks for your input.
What I am looking at is GNU CommonC++ which seems to have what I want.
Ian Semmel wrote:
> In windows I would use CreateFile and overlapped I/O to read/write to
> the comms port in threads.
>
> Is there an equivalent mechanism in STL or do I use <fcntl.h > etc ?
| |
| Ulrich Eckhardt 2005-08-15, 4:01 am |
| Ian Semmel wrote:
> In windows I would use CreateFile and overlapped I/O to read/write to the
> comms port in threads.
>
> Is there an equivalent mechanism in STL or do I use <fcntl.h > etc ?
There are two ways I see:
1. Most implementations come with extensions to the C++ IOStreams that allow
to use native filehandles to construct streams, you could use one of those.
2. Write your own streambuffer. The mechanisms are pretty simple, in the
most simple case you only need to supply the overflow() member function
that dumps a single byte to a sink. You can then use this streambuffer with
a normal IOStream.
HTH
Uli
| |
| Jonathan Turkanis 2005-08-16, 4:02 am |
| Ulrich Eckhardt wrote:
> Ian Semmel wrote:
>
> There are two ways I see:
> 1. Most implementations come with extensions to the C++ IOStreams
> that allow to use native filehandles to construct streams, you could
> use one of those.
You can use stream<file_descriptor> or stream_buffer<file_descriptor> from
Boost.Iostreams: http://tinyurl.com/dafln.
> 2. Write your own streambuffer. The mechanisms are pretty simple, in
> the most simple case you only need to supply the overflow() member
> function that dumps a single byte to a sink. You can then use this
> streambuffer with a normal IOStream.
This is also easy with Boost.Iostreams:
http://www.boost.org/libs/iostreams...html?path=2.1.3
Jonathan
| |
| P.J. Plauger 2005-08-16, 5:10 pm |
| "Jonathan Turkanis" <technews@kangaroologic.com> wrote in message
news:%232ZK44hoFHA.1148@TK2MSFTNGP12.phx.gbl...
> Ulrich Eckhardt wrote:
>
> You can use stream<file_descriptor> or stream_buffer<file_descriptor> from
> Boost.Iostreams: http://tinyurl.com/dafln.
Or just use the facilities that come with the Standard C++
library in VC++. You can construct a filebuf from a file
descriptor.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
| |
| Jonathan Turkanis 2005-08-16, 5:10 pm |
| P.J. Plauger wrote:
> "Jonathan Turkanis" <technews@kangaroologic.com> wrote in message
> news:%232ZK44hoFHA.1148@TK2MSFTNGP12.phx.gbl...
>
>
> Or just use the facilities that come with the Standard C++
> library in VC++. You can construct a filebuf from a file
> descriptor.
Right, that was Ulrich's first point.
Jonathan
|
|
|
|