![]() |
Reading from serial ports using C++
Hi does anyone here know how to read from a serial port using c++?
I just got this got from the internet but it doesnt work: CSerial serial; if (serial.Open(2, 9600)) AfxMessageBox("Port opened successfully"); else AfxMessageBox("Failed to open port!"); |
Re: Reading from serial ports using C++
I've used the WinAPI directly; this was to open the com port for writing and I just had a terminal emulator on the other end listening and displaying debug messages from my program. Probably doesn't take a lot of adapting (in fact may be usable directly for reading from the port):
Code:
CommPortHandle = OpenComm("com1",CommBufferSize,CommBufferSize); |
Re: Reading from serial ports using C++
thanks xpi0t0s...hey does the following code do the same thing?
Code:
#include "windows.h" |
Re: Reading from serial ports using C++
No. I vaguely remember (from about 1993) experimenting with CreateFile as the "correct" way to use COM ports, not getting anywhere (probably because it involved millions of cryptic parameters), then finding that OpenComm worked perfectly well for what I wanted.
Checking the help in VS2005 it seems OpenComm has disappeared, so ignore what I said earlier. That code was written back in the Windows 3.1 days and seems now to be completely obsolete. Sorry about that... |
| All times are GMT +5.5. The time now is 10:07. |