PHP 串口通讯

dio 扩展 https://pecl.php.net/package/dio
linux代码

 F_WRLCK )) == - 1 ) {
    // the file descriptor appears locked
    echo  "The lock can not be cleared. It is held by someone else.\n" ;
} else {
   echo  "Lock successfully set/cleared\n" ;
}
 
dio_tcsetattr ( $fd , array(
   'baud'  =>  9600 ,
   'bits'  =>  8 ,
   'stop'   =>  1 ,
   'parity'  =>  0
)); 
 
while ( 1 ) {
   $data  =  dio_read ( $fd ,  9999 );
   if ( $data  ) {
      echo  bin2hex($data)."\n";
   }  
   usleep(300000);
}

windows 代码

其他参考: https://www.php.cn/php-ask-480151.html

你可能感兴趣的:(PHP 串口通讯)