Click here to Skip to main content
15,850,751 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I sent USSD command using this code:

C#
SerialPort port = new SerialPort();

port.BaudRate = 921600;
port.PortName = "COM16";
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.ReadTimeout = 3000;
port.WriteTimeout = 3000;
port.DataReceived += port_DataReceived;

port.Open();

port.Write("AT+CUSD=1,\"*140*1#\"" + "\r\n");

void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
        SerialPort spL = (SerialPort)sender;
        byte[] buf = new byte[spL.BytesToRead];
        spL.Read(buf, 0, buf.Length);

        foreach (Byte b in buf)
        {
            message += b.ToString();
        }

        var result = Encoding.ASCII.GetString(buf);//just return OK
    }

Why just retrieve OK in result?

in this case i want to retrieve my balance and i must receive answer like this: "your balance is 100$..." but just retrieve: "AT+CUSD=1,\"*140*1#\"\r\n\OK\r\n" but when i send this command by modem's own application retrieve correct response from operator this means my sending command is OK but that application receive all answer but i receive half.
Posted
Updated 30-Aug-13 2:12am
v3
Comments
Nelek 30-Aug-13 5:14am    
Not really clear, would you mind to use "improve question" to explain your problem better?
davidstein 30-Aug-13 7:01am    
in this case i want to retrieve my balance and i must receive answer like this: "your balance is 100$..." but just retrieve:
"AT+CUSD=1,\"*140*1#\"\r\n\OK\r\n" but when i send this command by modem's own application retrieve correct response from operator this means my sending command is OK but that application receive all answer but i receive half.
[no name] 30-Aug-13 5:29am    
Probably because the command was successful.
Andy411 30-Aug-13 6:19am    
What kind of answer do you excpect?
davidstein 30-Aug-13 7:06am    
"your balance is 100$..."

Hello David,

Add ,15 at the end

eg: "AT+CUSD=1,\"*140*1#\"" + ",15\r\n"

Hope u find this answer helpful

Regards
 
Share this answer
 
Comments
Hasan Habib Surzo 28-May-15 6:24am    
I try this but not get any result. could you please share some real working example. i try many developers c# and vb.net code using google but none of them work properly.
mdrizwan_1 13-Jul-15 7:43am    
Hello Hasan,

Can you please provide sample code or brief requirements, so that i can help if i can.

Regards
this might help you
vb USSD code sending
or
u can copy URL http://www.experts-exchange.com/questions/23017550/AT-COMMAND-GSM-Modem-using-USSD-Vbscript.html
<br />
vance<br />
Sub USSD()<br />
Set MSComm1=CreateObject("MSCOMMLib.MSComm")<br />
MSComm1.Settings = "9600,n<br />
MSComm1.InputLen = 0<br />
MSComm1.RThreshold = 5<br />
MSComm1.CommPort = 4<br />
MSComm1.InBufferCount = 0<br />
MSComm1.PortOpen = True<br />
MSComm1.Output="AT+CMGF=1"<br />
WScript.Sleep(1000) TextCommand = "*124#" strCommand = "AT+CUSD=1," & Chr(34) & TextCommand & Chr(34) & ",15"     MSComm1.Output=strCommand     WScript.Sleep(10000)     strResponse=MSComm1.Input     If (InStr(strResponse, "OK") > 0) Then ' Re MSComm1.Output=" "<br />
WScript.Sleep(10000)<br />
strResponse2=MSComm1.Input<br />
If (InStr(strResponse2, "+CUSD:") > 0) Then          ' If USSD response             strFields = Split(strResponse2, Chr(34))             modemReply = strFields(<br />
Else<br />
    modemReply = "Error st End If ELSE <br />
modemReply = "Error st<br />
End if <br />
MSComm1.PortOpen = False <br />
set MSComm1=nothing<br />
 End Sub <br />
Call USSD() <br />
msgbox modemReply<br />

there are some mistakes but u can fix them, i just sent that thru a phone en phone dnt hold that much copied data in the clipboard with tabs en returns
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900