Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > .NET

Lost Password?

Thread Tools Display Modes
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 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(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);

var asPDUencoded = Calc.IntToHex(TextDataConverter.SeptetsToOctetsInt (data));

asPDUencoded = "\"" + asPDUencoded + "\"";

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))
protocol.Receive(out gottenString);
} 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 { }
return "";

Kindly help to import the working code from GSMComm Library to the one I am using with reference to SMSApplication project.
Reply With Quote

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 04:51 AM.

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