I publish this because it is one of the best results regarding terminating USSD sessions using AT commands, and also because the answers are vague. This is the C # code that I used at the end (I sent commands to the gsm modem). Hope this helps someone else.
SerialPort SendingPort=null;
public string TerminateUssdSession()
{
InitializePort();
string cmd = "";
cmd = "AT+CUSD=2\r";
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;
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();
}
}
source
share