ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

etGatherDigitsWorkAround Sample Program Source Code

Private Const MILLISECOND = 0.000000011574

Private sDigits As String 'Used to store the digits as they come in


Private Sub SetGatherDigits()
    If CheckActive.Value = Unchecked Then
        ' Disable the timeout timer
        TimerDigitTimout.Enabled = False
        ' Stop monitoring digits
        etLine1.CallMonitorDigitsActive = False
    Else
        ' Clear the digit display
        TextDigits.Text = ""

        ' Clear out the current digits
        sDigits = ""

        etLine1.CallMonitorDigitsActive = True
    End If

    ' Update the Active check box
    If etLine1.CallMonitorDigitsActive Then
        TextStatusetLine.Text = "Gathering Digits"

        CheckActive.Value = Checked

        'Lock the following controls while gathering digits
        TextTimeOut.Locked = True
        TextTerminate.Locked = True
        TextCount.Locked = True
        TextHangupDelay.Locked = True
    Else
        TextStatusetLine.Text = "Not Gathering Digits"

        CheckActive.Value = Unchecked

        'Unlock the following controls while not gathering digits
        TextTimeOut.Locked = False
        TextTerminate.Locked = False
        TextCount.Locked = False
        TextHangupDelay.Locked = False
    End If

    If etLine1.CallActive Then
        ' There is an active call
        If CheckActive.Value = Checked Then
            ' If Gathering Digits is active then set then timer interval and
            ' enable the timer
            TimerDigitTimout.Interval = Val(TextTimeOut.Text)
            If TimerDigitTimout.Interval > 0 Then
                TimerDigitTimout.Enabled = True
            End If
        End If
    Else
        TextStatusetLine.Text = "OnIdle"
    End If
End Sub

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 OnDigitsGathered(ByVal Digits As String, ByVal Termination As Long)
    'Disable the timer
    TimerDigitTimout.Enabled = False

    CheckActive.Value = Unchecked

    ' Display the gathered Digits
    TextDigits.Text = Digits

    ' Display the reason why digit gathering stopped
    Select Case Termination
        Case LINEGATHERTERM_BUFFERFULL
            TextStatusetLine.Text = "OnDigitsGathered - Buffer full"
        Case LINEGATHERTERM_TERMDIGIT
            TextStatusetLine.Text = "OnDigitsGathered - Terminating digit"
        Case LINEGATHERTERM_FIRSTTIMEOUT
            TextStatusetLine.Text = "OnDigitsGathered - Timeout"
        Case LINEGATHERTERM_INTERTIMEOUT
            TextStatusetLine.Text = "OnDigitsGathered - Timeout"
        Case LINEGATHERTERM_CANCEL
            TextStatusetLine.Text = "OnDigitsGathered - Canceled"
        Case Else
            TextStatusetLine.Text = "OnDigitsGathered - Unknown"
    End Select
End Sub

Private Sub CheckActive_Click()
    SetGatherDigits
End Sub

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

    ' Check to see if the selected device supports gathering digits
    ' Voice modems do support monitoring digits however this feature is not
    ' reported correctly
    If ((etLine1.AddressCapabilitiesCallFeatures And _
         LINECALLFEATURE_MONITORDIGITS) = 0) And _
        (Not IsVoiceModem) Then
        MsgBox ("This device do not supports Monitor Digits")
        ' Disable the Active check box
        CheckActive.Enabled = False
    Else
        If ((etLine1.AddressCapabilitiesCallFeatures And _
             LINECALLFEATURE_GATHERDIGITS) > 0) Then
            MsgBox ("This device supports Gathering Digits" & vbCrLf & vbCrLf & _
                    "Use the etGatherDigits sample program.")
            ' Disable the Active check box
            CheckActive.Enabled = False
        Else
            'Active the line device
            etLine1.DeviceActive = True

            If etLine1.DeviceActive Then
                TextStatusetLine.Text = "OnIdle"
                ' Enable the Dial button
                CheckActive.Enabled = True
            Else
                TextStatusetLine.Text = "Device.Active = False"
                ' Disable the Active check box
                CheckActive.Enabled = False
            End If
        End If
    End If
End Sub

Private Sub etLine1_OnCallEnd(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnIdle"
End Sub

Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnConnected"
    ' Check to see if Gathering Digits should begin
    SetGatherDigits
End Sub

Private Sub etLine1_OnDigitReceived(ByVal CallHandle As Long, _
                                    ByVal Digit As _
                                    Integer, ByVal Tag As Long)
    'Disable the timer
    TimerDigitTimout.Enabled = False

    If (InStr(1, TextTerminate.Text, Chr(Digit), 1) > 0) Then
        ' Gathering Digits is comeplete because a termination character was
        ' received
        Call OnDigitsGathered(sDigits, LINEGATHERTERM_TERMDIGIT)
    Else
        ' Add the new digit to the stored digits
        sDigits = sDigits & Chr(Digit)
        If Len(sDigits) = Val(TextCount.Text) Then
            ' Gathering Digits is comeplete because enough characters were
            ' received
            Call OnDigitsGathered(sDigits, LINEGATHERTERM_BUFFERFULL)
        Else
            ' Restart the timeout timer
            TimerDigitTimout.Interval = Val(TextTimeOut.Text)
            If TimerDigitTimout.Interval > 0 Then
                TimerDigitTimout.Enabled = True
            End If
        End If
    End If
End Sub

Private Sub etLine1_OnDisconnected(ByVal CallHandle As Long)
Dim dtStart

    TextStatusetLine.Text = "OnDisconnected"
    If etLine1.CallMonitorDigitsActive Then
        ' if Monitoring digits active then stop
        etLine1.CallMonitorDigitsActive = False

        ' Some telephony devices may required a short delay after terminating the
        ' MonitorDigits
        If Val(TextHangupDelay.Text) > 0 Then
            ' Store the current time
            dtStart = Now
            ' Loop until the milliseconds in TextHangupDelay.Text has passed
            Do While Now < dtStart + (MILLISECOND * Val(TextHangupDelay.Text))
                ' Allow Windows messages to be processed
                DoEvents
            Loop
        End If

    End If
    etLine1.CallHangup
End Sub

Private Sub etLine1_OnError()
    If etLine1.ErrorNumber = TAPIREPLYTIMEOUT Then
        MsgBox (etLine1.ErrorText & vbCrLf & _
            "The program will terminate when you click OK" & vbCrLf & vbCrLf & _
            "Increase the Delay value and try again...")
        End
    End If
End Sub

Private Sub etLine1_OnOffering(ByVal CallHandle As Long)
    TextStatusetLine.Text = "OnOffering"
    TextDigits.Text = ""
    'Answer the call as soon as it is available
    etLine1.CallAnswer
End Sub

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

    'Set the timeout to a lower value for testing
    etLine1.TAPIREPLYTIMEOUT = 15000

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

Private Sub TimerDigitTimout_Timer()
    ' Gathering Digits is comeplete because it timed out
    Call OnDigitsGathered(sDigits, LINEGATHERTERM_INTERTIMEOUT)
End Sub

 

 
 


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

Contact Us