0

I've a php file that should display the data read by com7 as shown below.

Perform communication/data transmission through PuTTY and Tera Term, both programs send data correctly but when executing the script in PHP it does not work, always shows this error

Waiting date... COM not receive data. Waiting 5 seconds...

<?php
require_once('PhpSerial.php');

$serial = new PhpSerial;
$serial->deviceSet("COM7");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("xon/xoff");

if (!$serial->deviceOpen()) {
    die("Error: Cant open port.");
}

function handleDataReceived($serial) {
    $data_rec = $serial->readPort();

    if (!empty($data_rec)) {
        echo "New data: " . trim($data_rec);
    } else {
        echo "COM not receive data.";
    }
}

$interval = 5;

while (true) {
    echo "Waiting data...";
    handleDataReceived($serial);
    echo "Waiting $interval seconds...";
    sleep($interval);
}

$serial->deviceClose();
?>

How can I get this script to work? I'm using this class called PhpSerial

https://github.com/Xowap/PHP-Serial

and Wampserver windows 10

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.