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.