你可以看一下SPCOMM的说明文件的:
function GetModemState : DWORD;
Get and return the modem state right now. They are the state of modem
input pin from MSR.
The return value can be one or more of the following codes:
Value Meaning
---------- -----------------------------------------------------------
MS_CTS_ON The CTS (clear-to-send) signal is on.
MS_DSR_ON The DSR (data-set-ready) signal is on.
MS_RING_ON The ring indicator signal is on.
MS_RLSD_ON The RLSD (receive-line-signal-detect) signal is on.
The function fails if the hardware does not support the
control-register values.
可以在一个Timer时间里面检测这些值,这样就可以知道他们是联机的方式还是已经断开了。
例子程序如下,Timer可以设置为100ms。
procedure TForm1.Timer1Timer(Sender: TObject);
var X,Y : integer;
begin
X:=Comm1.GetModemState;
if X=0 then
Label12.Caption:='连接状态:脱机'
else
Label12.Caption:='连接状态:联机';
end;