重叠IO

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
Handle to an event set to the signaled state when the operation has been completed. The calling process must set this member either to zero or a valid event handle before calling any overlapped functions. To create an event object, use the CreateEvent function.

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

 

FunctionDescription
CreateFileOpens a serial port.
GetCommStateFills in a device-control block—DCB structure—with the current control settings for a specified communication device.
SetCommStateConfigures 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.
GetCommTimeoutsRetrieves the time-out parameters for all read/write operations on a specified communication device.
SetCommTimeoutsSets the time-out parameters for all read/write operations on a specified communication device.
WriteFileWrites data to a serial port, which transfers data to the device at the other end of a serial connection.
ReadFileReads data from a serial port, which receives data from a device at the other end of a serial connection.
SetCommMaskSpecifies a set of events to monitor for a communication device.
GetCommMaskRetrieves the value of the event mask for a specified communication device.
WaitCommEventWaits 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.
EscapeCommFunctionDirects a specified communication device to perform an extended function. Often used to set a serial port to IR mode.
ClearCommBreakRestores character transmission for a specified communication device and places the transmission line in a non-break state.
ClearCommErrorRetrieves communication error data and reports the current status of a specified communication device.

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值