Can not open serial port using PHP

时间秒杀一切 提交于 2019-12-11 07:52:19

问题


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

回答1:


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

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


来源:https://stackoverflow.com/questions/6359724/can-not-open-serial-port-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!