|
|
etThreeWayFlash Sample Program Source Code
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim bTSVisible As Boolean
Private Sub Form_Load()
Dim L As Integer
'Enable all of the ExceleTel TeleTools controls before using them!
etLine1.Enabled = True
'Uses the etLine DeviceIdleDelay property to delay the OnIdle event from
'firing for 2 seconds. This gives devices such as modems and Dialogic
'cards that need time, to reset between calls. Comment this line out and
'try quickly dialing and hanging up calls and see if you
get
' RESOURCE_UNAVAILABLE or other errors.
etLine1.DeviceIdleDelay = 2000
ComboDevice.Clear
'clear device box and use devicelist to fill the list with TAPI
devices
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
MsgBox ("This program will only work if the 'Flash duration' parameter is set"
_
& vbCrLf & _
"correctly. For most TRUE telephony devices, you must set the number of" & vbCrLf & _
"milliseconds for flash in the TSP configuration." & vbCrLf & vbCrLf & _
"MODEM USERS: Modems cannot set the flash duration programatically!" & vbCrLf & _
"You must change the 'DTMF duration' by modifying your INF file and" & vbCrLf & _
"re-installing the modem, or by changing your registry, or by using" & vbCrLf & _
"'Passthrough mode' to send AT commands to the modem. A flash duration" & vbCrLf & _
"too short will just briefly click the line and do nothing. A flash" & vbCrLf & _
"duration too long will hang up the call." & vbCrLf & vbCrLf & _
"Please see the help file for this program on the web. Click OK to continue.")
WriteLog ("Make sure your flash duration parameter is set" & vbCrLf & _
"correctly or this program will not work properly")
cmdButtonDial.Enabled = False
cmdButtonSecondCall.Enabled = False
cmdButton3Way.Enabled = False
End Sub
'****************************************************************
' CheckActive_Click - Activate and Deactivate the TAPI Line device
'****************************************************************
Private Sub CheckActive_Click()
If CheckActive.Value = 0 Then
If etLine1.DeviceActive Then
WriteLog ("etLine1.DeviceActive = False")
etLine1.DeviceActive = False
If Not etLine1.DeviceActive Then
cmdButtonDial.Enabled = False
Else
WriteLog (vbTab & "Error = " & etLine1.ErrorText)
CheckActive.Value = 1
End If
End If
Else
If Not etLine1.DeviceActive Then
cmdButtonHangup.Enabled = False
etLine1.DeviceActive = True
If etLine1.ErrorNumber = INVALID_SERIAL_NUMBER Then
MsgBox ("Error opening line device: " & etLine1.ErrorText & vbCrLf &
_
vbCrLf &
"See the help topic:" & vbCrLf & vbCrLf &
vbTab & _
"Why Serial Numbers Are Important")
End If
' Check for invalid_mediamode error and check tsp property for a non compliant modem
If (Not etLine1.DeviceActive) And
_
(etLine1.ErrorNumber = LINEERR_INVALMEDIAMODE) And _
(InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) Then
' set proper priviledge for incompatible modems
etLine1.PrivilegeNone = True '
etLine1.DeviceActive = True
MsgBox ("The program has detected that your device is a (" + etLine1.DeviceName & _
") DATA modem and therefore has no voice capabilities." & vbCrLf & vbCrLf & _
"We will now force a compatibility mode in order to allow you to " & _
" continue while greying out options your modem may not support." & vbCrLf & vbCrLf & _
"This device will be able to:" & vbCrLf & vbCrLf & vbTab & "DIAL" & vbCrLf & vbCrLf & _
"If you think you have a voice modem, expected more functionality, " & _
"or other programs provide more functionality with this modem, see the " & _
"topic 'Working with Modems' in the Appendix of the TeleTools help file.")
End If
If etLine1.DeviceActive Then
WriteLog ("etLine.DeviceActive = True")
cmdButtonDial.Enabled = True
Else
WriteLog ("Error = " & etLine1.ErrorText)
CheckActive.Value = 0
End If
End If
End If
End Sub
' **********************************************************************
' ComboDevice_Click - Process device change. If no errors, then it is TAPI
' compliant and so make sure Privileges are set properly
' **********************************************************************
Sub ComboDevice_Click()
If etLine1.DeviceActive Then CheckActive.Value = 0
WriteLog ("etLine.DeviceID = " & CStr(ComboDevice.ListIndex))
etLine1.DeviceID = ComboDevice.ListIndex
If etLine1.ErrorNumber <> 0 Then
WriteLog (vbTab & "Error = " & etLine1.ErrorText)
Else
etLine1.PrivilegeMonitor = True
etLine1.PrivilegeOwner = True
End If
End Sub
' ********************************************************
' cmdButtonDial_Click - Dial the phone with the etLine.CallDial method
' ********************************************************
Private Sub cmdButtonDial_Click()
etLine1.CallPhoneNumber = txtPhoneNumber.text
WriteLog ("Dialing [" & txtPhoneNumber.text & "]")
' This is where you dial a call. Rather than executing etLine1.CallDial and having to
' check if an error was generated, we use the method as a simple function. By putting
' it in an IF statement, we dial the phone and check to see if the result returned was
' true of false. See the help file section "How Do I Do That | Make a Call"
If etLine1.CallDial Then
cmdButtonDial.Enabled = False
cmdButtonHangup.Enabled = True
Else
' this will cause the to show twice in the log since we are using as simple OnError
' event handler also
WriteLog (vbTab & "Error = " & etLine1.ErrorText)
etLine1.CallHangup 'Just in case the device didn't drop the call
End If
End Sub
' ********************************************************
' cmdButtonHangup_Click - Hang up the call
' ********************************************************
Private Sub cmdButtonHangup_Click()
WriteLog ("Hangup")
If (etLine1.CallHandle <> 0) And (etLine1.CallState <> LINECALLSTATE_IDLE) Then
If Not etLine1.CallHangup Then
WriteLog (vbTab & "Error = " & etLine1.ErrorText)
End If
cmdButtonSecondCall.Enabled = False
cmdButton3Way.Caption = "Connect 3-Way"
cmdButton3Way.Enabled = False
cmdButton3Way.Enabled = False
End If
End Sub
' ********************************************************
' etLine_OnCallBegin event - Call has started, use
' ********************************************************
Private Sub etLine1_OnCallBegin(ByVal CallHandle As Long)
WriteLog ("etLine1_OnCallBegin")
End Sub
' ********************************************************
' etLine_OnDialtone event - a dialtone was detected on the line
' ********************************************************
Private Sub etLine1_OnDialtone(ByVal CallHandle As Long)
WriteLog ("etLine1_OnDialtone")
End Sub
' ********************************************************
' etLine_OnDialing event - the phone is being dialed
' ********************************************************
Private Sub etLine1_OnDialing(ByVal CallHandle As Long)
WriteLog ("etLine1_OnDialing")
End Sub
' ********************************************************
' etLine_OnBusy - A busy signal was detected
' ********************************************************
Private Sub etLine1_OnBusy(ByVal CallHandle As Long)
WriteLog ("etLine1_OnBusy")
cmdButtonHangup_Click
End Sub
' ********************************************************
' etLine_OnProceeding - the call is proceeding through the system
' ********************************************************
Private Sub etLine1_OnProceeding(ByVal CallHandle As Long)
WriteLog ("etLine1_OnProceeding")
End Sub
' ********************************************************
' etLine_OnCallerID - Caller ID information was detected
' ********************************************************
Private Sub etLine1_OnCallerID(ByVal CallHandle As Long)
WriteLog ("etLine1_OnCallerID")
WriteLog (vbTab & "CallerIDName = " & etLine1.CallCallerIDName)
WriteLog (vbTab & "CallerIDNumber = " & etLine1.CallCallerIDNumber)
End Sub
' ********************************************************
' etLIne_OnCalledID - The Called Party ID was detected
' ********************************************************
Private Sub etLine1_OnCalledID(ByVal CallHandle As Long)
etLine1.CallHandle = CallHandle ' make sure you have the right call
WriteLog ("etLine1_OnCallerID")
WriteLog (vbTab & "CallerIDName = " & etLine1.CallCallerIDName)
WriteLog (vbTab & "CallerIDNumber = " & etLine1.CallCallerIDNumber)
End Sub
' ********************************************************
' etLine_OnConnected - The call is connected
' ********************************************************
Private Sub etLine1_OnConnected(ByVal CallHandle As Long)
WriteLog ("etLine1_OnConnected")
cmdButtonHangup.Enabled = True
cmdButtonSecondCall.Enabled = True
End Sub
' ********************************************************
' etLine_OnCallEnd - The call has ended
' ********************************************************
Private Sub etLine1_OnCallEnd(ByVal CallHandle As Long)
WriteLog ("etLine_OnCallEnd")
End Sub
' ********************************************************
' etLine_OnDisconnected - The remote party has hung up
' ********************************************************
Private Sub etLine1_OnDisconnected(ByVal CallHandle As Long)
WriteLog ("etLine1_OnDisconnected")
WriteLog (vbTab & "Call.DisconnectMode = " & _
etLine1.StringLINEDISCONNECTMODE(etLine1.CallDisconnectMode))
cmdButtonHangup_Click
End Sub
' ********************************************************
' etLine_OnIdle - the call is idle and the device ready for a new call
' ********************************************************
Private Sub etLine1_OnIdle(ByVal CallHandle As Long)
WriteLog ("etLine1_OnIdle")
cmdButtonHangup.Enabled = False
cmdButtonDial.Enabled = True
End Sub
' ********************************************************
' etLine_
' ********************************************************
Private Sub etLine1_OnOffering(ByVal CallHandle As Long)
WriteLog ("etLine_OnOffering")
End Sub
' ********************************************************
' etLine_OnRing event - Incoming ring detected
' ********************************************************
Private Sub etLine1_OnRing(ByVal Count As Long, ByVal RingMode As Long)
WriteLog ("etLine1_OnRing [" & Str(Count) & ", " & Str(RingMode) & "]")
End Sub
' ********************************************************
' etLine_OnRingback - Fire if we detect remote party's phone ringing
'
(Not supported by all devices)
' ********************************************************
Private Sub etLine1_OnRingBack(ByVal CallHandle As Long)
WriteLog ("etLine_OnRingBack")
End Sub
' ********************************************************
' etLine_OnSpecialInfo event - fire if SIT tone detected on outbound call
' ********************************************************
Private Sub etLine1_OnSpecialInfo(ByVal CallHandle As Long)
WriteLog ("etLine1_OnSpecialInfo")
WriteLog (vbTab & "etLine1.CallSpecialInfo = " & _
etLine1.StringLINESPECIALINFO(etLine1.CallSpecialInfo))
End Sub
' ********************************************************
' etLine_OnDigitsSent event - fire when any DTMF digits (tones) are sent
' ********************************************************
Private Sub etLine1_OnDigitsSent(ByVal CallHandle As Long)
WriteLog ("etLine_OnDigitsSent")
End Sub
' ********************************************************
' etLine1_OnError Event - Trap any TAPI telephony errors
' ********************************************************
Private Sub etLine1_OnError()
WriteLog ("etLine1_OnError")
WriteLog (vbTab & "etLine1_Error = " & etLine1.ErrorText)
End Sub
Private Sub Form_Unload(Cancel As Integer)
' We would have to close the wave device here if using etPlay and/or etRecord anywhere
' CommandHangup_Click, etLine1_OnDisconnected, etLine1_OnIdle and Form_Unload
' Decide here if you need to hangup the call since some devices will hangup when the
' control is deactivated and some will keep the call active. You may want to not
' interrup a call if the application is closed or you may want to ensure that the
_
' call is terminated. Close the etLine control when closing the form
etLine1.DeviceActive = False
End Sub
Private Sub cmdButtonSecondCall_Click()
Dim result As Boolean
' NOTE: The hook flash does not support the duration parameter! That is why
' it is set to zero below. You must set the flash duration parameter
' in the TSP for the device, or in the case of voicemodems by following
' the instructions a the top setup section or on our web page for this
' sample program.
result = etLine1.CallSendDigits("!", 0)
WriteLog ("etLine1.CallSendDigits(""!"",0)" & " ' ""Flash""")
Sleep (1200)
WriteLog ("Pause 1.2 seconds")
result = etLine1.CallSendDigits(txt3WayNumber.text,
CInt(txtToneDuration.text))
WriteLog ("etLine1.CallSendDigits(" & """" & txt3WayNumber.text & _
"""" & ", " & txtToneDuration.text & ")")
cmdButtonSecondCall.Enabled = False
cmdButton3Way.Enabled = True
End Sub
' ********************************************************
' cmdButton3Way_Click - Make the threeway call by sending
"flash"
' ********************************************************
Private Sub cmdButton3Way_Click()
Dim result As Boolean
result = etLine1.CallSendDigits("!", 0)
WriteLog ("etLine1.CallSendDigits(""!"",0)" + " ' ""Flash""")
cmdButton3Way.Caption = "Flash Again"
End Sub
' ********************************************************
' Clear the textbox log
' ********************************************************
Private Sub cmdButtonClear_Click()
txtCallProgress.text = ""
End Sub
' ********************************************************
' Display the device configuration screen for
' the TAPI hardware. This is tied to the
' hardware manufacturer's Terminal Service Provider
' or driver, also known as the TSP
' ********************************************************
Private Sub CommandConfigDlg_Click()
etLine1.DeviceConfigure
End Sub
' ********************************************************
' WriteLog - Write text to the log window
' ********************************************************
Private Sub WriteLog(text As String)
txtCallProgress.text = txtCallProgress.text & text & vbCrLf
txtCallProgress.SelStart = Len(txtCallProgress.text)
End Sub
' ********************************************************
' btnInfo_Click - Display program info box
' ********************************************************
Private Sub btnInfo_Click()
' Display About Box
MsgBox (" etThreeWayFlash Sample Program" & vbCrLf & vbCrLf &
_
"Copyright(c) 2003 ExceleTel Inc."
& vbCrLf & vbCrLf & " www.exceletel.com")
End Sub
' ********************************************************
' cmdTeleScope_Click - Display the TeleTools TeleScope TAPI Diagnostic
Utility
' ********************************************************
Private Sub cmdButtonTeleScope_Click()
' Toggle display of the TeleScope Utility
etLine1.TeleScopeVisible = Not bTSVisible
bTSVisible = Not bTSVisible
End Sub
|