Reading data from serial port

Oct 02, 2005 4 Replies

I am trying to read/write data to/from Serial port using C++ in Windows



  1. I want to do this using fopen(), fwrite() and fread()functions or inportb()and outportb() functions. But i don't know how to set the port properties including baud rate, buffer size etc and to make the control lines of port ready for reading/writting data. Please help me...

Google "16550 UART", buy a book, or look here:

formatting link

Regards, Richard.

formatting link

Use CreateFile, ReadFile, WriteFile, SetupComm, SetCommState, SetCpmmTimeouts etc. which should work an all Win32 platforms, while manipulating the UART bits directly work in Win9x only.

Paul

Use Cygwin, or learn Windows APIs.

fopen, fread and fwrite for serial I/O? Hmm, since ANSI C doesn't cover serial I/O, why use ANSI calls instead of generic Win32 API? After all, it won't work.

What the heck is inportb()and outportb()? Neither ANSI, nor Win32. You want to access hardware registers? No need for Windows then.

See

formatting link
made by Andi Martin with some contributions from me. Lacks still some documentation (volunteers?), but is stable.

Since you have no clue (no offence meant), this seems to be the easiest way.

Otherwise, get the Win32 Platform SDK and read at least "Serial Communications in Win32" by Allen Denver

formatting link

Oliver

Oliver Betz, Muenchen (oliverbetz.de)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required