dongming4994 2018-10-24 11:46
浏览 71

在Windows上读取串行端口

I am trying to use PHP to read weighing machine value(i.e., weight). Whenever I run the code below, it says

Fatal error: Maximum execution time of 300 seconds exceeded

I did something wrong, I don't know where it is?

The PHP Serial class offers a readPort() function, does not return (My assumption).

My PHP code:

<html>
<body>
<h1>Works with php</h1>
<p>First Page in PHP</p>

<?php
include 'PhpSerial.php';

    $serial = new phpSerial();
    $serial->deviceSet("COM3");
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    $serial->sendMessage("s");

    $read = $serial->readPort();
    echo ("Weight--->".$read );
    $serial->deviceClose();
?> 

<p>Sent Data to server </p>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • douyeyan0650 2018-10-24 11:54
    关注

    try like this:

    require_once 'PhpSerial.php';
    $serial=new phpSerial();
    $serial->deviceSet('/dev/ttyACM2');
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    
    if($_GET['status']){
        $serial->sendMessage($_GET['status']);
        $read=$serial->readPort();
    
        var_dump($read);
        echo $read;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号