Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel USSD need response

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#?

like image 686
Omani-Ghost Avatar asked Nov 13 '22 08:11

Omani-Ghost


1 Answers

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();
        }
    }
like image 77
Nsubuga Kasozi Avatar answered Nov 16 '22 03:11

Nsubuga Kasozi