Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
An application calls the ReadFile function to receive data from a device at the other end of a serial connection.
ReadFile takes the same parameters as the WriteFile function.
Typically, a read operation is a separate thread that is always ready to process data arriving at a serial port. A communication event signals the read thread that there is data to read at a serial port. Then the read thread waits for another communication event.
Typically, an application waits for an EV_RXCHAR and then reads (with a very short timeout) all data that is available.
For more information about communication events, see Using Communication Events.
To read from a serial port
Pass the port handle to ReadFile in the hFile parameter.
The CreateFile function returns this handle when an application opens a port.
Specify a pointer to receive the data that is read in lpBuffer.
Specify the number of characters to read in nNumberOfBytesToRead.
Specify a pointer to a location where ReadFile will store the number of bytes read in lpNumberOfBytesRead.
Be sure that lpOverlapped is NULL.
Windows CE does not support overlapped I/O.
The following code example shows how to receive data using the ReadFile function.
BYTE Byte;
DWORD dwBytesTransferred;
ReadFile (hPort, // Port handle
&Byte, // Pointer to data to read
1, // Number of bytes to read
&dwBytesTransferred, // Pointer to number of bytes
// read
NULL // Must be NULL for Windows CE
);
See Also
Programming Serial Connections
Send Feedback on this topic to the authors