OVERLAPPED
The OVERLAPPED structure contains information used in asynchronous input and output (I/O).
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
DWORD Offset;
DWORD OffsetHigh;
HANDLE hEvent;
} OVERLAPPED;
hEvent
Functions such as WriteFile set the event to the nonsignaled state before they begin an I/O operation.
与重叠I\O操作关系最密切的是串口的读写操作,即ReadFile和WriteFile。
BOOL ReadFile(
HANDLE hFile, // handle to file
LPVOID lpBuffer, // data buffer
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // number of bytes read
LPOVERLAPPED lpOverlapped // overlapped buffer
);
在允许I\O重叠操作模式下,当ReadFile返回FALSE时并不代表读操作失败,GetLastError可能返回ERROR_IO_PENDING,即读操作还没有完成,但是函数立即返回.(在WinXP操作系统中有时会返回87, 待之后分析)。
Serial Communication Functions
Function | Description |
---|---|
CreateFile | Opens a serial port. |
GetCommState | Fills in a device-control block—DCB structure—with the current control settings for a specified communication device. |
SetCommState | Configures a communication device according to the specifications in a DCB structure. The function reinitializes all hardware and control settings, but does not empty I/O queues. |
GetCommTimeouts | Retrieves the time-out parameters for all read/write operations on a specified communication device. |
SetCommTimeouts | Sets the time-out parameters for all read/write operations on a specified communication device. |
WriteFile | Writes data to a serial port, which transfers data to the device at the other end of a serial connection. |
ReadFile | Reads data from a serial port, which receives data from a device at the other end of a serial connection. |
SetCommMask | Specifies a set of events to monitor for a communication device. |
GetCommMask | Retrieves the value of the event mask for a specified communication device. |
WaitCommEvent | Waits for an event to occur for a specified communication device. The set of events monitored by WaitCommEvent is contained in the event mask associated with the device handle. |
EscapeCommFunction | Directs a specified communication device to perform an extended function. Often used to set a serial port to IR mode. |
ClearCommBreak | Restores character transmission for a specified communication device and places the transmission line in a non-break state. |
ClearCommError | Retrieves communication error data and reports the current status of a specified communication device. |