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

📄 dial.bas

📁 三汇CTI示例程序源码
💻 BAS
字号:
Attribute VB_Name = "Dial"

'APP_USER_STATE
Const USER_IDLE = 0
Const USER_GET_PHONE_NUM = 1
Const USER_WAIT_DIAL_TONE = 2
'Const USER_DIALING = 3
Const USER_WAIT_REMOTE_PICKUP = 3
Const USER_TALKING = 4
Const USER_WAIT_HANGUP = 5

Type CH_INFO
    'user channel vars
    EnCalled As Boolean
    lineState As Integer
    nStep As Integer
    nToTrkCh As Integer
    pPhoNumBuf As String * 50
    nTimeOut As Integer
    'trunck channel vars
    InUse As Integer
    DtmfBuf As String * 100
End Type

Dim nTotalCh As Integer
Dim ChInfo(0 To 100) As CH_INFO

Function myGetAnIdleChannel() As Integer 'find an ilde trunck channel
    Dim i As Integer
    For i = 0 To nTotalCh - 1
        If (ChInfo(i).InUse = 0) And ChInfo(i).EnCalled Then Exit For
    Next i
    
    If i = nTotalCh Then
        myGetAnIdleChannel = -1
    Else
        myGetAnIdleChannel = i
    End If
End Function

Public Function InitCtiBoard() As Boolean
    'Initialization of CTI driver
    Dim fnIni As String * 260
    Dim CurPath As String * 260
    Dim str1 As String * 200
    Dim nDirection As Long
    
    CurPath = App.Path + "\ShConfig.ini" + Chr(0)
    fnIni = App.Path + "\ShIndex.ini" + Chr(0)
    If (SsmStartCti(CurPath, fnIni) <> 0) Then
        SsmGetLastErrMsg (str1)
        MsgBox str1
        InitCtiBoard = False
    Else
        nTotalCh = SsmGetMaxCh()
        For i = 0 To nTotalCh - 1
        ChInfo(i).EnCalled = False
        If SsmGetChType(i) = 2 Then ' user channnel
           SsmSetASDT i, True
           ChInfo(i).pPhoNumBuf = ""
           ChInfo(i).nStep = USER_IDLE
        Else
        'Initialization of channels on trunk-board
           If (SsmGetAutoCallDirection(i, nDirection) = 1) Then
               If (nDirection = 1 Or nDirection = 2) Then
                    ChInfo(i).InUse = 0
                    ChInfo(i).DtmfBuf = ""
                    SsmSetMinVocDtrEnergy i, 30000
                    ChInfo(i).EnCalled = True
               End If
           End If
        End If
            
        Next i
        
        InitCtiBoard = True
    End If
End Function

Public Sub DrawTrunkChState()
    Dim state As String
    Dim i As Integer
    Dim TheIndex As Integer
    Dim nindex As Integer
    
    nindex = 0

    For i = 0 To nTotalCh - 1
    If ChInfo(i).EnCalled = True Then
        TheIndex = MainForm.TrkChGrid.Cols * (nindex + 1) + 1
        
        Select Case (ChInfo(i).InUse)
        Case 0
            state = "Idle"
        Case 1
            state = "OffHook"
        Case 2
            state = "Dialing"
        Case 3
            state = "WaitForCalledPartyPickup"
        Case 4
            state = "Talking"
        End Select
        If MainForm.TrkChGrid.TextArray(TheIndex) <> state Then MainForm.TrkChGrid.TextArray(TheIndex) = state
        
        TheIndex = TheIndex + 1
        SsmGetDtmfStr i, ChInfo(i).DtmfBuf
        If MainForm.TrkChGrid.TextArray(TheIndex) <> ChInfo(i).DtmfBuf Then MainForm.TrkChGrid.TextArray(TheIndex) = ChInfo(i).DtmfBuf
        nindex = nindex + 1
    End If
    Next i
End Sub

Public Sub DrawUserChState()
    Dim state As String
    Dim i As Integer
    Dim TheIndex As Integer
    Dim nindex As Integer
    
    nindex = 0
    For i = 0 To nTotalCh - 1
    If (SsmGetChType(i) = 2) Then
        TheIndex = MainForm.UserChGrid.Cols * (nindex + 1) + 1
        Select Case (ChInfo(i).nStep)
        Case USER_IDLE
            state = "Idle"
        Case USER_GET_PHONE_NUM
            state = "ReceivePhoNumber"
        Case USER_WAIT_DIAL_TONE
            state = "WaitForDialTone"
        Case USER_DIALING
            state = "Dialing"
        Case USER_WAIT_REMOTE_PICKUP
            state = "WaitForCalleePickup"
        Case USER_TALKING
            state = "Talking"
        Case USER_WAIT_HANGUP
            state = "WaitForStationHangup"
        End Select
        If MainForm.UserChGrid.TextArray(TheIndex) <> state Then MainForm.UserChGrid.TextArray(TheIndex) = state
        
        TheIndex = TheIndex + 1
        If MainForm.UserChGrid.TextArray(TheIndex) <> ChInfo(i).pPhoNumBuf Then MainForm.UserChGrid.TextArray(TheIndex) = ChInfo(i).pPhoNumBuf
        
        nindex = nindex + 1
    End If
    Next i
End Sub

Public Sub DoUserWork()
    Dim ch As Integer
    Dim i As Integer
    Dim PhoNumLen As Integer
    
    For i = 0 To nTotalCh - 1
    If SsmGetChType(i) = 2 Then
        Select Case (ChInfo(i).nStep)
        Case USER_IDLE
            ChInfo(i).pPhoNumBuf = ""
            SsmClearRxDtmfBuf (i)
            If (SsmGetHookState(i) = 1) Then     'user-pickup detected
                ChInfo(i).nStep = USER_GET_PHONE_NUM
            End If

        Case USER_GET_PHONE_NUM
            PhoNumLen = CInt(MainForm.Text1.Text)
            If (SsmGetRxDtmfLen(i) >= PhoNumLen) Then
                SsmGetDtmfStr i, ChInfo(i).pPhoNumBuf     'retrieve phone num
                
                Mid$(ChInfo(i).pPhoNumBuf, PhoNumLen + 1, 1) = Chr$(0)
                
                ch = myGetAnIdleChannel()
                If (ch = -1) Then      'no idle trunk channel available
                    SsmSendTone i, 1   'send busy tone
                    ChInfo(i).nStep = USER_WAIT_HANGUP
                Else
                    SsmPickup (ch)
                    ChInfo(ch).InUse = 1
                    
                    ChInfo(i).nToTrkCh = ch
                    ChInfo(i).nStep = USER_WAIT_DIAL_TONE
                End If
            
            ElseIf (SsmGetHookState(i) = 0) Then           'user-hangup detected
                SsmClearRxDtmfBuf (i)
                ChInfo(i).nStep = USER_IDLE
            End If

        Case USER_WAIT_DIAL_TONE
            ch = ChInfo(i).nToTrkCh
'            If (SsmGetToneAnalyzeResult(ch) = 1) Then 'dial tone detected
'                SsmCloseToneAnalyze (ch)
'                SsmTxDtmf ch, ChInfo(i).pPhoNumBuf
'                ChInfo(ch).InUse = 2
'
'                ChInfo(i).nStep = USER_DIALING
'            ElseIf (ChInfo(i).nTimeOut > 40) Then '2 second time out, no dial-tone found
'                SsmHangup (ch)
'                ChInfo(ch).InUse = 0
'                SsmClearRxDtmfBuf (ch)
'
'                SsmSendTone i, 1 'send busy tone
'                ChInfo(i).nStep = USER_WAIT_HANGUP
'            End If
            If (SsmAutoDial(ch, ChInfo(i).pPhoNumBuf) = 0) Then
                ChInfo(ch).InUse = 2
                ChInfo(i).nStep = USER_WAIT_REMOTE_PICKUP
            Else
                SsmHangup (ch)
                ChInfo(ch).InUse = 0
                SsmClearRxDtmfBuf (ch)

                SsmSendTone i, 1
                ChInfo(i).nStep = USER_WAIT_HANGUP
            End If

'        Case USER_DIALING
'            ch = ChInfo(i).nToTrkCh
'            If (SsmChkTxDtmf(ch) = 0) Then ' end of dialing
'                SsmStartToneAnalyze (ch)
'                SsmTalkWith ch, i
'                ChInfo(ch).InUse = 3
'
'                ChInfo(i).nTimeOut = 0
'                ChInfo(i).nStep = USER_WAIT_REMOTE_PICKUP
'            End If

        Case USER_WAIT_REMOTE_PICKUP
            ch = ChInfo(i).nToTrkCh
            ChInfo(ch).lineState = SsmGetChState(ch)
'            If (SsmGetToneAnalyzeResult(ch) = 6) Then    'remote user pickup
'                SsmListenTo i, ch
'                ChInfo(ch).InUse = 4
'
'                ChInfo(i).nStep = USER_TALKING
            If (SsmChkAutoDial(ch) = 7) Then               'remote user pickup
                SsmTalkWith i, ch
                ChInfo(ch).InUse = 4
                
                ChInfo(i).nStep = USER_TALKING
            ElseIf (SsmGetHookState(i) = 0) Then  'user hangup
                SsmHangup (ch)
  '              SsmStopTalkWith ch, i
                ChInfo(ch).InUse = 0
                SsmClearRxDtmfBuf (ch)

                SsmClearRxDtmfBuf (i)
                ChInfo(i).nStep = USER_IDLE
            ElseIf ((ChInfo(ch).lineState = S_CALL_PENDING) Or (SsmChkAutoDial(ch) = 10)) Then 'busy tone or 30s time out
                SsmHangup (ch)
  '              SsmStopTalkWith ch, i
                ChInfo(ch).InUse = 0
                SsmClearRxDtmfBuf (ch)
                
                SsmSendTone i, 1                   'send busy tone
                ChInfo(i).nStep = USER_WAIT_HANGUP
            End If

        Case USER_TALKING
            ch = ChInfo(i).nToTrkCh
            ChInfo(ch).lineState = SsmGetChState(ch)
            If SsmGetHookState(i) = 0 Or ChInfo(ch).lineState = S_CALL_PENDING Then  'remote user hangup
                SsmHangup (ch)
                SsmStopTalkWith ch, i
                SsmClearRxDtmfBuf (ch)
                ChInfo(ch).InUse = 0
                
                If (SsmGetHookState(i) = 0) Then             'user hangup first
                    ChInfo(i).nStep = USER_IDLE
                Else                                        'remote user hangup first
                    SsmSendTone i, 1               'send busy tone
                    ChInfo(i).nStep = USER_WAIT_HANGUP
                End If
            End If
            
        Case USER_WAIT_HANGUP
            If (SsmGetHookState(i) = 0) Then   'user hangup
                SsmStopSendTone (i)                 'stop sending busy tone
                SsmClearRxDtmfBuf (i)
                ChInfo(i).nStep = USER_IDLE
            End If

        Case Else
            ChInfo(i).nStep = USER_IDLE
        End Select
    End If
    Next i
End Sub

Public Sub InitUserChGrid()
    Dim i%
    MainForm.UserChGrid.Cols = 3
    MainForm.UserChGrid.Row = 0
    
    MainForm.UserChGrid.Col = 0
    MainForm.UserChGrid.Text = "Channel"
    
    MainForm.UserChGrid.Col = 1
    MainForm.UserChGrid.Text = "StationChState"
    
    MainForm.UserChGrid.Col = 2
    MainForm.UserChGrid.Text = "CalledId"
    
    MainForm.UserChGrid.ColWidth(0) = 80 * 12
    MainForm.UserChGrid.ColWidth(1) = 150 * 12
    MainForm.UserChGrid.ColWidth(2) = 70 * 12
     
    MainForm.UserChGrid.Rows = 1
    For i = 0 To nTotalCh - 1
        If (SsmGetChType(i) = 2) Then MainForm.UserChGrid.AddItem (Str(i))
    Next i%
End Sub

Public Sub InitTrunkChGrid()
    Dim i%
    MainForm.TrkChGrid.Cols = 3
    MainForm.TrkChGrid.Row = 0
    
    MainForm.TrkChGrid.Col = 0
    MainForm.TrkChGrid.Text = "Channel"
    
    MainForm.TrkChGrid.Col = 1
    MainForm.TrkChGrid.Text = "TrunkChState"
    
    MainForm.TrkChGrid.Col = 2
    MainForm.TrkChGrid.Text = "DTMF"
    
    MainForm.TrkChGrid.ColWidth(0) = 80 * 12
    MainForm.TrkChGrid.ColWidth(1) = 150 * 12
    MainForm.TrkChGrid.ColWidth(2) = 100 * 12
     
    MainForm.TrkChGrid.Rows = 1
    For i = 0 To nTotalCh - 1
        If (ChInfo(i).EnCalled = True) Then MainForm.TrkChGrid.AddItem (Str(i))
    Next i%
End Sub

⌨️ 快捷键说明

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