Anyone of you know what is the type of service to check the credit balance for the modem using *[number]#
?
I am trying to check balance by using this code.
public AutoResetEvent receiveNow;
public string CheckBalance(SerialPort port)
{
string balance = string.Empty;
try
{
#region Execute Command
//string recievedData = SendATCommand(port, "AT", 300, "No phone connected at ");
string recievedData = SendATCommand(port, "AT", 300, "No phone connected at ");
recievedData = SendATCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
String command = @"AT+CUSD=1,""*121#"",15";
recievedData = SendATCommand(port, command, 5000, "Failed to count SMS message");
balance = recievedData;
#endregion
}
catch (Exception ex)
{
ErrorLog(ex.Message);
}
return balance;
}
public string SendATCommand(SerialPort port, string command, int responseTimeout, string errorMessage)
{
string input = string.Empty;
try
{
port.DiscardOutBuffer();
port.DiscardInBuffer();
receiveNow.Reset();
port.Write(command + "\r");
input = ReadResponse(port, responseTimeout);
if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
ErrorLog("No success message was received.");
}
catch (Exception ex)
{
ErrorLog(ex.Message);
}
return input;
}
public string ReadResponse(SerialPort port, int timeout)
{
string serialPortData = string.Empty;
try
{
do
{
if (receiveNow.WaitOne(timeout, false))
{
string data = port.ReadExisting();
serialPortData += data;
}
else
{
if (serialPortData.Length > 0)
ErrorLog("Response received is incomplete.");
else
ErrorLog("No data received from phone.");
}
}
while (!serialPortData.EndsWith("\r\nOK\r\n") && !serialPortData.EndsWith("\r\n> ") && !serialPortData.EndsWith("\r\nERROR\r\n"));
}
catch (Exception ex)
{
ErrorLog(ex.Message);
}
return serialPortData;
}
first two exec command returns ok,but the third exec command returns error.
USSD code is working from providers mobile partner application,
what sets of AT command do i need to send to handle ussd application properly?