Public Sub Connect(ByVal Number As String)
Dim Index, RegCookie, MediaTypes, T As Integer
Dim Found As Boolean
Dim hcomm As Microsoft.Win32.SafeHandles.SafeFileHandle
Dim Mediasupport As ITMediaSupport
If IsNothing(_myAddress) And _useDevice = "" Then Throw New _
ApplicationException("Device wurde noch nicht zugewiesen!")
If IsNothing(_myAddress) And _useDevice <> "" Then
For Index = 1 To _myAddresses.Count
Dim Def As ITAddress
Def = CType(_myAddresses.Item(Index), ITAddress)
If Def.AddressName = _useDevice Then Found = True : _myAddress _
= Def : Exit For
Next
End If
'Eventhandler aktivieren
Mediasupport = CType(_myAddress, ITMediaSupport)
MediaTypes = Mediasupport.MediaTypes
Mediasupport = Nothing
RegCookie = _myTapi.RegisterCallNotifications(_myAddress, True, False, _
MediaTypes, 1)
_myTapi.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or _
TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
'Verbindung herstellen
_myCall = _myAddress.CreateCall(Number, _
TapiConstants.LINEADDRESSTYPE_PHONENUMBER, _
TapiConstants.TAPIMEDIATYPE_DATAMODEM)
_myCall.Connect(True)
For t = 0 To 2000 : Application.DoEvents() : Next
If _ConnState = False Then Throw New ApplicationException("Verbindung" & _
"konnte nicht hergestellt werden!")
'Verbindungshandle an den Filestream binden
hcomm = New Microsoft.Win32.SafeHandles.SafeFileHandle( _
Marshal.ReadIntPtr(CType(_myCall, _
ITLegacyCallMediaControl2).GetIDAsVariant("comm/datamodem"), 0), True)
fs = New System.IO.FileStream(hcomm, IO.FileAccess.ReadWrite, 256, True)
End Sub
Public Function Read() As String
Dim inStream(256) As Byte, ClearText As String
Dim ascBuffer As New System.Text.ASCIIEncoding
If _ConnState = False Then Throw New ApplicationException("Device hat" & _
"keine Verbindung!")
fs.Read(inStream, 0, inStream.Length - 1)
ClearText = ascBuffer.GetString(inStream).Replace(Chr(0), "")
Debug.WriteLine("Reading :" & ClearText)
Return ClearText
End Function
Public Sub Write(ByVal Text As String)
Dim ascBuffer As New System.Text.ASCIIEncoding
Dim outStream() As Byte = ascBuffer.GetBytes(Text)
If _ConnState = False Then Throw New ApplicationException("Device hat" & _
"keine Verbindung!")
Debug.WriteLine("Writing: " & Text)
fs.Write(outStream, 0, outStream.Length - 1)
fs.Flush()
End Sub
Private Sub _myTapi_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal _
pEvent As Object) Handles _myTapi.Event
If TapiEvent = TAPI_EVENT.TE_CALLSTATE Then
CallStateObject = CType(pEvent, ITCallStateEvent)
CallStateEvent()
End If
End Sub
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
_ConnState = True
Case CALL_STATE.CS_QUEUED
Case CALL_STATE.CS_HOLD
Case CALL_STATE.CS_DISCONNECTED
_ConnState = False
End Select
End Sub
End Class VB RULEZ !  |