无法使用PHP打开串口 [英] Can not open serial port using PHP

查看:64
本文介绍了无法使用PHP打开串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向 VSP200 设备发送请求,我的设备已连接到 Windows 机器的 com 端口 8.我正在使用 PHP 的 fopen() 打开 com 端口,但出现错误

I am working on to send request to VSP200 device, my device is connected to com port8 of windows machine. I am using fopen() of PHP to open the com port, but I am getting an error

Warning: fopen(COM8:) [function.fopen]: failed to open stream

你能告诉我,我的代码有什么问题,

can you please tell me, what is wrong in my code,

$fp = fopen ("COM8:", "w+");
if (!$fp) {
    echo 'not open';
}
else{
    echo 'port is open for write<br/>';
    $string .= '<STX>C30C10178C10100C103110606C103081000C10100C10101C100<ETX>';
    fputs ($fp, $string );
    echo $string;
    fclose ($fp);
}
$fp = fopen ("COM8:", "r+");
if (!$fp) {
    echo 'not open for read';
}
else{
    echo '<br/> port is open for read<br/>';
    $buffer = fread($fp, 128 );
    echo $buffer;
    fclose ($fp);
}

推荐答案

您不应在端口名称中包含尾随冒号:

You should not include the trailing colon in the port name:

$fp = fopen ("COM8", "w+");

这篇关于无法使用PHP打开串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆