elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 08:40  


Tema destacado: Grupo de Facebook de elhacker.net

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (Moderador: [D4N93R])
| | | |-+  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 300 veces)
piwi


Desconectado Desconectado

Mensajes: 439



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

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
    Public CallerID As String
   Private Const MediaAudio As Integer = 8
   Private Const MediaModem As Integer = 16
   Private Const MediaFax As Integer = 32
   Private Const MediaVideo As Integer = 32768
   Private WithEvents oTAPI As TAPI3Lib.TAPI '
   Private oAddress As ITAddress
   Private RegCookie As Integer
 

Lo primero es realizar la conexión con la centralita:
Código
Try
 
           Dim m_TAPI As New TAPIClass
 
           Dim MediaTypes As Integer
           m_TAPI.Initialize()
           oTAPI = m_TAPI
 
           m_TAPI = Nothing
 
           Dim AddressCollection As ITCollection = oTAPI.Addresses()
 
           For Each Address As ITAddress In AddressCollection
 
               If Address.State = ADDRESS_STATE.AS_INSERVICE Then
 
                   Dim MediaSupport As ITMediaSupport = Address
 
                   MediaTypes = MediaSupport.MediaTypes
 
                   MediaSupport = Nothing
 
                   If MediaTypes And MediaModem = MediaModem Then
 
                       If MediaTypes And MediaAudio = MediaAudio Then
 
                           oAddress = Address
 
                           MsgBox(oAddress.AddressName)
 
                           Exit For
                       End If
                   End If
 
               End If
 
           Next Address
 
           If Not oAddress Is Nothing Then
 
               RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
               oTAPI.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
           Else
               MsgBox("No se encontró ninguna extensión.")
           End If
 
       Catch ex As Exception
           MsgBox("Error TAPI:" & vbCrLf & ex.Message, MsgBoxStyle.Critical)
       End Try
 


El siguiente código es para capturar los eventos.
Código
 
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event
 
       Dim thAsyncCall As System.Threading.Thread
 
       Select Case TapiEvent
           Case TAPI_EVENT.TE_CALLNOTIFICATION
               thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent)
               CallNotificationObject = CType(pEvent, ITCallNotificationEvent)
               thAsyncCall.Start()
           Case TAPI_EVENT.TE_CALLSTATE
               thAsyncCall = New Threading.Thread(AddressOf CallStateEvent)
               CallStateObject = CType(pEvent, ITCallStateEvent)
               thAsyncCall.Start()
           Case TAPI_EVENT.TE_CALLINFOCHANGE
               thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent)
               CallInfoObject = CType(pEvent, ITCallInfoChangeEvent)
               thAsyncCall.Start()
       End Select
 
   End Sub
 
Private CallNotificationObject As ITCallNotificationEvent
 
   Private Sub CallNotificationEvent()
       Select Case CallNotificationObject.Event
           Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
           Case CALL_NOTIFICATION_EVENT.CNE_OWNER
       End Select
   End Sub
 
   Private CallStateObject As ITCallStateEvent
 
   Private Sub CallStateEvent()
       Select Case CallStateObject.State
           Case CALL_STATE.CS_IDLE
           Case CALL_STATE.CS_INPROGRESS
           Case CALL_STATE.CS_OFFERING
           Case CALL_STATE.CS_CONNECTED
 
              Form2.ShowDialog()
 
           Case CALL_STATE.CS_QUEUED
           Case CALL_STATE.CS_HOLD
           Case CALL_STATE.CS_DISCONNECTED
 
 
       End Select
   End Sub
 
   Private CallInfoObject As ITCallInfoChangeEvent
 
   Private Sub CallInfoEvent()
 
       CallerID = CallInfoObject.Call.CallInfoString(CALLINFO_STRING.CIS_CALLERIDNUMBER) 'CIS_CALLERIDNAME)
 
   End Sub
 

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
 Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event
 
       Select Case TapiEvent
           Case TAPI_EVENT.TE_CALLNOTIFICATION
               CallNotificationEvent()
           Case TAPI_EVENT.TE_CALLSTATE
               CallNotificationEvent()
           Case TAPI_EVENT.TE_CALLINFOCHANGE
               CallNotificationEvent()
       End Select
 
   End Sub
 

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 por piwi » En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines