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 i
m 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