Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top