API to PocketPC Windows Mobile 6

142 Views Asked by At

I have a Ciperlab scanner running Windows Mobile 6 and developing with compact framework 3.5. I need to make a phone call and when the call is complete return to the program where the operator completes the transaction. I have used the Function PhoneMakeCall in the phone.dll but the resulting panel requires a number of buttons to be pressed. The perfect solution would be to hide the entire phone panel. Solutions from anyone who has done this before would be very welcome. I know the technology is old, but I am stuck with it as it comes with the scanner.

2

There are 2 best solutions below

0
josef On

To make a phone call, the Telephony API (TAPI) has to be used. This is an API provided by MS. Making a phone call requires many code lines and os it may be easier to use a wrapper like the OpenNetCF Telephony Compact Framwork Classes. Here is an example. There are other examples on using TAPI.

There is only minor information about TAPI use availabe by MS.

Some device vendors offer special Phone SDKs to support there devices in accessing the phone by code. For example the Intermec WWAN Toolkit.

I would first go with openNetCF.

0
John Agar On

Thanks for info josef. It was great

The first link takes you to :

http://programmaremobile.blogspot.co.za/2009/10/how-to-make-call-with-opennetcf-tapi.html

This has links to OpenNetCf but here the Wrapper (OpenNETCF.Telephony.dll) has been removed. There is another link to http://tapi.codeplex.com/ which has the source code for the wrapper and some samples. The OpenNETCF.Telephony.dll is included in the zip file for the examples but this version requires a licence and also does not have all the methods used by the samples. I downloaded the zipped source code and compiled it. It has some problems but works well.

I have one outstanding problem. To save battery I turn off the phone. It must be turned on 30 seconds before making a call otherwise the system drops into the phone raw panels.There is no status event informing that the GSM network has stabilised and a call can be make. At the moment I am using a timer but this not a clean solution.

I have attached my final code for reference:

In Declarations
Imports OpenNETCF.Telephony
Friend WithEvents tapi As Telephony
Friend WithEvents CellLine As Line
Friend WithEvents CellCall As [Call]
Public CellPhoneCoverage As Boolean = False
Shared CellCallState As Integer = 1

Private Function CreateCellLine() As Boolean
Dim i As Integer
Dim dc As DeviceCapabilities
'Open Tapi
Try
  tapi = New Telephony
  tapi.Initialize()
  If tapi.NumberOfDevices > 0 Then
     Try
       For i = 0 To tapi.NumberOfDevices - 1
         tapi.GetDeviceCapabilities(i, dc)
         If (dc.MediaModes And MediaMode.InteractiveVoice) = _ 
                MediaMode.InteractiveVoice Then
            'found the cellular line
            CellLine = tapi.CreateLine(i, dc.MediaModes, _ 
                 CallPrivilege.None)                                     
            'To save battery turn off phone. 
            'Note that it must be turned on for 30 seconds 
            ' before making a call otherwise we drop into the 
            ' phone raw panels
            NativeMethods.lineSetEquipmentState(CellLine.hLine, _ 
                      EquipmentState.Minimum)
            CreateCellLine = True

            'if battery is not an issue then check phone state
            'Dim es As EquipmentState
            'Dim rs As RadioState
            'NativeMethods.lineGetEquipmentState(CellLine.hLine, es, rs)
            'CreateCellLine = (es = EquipmentState.Full And rs = RadioState.On)
            Exit Function
         End If
       Next
       MsgBox("cell line not found")
       CreateCellLine = False
     Catch ex As Exception
         CreateCellLine = False
          MsgBox("CreateCellLine(1):" & ex.Message)
     End Try
  End If
Catch ex As Exception
  CreateCellLine = False
  MsgBox("CreateCellLine(2):" & ex.Message)
End Try
End Function

Handle events:
Private Sub CellCall_CallState(ByVal [call] As OpenNETCF.Telephony.Call, _
            ByVal state As OpenNETCF.Telephony.CallState) _ 
            Handles CellCall.CallState
 'Note that this state change is not called for disconencted and connected events
  MsgBox("Call state is " & state.ToString())
End Sub

Private Sub CellCall_Connected(ByVal [call] As OpenNETCF.Telephony.Call, _
            ByVal state As OpenNETCF.Telephony.CallState) _ 
            Handles CellCall.Connected
  MsgBox("Connected")
End Sub

Private Sub CellCall_Disconnected(ByVal [call] As OpenNETCF.Telephony.Call, _
            ByVal state As OpenNETCF.Telephony.CallState) _ 
            ByVal disconnectMode As OpenNETCF.Telephony.DisconnectMode) _
            Handles CellCall.Disconnected
  MsgBox("Disconnected")
End Sub

In the form_load procedure:
   'Open Tapi and check we have cell phone coverage
   CellPhoneCoverage = CreateCellLine()

To make a call:
   'If the phone if off then it must be turned on for 30 seconds 
   ' before making a call otherwise we drop into the phone raw panels

   Dim rc As Integer
   Dim es As EquipmentState
   Dim rs As RadioState
   NativeMethods.lineGetEquipmentState(CellLine.hLine, es, rs)
   If Not (es = EquipmentState.Full) Then
     rc = NativeMethods.lineSetEquipmentState(CellLine.hLine, EquipmentState.Full)
   Else
     If (es = EquipmentState.Full And rs = RadioState.On) Then
        CellCall = CellLine.MakeCall("0812500163", 27, False)
     End If
   End If

To end a call:
   CellCall.Hangup()
   If Not ((CellCallState = OpenNETCF.Telephony.CallState.Idle) Or _ 
           (CellCallState = OpenNETCF.Telephony.CallState.Disconnected)) Then
     'must do check otherwise get a null exception
     Try
       CellCall.Hangup()
       Catch ex As Exception
         MsgBox("CellCall.Hangup: " & ex.Message)
     End Try
   End If

   'if battery is not an issue then leave phone on
   ' remember when making a call allow time for the network to connect
   ' otherwise we drop into the phone raw panels
   NativeMethods.lineSetEquipmentState(CellLine.hLine, _
                 EquipmentState.Minimum)