发信人: leezy (【HIT】穆子), 信区: BorlandDev
标 题: 在Win32下获得调制解调器的状态
发信站: 哈工大紫丁香 (2002年01月19日15:50:57 星期六), 站内信件
摘 要:如何在Win32下获得调制解调器的状态?
关键字:CreateFile Comm Port
类 别:网络
面的例子演示如何在Win32下获得调制解调器控制寄存器的当前状态。
例子:
procedure TForm1.Button1Click(Sender: TObject);
var
CommPort : string;
hCommFile : THandle;
ModemStat : DWord;
begin
CommPort := 'COM2';
{打开串口}
hCommFile := CreateFile(PChar(CommPort),
GENERIC_READ,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if hCommFile = INVALID_HANDLE_VALUE then
begin
ShowMessage('Unable to open '+ CommPort);
exit;
end;
{获得调制解调器的状态}
if GetCommModemStatus(hCommFile, ModemStat) <> false then begin
if ModemStat and MS_CTS_ON <> 0 then
ShowMessage('The CTS (clear-to-send) is on.');
if ModemStat and MS_DSR_ON <> 0 then
ShowMessage('The DSR (data-set-ready) is on.');
if ModemStat and MS_RING_ON <> 0then
ShowMessage('The ring indicator is on.');
if ModemStat and MS_RLSD_ON <> 0 then
ShowMessage('The RLSD (receive-line-signal-detect) is
on.');
end;
{关闭串口}
CloseHandle(hCommFile);
end;
--
°★.☆° .★·°∴°★.°·∴°☆ ·°∴° ☆..·°∴°.☆°★°∴°
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.230.122]
※ 修改:·leezy 於 01月19日18:40:24 修改本文·[FROM: 202.118.230.122]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:8.762毫秒