hi everyone,
Im trying serial communication using PHP. At the moment i can connect to a modem which is on port COM4. But the problem im facing is i do not know how to send AT commands to communicate with the modem.

does any body know how to send AT commands to a modem using PHP?

I will give my coding for you all to get an idea,

<?php

// Use this code to write directly to the COM4 serial port
// First, you want to set the mode of the port. You need to set
// it only once; it will remain the same until you reboot.
// Note: the backticks on the following line will execute the
// DOS 'mode' command from within PHP

mode com4: BAUD=115200 PARITY=N data=8 stop=1;
@$fp = fopen ("COM4:", "w+");
if (!$fp)
{
echo "Uh-oh. Port not opened.";
}
else
{
@$string="AT\r\n";
fputs ($fp, $string )or die ("error 1");
do
{
$dummy=fread(@$fp,1) or die ("error 1.1");
print "value=".$dummy."<br>";

}while ($dummy!="Q");

@$string="AT+CMGF=1\r\n";
fputs ($fp, $string )or die ("error 2");
do
{
$dummy=fread(@$fp,1)or die ("error 2.1");
print "value=".$dummy."<br>";

}while ($dummy!="Q");

@$string="AT+CMGS="."\r\"+94777331580\"\r".",129\r\n";
fputs ($fp, $string )or die ("error 3");

@$string="TEST MESSAGE";

fputs ($fp, $string )or die ("error 4");

fclose ($fp);
echo $string;

}
?>

eventhough This code executes properly, it does not send the SMS to the destination phone.

Ideas and suggestions are really welcome.

I would really appreciate if anyone can help.

thanx a lot,

regards,
Niroshan

    13 days later

    I'm having the same sort of problem with my script - although i'm using linux. i found a hint in some c code that said that if the modem handle isn't closed after each command is sent, it may not work properly. it seemed to help a little, but it still doesn't dial. the correct modem lights go on, but only for about 1/10 of a second. the modem never actually dials out.

    if anybody has any clues or help to give it would be greatly appreciated. i've pasted the relavent code below...

    --brien.

    [FONT=courier new]
    #!/usr/bin/php
    <?php

    $MODEM = "/dev/modem";
    $DIAL = "atdt 1234567\n";
    $HANGUP = "ath0\n";
    $RESET = "atz\n";

    function send_modem_string( $string ){
    global $MODEM;
    if( $modem = fopen( $MODEM, "r+" ) ){
    flock( $modem, LOCK_EX );
    fputs( $modem, $string );
    flock( $modem, 3 );
    fclose($modem);
    }
    }

    function dial_out(){
    global $DIAL, $HANGUP, $RESET;
    print("Resetting modem...\n");
    send_modem_string($RESET);
    sleep(1);
    print("Modem reset. Dialing...\n");
    send_modem_string($DIAL);

        print("Dialed. Waiting for call...\n");
        sleep(30);
        print("Hanging up.\n\n");
        send_modem_string($HANGUP);

    }

    dial_out();

    ?>[/FONT]

      Write a Reply...