// 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)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.