gregorj / serial-port
PHP interfaces and classes for serial port communication.
Requires
- php: ^8.1
- ext-sockets: *
- kba-team/byte-debug: ^2.0
Requires (Dev)
- ext-pcntl: *
- ext-posix: *
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2026-04-02 17:36:40 UTC
README
PHP class SerialPort to connect to serial ports using streams. Nothing more. Only socket TCP streams are implemented at the moment.
You need to create classes implementing Command, Response and Value. The implementations of these interfaces depend on the device you want to communicate with.
Usage
Use pySerial to map a serial device to a TCP port.
Create a TcpSocket and pass it to a new SerialPort instance. Then implement a Command subclass and invoke it via $command->invoke($serialPort) to get either null or a Response.
A Command instance represents a string to send to a device via the SerialPort. Your implementation of Command needs to define the command string, its terminators, and how to read and parse the device's response into a Response object.