使用php通过蓝牙向手机发送AT命令

发布于 2024-10-12 21:29:42 字数 747 浏览 2 评论 0原文

我使用的是 Windows 7 并使用蓝牙连接我的手机。此连接使用虚拟 COM 端口进行通信,在调用 php 函数之前,我已将其配置为指定的波特率、流量控制、字长等


function sendmsg($str = 'AT\r\n', $device = 'COM5'){
  $handle = fopen($device, "w+b");
  stream_set_blocking($handle, 0);
  fwrite($handle, $str);
  fclose($handle);
  return true;
}

Now the problem is fopen() throws me an error saying that it is an invalid argument and it has failed to opened stream and all else fails. But my phone says it is connected to my computer and then flashes an alert that bluetooth connection has failed. When I tried the same configuration parameters over PuTTY I was able to do what I wanted to do. I've also tried it on C# but that too ended up with the same result :(

I'm using windows 7 and connected my phone using bluetooth. This connection uses a virtual COM port for communication, which I've configured to specified baud rate, flow control, word length, etc. before I call my php function


function sendmsg($str = 'AT\r\n', $device = 'COM5'){
  $handle = fopen($device, "w+b");
  stream_set_blocking($handle, 0);
  fwrite($handle, $str);
  fclose($handle);
  return true;
}

Now the problem is fopen() throws me an error saying that it is an invalid argument and it has failed to opened stream and all else fails. But my phone says it is connected to my computer and then flashes an alert that bluetooth connection has failed. When I tried the same configuration parameters over PuTTY I was able to do what I wanted to do.
I've also tried it on C# but that too ended up with the same result :(

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

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

发布评论

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

评论(2

合约呢 2024-10-19 21:29:42

我已经做了类似的事情,但用 Python 实现并且它有效 - Windows Vista 与诺基亚 N70 手机通话。手机通过蓝牙进行配对,并使用配对时创建的 COM 端口完成通信。它基于一个名为 pySerial 的开源项目

I have done something similar but in Python and it worked - Windows Vista talking with a Nokia N70 phone. The phone was paired over bluetooth and the communication it was done using a COM port created along with pairing. It was based on a open source project called pySerial

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文