ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

etVoiceModemJoinCall Sample Program Source Code

Private Const STATE_IDLE = 0
Private Const STATE_RECORDING = 1
Private Const STATE_PLAYING = 2

Private CurrentState As Integer

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 CheckPlay_Click()
    If CheckPlay.Value = 1 Then
        ' Disable recording
        CheckRecord.Enabled = False

        ' Set the state so when the etline.OnConnected event fires
        ' playing will begin
        CurrentState = STATE_PLAYING

        ' Dial to join the call
        Dial
    Else
        ' Stop recording
        etPlay1.DeviceActive = False

        ' The etPlay.onDone event does not automaticly fire when playing
        ' is stopped manually. In this case etPlay1_OnDone needs to be called
        etPlay1_OnDone
    End If
End Sub

Private Sub CheckRecord_Click()
    If CheckRecord.Value = 1 Then
        ' Disable playing
        CheckPlay.Enabled = False

        ' Set the state so when the etline.OnConnected event fires
        ' recording will begin
        CurrentState = STATE_RECORDING

        ' Dial to join the call
        Dial
    Else
        TextStatus.Text = "Resetting voice modem..."
        'Deactivate the wave play device
        etRecord1.DeviceActive = False

        CurrentState = STATE_IDLE

        'Deactivate the line device
        etLine1.DeviceActive = False

        ' Set etPlay1 to use the same wave file as etRecord1
        etPlay1.SourceFileName = etRecord1.SourceFileName

        ' Check to see if the wave file exists
        If etPlay1.SourceValid Then
            CheckPlay.Enabled = True
        Else
            CheckPlay.Enabled = False
        End If
        TextStatus.Text = "Idle"
    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
        TextStatus.Text = "Idle"
        ' Allow wave files to be recorded
        CheckRecord.Enabled = True

        ' Set etPlay1 to use the same wave file as etRecord1
        etPlay1.SourceFileName = etRecord1.SourceFileName

        ' Check to see if the wave file exists
        If etPlay1.SourceValid Then
            CheckPlay.Enabled = True
        Else
            CheckPlay.Enabled = False
        End If
    Else
        TextStatus.Text = "Not active"
        CheckRecord.Enabled = False
        CheckPlay.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 Function Dial() As Boolean
    ' Active the TAPI Line device
    etLine1.DeviceActive = True
    If Not etLine1.DeviceActive Then
        MsgBox ("Error opening line device: " & etLine1.ErrorText)
        Dial = False
    Else
        TextStatus.Text = "Joining the call already in progress... Please wait..."
        If OptionQuietAnswer.Value Then
            'Use the "Wait for quiet answer" dialing feature
            etLine1.CallPhoneNumber = "@"
        Else
            'Use the "Wait for quiet answer" dialing feature
            etLine1.CallPhoneNumber = "!"
        End If
        'Dial to create join the call already in progress
        If etLine1.CallDial Then
            Dial = True
        Else
            Dial = False
            CurrentState = STATE_IDLE
        End If
    End If
End Function

Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
    ' Check the current state
    If CurrentState = STATE_PLAYING Then
        TextStatus.Text = "Playing wave file..."

        'Set wave play device
        etPlay1.DeviceID = etLine1.WavePlayID

        ' Begin playing the wave file
        etPlay1.DeviceActive = True
    Else
        If CurrentState = STATE_RECORDING Then
            TextStatus.Text = "Recording wave file..."

            'Set wave record device
            etRecord1.DeviceID = etLine1.WaveRecordID

            ' Begin recording the wave file
            etRecord1.DeviceActive = True
        End If
    End If
End Sub

Private Sub etPlay1_OnDone()
    TextStatus.Text = "Resetting voice modem..."
    CheckPlay.Value = Unchecked

    'Deactivate the line device
    etLine1.DeviceActive = False

    ' Enabled recording
    CheckRecord.Enabled = True
    TextStatus.Text = "Idle"
End Sub

Private Sub Form_Load()
    CurrentState = STATE_IDLE

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

    etRecord1.SourceFileName = App.Path & "\WaveFile.wav"

    'Volume control is disabled because Voice modems do not support this feature
    etPlay1.VolumeEnabled = False

    ' Fill the combobox 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 telephony device
    If ComboDevice.ListCount > 0 Then
        ComboDevice.Text = ComboDevice.List(0)
    End If
End Sub


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

 

 
 


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

Contact Us