ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

etVoiceModemAutoDial Sample Program Source Code

Private CurrentPhoneNumber As Integer
Private GreetingLoopCount As Integer


Private Function IsOnlyDataModem() As Boolean
im ModemMediaModes As Integer

    ' These are the minimal media modes expected for standard data modems
    ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE + LINEMEDIAMODE_DATAMODEM

    ' Check to see if the selected device is a modem and it is a voice modem
    If (InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) And _
        ((etLine1.DeviceMediaModesAvailable And ModemMediaModes) = _
            ModemMediaModes) Then
        IsOnlyDataModem = True
    Else
        IsOnlyDataModem = False
    End If
End Function

Private Function IsVoiceModem() As Boolean
Dim ModemMediaModes As Integer
Dim VoiceModemMediaModes As Integer

    ' These are the minimal media modes expected for standard data modems
    ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE + LINEMEDIAMODE_DATAMODEM
    ' These are the minimal media modes expected for voice modems
    VoiceModemMediaModes = ModemMediaModes + LINEMEDIAMODE_UNKNOWN + _
                            LINEMEDIAMODE_AUTOMATEDVOICE

    ' Check to see if the selected device is a modem and it is a voice modem
    If (InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) And _
        ((etLine1.DeviceMediaModesAvailable And VoiceModemMediaModes) >= _
            VoiceModemMediaModes) Then
        IsVoiceModem = True
    Else
        IsVoiceModem = False
    End If
End Function

Private Sub SetCompletion(ByVal Status As String)
    Select Case CurrentPhoneNumber
        Case 1
            If TextCompletion1.Text = "" Then
                TextCompletion1.Text = Status
            End If
        Case 2
            If TextCompletion2.Text = "" Then
                TextCompletion2.Text = Status
            End If
        Case 3
            If TextCompletion3.Text = "" Then
                TextCompletion3.Text = Status
            End If
        Case 4
            If TextCompletion4.Text = "" Then
                TextCompletion4.Text = Status
            End If
        Case 5
            If TextCompletion5.Text = "" Then
                TextCompletion5.Text = Status
            End If
    End Select
End Sub

Private Sub Dial()
    ' Set the phone number
    Select Case CurrentPhoneNumber
        Case 1
            etLine1.CallPhoneNumber = TextPhoneNumber1.Text
        Case 2
            etLine1.CallPhoneNumber = TextPhoneNumber2.Text
        Case 3
            etLine1.CallPhoneNumber = TextPhoneNumber3.Text
        Case 4
            etLine1.CallPhoneNumber = TextPhoneNumber4.Text
        Case 5
            etLine1.CallPhoneNumber = TextPhoneNumber5.Text
    End Select

    If etLine1.CallPhoneNumber = "" Then
        ' No phone number found
        TextStatus.Text = "No phone number"
        SetCompletion ("No phone number")
        ' Go on to the next call
        etLine1_OnIdle (0)
    Else
        ' Dial
        etLine1.CallDial
        If etLine1.ErrorNumber > 0 Then
            TextStatus.Text = "Error Dialing - " & etLine1.ErrorText
            SetCompletion ("Error Dialing - " & etLine1.ErrorText)
            CheckDial.Value = Unchecked
        Else
            TextStatus.Text = "Dialing - " & etLine1.CallPhoneNumber
        End If
    End If
End Sub

Private Sub Hangup()
    TimerWaveLoop.Enabled = False
    If (etLine1.CallCount > 0) And _
        (etLine1.CallHandle <> 0) And _
        (etLine1.CallState <> LINECALLSTATE_IDLE) Then
        etLine1.CallHangup
    End If
End Sub

Private Sub CheckDial_Click()
    If CheckDial.Value = Unchecked Then
        ' Deactive the TAPI Line device
        etLine1.DeviceActive = False
    Else
        ' Active the TAPI Line device
        etLine1.DeviceActive = True

        etPlay1.DeviceID = etLine1.WavePlayID

        If Not etLine1.DeviceActive Then
            TextStatus.Text = "Error opening line device: " & etLine1.ErrorText
        Else
            ' Clear the status
            TextStatus.Text = ""

            ' Clear the Completetions
            TextCompletion1.Text = ""
            TextCompletion2.Text = ""
            TextCompletion3.Text = ""
            TextCompletion4.Text = ""
            TextCompletion5.Text = ""

            ' Dail the first number
            CurrentPhoneNumber = 1
            Dial
        End If
    End If
End Sub

Private Sub ComboDevice_Click()
    ' Set the TAPI Line device
    etLine1.DeviceName = ComboDevice.Text

    ' Check to see if the selected device is a Voice modem
    If IsVoiceModem Then
        ' Enable the Dial button
        CheckDial.Enabled = True
    Else
        ' Disable the Dial button
        CheckDial.Enabled = False
        ' Check to see if the selected device is a modem
        If IsOnlyDataModem Then
            MsgBox ("This device is Data Modem!" & vbCrLf & _
                    "Use the etDataModemDial sample program.")
        Else
            MsgBox ("This device is not a Modem")
        End If
    End If
End Sub

Private Sub etLine1_OnBusy(ByVal CallHandle As Long)
    SetCompletion ("Busy")
    Hangup
End Sub

Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
    ' Prepare to play the greeting wave file
    etPlay1.SourceFileName = App.Path & "\Greeting"
    GreetingLoopCount = 0

    ' Voice modems can not detect busy signials while playing wave files
    ' This cause the wave file to delay playing giving the
    ' voice modem time to detect busy signals.
    TimerWaveLoop.Enabled = True

    ' Begin monitoring for digits
    etLine1.CallMonitorDigitsActive = True
End Sub

Private Sub etLine1_OnDigitReceived(ByVal CallHandle As Long, _
                                    ByVal Digit As Integer, _
                                    ByVal Tag As Long)
    If Chr(Digit) = "1" Then
        ' Do not play the greeing again
        TimerWaveLoop.Enabled = False

        ' Stop monitoring for digits
        etLine1.CallMonitorDigitsActive = False

        If etPlay1.DeviceActive Then
            ' If a wave file is playing then stop it
            etPlay1.DeviceActive = False
        End If

        ' Play a wave file to acknowledge that the remote party has entered the
        ' correct digit
        etPlay1.SourceFileName = App.Path & "\ThankYou"
        etPlay1.DeviceActive = True
    End If
End Sub

Private Sub etLine1_OnDisconnected(ByVal CallHandle As Long)
    ' The remote party has hung up
    If etPlay1.DeviceActive Then
        ' If a wave file is playing then stop it
        etPlay1.DeviceActive = False
    End If
    SetCompletion ("Remote hang up")
    Hangup
End Sub

Private Sub etLine1_OnIdle(ByVal CallHandle As Long)
    ' The call is complete
    SetCompletion ("Hang up")

    If CurrentPhoneNumber >= 5 Then
        ' All calls have been made
        CheckDial.Value = Unchecked
    Else
        ' Go on to the next call
        CurrentPhoneNumber = CurrentPhoneNumber + 1
        Dial
    End If
End Sub

Private Sub etPlay1_OnDone()
' The wave file has finished playing
    ' Check to see if the call is in the connteced state
    If etLine1.CallState = LINECALLSTATE_CONNECTED Then
        If etPlay1.SourceFileName = App.Path & "\Greeting" Then
            ' If the file played was the Greeting then activate the timer to play 
            'it again
            TimerWaveLoop.Enabled = True
        Else
            If etPlay1.SourceFileName = App.Path & "\ThankYou" Then
                ' If the file played was to acknowledge correct digit then play
                ' the GoodBye file
                etPlay1.SourceFileName = App.Path & "\GoodBye"
                etPlay1.DeviceActive = True
            Else
                If etPlay1.SourceFileName = App.Path & "\GoodBye" Then
                    ' If the file played was GoodBye identify call is completed
                    ' normal
                    SetCompletion ("Normal")
                End If
                Hangup
            End If
        End If
    End If
End Sub

Private Sub Form_Load()
    'Enabled all ExceleTel TeleTools controls before using them
    etLine1.Enabled = True
    etPlay1.Enabled = True

    ' Fill the combo box with all available devices
    ComboDevice.Clear
    etLine1.DeviceID = 0
    For L = 0 To etLine1.DeviceCount - 1
        ComboDevice.AddItem etLine1.DeviceList(L)
    Next L
    'Select the first device
    If ComboDevice.ListCount > 0 Then
        ComboDevice.Text = ComboDevice.List(0)
    End If

    ' The etLine.OnIdle event is used to trigger subsequent calls.
    ' Voice modems need time to perpare for subsequent calls once a call is
    ' complete. Set etLine1.DeviceIdleDelay to 5000 milliseconds (seconds) to
    ' cause the etLine.OnIdle event to delay firing for 5 seconds.
    etLine1.DeviceIdleDelay = 5000

    ' Disable volume control because Voice modems do not support volume control
    etPlay1.VolumeEnabled = False
End Sub


Private Sub Form_Unload(Cancel As Integer)
    'Close the etLine control when closing the form
    etLine1.DeviceActive = False
End Sub

Private Sub TimerWaveLoop_Timer()
    ' Disable the timer
    TimerWaveLoop.Enabled = False
    If etLine1.CallState = LINECALLSTATE_CONNECTED Then
        If GreetingLoopCount < 10 Then
            ' Loop 10 time before going on the the next phone number
            GreetingLoopCount = GreetingLoopCount + 1
            etPlay1.DeviceActive = True
            If etPlay1.ErrorNumber > 0 Then
                TextStatus.Text = "Wave play error - " & etPlay1.ErrorText
                SetCompletion ("Wave play error")
                Hangup
            Else
                ' If an error did not occur then enable the time
                TimerWaveLoop.Enabled = True
            End If
        Else
            ' The acknowlegement digit has not been received
            SetCompletion ("No answer")
            Hangup
        End If
    End If
End Sub

 

 
 


Copyright © 1997-2009 ExceleTel Inc. All rights reserved.
Legal Notices Sunday September 21, 2008 03:02:33 AM

Contact Us