class for serial port access

Status
Not open for further replies.

mmike

Banned
Joined
Jun 4, 2006
Messages
122
Helped
14
Reputation
28
Reaction score
5
Trophy points
1,298
Activity points
0
class for serial port access. API functions used - CreateFile (), CloseHandle (), GetCommState (), SetCommState (), BuildCommDCBAndTimeouts (), SetCommTimeouts (), ReadFile (), WriteFile (), GetComTimeouts (), GetCommProperties (), GetCommModemStatus ().

Serial port wrapper usage example

#include "comport.hpp"

void someFunction ()
{
COMPort aPort ("COM2");
aPort.setBitRate (COMPort::br9600);
aPort.setParity (COMPort::Even);
aPort.setDataBits (COMPort::db7);
aPort.setStopBits (COMPort::sb1);

while (1)
{
char aData = aPort.read ();
// do processing
.
.
.
}

} // end someFunction

The code above opens serial port COM2 and configures it to 9600 bps baud rate, even parity, 7 data bits, 1 stop bit. Then data is read and processed in continuos loop.

In case of problems when writtin to COM port, try change hardware handshake mode by calling function setHandshaking (false).



**broken link removed**
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…