PHP code example of datagutten / php-serial

1. Go to this page and download the library: Download datagutten/php-serial 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/ */

    

datagutten / php-serial example snippets



et's start the class
$serial = new datagutten\phpSerial\SerialConnection();

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->setDevice("COM1");

// We can change the baud rate, parity, length, stop bits, flow control
$serial->setBaudRate(2400);
$serial->setParity("none");
$serial->setCharacterLength(8);
$serial->setStopBits(1);
$serial->setFlowControl("none");

// Then we need to open it
$serial->open();

// To write into
$serial->send("Hello, World!");
bash
composer