TAPI通过猫取来电显示电话号码?(串口通信或有经验的请指教)

lhz888 2003-10-23 05:48:10

我用TAPI通过猫做一个来电显示器,但是只能检测到响铃,并没有显示来电号码,请高手指点!!!!

代码如下:
========================================================================
... //前面略(要包含tapi单元)
public
{ Public declarations }
obj:TObject;
m_bConnected:bool;
iRingCount:integer; //响铃次数
exepath:string;


/////////////////////////
hCall: THCall;
line:THLine;
lineApp:THlineApp;

nDevs,tapiVersion:longint;
sappname:widestring;
CallParams:TlineCallParams;
////////////////////////////
procedure RecordWav; //录音
procedure PlayMusic; //播放音乐


procedure init_listen; //初始化并侦听
end;



var
Form1: TForm1;
callinfo: TLineCallInfo;
buf:array[0..1023] of char;
implementation

{$R *.dfm}
//回调函数处理消息
procedure lineCallback(hDevice, dwMsg, dwCallbackInstance,
dwParam1, dwParam2, dwParam3: LongInt);
{$IFDEF WIN32}
stdcall;
{$ELSE}
export;
{$ENDIF}
var
Str: string;
hCall: THCall;
begin
if dwMsg = LINE_APPNEWCALL then
Form1.lstMsg.items.Add('LINE_APPNEWCALL')
else
if dwMsg = LINE_CLOSE then
Form1.lstMsg.items.Add('LINE_CLOSE ')
else
if dwMsg = LINE_CREATE then
Form1.lstMsg.items.Add('LINE_CREATE ')
else
if dwMsg = LINE_MONITORTONE then
Form1.lstMsg.items.Add('LINE_MONITORTONE ')
else
if dwMsg = LINE_REPLY then // LineMakeCall的结果
begin
if dwParam2 < 0 then
Form1.lstMsg.items.Add('线路测试错误')
else
Form1.lstMsg.items.Add('线路测试成功');
end
else
if dwMsg = LINE_CALLINFO then //呼叫信息处理
begin
///////////////////////
Form1.lstMsg.items.Add('LINE_CALLINFO ') //----->本来响铃后就在这里取来电显示住处,但现在这里不能进来????
{ case dwParam1 of
LINECALLINFOSTATE_CALLERID:
Form1.lstMsg.items.Add('callerid!!');
LINECALLINFOSTATE_OTHER :
Form1.lstMsg.items.Add('other!!');
LINECALLINFOSTATE_RELATEDCALLID :
Form1.lstMsg.items.Add('other!!');

end;}
//Proc_CallInfo(hDevice, dwMsg,dwParam1, dwParam2, dwParam3);
end
else
if dwMsg = LINE_CALLSTATE then // 线路状态改变
begin
hCall := THCall(hDevice); //类型转换为LongInt
Form1.lstMsg.items.Add( 'LINE_CALLSTATE');
case dwParam1 of
LINECALLSTATE_IDLE: //呼叫终止处于空闲状态
if hcall <> 0 then
begin
lineDeallocateCall(hCall); //重新分配监视呼叫句柄
Form1.lstMsg.items.Add( '空闲状态,监视呼叫重新分配');
Form1.button1.Enabled := True;
end;
LINECALLSTATE_OFFERING: //响铃.....
begin
Form1.lstMsg.items.Add('RING!!');
lineAnswer(hcall,@str,1024);
end;

//case dwParam2 of
LINECALLSTATE_ACCEPTED :
Form1.lstMsg.items.Add('ACCEPTED!!');
//end;
LINECALLSTATE_CONNECTED: //已经连接
if hCall <> 0 then
begin
Form1.lstMsg.items.Add('Connected');
callinfo.dwTotalSize := 4096;
if lineGetCallInfo(hCall, callinfo) = 0 then
begin
if callinfo.dwAppNameSize > 0 then
begin
{$IFDEF WIN32} str:='应用程序名字: '+(buf+callinfo.dwAppNameOffset);
{$ELSE} str:= '应用程序名字: ' + StrPas((buf + callinfo.dwAppNameOffset));
{$ENDIF} Form1.lstMsg.items.Add(str);
end;
end;
end;
LINECALLSTATE_PROCEEDING:
Form1.lstMsg.items.Add( '正在处理');
LINECALLSTATE_DIALING: //正在拨号
Form1.lstMsg.items.Add( '拨号...');
LINECALLSTATE_DISCONNECTED: //断开连接
begin
Form1.Button2.Click;
str := '已断开: ';
if dwParam2 = LINEDISCONNECTMODE_NORMAL then
str := str + '正常'
else if dwParam2 = LINEDISCONNECTMODE_BUSY then
str := str + '线路忙';
Form1.lstMsg.items.Add(str);
//TAPIForm.button3.Click;
end;
LINECALLSTATE_BUSY: //忙音信号
Form1.lstMsg.items.Add('线路忙');
end;//case
end
end;

================================================

以下函数是初始化线路,并开启侦听功能
================================================
/////////////////////////
procedure TForm1.init_listen;
var
extid: TLineExtensionID;
lpLineDevCaps_:LPLINEDEVCAPS;
ModemName:string;
i:integer;
begin
line:=0;
///TAPI
with CallParams do
begin
dwTotalSize:=sizeof(CallParams);
dwBearerMode:=LINEBEARERMODE_VOICE;
end;

if lineInitialize(lineApp, HInstance,lineCallback, nil, nDevs) < 0 then
lineApp := 0 //出错
else if nDevs = 0 then//无TAPI设备
begin
lineShutDown(lineApp);//关闭线路
lineApp := 0;
end ;
if lineNegotiateAPIVersion(lineApp, 0, $00010000, $10000000,
tapiVersion, extid) <> 0 then
//协商TAPI版本号 TAPI1.4到TAPI2.0间,各版本提供的功能不同
begin
lineShutDown(lineApp);
lineApp := 0;
end
else begin
cmbLines.clear;
GetMem(lpLineDevCaps_,sizeof(TLINEDEVCAPS)+1024);
for i:=0 to nDevs-1 do
begin
fillchar(lpLineDevCaps_^,sizeof(TLINEDEVCAPS)+1024,0);
lpLineDevCaps_.dwTotalSize:=sizeof(TLINEDEVCAPS)+1024;
lineGetDevCaps(lineApp,i,tapiVersion,0,lpLineDevCaps_^);
if ((lpLineDevCaps_^.dwLineNameSize <> 0) and
(lpLineDevCaps_^.dwLineNameOffset <> 0) and
(lpLineDevCaps_^.dwStringFormat = STRINGFORMAT_ASCII)) then
ModemName:=string(PChar(integer(lpLineDevCaps_)+lpLineDevCaps_^.dwLineNameOffset))
else ModemName:='';
cmbLines.Items.add(ModemName);
end;
freeMem(lpLineDevCaps_);
cmbLines.itemindex:=0;
//FormDevice.showmodal;
if lineOpen(lineApp, cmbLines.itemindex, line, tapiVersion, 0, 0,
LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_DATAMODEM, nil) < 0 then
begin//失败
lineShutDown(lineApp);
lineApp := 0;
line := 0;
end;
end;
if line = 0 then lstMsg.items.Add('错误!!')
//showmessage(sappname);
//ZeroMemory(@callinfo,sizeof(callinfo));
//lineGetCallInfo(hCall,callinfo);
//showmessage(inttostr(callinfo.dwCallID));
end;
///////////////////////////////////////////////





...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhz888 2003-10-27
  • 打赏
  • 举报
回复
已经开通,并在MS超级终端下能看看到来电显示~~
outer2000 2003-10-25
  • 打赏
  • 举报
回复
先要到电信局开通来电显示
vagerent 2003-10-24
  • 打赏
  • 举报
回复
先要到电信局开通来电显示
ctx 2003-10-24
  • 打赏
  • 举报
回复
首先你的猫必须支持来电显示,然后还要电信给你开通来电显示功能,
最后才能考虑你的程序,温锦山写的一本书有来电显示的代码,我试了
可以用
guothreelove2003 2003-10-24
  • 打赏
  • 举报
回复
xue xi

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧