Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > .NET

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2015, 06:17 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 299
Default USSD using AT command in c# dotnet

Dear Expert,

Hi I am developing a project which sends and recieve SMS using AT commands with reference to SMSApplication project available in codeproject.com. 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.HexTo Int(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.
__________________
Rmt
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:23 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.