项目作者: lepiaf

项目描述 :
PHP Serial Port
高级语言: PHP
项目地址: git://github.com/lepiaf/serialport.git
创建时间: 2016-10-31T18:41:17Z
项目社区:https://github.com/lepiaf/serialport

开源协议:MIT License

下载


SerialPort

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

  1. 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.

  1. <?php
  2. use lepiaf\SerialPort\SerialPort;
  3. use lepiaf\SerialPort\Parser\SeparatorParser;
  4. use lepiaf\SerialPort\Configure\TTYConfigure;
  5. $serialPort = new SerialPort(new SeparatorParser(), new TTYConfigure());
  6. $serialPort->open("/dev/ttyACM0");
  7. while ($data = $serialPort->read()) {
  8. echo $data."\n";
  9. if ($data === "OK") {
  10. $serialPort->write("1\n");
  11. $serialPort->close();
  12. }
  13. }

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