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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题