【发布时间】:2013-05-31 15:17:04
【问题描述】:
我正在使用 php 中的 COM 端口连接到华为 3G 调制解调器的应用程序。这是我的代码:
<?php
include("sms.php");
$sms = new sms();
$device = "COM11";
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<br/>");
}else{
echo "Com Port Open<br/>";
}
//Set non-blocking mode for writing
//stream_set_blocking($comport, 0);
$sms->_blocking($comport,0);
$atcmd = "AT\r";
fputs($comport, $atcmd);
sleep(5); // Sleep for response from the modem
// Set blocking mode for reading
$sms->_blocking($comport,1);
$res = fgets($comport, 4017);
if(trim($res) == "OK"){
echo "Modem supports AT Commands<br/>";
}else{
echo "Error response: ".$res;
}
fclose($comport);
?>
sms.php:
<?php
class sms{
function _blocking($device,$mode){
stream_set_blocking($device, $mode);
return true;
}
}
?>
这对我来说很好用。现在的挑战是每次我连接到新的 USB 端口时,COM 都会为我的调制解调器而改变。有没有其他方法可以在windows中使用php自动检测设备?
【问题讨论】:
-
我已将我的 USB 调制解调器连接到 COM13。在你的代码中改变它之后,我得到了。警告:fopen(COM13) [function.fopen]: 无法打开流:第 6 行的 C:\xampp\htdocs\sms\index.php 中没有这样的文件或目录打开 com por
-
在
COM13查看天气模式是否可用 -
错误以某种方式消失了,但没有发送消息。将消息发送到特定号码的确切命令是什么?我们也可以屏蔽这个数字吗?
-
@AhmadShahwaiz 你不能屏蔽这个数字。看到这个
http://developer.nokia.com/Community/Wiki/Using_AT_commands_to_send_and_read_SMS你可能知道如何将消息发送到特定号码。
标签: windows serial-port gsm modem