简体   繁体   中英

Read Serial Port on Windows

I am trying to use PHP to read weighing machine value(ie, 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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM