I'm trying to run ussd code via gsm modem to get sim balance. I'm using GsmComm library, ASP.NET Web Form, C#. Below is my code :
public string SendUssdRequest2(string request)
{
comm = ConnectAndGetComm();
string data = TextDataConverter.StringTo7Bit(request);
string msg = "";
var asPDUencoded = Calc.IntToHex(TextDataConverter.SeptetsToOctetsInt(data));
try
{
IProtocol protocol = comm.GetProtocol();
string gottenString = protocol.ExecAndReceiveMultiple("AT+CUSD=1," + asPDUencoded + ",15");
var re = new Regex("\".*?\"");
int i = 0;
if (!re.IsMatch(gottenString))
{
do
{
protocol.Receive(out gottenString);
++i;
} while (!(i >= 5
|| re.IsMatch(gottenString)
|| gottenString.Contains("\r\nOK")
|| gottenString.Contains("\r\nERROR")
|| gottenString.Contains("\r\nDONE")));
}
string m = re.Match(gottenString).Value.Trim('"');
return PduParts.Decode7BitText(Calc.HexToInt(m));
}
catch(Exception e)
{
msg = e.Message;
}
finally
{
comm.ReleaseProtocol();
}
return msg;
}
I debug and found Modem is connected. On "ExecAndReceiveMultiple" I'm Getting the error - No data received from phone after waiting for 29999 / 30030 ms. Is the code alright ? What could be the problem ? Any other suggestion like other library or code to get sim balance would be great help. Thank You.
DONE
is not a valid Final result code and should not be checked for. There exists more final result codes than just OK and ERROR, so you must check for all of them. Also you should change the serial input handling to do proper framing. – Dyaus