Serial port access convenience class

v1.1.0 2020-10-31 02:46 UTC

This package is auto-updated.

Last update: 2023-05-29 01:06:28 UTC


Connect to serial port with PHP

Inspired by PHP-Serial, I simplify it and include composer.json to install via composer.

Actually, it works on linux. This library is suitable for working with Arduino.

Install via composer

composer require "lepiaf/serialport"

How to use

You can check a full example in example folder. It contains a basic Arduino sketch and php file to read it.

Instantiate a new SerialPort object with a parser and configure tty.


use lepiaf\SerialPort\SerialPort;
use lepiaf\SerialPort\Parser\SeparatorParser;
use lepiaf\SerialPort\Configure\TTYConfigure;

$serialPort = new SerialPort(new SeparatorParser(), new TTYConfigure());

while ($data = $serialPort->read()) {
    echo $data."\n";

    if ($data === "OK") {

For mac os, you must use TTYMacConfigure. It will use stty -f instead of stty -F.