I sent USSD command using this code:
SerialPort port = new SerialPort();
port.BaudRate = 921600;
port.PortName = "COM16";
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.ReadTimeout = 3000;
port.WriteTimeout = 3000;
port.DataReceived += port_DataReceived;
port.Open();
port.Write("AT+CUSD=1,\"*140*1#\"" + "\r\n");
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort spL = (SerialPort)sender;
byte[] buf = new byte[spL.BytesToRead];
spL.Read(buf, 0, buf.Length);
foreach (Byte b in buf)
{
message += b.ToString();
}
var result = Encoding.ASCII.GetString(buf);//just return OK
}
Why just retrieve OK in result?
in this case i want to retrieve my balance and i must receive answer like this: "your balance is 100$..." but just retrieve: "AT+CUSD=1,\"*140*1#\"\r\n\OK\r\n" but when i send this command by modem's own application retrieve correct response from operator this means my sending command is OK but that application receive all answer but i receive half.