I have Nokia device connected to the PC
This is the code that I use to send USSD command:
Port.Write("AT+CUSD=0,\"*147*1*#\",15\r\n");
It works fine, BUT it displays an option to choose the service. What I want is to stop it OR Exit (Quit) from that message. I can press cancel option from the phone, but how I can do it using C#?
I am posting this because this is one of the top results regarding terminating USSD sessions using AT commands and also because the answers are vague. This is the c# code i used in the end(I was sending the commands to a gsm modem). Hope it helps someone else
SerialPort SendingPort=null;
public string TerminateUssdSession()
{
InitializePort();
//// generate terminate command for modem
string cmd = "";
cmd = "AT+CUSD=2\r";
// send cmd to modem
OpenPort();
SendingPort.Write(cmd);
Thread.Sleep(500);
string response = SendingPort.ReadExisting();
return response;
}
private void InitializePort()
{
if (SendingPort == null)
{
SendingPort = new SerialPort();
SendingPort.PortName = PortName;//put port name e.g COM5
SendingPort.BaudRate = 112500;
SendingPort.Parity = Parity.None;
SendingPort.DataBits = 8;
SendingPort.StopBits = StopBits.One;
SendingPort.Handshake = Handshake.None;
SendingPort.ReadTimeout = 500;
}
}
private void OpenPort()
{
if (!SendingPort.IsOpen)
{
SendingPort.Open();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With