Dial, Answer, Reject Call using .NET SMS Library
By admin on Sep 17, 2007 in .NET, open source, Programming
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.
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.
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 SubPrivate 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 IfoGsmModem.Port = cboComPort.Text
If cboBaudRate.Text <> String.Empty Then
oGsmModem.BaudRate = Convert.ToInt32(cboBaudRate.Text)
End IfIf cboDataBit.Text <> String.Empty Then
oGsmModem.DataBits = Convert.ToInt32(cboDataBit.Text)
End IfIf 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 IfIf 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 IfTry
oGsmModem.Connect()
oGsmModem.IncomingCallIndication = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Return
End TrybtnDial.Enabled = True
btnAnswer.Enabled = True
btnHangUp.Enabled = True
btnHangUpCall.Enabled = True
btnDisconnect.Enabled = TrueMsgBox(“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 TrybtnDial.Enabled = False
btnDisconnect.Enabled = False
btnAnswer.Enabled = False
btnHangUp.Enabled = False
btnHangUpCall.Enabled = FalsebtnConnect.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 SubPrivate 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 SubPrivate 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 SubPrivate 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 IfTry
oGsmModem.Dial(txtPhoneNumber.Text.Trim)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End SubPrivate 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
ADAM | Dec 9, 2007 | Reply
how use ussd ?? i m newbe……
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.
Deepak | Apr 22, 2009 | Reply
It is working fine when connected to GSM phone. But, how to interact with mic and speaker.
sandeep | Oct 23, 2009 | Reply
i have connect nokia 3110c mobile verthing working fine expect hangup can any tell me how correct this error