提出问题提出问题
 

已答复TAPI & PBX

  • 2007年9月8日 20:33john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Hi,
    Can anyone show me the way to connect TAPI and PBX including recieve incomming call,Out going call, and transfer call in VB 2005 or C#?

    Waiting for reply,

    Thanks

    John

答案

  • 2007年9月11日 5:21Bruno YuMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    john1982,

     

    MichaelLee,

     

    According to your demand, I would like to provide you some examples in Code Project:

     

    1. .NET Phone Communication Library Part I - Retrieve Phone Settings

    http://www.codeproject.com/smartclient/phoneat.asp

     

    2. .NET Phone Communication Library Part II - Send SMS

    http://www.codeproject.com/useritems/phonesms.asp

     

    3. .NET Phone Communication Library Part III - Dial, Answer, Reject Call

    http://www.codeproject.com/useritems/phonecall.asp

     

    4. .NET Phone Communication Library Part IV - Receive SMS

    http://www.codeproject.com/vb/net/phonesmsrecv.asp

     

    5. .NET Phone Communication Library Part V - Send vCard, vCalendar and Wap Push Message

    http://www.codeproject.com/useritems/phonemsg.asp

     

    The following two download page can solve the second problem on TAPI on Vista X64:

     

    http://www.bestvistadownloads.com/software/k-tapi-t-free-phonetray-dialup-download-wwlvgioj.html

     

    http://www.programurl.com/software/tapi.htm

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

  • 2007年9月14日 3:25Bruno YuMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    john1982,

     

    Thanks for your reply. Since the third project sample cannot wirking properly on your local machine, please check the version and related APIs of your operating system.

     

    Furthermore, I would like to provide you the TAPI Quick Start that can help you start writing Telephony Application Programming Interface (TAPI) applications or adding features to existing applications.

     

    The following SDK topics describe basic TAPI operations using code examples:


    Initialize TAPI
    Select an Address
    Register Events
    Select a Terminal
    Make a Call
    Receive a Call
    Create a Simple Conference
    Transfer a Call

    You can also post the question in Smart Devices VB and C# Projects if you are developing on .NET Compact Framework. There are a lot of TAPI questions in this forum, too.

     

    Hope that can help you.

  • 2007年12月14日 21:16John T. M 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    'Filename: DialerGlobal.vb
    'Desc: Extends Inheritable Dialer Class with TAPI Methods
    'Date: 10/24/2007
    'Auth: John T. M DATAMODEM  Dialer Project
    '
    '
    'Description:
    ' Class to implement call handeling using DATAMODEM DTMF Device.  
    ' Detects modem as DATAMODEM.
    '
    'Dependancies:
    ' To Do - Implement SIP Session Initiation Protocol for PBX (VoIP) Functionality.
    ' IP telephony signaling protocol used to establish, modify and terminate VOIP telephone calls.
    ' SIP was developed by the IETF and published as RFC 3261 http://tools.ietf.org/html/rfc3261

    '  Implements TAPI 3.x Class Members - TAPI3Lib
    '
    '
    ' References:
    ' ms-help://MS.PSDKSVR2003SP1.1033/tapi/tapi3/tapi_quick_start.htm

    Imports TAPI3Lib
    Public Class Dialer

        Private TAPI3 As TAPI                            ' TAPI 3.x Class
        Public TAPIException As Exception                ' TAPI Errors encountered during execution
        Public TAPIExceptionMessage As String            ' TAPI Exception Message
        Public TAPI3Initalized As Boolean                ' TAPI 3 Initalized state                 
        Private TAPIAddress As ITAddress                 ' Address of Supported Media Type
        Public TAPIAddressName As String                 ' TAPIAddress.AddressName 
        Public TAPIDataModemAddress As ITAddress         ' Address of Data Modem Device 
        Private TAPICollAddresses As ITCollection        ' Collection of Media Type Addresses
        Private TAPIMediaSupport As ITMediaSupport
        Private TAPIAddressCapabilities As ITAddressCapabilities ' Capabilities of Device
        Private TAPICallControl As ITBasicCallControl    ' Call Control Object
        Private TAPICallState As CALL_STATE              ' TAPI Call State for active call
        Private TAPICallStateTimer As System.Timers.Timer       ' TAPICall State Timer
        Public TAPICallInfo As ITCallInfo                ' Information about calls
        Private TAPICalls As ITCollection                ' Maintains Collection of calls
        Private TAPICallTerminal As ITTerminal           ' Call Terminals Object
        Private TAPITerminalSupport As ITTerminalSupport2 ' Terminal Support Object  
        Public CallAddressState As ADDRESS_STATE         ' State of ITAddress object
        Public DATA_MODEM_DEVICE As Boolean              ' Call Device (ITAddress DATAMODEM) available  
        Public MEDIA_SUPPORT_AUDIO As Boolean            ' Call Device Supports Audio
        Public MEDIA_SUPPORT_VIDEO As Boolean            ' Call Device Supports Video 
        Public DTMFH323Support As Boolean                ' Call Device Support DTMF Streams.
        Private WithEvents TAPIWithEvents As TAPI        ' TAPI Event Handler
        Private TAPIRegistrationToken As Integer         ' Handle for event registration
        Private fOwner As Boolean, fMonitor As Boolean   ' Registration options RegisterCallNotifications
        Private lMediaTypes As Integer, lCallbackInstance As Integer
        ' Call event notifications and constants
        Const CallEvents As TAPI_EVENT = _
                                         TAPI_EVENT.TE_CALLMEDIA _
                                         Or TAPI_EVENT.TE_CALLSTATE _
                                         Or TAPI_EVENT.TE_CALLNOTIFICATION _
                                         Or TAPI_EVENT.TE_TONEEVENT _
                                         Or TAPI_EVENT.TE_DIGITEVENT

        Const LINEADDRESSTYPE_PHONENUMBER = 1            ' Standard Phone Number
        Const LINEADDRESSTYPE_IPADDRESS = 16             ' Standard TCP/IP Address IPV4
      
      Public Enum MEDIA_TYPE As Integer                ' TAPIConstants.TAPIMEDIATYPE_ Constants
            AUDIO = 8          ' &H0008
            DATAMODEM = 16     ' &H0010
            G3FAX = 32         ' &H0020
            VIDEO = 32768      ' &H8000
            AUDIOVIDEO = 32776 ' &H8008
       End Enum
     
       Public Enum LINEDIGIT_MODE As Integer            ' TAPIConstants.LINEDIGITMODE_ Constants
            LINEDIGITMODE_PULSE = 1
            LINEDIGITMODE_DTMF = 2
            LINEDIGITMODE_DTMFEND = 4
        End Enum

        ' Initialize TAPI 3.x Class, Must call Shutdown() when finished   
        Public Sub Initialize()
            If Not TAPI3Initalized Then                   ' TAPI Objects Not Initialized  
                TAPI3 = New TAPI                          ' Create the new TAPI Object
                TAPIException = Nothing
                TAPIExceptionMessage = Nothing
                TAPICallTerminal = Nothing
                TAPICallControl = Nothing
                TAPITerminalSupport = Nothing
                TAPICalls = Nothing
                TAPI3.Initialize()                          ' Initalize TAPI Instance
                TAPIRegistrationToken = 0                   ' Null Registration
                DATA_MODEM_DEVICE = False                   ' Selected Call device available.
                MEDIA_SUPPORT_AUDIO = False
                MEDIA_SUPPORT_VIDEO = False
                TAPICollAddresses = TAPI3.Addresses         ' Addresses to Enumerate into collection.
                TAPICallState = CALL_STATE.CS_DISCONNECTED  ' Default Call State is Disconnected.

                ' Select default call Notifications for TAPI
                fOwner = False                              ' Application Owns incomming calls
                fMonitor = True                             ' Application Monitors calls.
                lMediaTypes = MEDIA_TYPE.DATAMODEM          ' Default Media type handled by Dialer.
                lCallbackInstance = 1

                TAPIDataModemAddress = FindMediaType(MEDIA_TYPE.DATAMODEM) ' Select Defualt DTMF Modem Device

                ' Set ITTAPIEventNotification::Event interface
                TAPI3.EventFilter = CallEvents              ' Set TAPI Call Event Notifications
                TAPIWithEvents = TAPI3                      ' Register the outgoing events.

                If Not TAPIDataModemAddress Is Nothing Then ' Data Modem Support ..?
                    SetITAddress(TAPIDataModemAddress)      ' Set Data Modem as active TAPIAddress (ITAddress)
                    TAPI3Initalized = True                  ' TAPI Initalized
                    TAPI3.SetApplicationPriority(Application.ProductName, lMediaTypes, True) ' Application is DATAMODEM GOD
                    TAPICallStateTimer = New System.Timers.Timer ' New Call Timer
                    AddHandler TAPICallStateTimer.Elapsed, AddressOf TAPICallStateTimerElapsed
                    TAPICallStateTimer.Interval = 10000      ' 10 Second Call Interval Timer 
                    TAPICallStateTimer.Stop()
                    ' MakeCall("###-###-####")                   ' Debugging application only
                End If

            End If

        End Sub

        'Find address that supports the desired type Media Type (nMedia).
        'Returns ITAddress (Usable Address) of requested Media Type (TapiConstants) on Success.
        Public Function FindMediaType(ByVal nMedia As MEDIA_TYPE) As ITAddress
            Dim tAddressIndex As Integer                  ' Address Index of Supported Media type
            Dim TAPIoAddress As Object                    ' Usable Address Object 
            TAPIAddress = Nothing                         ' Set to Invalid Address

            For tAddressIndex = 1 To TAPICollAddresses.Count
                TAPIoAddress = TAPICollAddresses.Item(tAddressIndex)
                TAPIMediaSupport = TAPIoAddress

                If TAPIMediaSupport.QueryMediaType(nMedia) Then
                    TAPIAddress = TAPIoAddress
                    lMediaTypes = TAPIMediaSupport.MediaTypes ' Media Types supported by this address.
                    Exit For ' Set Current Address to requested TAPICollAddresses.Item(tAddressIndex)
                End If
            Next

            TAPIoAddress = Nothing                         ' Set to Invalid Address
            TAPIMediaSupport = Nothing                     ' Destroy Object  

            Return TAPIAddress
        End Function

        ' Set device address active for selected call device returned by FindMediaType.
        ' Device is DTMF compatible and can generate and monitor tones.
        Private Function SetITAddress(ByVal xITAddress As ITAddress) As Boolean
            Dim DeviceAvailable = False
            DATA_MODEM_DEVICE = False
            MEDIA_SUPPORT_VIDEO = False
            MEDIA_SUPPORT_AUDIO = False
            lMediaTypes = 0

            CallAddressState = xITAddress.State

            If CallAddressState = ADDRESS_STATE.AS_INSERVICE Then
                TAPIAddress = Nothing                            ' Release Address Object   
                TAPIAddress = xITAddress                       ' Set Active device address.
                TAPIAddressName = TAPIAddress.AddressName    ' Set Active address name for selected device.
                TAPIMediaSupport = TAPIAddress             ' Detect Media Support Type for selected address. 
                TAPIAddressCapabilities = TAPIAddress    ' Set Address Capabilities.
                TAPICalls = TAPIAddress.Calls                 ' Get collection of ITCallInfo pointers for specified address. 

                ' Determine type of media supported by selected device. 
                If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.DATAMODEM) Then DATA_MODEM_DEVICE = True

                If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.AUDIOVIDEO) Then
                    MEDIA_SUPPORT_VIDEO = True
                    MEDIA_SUPPORT_AUDIO = True
                Else
                    If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.AUDIO) Then MEDIA_SUPPORT_AUDIO = True
                    If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.VIDEO) Then MEDIA_SUPPORT_VIDEO = True
                End If

                ' Set lMediaTypes Supported for this address.
                If DATA_MODEM_DEVICE Then lMediaTypes = MEDIA_TYPE.DATAMODEM
                If Not DATA_MODEM_DEVICE Then lMediaTypes = TAPIMediaSupport.MediaTypes

                ' If device supports incomming calls register.
                If TAPIRegistrationToken Then TAPI3.UnregisterNotifications(TAPIRegistrationToken)

                Try ' Register Call Notification for DATAMMODEM Device.
                    TAPIRegistrationToken = TAPI3.RegisterCallNotifications(xITAddress, fMonitor, _
                     fOwner, lMediaTypes, lCallbackInstance)
                    DeviceAvailable = True                       ' Set Device Available.
                Catch ex As Exception   ' Incomming calls not supported by interface.
                    TAPIException = ex
                    TAPIExceptionMessage = ex.Message
                End Try

            End If

            TAPIMediaSupport = Nothing                      ' Disreguard Objects.
            TAPIAddressCapabilities = Nothing

            Return DeviceAvailable
        End Function

        ' Create a new Call Control Object and associate with xITAddress (use default Modem device)  
        Private Function SetCallControl(ByVal phNumber As String) As Boolean
            Dim nControlState As Boolean = False
            'TAPICallTerminal = Nothing
            TAPICallControl = Nothing
            TAPICallInfo = Nothing

            ' Device available and ITAddress is DTMF enabled.
            If phNumber.Length >= 8 And Not TAPIAddress Is Nothing Then  ' Valid phone number.

                ' Create a new Call Control Object for this call.
                TAPICallControl = TAPIAddress.CreateCall(phNumber, _
                  LINEADDRESSTYPE_PHONENUMBER, lMediaTypes)

                If Not TAPICallControl Is Nothing Then     ' Set Tapi Call Control and Information.

                    TAPICallInfo = TAPICallControl         ' Set Call Information
                    TAPICallState = TAPICallInfo.CallState ' Get Call State information

                    ' Try  ' Is terminal support available does an MSP exist for this address ?
                    ' TAPITerminalSupport = TAPIAddress      ' Terminal Support Object      
                    ' TAPICallTerminal = TAPITerminalSupport.GetDefaultStaticTerminal( _
                    '                   lMediaTypes, TERMINAL_DIRECTION.TD_CAPTURE)

                    ' Catch ex As System.Exception               ' Terminal Support Not available for this device.
                    ' TAPIException = ex
                    ' TAPIExceptionMessage = ex.Message
                    ' End Try

                    If TAPICallState = CALL_STATE.CS_IDLE Then nControlState = True
                End If
            End If

            Return nControlState
        End Function

        ' Place a new Call to PhoneNumber, Returns True on Success
        ' Sets Call Control using default Data Modem device.
        ' If the call is synchronous, this method will not return until
        ' the call is in the connected state or fails.
        Public Function MakeCall(ByVal phNumber As String) As Boolean
            Dim nControlState As Boolean = False

            If Not TAPI3Initalized Then Initialize() ' Initalize TAPI 3
         
            If DATA_MODEM_DEVICE Then                ' Modem Device is ready.
                If SetCallControl(phNumber) Then
                    Try ' Try to place the call syncronusly
                        TAPICallControl.Connect(False)         ' Place call and return asyncronusly.
                        TAPICallState = TAPICallInfo.CallState ' Set Call State information for active connection.
                        nControlState = True ' Call was placed.  

                    Catch ex As Exception  ' Call Failed
                        TAPIException = ex
                        TAPIExceptionMessage = ex.Message
                        Shutdown()         ' Stop TAPI3
                    End Try
                End If
            End If


            Return nControlState
        End Function

        ' Close all TAPI Sessions and Clean up objects 
        Public Sub Shutdown()
            ' Check for valid registration token  
            If TAPI3Initalized Then
                If Not TAPICallInfo Is Nothing Then ' Is there an active call
                    If TAPICallInfo.CallState <> CALL_STATE.CS_DISCONNECTED Then   TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
                    TAPICallState = CALL_STATE.CS_DISCONNECTED
                End If
                If TAPIRegistrationToken Then TAPI3.UnregisterNotifications(TAPIRegistrationToken)
                MEDIA_SUPPORT_AUDIO = False
                MEDIA_SUPPORT_VIDEO = False
                TAPICallInfo = Nothing
                TAPICallTerminal = Nothing
                TAPITerminalSupport = Nothing
                TAPICallControl = Nothing
                TAPIMediaSupport = Nothing
                TAPIWithEvents = Nothing
                TAPI3.Shutdown()
                DATA_MODEM_DEVICE = False
                TAPIDataModemAddress = Nothing
                TAPIAddress = Nothing
                TAPIAddressCapabilities = Nothing
                TAPICollAddresses = Nothing
                TAPICalls = Nothing
                TAPI3Initalized = False
                TAPIException = Nothing
                TAPIExceptionMessage = Nothing
                TAPIRegistrationToken = 0
                TAPI3 = Nothing ' Release TAPI
            End If
        End Sub

        Private Sub TAPIWithEvents_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles TAPIWithEvents.Event
            ' TAPI Event Handler for TapiEvent use MakeCall with TAPICallControl.Connect(False) for asyncronus operation.
            ' If the call is asynchronous, the application will receive information about the call's progress through
            ' the ITCallNotificationEvent outgoing interface.

            Select Case TapiEvent
                Case TAPI_EVENT.TE_CALLSTATE  ' Process Call State Events for active call (TAPICallState = TAPICallInfo.CallState)
                    Dim TAPICallStateEvent As ITCallStateEvent = pEvent
                    TAPICallState = TAPICallStateEvent.State  ' Update Call State for TAPICallInfo.CallState
                    TAPICallInfo = TAPICallStateEvent.Call    ' Update Call Information for this call. 
                    TAPICallStateEvent = Nothing              ' Discontinue object.

                    Select Case TAPICallState                 ' Process Call State for TAPICallInfo
                        Case CALL_STATE.CS_DISCONNECTED       ' Call was Disconnected so release objects.
                            TAPICallStateTimer.Stop()         ' Stop the Call State Timer

                        Case CALL_STATE.CS_INPROGRESS         ' Call is in progress
                            TAPICallStateTimer.Start()        ' Start the Call State Timer    

                        Case CALL_STATE.CS_CONNECTED          ' Call Was completed successfully
                            TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
                          

                    End Select

                Case TAPI_EVENT.TE_CALLNOTIFICATION         ' Process Incomming Call Here
                Case TAPI_EVENT.TE_CALLMEDIA
                Case TAPI_EVENT.TE_TONEEVENT
                Case TAPI_EVENT.TE_DIGITEVENT

            End Select


        End Sub
        ' Handles TAPI Call State timing (Timer to set Max Call Duration) 
        Private Sub TAPICallStateTimerElapsed(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs)
            TAPICallStateTimer.Stop() ' Process Call State for current call

            Select Case TAPICallState ' Process Call State for TAPICallInfo

                Case CALL_STATE.CS_INPROGRESS         ' Call is in progress
                    TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)

                Case CALL_STATE.CS_CONNECTED          ' Call Was completed successfully
                    TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
            End Select
        End Sub
    End Class

    ' Enjoy my code contribution TAPI3 API Rules.. John T. M

全部回复

  • 2007年9月11日 5:21Bruno YuMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    john1982,

     

    MichaelLee,

     

    According to your demand, I would like to provide you some examples in Code Project:

     

    1. .NET Phone Communication Library Part I - Retrieve Phone Settings

    http://www.codeproject.com/smartclient/phoneat.asp

     

    2. .NET Phone Communication Library Part II - Send SMS

    http://www.codeproject.com/useritems/phonesms.asp

     

    3. .NET Phone Communication Library Part III - Dial, Answer, Reject Call

    http://www.codeproject.com/useritems/phonecall.asp

     

    4. .NET Phone Communication Library Part IV - Receive SMS

    http://www.codeproject.com/vb/net/phonesmsrecv.asp

     

    5. .NET Phone Communication Library Part V - Send vCard, vCalendar and Wap Push Message

    http://www.codeproject.com/useritems/phonemsg.asp

     

    The following two download page can solve the second problem on TAPI on Vista X64:

     

    http://www.bestvistadownloads.com/software/k-tapi-t-free-phonetray-dialup-download-wwlvgioj.html

     

    http://www.programurl.com/software/tapi.htm

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

  • 2007年9月13日 12:41john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

     

    Thanks you for the help,  but this link is not working,

    3. .NET Phone Communication Library Part III - Dial, Answer, Reject Call

    http://www.codeproject.com/useritems/phonecall.asp

     

    Can i have anothers?

     

    Best regards,

     

    John

  • 2007年9月14日 3:25Bruno YuMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    john1982,

     

    Thanks for your reply. Since the third project sample cannot wirking properly on your local machine, please check the version and related APIs of your operating system.

     

    Furthermore, I would like to provide you the TAPI Quick Start that can help you start writing Telephony Application Programming Interface (TAPI) applications or adding features to existing applications.

     

    The following SDK topics describe basic TAPI operations using code examples:


    Initialize TAPI
    Select an Address
    Register Events
    Select a Terminal
    Make a Call
    Receive a Call
    Create a Simple Conference
    Transfer a Call

    You can also post the question in Smart Devices VB and C# Projects if you are developing on .NET Compact Framework. There are a lot of TAPI questions in this forum, too.

     

    Hope that can help you.

  • 2007年10月4日 18:11john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Dear Bruno Yu,

     

    Thank you very much for the helps, now i can call by using IP call from computer to computer, but i still can't work with phone. i mean i want to answer/recieve a call from phone. any ideas to do that? can you give me some document related to this?

     

    Thanks in advances

  • 2007年10月11日 17:21john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Dear,

     

    Suppose i want to calling from computer to phone call by using tapi, how can i setup hardware for that?

    if anyone knows, please post here i need to finished my thesis.. please help

    Thanks,

  • 2007年10月11日 17:21john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Dear,

     

    Suppose i want to calling from computer to phone call by using tapi, how can i setup hardware for that?

    if anyone knows, please post here i need to finish my thesis.. please help

    Thanks,

  • 2007年10月12日 16:42john1982 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Dear,

    When i try to call a phone number with the code bellows the program always generate an errors, but when i change it to TapiConstants.LINEADDRESSTYPE_IPAddress with H323 provider that is no problem.

    ..........................................

    Dim addr As String = TextBox1.Text

    Dim call_control As ITBasicCallControl

    call_control = oAddress.CreateCall(addr, TapiConstants.LINEADDRESSTYPE_PHONENUMBER, TapiConstants.TAPIMEDIATYPE_DATAMODEM Or TapiConstants.TAPIMEDIATYPE_AUDIO)

    Dim enum_stream As IEnumStream

    Dim pstream_control As ITStreamControl

    pstream_control = CType(call_control, ITStreamControl)

    pstream_control.EnumerateStreams(enum_stream)

    Dim p_stream As ITStream

    Dim a11 As UInt32

    enum_stream.Next(1, p_stream, a11)

    Dim imedia As Int32

    imedia = p_stream.MediaType

    Dim dir1 As TERMINAL_DIRECTION

    dir1 = p_stream.Direction

    Dim termi, termi1 As ITTerminal

    Dim term_support As ITTerminalSupport = CType(oAddress, ITTerminalSupport)

    termi = term_support.GetDefaultStaticTerminal(imedia, dir1)

    p_stream.SelectTerminal(termi)

     

     

    enum_stream.Next(1, p_stream, a11)

    termi1 = term_support.GetDefaultStaticTerminal(imedia, TERMINAL_DIRECTION.TD_CAPTURE)

    p_stream.SelectTerminal(termi1)

    call_control.Connect(False)

    End Sub

     

    ......................................

    can anyone tell me how to make a phone call by using MODEM provider?
  • 2007年12月14日 21:16John T. M 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    'Filename: DialerGlobal.vb
    'Desc: Extends Inheritable Dialer Class with TAPI Methods
    'Date: 10/24/2007
    'Auth: John T. M DATAMODEM  Dialer Project
    '
    '
    'Description:
    ' Class to implement call handeling using DATAMODEM DTMF Device.  
    ' Detects modem as DATAMODEM.
    '
    'Dependancies:
    ' To Do - Implement SIP Session Initiation Protocol for PBX (VoIP) Functionality.
    ' IP telephony signaling protocol used to establish, modify and terminate VOIP telephone calls.
    ' SIP was developed by the IETF and published as RFC 3261 http://tools.ietf.org/html/rfc3261

    '  Implements TAPI 3.x Class Members - TAPI3Lib
    '
    '
    ' References:
    ' ms-help://MS.PSDKSVR2003SP1.1033/tapi/tapi3/tapi_quick_start.htm

    Imports TAPI3Lib
    Public Class Dialer

        Private TAPI3 As TAPI                            ' TAPI 3.x Class
        Public TAPIException As Exception                ' TAPI Errors encountered during execution
        Public TAPIExceptionMessage As String            ' TAPI Exception Message
        Public TAPI3Initalized As Boolean                ' TAPI 3 Initalized state                 
        Private TAPIAddress As ITAddress                 ' Address of Supported Media Type
        Public TAPIAddressName As String                 ' TAPIAddress.AddressName 
        Public TAPIDataModemAddress As ITAddress         ' Address of Data Modem Device 
        Private TAPICollAddresses As ITCollection        ' Collection of Media Type Addresses
        Private TAPIMediaSupport As ITMediaSupport
        Private TAPIAddressCapabilities As ITAddressCapabilities ' Capabilities of Device
        Private TAPICallControl As ITBasicCallControl    ' Call Control Object
        Private TAPICallState As CALL_STATE              ' TAPI Call State for active call
        Private TAPICallStateTimer As System.Timers.Timer       ' TAPICall State Timer
        Public TAPICallInfo As ITCallInfo                ' Information about calls
        Private TAPICalls As ITCollection                ' Maintains Collection of calls
        Private TAPICallTerminal As ITTerminal           ' Call Terminals Object
        Private TAPITerminalSupport As ITTerminalSupport2 ' Terminal Support Object  
        Public CallAddressState As ADDRESS_STATE         ' State of ITAddress object
        Public DATA_MODEM_DEVICE As Boolean              ' Call Device (ITAddress DATAMODEM) available  
        Public MEDIA_SUPPORT_AUDIO As Boolean            ' Call Device Supports Audio
        Public MEDIA_SUPPORT_VIDEO As Boolean            ' Call Device Supports Video 
        Public DTMFH323Support As Boolean                ' Call Device Support DTMF Streams.
        Private WithEvents TAPIWithEvents As TAPI        ' TAPI Event Handler
        Private TAPIRegistrationToken As Integer         ' Handle for event registration
        Private fOwner As Boolean, fMonitor As Boolean   ' Registration options RegisterCallNotifications
        Private lMediaTypes As Integer, lCallbackInstance As Integer
        ' Call event notifications and constants
        Const CallEvents As TAPI_EVENT = _
                                         TAPI_EVENT.TE_CALLMEDIA _
                                         Or TAPI_EVENT.TE_CALLSTATE _
                                         Or TAPI_EVENT.TE_CALLNOTIFICATION _
                                         Or TAPI_EVENT.TE_TONEEVENT _
                                         Or TAPI_EVENT.TE_DIGITEVENT

        Const LINEADDRESSTYPE_PHONENUMBER = 1            ' Standard Phone Number
        Const LINEADDRESSTYPE_IPADDRESS = 16             ' Standard TCP/IP Address IPV4
      
      Public Enum MEDIA_TYPE As Integer                ' TAPIConstants.TAPIMEDIATYPE_ Constants
            AUDIO = 8          ' &H0008
            DATAMODEM = 16     ' &H0010
            G3FAX = 32         ' &H0020
            VIDEO = 32768      ' &H8000
            AUDIOVIDEO = 32776 ' &H8008
       End Enum
     
       Public Enum LINEDIGIT_MODE As Integer            ' TAPIConstants.LINEDIGITMODE_ Constants
            LINEDIGITMODE_PULSE = 1
            LINEDIGITMODE_DTMF = 2
            LINEDIGITMODE_DTMFEND = 4
        End Enum

        ' Initialize TAPI 3.x Class, Must call Shutdown() when finished   
        Public Sub Initialize()
            If Not TAPI3Initalized Then                   ' TAPI Objects Not Initialized  
                TAPI3 = New TAPI                          ' Create the new TAPI Object
                TAPIException = Nothing
                TAPIExceptionMessage = Nothing
                TAPICallTerminal = Nothing
                TAPICallControl = Nothing
                TAPITerminalSupport = Nothing
                TAPICalls = Nothing
                TAPI3.Initialize()                          ' Initalize TAPI Instance
                TAPIRegistrationToken = 0                   ' Null Registration
                DATA_MODEM_DEVICE = False                   ' Selected Call device available.
                MEDIA_SUPPORT_AUDIO = False
                MEDIA_SUPPORT_VIDEO = False
                TAPICollAddresses = TAPI3.Addresses         ' Addresses to Enumerate into collection.
                TAPICallState = CALL_STATE.CS_DISCONNECTED  ' Default Call State is Disconnected.

                ' Select default call Notifications for TAPI
                fOwner = False                              ' Application Owns incomming calls
                fMonitor = True                             ' Application Monitors calls.
                lMediaTypes = MEDIA_TYPE.DATAMODEM          ' Default Media type handled by Dialer.
                lCallbackInstance = 1

                TAPIDataModemAddress = FindMediaType(MEDIA_TYPE.DATAMODEM) ' Select Defualt DTMF Modem Device

                ' Set ITTAPIEventNotification::Event interface
                TAPI3.EventFilter = CallEvents              ' Set TAPI Call Event Notifications
                TAPIWithEvents = TAPI3                      ' Register the outgoing events.

                If Not TAPIDataModemAddress Is Nothing Then ' Data Modem Support ..?
                    SetITAddress(TAPIDataModemAddress)      ' Set Data Modem as active TAPIAddress (ITAddress)
                    TAPI3Initalized = True                  ' TAPI Initalized
                    TAPI3.SetApplicationPriority(Application.ProductName, lMediaTypes, True) ' Application is DATAMODEM GOD
                    TAPICallStateTimer = New System.Timers.Timer ' New Call Timer
                    AddHandler TAPICallStateTimer.Elapsed, AddressOf TAPICallStateTimerElapsed
                    TAPICallStateTimer.Interval = 10000      ' 10 Second Call Interval Timer 
                    TAPICallStateTimer.Stop()
                    ' MakeCall("###-###-####")                   ' Debugging application only
                End If

            End If

        End Sub

        'Find address that supports the desired type Media Type (nMedia).
        'Returns ITAddress (Usable Address) of requested Media Type (TapiConstants) on Success.
        Public Function FindMediaType(ByVal nMedia As MEDIA_TYPE) As ITAddress
            Dim tAddressIndex As Integer                  ' Address Index of Supported Media type
            Dim TAPIoAddress As Object                    ' Usable Address Object 
            TAPIAddress = Nothing                         ' Set to Invalid Address

            For tAddressIndex = 1 To TAPICollAddresses.Count
                TAPIoAddress = TAPICollAddresses.Item(tAddressIndex)
                TAPIMediaSupport = TAPIoAddress

                If TAPIMediaSupport.QueryMediaType(nMedia) Then
                    TAPIAddress = TAPIoAddress
                    lMediaTypes = TAPIMediaSupport.MediaTypes ' Media Types supported by this address.
                    Exit For ' Set Current Address to requested TAPICollAddresses.Item(tAddressIndex)
                End If
            Next

            TAPIoAddress = Nothing                         ' Set to Invalid Address
            TAPIMediaSupport = Nothing                     ' Destroy Object  

            Return TAPIAddress
        End Function

        ' Set device address active for selected call device returned by FindMediaType.
        ' Device is DTMF compatible and can generate and monitor tones.
        Private Function SetITAddress(ByVal xITAddress As ITAddress) As Boolean
            Dim DeviceAvailable = False
            DATA_MODEM_DEVICE = False
            MEDIA_SUPPORT_VIDEO = False
            MEDIA_SUPPORT_AUDIO = False
            lMediaTypes = 0

            CallAddressState = xITAddress.State

            If CallAddressState = ADDRESS_STATE.AS_INSERVICE Then
                TAPIAddress = Nothing                            ' Release Address Object   
                TAPIAddress = xITAddress                       ' Set Active device address.
                TAPIAddressName = TAPIAddress.AddressName    ' Set Active address name for selected device.
                TAPIMediaSupport = TAPIAddress             ' Detect Media Support Type for selected address. 
                TAPIAddressCapabilities = TAPIAddress    ' Set Address Capabilities.
                TAPICalls = TAPIAddress.Calls                 ' Get collection of ITCallInfo pointers for specified address. 

                ' Determine type of media supported by selected device. 
                If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.DATAMODEM) Then DATA_MODEM_DEVICE = True

                If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.AUDIOVIDEO) Then
                    MEDIA_SUPPORT_VIDEO = True
                    MEDIA_SUPPORT_AUDIO = True
                Else
                    If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.AUDIO) Then MEDIA_SUPPORT_AUDIO = True
                    If TAPIMediaSupport.QueryMediaType(MEDIA_TYPE.VIDEO) Then MEDIA_SUPPORT_VIDEO = True
                End If

                ' Set lMediaTypes Supported for this address.
                If DATA_MODEM_DEVICE Then lMediaTypes = MEDIA_TYPE.DATAMODEM
                If Not DATA_MODEM_DEVICE Then lMediaTypes = TAPIMediaSupport.MediaTypes

                ' If device supports incomming calls register.
                If TAPIRegistrationToken Then TAPI3.UnregisterNotifications(TAPIRegistrationToken)

                Try ' Register Call Notification for DATAMMODEM Device.
                    TAPIRegistrationToken = TAPI3.RegisterCallNotifications(xITAddress, fMonitor, _
                     fOwner, lMediaTypes, lCallbackInstance)
                    DeviceAvailable = True                       ' Set Device Available.
                Catch ex As Exception   ' Incomming calls not supported by interface.
                    TAPIException = ex
                    TAPIExceptionMessage = ex.Message
                End Try

            End If

            TAPIMediaSupport = Nothing                      ' Disreguard Objects.
            TAPIAddressCapabilities = Nothing

            Return DeviceAvailable
        End Function

        ' Create a new Call Control Object and associate with xITAddress (use default Modem device)  
        Private Function SetCallControl(ByVal phNumber As String) As Boolean
            Dim nControlState As Boolean = False
            'TAPICallTerminal = Nothing
            TAPICallControl = Nothing
            TAPICallInfo = Nothing

            ' Device available and ITAddress is DTMF enabled.
            If phNumber.Length >= 8 And Not TAPIAddress Is Nothing Then  ' Valid phone number.

                ' Create a new Call Control Object for this call.
                TAPICallControl = TAPIAddress.CreateCall(phNumber, _
                  LINEADDRESSTYPE_PHONENUMBER, lMediaTypes)

                If Not TAPICallControl Is Nothing Then     ' Set Tapi Call Control and Information.

                    TAPICallInfo = TAPICallControl         ' Set Call Information
                    TAPICallState = TAPICallInfo.CallState ' Get Call State information

                    ' Try  ' Is terminal support available does an MSP exist for this address ?
                    ' TAPITerminalSupport = TAPIAddress      ' Terminal Support Object      
                    ' TAPICallTerminal = TAPITerminalSupport.GetDefaultStaticTerminal( _
                    '                   lMediaTypes, TERMINAL_DIRECTION.TD_CAPTURE)

                    ' Catch ex As System.Exception               ' Terminal Support Not available for this device.
                    ' TAPIException = ex
                    ' TAPIExceptionMessage = ex.Message
                    ' End Try

                    If TAPICallState = CALL_STATE.CS_IDLE Then nControlState = True
                End If
            End If

            Return nControlState
        End Function

        ' Place a new Call to PhoneNumber, Returns True on Success
        ' Sets Call Control using default Data Modem device.
        ' If the call is synchronous, this method will not return until
        ' the call is in the connected state or fails.
        Public Function MakeCall(ByVal phNumber As String) As Boolean
            Dim nControlState As Boolean = False

            If Not TAPI3Initalized Then Initialize() ' Initalize TAPI 3
         
            If DATA_MODEM_DEVICE Then                ' Modem Device is ready.
                If SetCallControl(phNumber) Then
                    Try ' Try to place the call syncronusly
                        TAPICallControl.Connect(False)         ' Place call and return asyncronusly.
                        TAPICallState = TAPICallInfo.CallState ' Set Call State information for active connection.
                        nControlState = True ' Call was placed.  

                    Catch ex As Exception  ' Call Failed
                        TAPIException = ex
                        TAPIExceptionMessage = ex.Message
                        Shutdown()         ' Stop TAPI3
                    End Try
                End If
            End If


            Return nControlState
        End Function

        ' Close all TAPI Sessions and Clean up objects 
        Public Sub Shutdown()
            ' Check for valid registration token  
            If TAPI3Initalized Then
                If Not TAPICallInfo Is Nothing Then ' Is there an active call
                    If TAPICallInfo.CallState <> CALL_STATE.CS_DISCONNECTED Then   TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
                    TAPICallState = CALL_STATE.CS_DISCONNECTED
                End If
                If TAPIRegistrationToken Then TAPI3.UnregisterNotifications(TAPIRegistrationToken)
                MEDIA_SUPPORT_AUDIO = False
                MEDIA_SUPPORT_VIDEO = False
                TAPICallInfo = Nothing
                TAPICallTerminal = Nothing
                TAPITerminalSupport = Nothing
                TAPICallControl = Nothing
                TAPIMediaSupport = Nothing
                TAPIWithEvents = Nothing
                TAPI3.Shutdown()
                DATA_MODEM_DEVICE = False
                TAPIDataModemAddress = Nothing
                TAPIAddress = Nothing
                TAPIAddressCapabilities = Nothing
                TAPICollAddresses = Nothing
                TAPICalls = Nothing
                TAPI3Initalized = False
                TAPIException = Nothing
                TAPIExceptionMessage = Nothing
                TAPIRegistrationToken = 0
                TAPI3 = Nothing ' Release TAPI
            End If
        End Sub

        Private Sub TAPIWithEvents_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles TAPIWithEvents.Event
            ' TAPI Event Handler for TapiEvent use MakeCall with TAPICallControl.Connect(False) for asyncronus operation.
            ' If the call is asynchronous, the application will receive information about the call's progress through
            ' the ITCallNotificationEvent outgoing interface.

            Select Case TapiEvent
                Case TAPI_EVENT.TE_CALLSTATE  ' Process Call State Events for active call (TAPICallState = TAPICallInfo.CallState)
                    Dim TAPICallStateEvent As ITCallStateEvent = pEvent
                    TAPICallState = TAPICallStateEvent.State  ' Update Call State for TAPICallInfo.CallState
                    TAPICallInfo = TAPICallStateEvent.Call    ' Update Call Information for this call. 
                    TAPICallStateEvent = Nothing              ' Discontinue object.

                    Select Case TAPICallState                 ' Process Call State for TAPICallInfo
                        Case CALL_STATE.CS_DISCONNECTED       ' Call was Disconnected so release objects.
                            TAPICallStateTimer.Stop()         ' Stop the Call State Timer

                        Case CALL_STATE.CS_INPROGRESS         ' Call is in progress
                            TAPICallStateTimer.Start()        ' Start the Call State Timer    

                        Case CALL_STATE.CS_CONNECTED          ' Call Was completed successfully
                            TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
                          

                    End Select

                Case TAPI_EVENT.TE_CALLNOTIFICATION         ' Process Incomming Call Here
                Case TAPI_EVENT.TE_CALLMEDIA
                Case TAPI_EVENT.TE_TONEEVENT
                Case TAPI_EVENT.TE_DIGITEVENT

            End Select


        End Sub
        ' Handles TAPI Call State timing (Timer to set Max Call Duration) 
        Private Sub TAPICallStateTimerElapsed(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs)
            TAPICallStateTimer.Stop() ' Process Call State for current call

            Select Case TAPICallState ' Process Call State for TAPICallInfo

                Case CALL_STATE.CS_INPROGRESS         ' Call is in progress
                    TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)

                Case CALL_STATE.CS_CONNECTED          ' Call Was completed successfully
                    TAPICallControl.Disconnect(DISCONNECT_CODE.DC_NORMAL)
            End Select
        End Sub
    End Class

    ' Enjoy my code contribution TAPI3 API Rules.. John T. M
  • 2009年3月31日 20:36waters2009 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    It seems to be good solution http://voipsipsdk.com/Download.aspx