ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

etVoiceModemCallBlocker Sample Program Source Code

'Used to calculate the timer duration
Dim dtFirstRing As Date
Dim dtRingDuration As Date

Private Function IsOnlyDataModem() As Boolean
Dim 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 ComboDevice_Click()
    ' Set the TAPI Line device
    etLine1.DeviceName = ComboDevice.Text

    ' Check to see if the selected device is a Voice modem
    If Not IsVoiceModem Then
        ' 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
    Else
        etLine1.DeviceActive = True

        If (Not etLine1.DeviceActive) Then
            MsgBox ("Error opening line device: " & etLine1.ErrorText)
        Else
            ' Use the wave play audio device associated with the select line
            ' device
            etPlay1.DeviceID = etLine1.WavePlayID
            ' Voice modems do not support volume control
            etPlay1.VolumeEnabled = False
        End If
    End If
End Sub

Private Sub etLine1_OnCallerID(ByVal CallHandle As Long)
    ' Some voice modems fire the etLine.OnCallerID event more than once
    ' This "If" statement keeps the program from responding to subsequent _
    ' CallerID events
    If TextCallerIDName.Text = "" Then
        ' Check the flags to see if the CallerID Name is available
        If ((etLine1.CallCallerIDFlags And LINECALLPARTYID_NAME) <> 0) Then
            TextCallerIDName.Text = etLine1.CallCallerIDName
        End If
        ' Check the flags to see if the CallerID Number is available
        If ((etLine1.CallCallerIDFlags And LINECALLPARTYID_ADDRESS) <> 0) Then
            TextCallerIDNumber.Text = etLine1.CallCallerIDNumber
        End If
        ' Voice modems utilize the etLine1.Call.CallerID.Flags property to
        ' identify "Blocked" and "Out of Area" calls. Instead both types of calls
        ' are flagged as "Out of Area"
        If etLine1.CallCallerIDOutOfArea Then
            ' Disable the timer
            TimerCallAnswered.Enabled = False
            If etLine1.CallCallerIDName = "P" Then
                ' Voice modems identify calls Blocked CallerID by putting a "P"
                ' in the CallerID Name
                TextCallerIDName.Text = "Blocked"
                ' Set the wave file to Blocked.wav
                ' This file will be play when the etLine.OnConnected event fires
                etPlay1.SourceFileName = App.Path & "\Blocked"
            Else
                If etLine1.CallCallerIDName = "O" Then
                    ' Voice modems identify calls "Out of Area" CallerID by
                    ' putting an 'O' in the CallerID Name
                    TextCallerIDName.Text = "Out of area"
                    ' Set the wave file to SIT.wav
                    ' This file will be play when the etLine.OnConnected event
                    ' fires
                    etPlay1.SourceFileName = App.Path & "\SIT"
                End If
            End If
            ' Answer the call.
            ' This will cause the etLine.OnConnected event to fire
            etLine1.CallAnswer
        End If
    End If
End Sub

Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
    etPlay1.DeviceActive = True
End Sub

Private Sub etLine1_OnOffering(ByVal CallHandle As Long)
' A new call!

    ' Clear the CallerID information
    TextCallerIDName.Text = ""
    TextCallerIDNumber.Text = ""

    If dtRingDuration = 0 Then
        ' Reset the timer duration calculator variables if they were set
        ' incorrectly. This can happen if the first call is answered before the
        ' second ring or if the caller hangs up before the second ring.
        dtFirstRing = 0
    End If
End Sub

Private Sub etLine1_OnRing(ByVal Count As Long, ByVal RingMode As Long)
    ' As long as rings are detected deactivate the timer before it has an
    ' opportunity to fire
    TimerCallAnswered.Enabled = False

    ' The following If statement is used to caculate the interval for the time.
    ' Until a new interval is calulated the default value of 6187 milliseconds is
    ' used.
    If dtFirstRing = 0 Then
        ' Store the time of the first ring
        dtFirstRing = Now
    Else
        If dtRingDuration = 0 Then
            ' Calculate the duration between the first and second ring
            dtRingDuration = Now - dtFirstRing
            ' Set the timer interval to the duration in miliseconds plus 1/4 of a
            ' second. This will cause the timer to fire 1/4 of a second after a
            ' ring was expected
            TimerCallAnswered.Interval = (dtRingDuration / 0.000000011574) + 250
        End If
    End If

    ' Enabled the timer
    TimerCallAnswered.Enabled = True
End Sub

Private Sub etPlay1_OnDone()
    TimerCallAnswered_Timer
End Sub

Private Sub Form_Load()
    ' Set the timer duration calculator variable to zero
    dtFirstRing = 0
    dtRingDuration = 0

    'Enabled all ExceleTel TeleTools controls before using them
    etLine1.Enabled = True
    etPlay1.Enabled = True

    ' Fill in the list box with all available telephony devices
    ComboDevice.Clear
    etLine1.DeviceID = 0
    For L = 0 To etLine1.DeviceCount - 1
        ComboDevice.AddItem etLine1.DeviceList(L)
    Next L

    ' Select the first device in the list
    If ComboDevice.ListCount > 0 Then
        ComboDevice.Text = ComboDevice.List(0)
    End If
    ComboDevice.ListIndex = 0
End Sub


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

Private Sub TimerCallAnswered_Timer()
    ' The timer to fire 1/4 of a second after a ring was expected
    ' It is assumed that the remote party hung up or the call was answered

    ' Disable the timer
    TimerCallAnswered.Enabled = False

    ' Deactivate the etLine control to ignore the call
    etLine1.DeviceActive = False

    ' Active the etLine control
    etLine1.DeviceActive = True
End Sub

 

 
 


Copyright © 1997-2007 ExceleTel Inc. All rights reserved. Friday August 17, 2007 11:05:24 AM

Contact Us