从php拨打Windows串口调制解调器

时间:2010-04-14 01:48:59

标签: php windows serial-port modem

我正在尝试从php拨打电话号码(我在数据库中有一个客户列表,并且当我点击他们的名字时我想可以用它来振铃它们

这是我的代码,它似乎不起作用。我可以听到电话线点击,但它似乎没有拨号。也许我错过了一些需要在atdt之前发送的命令?

$device = "COM4";

exec("mode $device BAUD=9600 PARITY=n DATA=8 STOP=1 xon=off octs=off rts=on");

$comport = fopen($device, "r+b");

if ($comport === false) {
    die ("Failed opening com port");
} else {
    echo "Com Port Open";
}

stream_set_blocking($comport, 0);

$atcmd = "ATDT222222222222\r"; // dial fake number
if (fwrite($comport, $atcmd ) === false) {
    die ("Failed writing to com port"); 
} else {
    echo "Wrote $atcmd to com port";
}

sleep(10); // added fix to make program work, was closing port too soon for it to dial

fclose($comport);

2 个答案:

答案 0 :(得分:2)

解决了,傻了我

所需要的只是fclose之前的sleep() 它只是关闭端口才能实际进行任何拨号 除此之外它似乎工作正常

答案 1 :(得分:1)

尝试

$comport = fopen($device, "w+");
...
$atcmd = "ATDT222222222222\r\n";