无法使用PHP打开串口

时间:2011-06-15 14:53:58

标签: php serial-port

我正在向VSP200设备发送请求,我的设备连接到Windows机器的com port8。我正在使用PHP的fopen()来打开com端口,但是我收到了错误

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

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

$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);
}

1 个答案:

答案 0 :(得分:1)

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

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