使用php通过蓝牙向手机发送AT命令
我使用的是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://code.google.com/p/php-serial/
http://code.google.com/p/php-serial/
我已经做了类似的事情,但用 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