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