Hi I am developing a project which sends and recieve SMS using AT commands with reference to SMSApplication project. Now I want to send USSD command .But while using the below code to send USSD command, I am getting 'OK' in first message followed by error "Could not find any recognizable digits" .
The code to send USSD command is as below:
string recievedData = objclsSMS.ExecCommand(this.port, "AT", 300, "No phone connected");
String gottenString = objclsSMS.ExecCommand(this.port, "AT+CUSD=1,\"AA1C2C3602\",15", 300, "Failed to set message format.");
string strCommand = "AT+CMGL=\"ALL\"";
objShortMessageCollection = objclsSMS.ReadSMS(this.port, strCommand);
foreach (ShortMessage msg in objShortMessageCollection)
{
gottenString = msg.Message;
}
MessageBox.Show(gottenString);
MessageBox.Show(PduParts.Decode7BitText(Calc.HexToInt(gottenString)));
But if I use GSMComm Library, I can successfully receive the response for USSD command; the code is as below.
public string SendUssdRequest(string port,string request)
{
GsmCommMain comm = new GsmCommMain(port, 9600, 300);
comm.Open();
var asPDUencoded = Calc.IntToHex(TextDataConverter.SeptetsToOctetsInt(data));
asPDUencoded = "\"" + asPDUencoded + "\"";
try
{
IProtocol protocol = comm.GetProtocol(); ;// _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"))); //additional tests "just in case"
}
string m = re.Match(gottenString).Value.Trim('"');
return PduParts.Decode7BitText(Calc.HexToInt(m));
}
catch { }
finally
{
comm.ReleaseProtocol();
}
return "";
}
Kindly help to import the working code from GSMComm Library to the one I am using with reference to SMSApplication project.