⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faxfunc.pas

📁 三汇CTI示例程序源码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit FaxFunc;

interface

type APP_FAX_STATE=(
	FAX_IDLE,
	FAX_BUSY,
	FAX_WAIT_HANGUP
        );
type APP_TRUNK_STATE=(
        TRUNK_PRE_IDLE,
        TRUNK_IDLE,
        TRUNK_PICK_UP,
        TRUNK_DAIL,
        TRUNK_WAIT_F2,
        TRUNK_WAIT_F1,
        TRUNK_WAIT_RCV_DTMF,
        TRUNK_TO_FAX_TX,
        TRUNK_WAIT_FAX_END,
	TRUNK_BUSY,
        TRUNK_TO_FAX_RX,
	TRUNK_WAIT_HANGUP
        );
type TRUNK_CH_INFO=record
	InUse:Integer;
	DtmfBuf:array [0..250] of char;
        sCallerID:string;
        nStep:APP_TRUNK_STATE;
	nTimeOut:Integer;
        nToFaxCh:Integer;
  bCircleSendingFax:boolean;
  sPhoneNum:string;
  nFaxCnt,nFaxCntSuccess:integer;
  bMultSendFax:boolean;
  nnResult,nnResult1:integer;
  nA_LineVoltage:integer;
  SLogDerectionTx:String;
  SLogDerectionRx:String;
  sFileCuDerection:string;
  sTifName:string;
  sSoundFileName:string;
  F: TextFile;
  bLogFileCreate:boolean;

end;

type FAX_CH_INFO=record
        InUse:Integer;
        EnCalled:boolean;
	lineState:integer;
	nStep:APP_FAX_STATE;
	nToTrkCh:Integer;
	nTimeOut:Integer;
end;
///////////////////////////////////////////////////////////
var
  nTotalCh:WORD;
  FAXCh:array [0..99]of FAX_CH_INFO;
  TrunkCh:array [0..99] of TRUNK_CH_INFO;
  FFaxMsg:PCHAR;
  wnResult,nResult:Integer;
  nTelCnt:integer;

  StartTime,EndTime:TDateTime;

///////////////////////////////////////////////////////////

///////////////////////////////////////////
function myGetAnIdleChannel():Integer;
function myGetAnIdleFaxChannel():Integer;
function InitCtiBoard():boolean;
procedure DrawTrunkChState;
//procedure DrawUserChState;
procedure DoTruckWork;
procedure ExitCtiBoard;
procedure GetVersion;
function  CreateLog(i:integer;sDerection:string;FileName:string):boolean;
function  CloseLog(i:integer):boolean;
function  WriteLog(i:integer;p1:string;p2:string;p3:string):boolean;
implementation
uses Shpa3api,Main,filectrl,Windows, Messages, SysUtils, Classes, Graphics,
     Controls, Forms, Dialogs,ComCtrls, ExtCtrls;

////////////////////////////////////////////////////////////
function  WriteLog(i:integer;p1:string;p2:string;p3:string):boolean;
begin
      writeln(TrunkCh[i].F,DateTimeToStr(Now),'   ',p1,'   ',p2,'   ',p3);
      WriteLog:=true;
end;
function  CreateLog(i:integer;sDerection:string;FileName:string):boolean;
begin
     if(TrunkCh[i].bLogFileCreate)then CloseLog(i);
     AssignFile(TrunkCh[i].F, sDerection +'\'+FileName+'.log');
     Rewrite(TrunkCh[i].F);
     TrunkCh[i].bLogFileCreate :=True;
     CreateLog:= true;

end;
function  CloseLog(i:integer):boolean;
begin
     CloseFile(TrunkCh[i].F);
     TrunkCh[i].bLogFileCreate :=False;
     CloseLog:= true;
end;
procedure DoTruckWork;
var
  ch:Integer;
  i:Integer;
  PhoNumLen:Integer;

  Fax_Ch:Integer;
  nTimerOut:Integer;
  Mem:pChar;
  ErrMsg:PChar;
  FaxMsg:PChar;
  sDtmf:char;
  DateTime:TDateTime;
  str : string;
  SystemTime: TSystemTime;

begin
  for i:=0 to nTotalCh-1 do
  begin
   case TrunkCh[i].nStep of
  TRUNK_PRE_IDLE:
  begin
       if SsmGetChType(i)=0then
       begin
            if SsmGetLineVoltage(i)<3then
            begin
                 dec(TrunkCh[i].nA_LineVoltage);
                 if(TrunkCh[i].nA_LineVoltage<=0)then
                 begin
                      TrunkCh[i].nA_LineVoltage :=10;
                      if(TrunkCh[i].bCircleSendingFax)then
                      begin
                           TrunkCh[i].nTimeOut :=0;
                      end;
                      if(TrunkCh[i].bMultSendFax)then
                      begin
                           TrunkCh[i].nTimeOut :=0;
                      end;
                 end;
            end
            else begin
                 inc(TrunkCh[i].nA_LineVoltage);
                 if(TrunkCh[i].nA_LineVoltage>=15)then
                 begin
                      if(TrunkCh[i].bLogFileCreate)then CloseLog(i);
                      TrunkCh[i].nA_LineVoltage :=15;
                      TrunkCh[i].nStep :=TRUNK_IDLE;
                 end;
            end;
       end;
  end;
	TRUNK_IDLE:
        begin

               if SsmGetChType(i)=0then
       begin
            if SsmGetLineVoltage(i)<3then
            begin
                 dec(TrunkCh[i].nA_LineVoltage);
                 if(TrunkCh[i].nA_LineVoltage<=0)then
                 begin
                      TrunkCh[i].nA_LineVoltage :=10;
                      TrunkCh[i].nStep :=TRUNK_PRE_IDLE;
                      if(TrunkCh[i].bCircleSendingFax)then
                      begin
                           TrunkCh[i].nTimeOut :=0;
                      end;
                      if(TrunkCh[i].bMultSendFax)then
                      begin
                           TrunkCh[i].nTimeOut :=0;
                      end;
                 end;
            end
            else begin
                 inc(TrunkCh[i].nA_LineVoltage);
                 if(TrunkCh[i].nA_LineVoltage>=15)then
                 begin
                      TrunkCh[i].nA_LineVoltage :=15;
                 end;
            end;
       end;
             if(TrunkCh[i].bMultSendFax)then
             begin
                  inc(TrunkCh[i].nTimeOut);
                  if (TrunkCh[i].nTimeOut >= 20)then
                  begin
                       if(nTelCnt>=mainform.ListBox3.Items.Count)then
                       begin
                            TrunkCh[i].bMultSendFax :=False;
                            continue;
                       end;
                       if(mainform.ListBox3.Items.Strings[nTelCnt]<>'')then
                       begin
                            if SsmPickUp(i)=-1then
                            begin
                                 TrunkCh[i].nTimeOut :=0;
                                 GetMem(ErrMsg,200);
                                 SsmGetLastErrMsg(ErrMsg);
                                 Application.MessageBox(ErrMsg,'错误', MB_OK);
                                 FreeMem(ErrMsg);
                                 SsmHangup(i);
                                 //exit;
                            end;

                            SsmClearToneAnalyzeResult(i);

                            TrunkCh[i].InUse:=1;
                            TrunkCh[i].nStep:=TRUNK_PICK_UP;
                            mainform.ListBox1.Items.Add('外线摘机');
                            if SsmAutoDial(i,Pchar(mainform.ListBox3.Items.Strings[nTelCnt]))=-1 then
                            begin
                                 GetMem(ErrMsg,200);
                                 SsmGetLastErrMsg(ErrMsg);
                                 Application.MessageBox(ErrMsg,'错误', MB_OK) ;
                                 FreeMem(ErrMsg);
                                 SsmHangup(i);
                                 //exit;
                            end;

                            inc(TrunkCh[i].nFaxCnt);
                            TrunkCh[i].nTimeOut :=0;
                            TrunkCh[i].InUse:=2;
                            TrunkCh[i].nStep:=TRUNK_DAIL;
                            GetLocalTime(SystemTime);
                            TrunkCh[i].sFileCuDerection :=TrunkCh[i].SLogDerectionTx+'\'+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond)+inttostr(SystemTime.wMilliseconds );
                            CreateDir(TrunkCh[i].sFileCuDerection );
                            TrunkCh[i].sSoundFileName :='T Ch'+inttostr(i)+'-'+inttostr(SystemTime.wMonth)+inttostr(SystemTime.wDay)+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond)+'-'+mainform.ListBox3.Items.Strings[nTelCnt];
                            SsmRecToFile(i, pChar(TrunkCh[i].sFileCuDerection +'\'+TrunkCh[i].sSoundFileName+'.wav'), -1, 0, $ffffffff, $ffffffff, 1);

                            CreateLog(i,TrunkCh[i].sFileCuDerection,TrunkCh[i].sSoundFileName);
                            WriteLog(i,'外线摘机','','');

                            mainform.ListBox1.Items.Add('外线自动向外拨号:'+mainform.ListBox3.Items.Strings[nTelCnt]);
                            inc(nTelCnt);
                       end
                       else begin
                            mainform.ListBox1.Items.Add('没有设置被叫号码!拨号失败!!');
                            SsmHangup(i);
                            TrunkCh[i].InUse:=0;
                            TrunkCh[i].nStep:= TRUNK_PRE_IDLE;
                       end;
                  end;
             end;
             if(TrunkCh[i].bCircleSendingFax)then
             begin
                  inc(TrunkCh[i].nTimeOut);
                  if (TrunkCh[i].nTimeOut >= 20)then
                  begin
                       if SsmPickUp(i)=-1then
                       begin
                            TrunkCh[i].nTimeOut :=0;
                            GetMem(ErrMsg,200);
                            SsmGetLastErrMsg(ErrMsg);
                            Application.MessageBox(ErrMsg,'错误', MB_OK);
                            FreeMem(ErrMsg);
                            SsmHangup(i);
                            //exit;
                       end;
                       GetLocalTime(SystemTime);

                       TrunkCh[i].sFileCuDerection := TrunkCh[i].SLogDerectionTx+'\'+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond)+inttostr(SystemTime.wMilliseconds );
                       CreateDir(TrunkCh[i].sFileCuDerection);
                       TrunkCh[i].sSoundFileName :='T Ch'+inttostr(i)+'-'+inttostr(SystemTime.wMonth)+inttostr(SystemTime.wDay)+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond);
                       SsmRecToFile(i, pChar(TrunkCh[i].sFileCuDerection+'\'+TrunkCh[i].sSoundFileName+'.wav'), -1, 0, $ffffffff, $ffffffff, 1);

                       CreateLog(i,TrunkCh[i].sFileCuDerection,TrunkCh[i].sSoundFileName);
                       WriteLog(i,'外线摘机','','');

                       SsmClearToneAnalyzeResult(i);

                       TrunkCh[i].InUse:=1;
                       TrunkCh[i].nStep:=TRUNK_PICK_UP;
                       mainform.ListBox1.Items.Add('外线摘机');
                       if(TrunkCh[i].sPhoneNum<>'')then
                       begin
                            if SsmAutoDial(i,Pchar(TrunkCh[i].sPhoneNum))=-1 then
                            begin
                                 GetMem(ErrMsg,200);
                                 SsmGetLastErrMsg(ErrMsg);
                                 Application.MessageBox(ErrMsg,'错误', MB_OK) ;
                                 FreeMem(ErrMsg);
                                 SsmHangup(i);
                                 //exit;
                            end;
                            inc(TrunkCh[i].nFaxCnt);
                            TrunkCh[i].nTimeOut :=0;
                            TrunkCh[i].InUse:=2;
                            TrunkCh[i].nStep:=TRUNK_DAIL;
                            mainform.ListBox1.Items.Add('外线自动向外拨号');
                       end
                       else begin
                            mainform.ListBox1.Items.Add('没有设置被叫号码!拨号失败!!');
                            SsmHangup(i);
                            TrunkCh[i].InUse:=0;
                            TrunkCh[i].nStep:= TRUNK_IDLE;
                       end;


                  end;
             end;
             if(SsmGetChState(i)=2)then
             begin
                  GetLocalTime(SystemTime);
                  TrunkCh[i].sFileCuDerection := TrunkCh[i].SLogDerectionRx +'\'+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond)+inttostr(SystemTime.wMilliseconds );
                  CreateDir(TrunkCh[i].sFileCuDerection);
                  TrunkCh[i].sSoundFileName :='R Ch'+inttostr(i)+'-'+inttostr(SystemTime.wMonth)+inttostr(SystemTime.wDay)+inttostr(SystemTime.wHour)+inttostr(SystemTime.wMinute)+inttostr(SystemTime.wSecond);
                  SsmRecToFile(i, pChar(TrunkCh[i].sFileCuDerection+'\'+ TrunkCh[i].sSoundFileName +'.wav'), -1, 0, $ffffffff, $ffffffff, 1);
                  CreateLog(i,TrunkCh[i].sFileCuDerection,TrunkCh[i].sSoundFileName);
                  WriteLog(i,'外线拨入','','');
                  GetMem(Mem,100);
                  if SsmGetCallerId(i,Mem)>0 then
                  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -