Using the serial ports in C++ using mingw

Windows (95+) already contains routines that deal with the serial ports. Thierry Schneider (www.tetraedre.com) has provided some documentation, and a bit of C++ that wraps the windows interface in a C++ class.

The minimum you need is:

Be aware that there is a lot of variability in the way different serial devices are configured. Variables include the type of plug or socket, the pins that are used, what handshaking is used, the speed of the data stream, the number of bits in the data, the meaning of the charcters transmitted, how messages are terminated, and what kind of responses they yield. Horowitz and Hill's "The art of electronics" (second edition pp. 720-726, "serial communication") is pretty informative about all this, as is the Microsoft documentation. There are too many variables for trial and error methods to be satisfactory; read the manual for the device concerned.

On the PC side, you can change the software to suit the device concerned. This may mean altering some settings inside tserial.cpp, after consulting the Microsoft documentation. It may be helpful to know that (using the jargon explained in the references above) the PC acts as a DTE (data terminal equipment), can listen to CTS (clear to send) and DSR (data set ready) handshakes, and can drive RTS (request to send) and DTR (data terminal ready).

The rest of Schneider's stuff is here


M.S. Colclough, Oct 2002