//------------------------------------------------------------------------------ // // 产品名称: 成晓旭的个人软件Delphi源码库 // 产品版本: CXXSoft delphi code source lib 2.0 // 模块名称: Delphi之东进模拟语音卡类 // 模块描述: // 单元文件: unDJCard160A.pas // 开发作者: 成晓旭 // 备注: 任何人使用此文件时,请保留此段自述文件,谢谢! // 开发时间: 2004-08-03 // 修改历史: // 修改描述: //------------------------------------------------------------------------------ unit unDJCard160A; interface uses Windows, unDJTC08a32,unDJNewSig, unBaseDefine,unDJ160ADefine, unDJChanne160A; type TCXXCommCard160A =class(TObject) private ChannelNumber:Word; channelObject:array of TCXXDJChannel160A; OnCardChannelState:TTrunkStatusEvent; procedure Stop(); procedure ReleaseCommDevice(); function GetChannelObjectOrder(const aChannelID:Word):Word; public constructor Create(const trunkEvent:TTrunkStatusEvent); destructor Destroy(); override; function LoadCommDevice(const loadAll:boolean=false):boolean; function Startup():boolean; function GetAFreeChannel():Word; function GetChannelNumber():Word; function DialPhone(const aChannelID:Word;const DialPhoneNumber:PChar):boolean; function HangUp(const aChannelID:Word):boolean; end; implementation ...{ TCXXCommCard160A } constructor TCXXCommCard160A.Create(const trunkEvent:TTrunkStatusEvent); begin ChannelNumber :=0; Self.OnCardChannelState := trunkEvent; end; destructor TCXXCommCard160A.Destroy; var Loop:Word; begin Stop(); if (Length(channelObject) >0) and (channelNumber >0) then begin for Loop :=0 to ChannelNumber -1do begin if Assigned(channelObject[Loop]) then begin channelObject[Loop].Free(); channelObject[Loop] := nil; end; end; end; ReleaseCommDevice(); end; function TCXXCommCard160A.DialPhone(const aChannelID: Word; const DialPhoneNumber: PChar): boolean; var K:Word; begin Result :=false; K := GetChannelObjectOrder(aChannelID); if (K <> ErrorTrunkNumber) and (Assigned(channelObject[K])) then begin Result := channelObject[K].DialPhone(DialPhoneNumber); end; end; procedure TCXXCommCard160A.ReleaseCommDevice(); begin DisableCard(); FreeDrv(); end; function TCXXCommCard160A.GetAFreeChannel(): Word; var Loop:Word; begin Result := ErrorTrunkNumber; for Loop := Low(channelObject) to High(channelObject) do begin if (channelObject[Loop].GetChannelType() = ctEmpty) then continue; if (channelObject[Loop].GetChannelStatus() = atsFree) then begin Result := channelObject[Loop].GetChannelID(); break; end; end; end; function TCXXCommCard160A.GetChannelNumber(): Word; begin Result := channelNumber; end; function TCXXCommCard160A.GetChannelObjectOrder( const aChannelID: Word): Word; var Loop:Word; begin Result := ErrorTrunkNumber; for Loop := Low(channelObject) to High(channelObject) do begin if (channelObject[Loop].GetChannelID = aChannelID) then begin Result := Loop; break; end; end; end; function TCXXCommCard160A.HangUp(const aChannelID: Word): boolean; var K:Word; begin Result :=false; K := GetChannelObjectOrder(aChannelID); if (K <> ErrorTrunkNumber) and (Assigned(channelObject[K])) then begin channelObject[K].ChannelHangUp(); Result :=true; end; end; function TCXXCommCard160A.LoadCommDevice(const loadAll:boolean): boolean; const loadEmpty =true; var Loop,tempNumber:Word; isFlag:LongInt; function CheckLoadTrunk():boolean; begin Result := loadAll or ((NOT loadAll) and(TChannelType(CheckChType(Loop)) <> ctEmpty)); end; begin isFlag := LoadDRV(); Result := (isFlag=0); if NOT Result then Exit; tempNumber := CheckValidCh(); Result := EnableCard(tempNumber,1024*8)=0; if NOT Result then begin FreeDrv(); Exit; end; Result := Sig_Init()=1; if NOT Result then Exit; SetBusyPara(700); SetPackRate(PACK_64KBPS ); channelNumber := tempNumber; SetLength(channelObject,channelNumber); for Loop :=0 to channelNumber -1do begin if CheckLoadTrunk() then begin channelObject[Loop] := TCXXDJChannel160A.Create(OnCardChannelState); channelObject[Loop].CreateCommChannel(Loop); end; end; end; function TCXXCommCard160A.Startup(): boolean; var Loop:integer; begin for Loop :=0 to channelNumber -1do begin channelObject[Loop].Resume(); end; Result :=true; end; procedure TCXXCommCard160A.Stop(); var Loop:integer; begin for Loop :=0 to channelNumber -1do begin channelObject[Loop].Suspend(); channelObject[Loop].Terminate(); channelObject[Loop] := nil; end; end; end.
11、
通道类源码:
//------------------------------------------------------------------------------ // // 产品名称: 成晓旭的个人软件Delphi源码库 // 产品版本: CXXSoft delphi code source lib 2.0 // 模块名称: Delphi之东进模拟语音卡通道类 // 模块描述: // 单元文件: unDJChanne160A.pas // 开发作者: 成晓旭 // 备注: 任何人使用此文件时,请保留此段自述文件,谢谢! // 开发时间: 2004-08-03 // 修改历史: // 修改描述: //------------------------------------------------------------------------------ unit unDJChanne160A; interface uses Windows,Classes,SysUtils, unBaseDefine,unDJ160ADefine, unDJTC08a32,unDJNewSig; Type TCXXDJChannel160A =class(TThread) //TCXXDJChannel160A = class(TObject) private channelType:TChannelType; oldChannelState,channelState:TTrunkState; channelID:Word; phoneNumber:string; dtmfString:string; isConntectd:boolean; isDialOut:boolean; aTrunkState:TTrunkStatus; procedure InformTrunkStatus(const aMsgFlag: TLVOperateFlag); procedure ClearTrunkStatus(); function CheckSigHangup():boolean; function CheckCallIn():boolean; function SwitchOnCallIn():boolean; procedure ProcessCallInSuccess(); procedure ProcessDialSuccess(); procedure ProcessCheckDialSend(); protected procedure Execute(); override; public strMessage:string; OnChannelState:TTrunkStatusEvent; constructor Create(const trunkEvent:TTrunkStatusEvent); destructor Destroy();override; procedure CreateCommChannel(const aChennelID: Word); procedure ChannelProcessor(); function GetChannelID():Word; function GetChannelStatus():TTrunkState; function GetChannelType():TChannelType; function DialPhone(const DialPhoneNumber:PChar):boolean;overload; function DialPhone(const DialPhoneNumber:PChar;const PreDialNumber:PChar):boolean;overload; procedure ChannelHangUp(); function GetDialOut():boolean; end; implementation ...{ TCXXDJChannel160A } procedure TCXXDJChannel160A.ChannelHangUp(); begin isDialOut :=false; StopSigCheck(channelID); HangUp(channelID); Sig_ResetCheck(channelID); StartSigCheck(channelID); InitDTMFBuf(channelID); ClearTrunkStatus(); InformTrunkStatus(lvofUpdate); end; procedure TCXXDJChannel160A.ChannelProcessor(); var dState:Word; begin PUSH_PLAY(); FeedSigFunc(); CheckCallIn(); case channelState of atsFree: begin // end; atsCallIning: begin SwitchOnCallIn(); end; atsCallInSuccess: begin if CheckSigHangup() then Exit; ProcessCallInSuccess(); end; atsCheckSendDial: begin ProcessCheckDialSend(); end; atsDialing: begin dState := Sig_CheckDial(channelID); case dState of // S_NORESULT: S_CONNECT: begin channelState := atsDialSuccess; isConntectd :=true; end; S_BUSY, S_NOBODY, S_NODIALSIG, S_NOSIGNAL: begin channelState := atsHangOff; end; end; strMessage :='拨号中...'; end; atsDialSuccess: begin if CheckSigHangup() then Exit; ProcessDialSuccess(); strMessage :='拨号成功'; end; atsHangOff: begin ChannelHangUp(); end; end; if (oldChannelState <> channelState) then begin oldChannelState := channelState; InformTrunkStatus(lvofUpdate); end; end; function TCXXDJChannel160A.CheckCallIn(): boolean; begin Result := RingDetect(channelID); if Result then begin OffHook(channelID); if isDialOut then channelState := atsDialSuccess else channelState := atsCallIning; end; end; function TCXXDJChannel160A.CheckSigHangup(): boolean; begin Result :=false; if (Sig_CheckBusy(channelID)=1) then begin strMessage :='对方已挂机'; InformTrunkStatus(lvofUpdate); StopPlayFile(channelID); channelState := atsHangOff; Result :=true; end; end; procedure TCXXDJChannel160A.ClearTrunkStatus(); begin channelState := atsFree; oldChannelState := channelState; phoneNumber :=''; dtmfString :=''; strMessage :=''; isConntectd :=false; end; constructor TCXXDJChannel160A.Create(const trunkEvent:TTrunkStatusEvent); begin Self.OnChannelState := trunkEvent; Self.FreeOnTerminate :=true; inherited Create(true); end; destructor TCXXDJChannel160A.Destroy; begin Suspend(); ChannelHangUp(); //inherited Destroy(); end; function TCXXDJChannel160A.DialPhone(const DialPhoneNumber:PChar; const PreDialNumber:PChar): boolean; begin isDialOut :=true; phoneNumber := DialPhoneNumber; OffHook(channelID); InitDTMFBuf(channelID); Result := Sig_StartDial(channelID,DialPhoneNumber,PreDialNumber,0)=1; channelState := atsCheckSendDial; end; function TCXXDJChannel160A.DialPhone( const DialPhoneNumber: PChar): boolean; begin Result := DialPhone(DialPhoneNumber,''); end; procedure TCXXDJChannel160A.Execute; begin while NOT Terminated do begin Synchronize(ChannelProcessor); Sleep(10); end; end; function TCXXDJChannel160A.GetChannelID(): Word; begin Result := channelID; end; function TCXXDJChannel160A.GetChannelStatus(): TTrunkState; begin Result := channelState; end; procedure TCXXDJChannel160A.InformTrunkStatus(const aMsgFlag: TLVOperateFlag); begin aTrunkState.lvFlag := aMsgFlag; aTrunkState.TrunkID := IntToStr(channelID); aTrunkState.TrunkType := channelType; aTrunkState.TrunkTypeStr := ChannelTypeString[channelType]; aTrunkState.TrunkStep := channelState; aTrunkState.TrunkStepStr := TrunkStateString[channelState]; aTrunkState.TrunkPhone := phoneNumber; aTrunkState.TrunkData := dtmfString; OnChannelState(aTrunkState); end; procedure TCXXDJChannel160A.ProcessCallInSuccess(); begin end; function TCXXDJChannel160A.SwitchOnCallIn(): boolean; begin OffHook(channelID); InitDTMFBuf(channelID); StartSigCheck(channelID); channelState := atsCallInSuccess; Result :=true; end; procedure TCXXDJChannel160A.ProcessDialSuccess(); begin end; procedure TCXXDJChannel160A.CreateCommChannel(const aChennelID: Word); begin channelID := aChennelID; channelType := TChannelType(CheckChType(channelID)); ClearTrunkStatus(); InformTrunkStatus(lvofAdd); end; function TCXXDJChannel160A.GetChannelType(): TChannelType; begin Result := channelType; end; function TCXXDJChannel160A.GetDialOut(): boolean; begin Result := isDialOut; end; procedure TCXXDJChannel160A.ProcessCheckDialSend(); begin if(CheckSendEnd(channelID) =1) then begin StartSigCheck(channelID); channelState := atsDialing; end; end; end.