kba-team/serial-port

Connect to serial ports using TCP connections.

v1.0.0 2020-12-17 10:03 UTC

This package is auto-updated.

Last update: 2024-04-17 19:03:01 UTC


README

License: MIT Build Status Maintainability Test Coverage

PHP class \kbATeam\SerialPort\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 \kbATeam\SerialPort\Interfaces\Communication\Command, \kbATeam\SerialPort\Interfaces\Communication\Container and \kbATeam\SerialPort\Interfaces\Communication\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.

Use Streams\Socket to create a connection to a SerialPort use SerialPort->invoke() to invoke a Communication\Command and get either NULL or a Communication\Container containing at least one Communication\Value.

A Communication\Command instance is a string sent to a SerialPort instance. The SerialPort instance invokes the Communication\Command using its Stream instance.

Your implementation of Communication\Command needs to define how to read the string returned by the device and either return a Communication\Container containing at least one Communication\Value, or NULL.