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

发布于 2024-08-28 18:14:53 字数 718 浏览 5 评论 0原文

我正在尝试从 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);

I am trying to dial a phone number from php (i have a client list in a database, and thought i could use it to ring them when i click on their name

here is my code, it doesn't seem to work. I can hear the phone line click, but it doesn't seem to dial. maybe i am missing some command that needs to be sent prior to 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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里泪两行 2024-09-04 18:14:54

解决了,愚蠢的我

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

solved, silly me

all that is needed is a sleep() before the fclose
it was just closing the port before it could actually do any dialing
apart from that it seems to work fine

站稳脚跟 2024-09-04 18:14:54

尝试

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

Try

$comport = fopen($device, "w+");
...
$atcmd = "ATDT222222222222\r\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文