PHPackages                             gregorj/serial-port - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gregorj/serial-port

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gregorj/serial-port
===================

PHP interfaces and classes for serial port communication.

v3.0.0(1mo ago)035↓90%MITPHPPHP ^8.1CI passing

Since Apr 2Pushed 1mo agoCompare

[ Source](https://github.com/gregor-j/SerialPort)[ Packagist](https://packagist.org/packages/gregorj/serial-port)[ RSS](/packages/gregorj-serial-port/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (5)Versions (13)Used By (0)

SerialPort
==========

[](#serialport)

[![License: MIT](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHPStan level](https://camo.githubusercontent.com/9297b720cc0749bd5e73e34d327b3fd68bec07ea9876550273be15f340c4d5a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f79616d6c3f75726c3d68747470732533412532462532466769746875622e636f6d253246677265676f722d6a25324653657269616c506f72742532467261772532467265667325324668656164732532466d61696e2532467068707374616e2e6e656f6e2671756572793d2532342e706172616d65746572732e6c6576656c267072656669783d6c6576656c253230267374796c653d666c61742d737175617265266c6162656c3d5048505374616e)](https://camo.githubusercontent.com/9297b720cc0749bd5e73e34d327b3fd68bec07ea9876550273be15f340c4d5a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f79616d6c3f75726c3d68747470732533412532462532466769746875622e636f6d253246677265676f722d6a25324653657269616c506f72742532467261772532467265667325324668656164732532466d61696e2532467068707374616e2e6e656f6e2671756572793d2532342e706172616d65746572732e6c6576656c267072656669783d6c6576656c253230267374796c653d666c61742d737175617265266c6162656c3d5048505374616e)[![Code Style](https://camo.githubusercontent.com/47ba0ec994bbc8cfb522d510e5b348e5f00587019b2b4de49378758fe29f475f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f786d6c3f75726c3d68747470732533412532462532466769746875622e636f6d253246677265676f722d6a25324653657269616c506f72742532467261772532467265667325324668656164732532466d61696e2532462e70687063732e786d6c2671756572793d25324625324672756c6573657425324672756c652535427374617274732d7769746828253430726566253243253230275053522729253544253246253430726566267374796c653d666c61742d737175617265266c6162656c3d436f64652532305374796c65)](https://camo.githubusercontent.com/47ba0ec994bbc8cfb522d510e5b348e5f00587019b2b4de49378758fe29f475f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f786d6c3f75726c3d68747470732533412532462532466769746875622e636f6d253246677265676f722d6a25324653657269616c506f72742532467261772532467265667325324668656164732532466d61696e2532462e70687063732e786d6c2671756572793d25324625324672756c6573657425324672756c652535427374617274732d7769746828253430726566253243253230275053522729253544253246253430726566267374796c653d666c61742d737175617265266c6162656c3d436f64652532305374796c65)

PHP classes to connect to serial devices using streams or HTTP(S) gateways.

This library separates the command model from the transport:

- `Command` defines command payload, terminators, timeout, and response mapping
- `Communication` executes the command (`StreamCommunication` or `HttpCommunication`) via `query()` or `write()`
- transport is provided by either `Stream` (for sockets) or `HttpTransport` (for gateways)

`BasicStringCommand`, `BasicVoidCommand`, and `StringResponse` are reference implementations for common command/response patterns.

Usage
-----

[](#usage)

You can either:

1. bridge a serial device to TCP (for example with [pySerial](https://pyserial.readthedocs.io/en/latest/examples.html) `tcp_serial_redirect`) and use `TcpStream`
2. call an HTTP(S) serial gateway and use `HttpCommunication` with `CurlTransport` or `StreamWrapperTransport`

### TCP stream communication

[](#tcp-stream-communication)

```
