PHP code example of fawno / php-serial

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

    

fawno / php-serial example snippets


    use Fawno\PhpSerial\SerialDio;
  use Fawno\PhpSerial\SerialConfig;
  use Fawno\PhpSerial\SerialBaudRates;
  use Fawno\PhpSerial\SerialStopBits;
  use Fawno\PhpSerial\SerialParity;
  use Fawno\PhpSerial\SerialDataBits;

  // Create default serial config
  $config = new SerialConfig;

  // Set Data Rate
  $config->setBaudRate(SerialBaudRates::B9600);

  // Set Data Bits
  $config->setDataBits(SerialDataBits::CS8);

  // Set Stop Bits
  $config->setStopBits(SerialStopBits::ONE);

  // Set Parity
  $config->setParity(SerialParity::NONE);

  // Set Flow Control
  $config->setFlowControl(true);

  // Create SerialDio object with COM3 as device
  $serial = new SerialDio('COM3', $config);

  // Open device
  $serial->open('r+b');

  // Set Blocking
  $serial->setBlocking(0);

  // Set Timeout
  $serial->setTimeout(0, 0);

  // Send data
  $serial->send($data);

  // Read data
  $data = $serial->read();

  composer