Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial Port Reading and Writing 1

Status
Not open for further replies.

Robertus

Programmer
Feb 16, 2001
81
RO
Is there any one who could tell me wich function(s) to use in order to read from serial port com2???
 
Hi Robertus,

This is what I use

// Used in all calls to reference the channel after it is created
HANDLE hConnection;

// Open the port
hConnection = CreateFile("COM2",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);


// Close the port
CloseHandle(hConnection);


// Read
ReadFile(hConnection,
cBuffer, // Character array to receive data
nNumberChar, // number of characters to receive
&dwCommCounter, // number actually received
NULL)

// Write
WriteFile(hConnection,
cBuffer, // Character array to send
nNumberChar, // number of characters to send
&dwCommCounter, // number successfully sent
NULL)

Hope this helps.

Dragoon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top