PHP code example of lepiaf / serialport
1. Go to this page and download the library: Download lepiaf/serialport library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lepiaf / serialport example snippets
use lepiaf\SerialPort\SerialPort;
use lepiaf\SerialPort\Parser\SeparatorParser;
use lepiaf\SerialPort\Configure\TTYConfigure;
$serialPort = new SerialPort(new SeparatorParser(), new TTYConfigure());
$serialPort->open("/dev/ttyACM0");
while ($data = $serialPort->read()) {
echo $data."\n";
if ($data === "OK") {
$serialPort->write("1\n");
$serialPort->close();
}
}