var
Stat: TComStat;
Errors: DWORD;
hCom: THandle;
begin
hCom := CreateFile('//./COM1',
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or
FILE_FLAG_OVERLAPPED,
0);
...
ClearCommError(hCom, Errors, @Stat);
// 结构 Stat中
// Stat.cbOutQue 为输出缓冲字节数
// Stat.cbInQue 为输入缓冲字节数
...
CloseHandle(hCom);
end;