elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Uso de Tapi
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Uso de Tapi  (Leído 1,918 veces)
piwi


Desconectado Desconectado

Mensajes: 439



Ver Perfil
Uso de Tapi
« en: 12 Septiembre 2011, 16:11 pm »

Hola a todos.

Estoy con la centralita Avaya y necesito capturar las llamadas entrantes.

Lo primero me he declarado unas variables a nivel de clase:
Código
  1.    Public CallerID As String
  2.    Private Const MediaAudio As Integer = 8
  3.    Private Const MediaModem As Integer = 16
  4.    Private Const MediaFax As Integer = 32
  5.    Private Const MediaVideo As Integer = 32768
  6.    Private WithEvents oTAPI As TAPI3Lib.TAPI '
  7.    Private oAddress As ITAddress
  8.    Private RegCookie As Integer
  9.  

Lo primero es realizar la conexión con la centralita:
Código
  1. Try
  2.  
  3.            Dim m_TAPI As New TAPIClass
  4.  
  5.            Dim MediaTypes As Integer
  6.            m_TAPI.Initialize()
  7.            oTAPI = m_TAPI
  8.  
  9.            m_TAPI = Nothing
  10.  
  11.            Dim AddressCollection As ITCollection = oTAPI.Addresses()
  12.  
  13.            For Each Address As ITAddress In AddressCollection
  14.  
  15.                If Address.State = ADDRESS_STATE.AS_INSERVICE Then
  16.  
  17.                    Dim MediaSupport As ITMediaSupport = Address
  18.  
  19.                    MediaTypes = MediaSupport.MediaTypes
  20.  
  21.                    MediaSupport = Nothing
  22.  
  23.                    If MediaTypes And MediaModem = MediaModem Then
  24.  
  25.                        If MediaTypes And MediaAudio = MediaAudio Then
  26.  
  27.                            oAddress = Address
  28.  
  29.                            MsgBox(oAddress.AddressName)
  30.  
  31.                            Exit For
  32.                        End If
  33.                    End If
  34.  
  35.                End If
  36.  
  37.            Next Address
  38.  
  39.            If Not oAddress Is Nothing Then
  40.  
  41.                RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
  42.                oTAPI.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
  43.            Else
  44.                MsgBox("No se encontró ninguna extensión.")
  45.            End If
  46.  
  47.        Catch ex As Exception
  48.            MsgBox("Error TAPI:" & vbCrLf & ex.Message, MsgBoxStyle.Critical)
  49.        End Try
  50.  


El siguiente código es para capturar los eventos.
Código
  1.  
  2. Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event
  3.  
  4.        Dim thAsyncCall As System.Threading.Thread
  5.  
  6.        Select Case TapiEvent
  7.            Case TAPI_EVENT.TE_CALLNOTIFICATION
  8.                thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent)
  9.                CallNotificationObject = CType(pEvent, ITCallNotificationEvent)
  10.                thAsyncCall.Start()
  11.            Case TAPI_EVENT.TE_CALLSTATE
  12.                thAsyncCall = New Threading.Thread(AddressOf CallStateEvent)
  13.                CallStateObject = CType(pEvent, ITCallStateEvent)
  14.                thAsyncCall.Start()
  15.            Case TAPI_EVENT.TE_CALLINFOCHANGE
  16.                thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent)
  17.                CallInfoObject = CType(pEvent, ITCallInfoChangeEvent)
  18.                thAsyncCall.Start()
  19.        End Select
  20.  
  21.    End Sub
  22.  
  23. Private CallNotificationObject As ITCallNotificationEvent
  24.  
  25.    Private Sub CallNotificationEvent()
  26.        Select Case CallNotificationObject.Event
  27.            Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
  28.            Case CALL_NOTIFICATION_EVENT.CNE_OWNER
  29.        End Select
  30.    End Sub
  31.  
  32.    Private CallStateObject As ITCallStateEvent
  33.  
  34.    Private Sub CallStateEvent()
  35.        Select Case CallStateObject.State
  36.            Case CALL_STATE.CS_IDLE
  37.            Case CALL_STATE.CS_INPROGRESS
  38.            Case CALL_STATE.CS_OFFERING
  39.            Case CALL_STATE.CS_CONNECTED
  40.  
  41.               Form2.ShowDialog()
  42.  
  43.            Case CALL_STATE.CS_QUEUED
  44.            Case CALL_STATE.CS_HOLD
  45.            Case CALL_STATE.CS_DISCONNECTED
  46.  
  47.  
  48.        End Select
  49.    End Sub
  50.  
  51.    Private CallInfoObject As ITCallInfoChangeEvent
  52.  
  53.    Private Sub CallInfoEvent()
  54.  
  55.        CallerID = CallInfoObject.Call.CallInfoString(CALLINFO_STRING.CIS_CALLERIDNUMBER) 'CIS_CALLERIDNAME)
  56.  
  57.    End Sub
  58.  

Tal como está el codigo me funciona abriendome el Form2 (eso si, tengo que ponerlo como Showdialog porque con el Show no lo veo y en callinfoevent tengo el numero entrante.

Mi problema está que solamente está funcionando con multihilo y al modificar el código de la siguiente manera  no me funciona.

Código
  1. Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event
  2.  
  3.        Select Case TapiEvent
  4.            Case TAPI_EVENT.TE_CALLNOTIFICATION
  5.                CallNotificationEvent()
  6.            Case TAPI_EVENT.TE_CALLSTATE
  7.                CallNotificationEvent()
  8.            Case TAPI_EVENT.TE_CALLINFOCHANGE
  9.                CallNotificationEvent()
  10.        End Select
  11.  
  12.    End Sub
  13.  

No debería ser lo mismo?

A ver si me se explicar. Tengo un formlario Form1, en él tengo declarado un array de forms publico. Con un botón voy abriendo las instancias del Form2 y los abiertos los voy guardando en el array. Dentro del Form2 tengo un botón para abrir la instancia del Form3, pasandole en el contructor el número del Form2 que ha abierto el form3 para que pueda hacer referncia a él. Desde el form3 cuando le cierro le paso los parametros al form2

form1.arraydeforms(id).variable = <valor>

donde el id es el número del form (Form2) de array que lo ha abierto (Form3)

Me imagino que es por el multihilo que cuando desde el Form3 hago la referencia al Form2, me dice que el array no lo tengo creado porque cuando hago lo mismo pero con un botón me funciona bien.

Perdonad pero creo que no se explicarme mejor.


« Última modificación: 12 Septiembre 2011, 16:14 pm por piwi » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines