.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

USSD using AT COMMAND

Posted By: Rashmita     Posted Date: April 06, 2015    Points:5   Category :C#
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.

Responses

No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend