授予 PHP 访问 COM 端口的权限
我正在创建一个 php 脚本,该脚本连接到通过 COM5 上的串行连接连接的 3G 调制解调器。
我收到以下错误,我相信这是因为 php 没有对 COM5 的读/写访问权限:
警告:fopen(COM5:) [function.fopen]:无法打开流:第 9 行 C:\xampp\htdocs\SMStest\test2.php 中没有此类文件或目录
// mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off
$fp = fopen ("COM5:", "w+");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
$e = chr(27);
$string = $e . "A" . $e . "H300";
$string .= $e . "V100" . $e . "XL1SATO";
$string .= $e . "Q1" . $e . "Z";
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
I'm creating a php script that connects to a 3G modem connected via serial connection on COM5.
I'm getting the following error and I believe it is because php does not have r/w access to COM5:
Warning: fopen(COM5:) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\SMStest\test2.php on line 9
// mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off
$fp = fopen ("COM5:", "w+");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
$e = chr(27);
$string = $e . "A" . $e . "H300";
$string .= $e . "V100" . $e . "XL1SATO";
$string .= $e . "Q1" . $e . "Z";
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Windows 上访问 COM 端口的方法有很多,替代方法是使用以下路径打开它:
\Device\00000123
(您可以在设备管理器、属性、详细信息、物理地址中找到正确的值)设备对象名称)\\.\com5
(如果我用 C 或其他语言编写程序,这就是我将端口作为文件打开的方式)There are many ways to access COM ports on windows, alternatives to your method are opening it with the following paths:
\Device\00000123
(You can find the correct value in device manager, properties, details, physical device object name)\\.\com5
(This is how I would open the port as a file if I was writing a program in C or something)