Serial Communication Code for Reading

Apr 24, 2010 at 10:38am
Hi, does anyone has any simple C++ code to read data from serial port? I'm doing a project to receive a temperature reading for every 5 seconds from the serial port, so it shouldn't be any complicated code needed to be implemented for data queue up function.

I've already searched through google for the code but it is either too complicated, too long to understand or has problem in compilation. So kindly ask for your help here. Thanks!
Apr 24, 2010 at 5:19pm
windows or linux or other OS
Apr 24, 2010 at 5:42pm
I'm using windows vista
Apr 24, 2010 at 5:50pm
This may be of some use.
This is about as simple as it gets
http://msdn.microsoft.com/en-us/library/aa363201%28VS.85%29.aspx

You use ReadFile and Writefile functions once you have the handle to the comport and you have set the baud rate as described in that article
Last edited on Apr 24, 2010 at 5:51pm
Apr 24, 2010 at 6:24pm
From which library do ReadFile and WriteFile function originate? How to use it? Anyway I plan to incorporate this code into my C++ WinApi, can C mix well with C++?
Apr 24, 2010 at 6:34pm
They are both declared in windows.h (which itself will include the standard api headers) .
The library is kernel32.lib.

The api mix with C++, the api headers have #ifdef __cplusplus conditionals.
Topic archived. No new replies allowed.