RSS Feed for This PostCurrent Article

Dial, Answer, Reject Call using .NET SMS Library


Download Source Code

To listen to an incoming call, CLIP must be turned on in your phone. The AT command to turn on CLIP is “AT+CLIP” and the value should be set to 1.
clip.jpg


As you can see, the possible values for +CLIP are either 0 or 1. By setting the value to 1, CLIP will be turned on. Value of 0 will turn off CLIP in your phone. Whenever there is an incoming call, the “RING” word will be received, and the phone number will follow, as you can see in the above picture.

In the SMS library, by setting IncomingCallIndication to true the NewIncomingCall event will be raised whenever there is a new call coming. You can then either answer or hang up the call.

The AT command to dial a call is “ATD” and to hang up the call is “ATH” or “AT+CHUP”, depending on your handset.

phonecall.jpg

Imports ATSMS

Public Class MainForm

Private WithEvents oGsmModem As New GSMModem

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
End Sub

Private Sub btnPhone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

If cboComPort.Text = String.Empty Then
MsgBox(“COM Port must be selected”, MsgBoxStyle.Information)
Return
End If

oGsmModem.Port = cboComPort.Text

If cboBaudRate.Text <> String.Empty Then
oGsmModem.BaudRate = Convert.ToInt32(cboBaudRate.Text)
End If

If cboDataBit.Text <> String.Empty Then
oGsmModem.DataBits = Convert.ToInt32(cboDataBit.Text)
End If

If cboStopBit.Text <> String.Empty Then
Select Case cboStopBit.Text
Case “1”
oGsmModem.StopBits = Common.EnumStopBits.One
Case “1.5”
oGsmModem.StopBits = Common.EnumStopBits.OnePointFive
Case “2”
oGsmModem.StopBits = Common.EnumStopBits.Two
End Select
End If

If cboFlowControl.Text <> String.Empty Then
Select Case cboFlowControl.Text
Case “None”
oGsmModem.FlowControl = Common.EnumFlowControl.None
Case “Hardware”
oGsmModem.FlowControl = Common.EnumFlowControl.RTS_CTS
Case “Xon/Xoff”
oGsmModem.FlowControl = Common.EnumFlowControl.Xon_Xoff
End Select
End If

Try
oGsmModem.Connect()
oGsmModem.IncomingCallIndication = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Return
End Try

btnDial.Enabled = True
btnAnswer.Enabled = True
btnHangUp.Enabled = True
btnHangUpCall.Enabled = True
btnDisconnect.Enabled = True

MsgBox(“Connected to phone successfully !”, MsgBoxStyle.Information)

End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
oGsmModem.Disconnect()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try

btnDial.Enabled = False
btnDisconnect.Enabled = False
btnAnswer.Enabled = False
btnHangUp.Enabled = False
btnHangUpCall.Enabled = False

btnConnect.Enabled = True

End Sub

Private Sub oGsmModem_NewIncomingCall(ByVal e As ATSMS.NewIncomingCallEventArgs) Handles oGsmModem.NewIncomingCall
txtIncomingCall.Text += “Incoming call from ” & e.CallerID & ControlChars.CrLf
End Sub

Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnswer.Click
Try
oGsmModem.Answer()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub

Private Sub btnHangUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHangUp.Click
Try
oGsmModem.HangUp()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub

Private Sub btnDial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDial.Click
If txtPhoneNumber.Text.Trim = String.Empty Then
MsgBox(“Phone number must not be empty”, MsgBoxStyle.Critical)
Return
End If

Try
oGsmModem.Dial(txtPhoneNumber.Text.Trim)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub

Private Sub btnHangUpCall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHangUpCall.Click
Try
oGsmModem.HangUp()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Class


Trackback URL


RSS Feed for This Post4 Comment(s)

  1. ADAM | Dec 9, 2007 | Reply

    how use ussd ?? i m newbe……

  2. Ramy Kassab | Nov 30, 2008 | Reply

    I tried this code, but it doesn’t work probably and this error always raise for me when incoming calls:

    “Index was outside the bounds of the array.”

    Really It bugs me alot

    Can you help me please.. thanks in advance.

  3. Deepak | Apr 22, 2009 | Reply

    It is working fine when connected to GSM phone. But, how to interact with mic and speaker.

  4. sandeep | Oct 23, 2009 | Reply

    i have connect nokia 3110c mobile verthing working fine expect hangup can any tell me how correct this error

Sorry, comments for this entry are closed at this time.