4

I'm having trouble sending commands to a 3G modem connected on COM5. The modem is accepting the connection and receiving the commands. But there is something wrong (I think it is in my syntax/AT commands). In hyperterminal the commands are returning errors. If anyone can help I would gladly appreciate it.

-------CODE BELOW-------

<?
exec("mode COM5 BAUD=9600 PARITY=N data=8 stop=1 xon=off");
$fp = fopen ("\\.\COM5:", "r+");
//$fp = dio_open('COM5:', O_RDWR | O_NOCTTY | O_NONBLOCK);
if (!$fp) 
{
    echo "Uh-oh. Port not opened.";
} 
else 
{

    $string  = "AT+CMGF=1";

    $string  = $string."OK";

    $string  = $string."AT+CMGS='+27824139864'";

    $string  = $string."> Hello World?<Ctrl>+<Z>";

    $string  = $string."+CMGS: 44";

    $string  = $string."OK";

    fputs ($fp, $string );
    echo $string."\n";
    fclose ($fp);
}

?>
Mchl
  • 61,444
  • 9
  • 118
  • 120
Nebula
  • 679
  • 2
  • 17
  • 37

2 Answers2

3

You need to append a \r to the end of each command rather than an "OK". The "OK" is the response you expect to be returned by the phone. Use a terminal program

1 second delay
+++
1 second delay
The modem should respond with "OK"
Type AT+CMGF=1
press enter key
Modem will repond with "OK"

Etc... It is possible your phone does not support SMS text mode only pdu mode

Type at+CMGF=?

Type enter key, if the response is at+CMGF (0,1) it supports both if (0) then pdu only. You will have to enter the SMS message in pdu mode.
There are plenty of examples on how to do this.

Mchl
  • 61,444
  • 9
  • 118
  • 120
  • Thanks David that seems right but if I type AT+CMGF=? I still get "ERROR" response. It seems that any command that I input gives me the "ERROR" msg. On AT returns "OK"..what could be problem be? Could it be settings on the modem? – Nebula Feb 13 '12 at 12:07
  • Are you sure com5 is the phone? Maybe you are talking to your in built modem (though they usually end up on com3, windoze anyway) – David cameron Feb 13 '12 at 21:36
  • Just had a thought do an at+cpin\r this will check if the pin is entered. It may be that error is returned until you have entered the pin – David cameron Feb 17 '12 at 11:12
0

You need to append a \r to the end of each command rather than an "OK". The "OK" is the response you expect to be returned by the phone. Use a terminal program

1 second delay +++ 1 second delay The modem should respond with "OK" Type AT+CMGF=1 press enter key Modem will repond with "OK"

Etc... It is possible your phone does not support SMS text mode only pdu mode

Type at+CMGF=?

Type enter key, if the response is at+CMGF (0,1) it supports both if (0) then pdu only. You will have to enter the SMS message in pdu mode. There are plenty of examples on how to do this.

CAN U GIVE ME THE CODE

jan srkl
  • 55
  • 1
  • 9