PHPackages                             microscrap/uart - 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. [Framework](/categories/framework)
4. /
5. microscrap/uart

ActiveLibrary[Framework](/categories/framework)

microscrap/uart
===============

Unix UART / Serial Bindings for The PHP Posi Extension

0.4.0(2w ago)02↓100%MITPHPPHP ^8.3

Since May 25Pushed 2w agoCompare

[ Source](https://github.com/microscrap/uart)[ Packagist](https://packagist.org/packages/microscrap/uart)[ Docs](https://dosr.projectsaturnstudios.com)[ RSS](/packages/microscrap-uart/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

microscrap/uart — Linux UART / Serial bindings for ScrapyardIO
==============================================================

[](#microscrapuart--linux-uart--serial-bindings-for-scrapyardio)

PHP library that wraps the [**posi**](https://github.com/php-io-extensions/posi) extension with global helpers, enums, and data objects. Every helper delegates to a facade class under `Microscrap\Bindings\UART`.

This project provides PHP bindings to the Linux POSIX termios serial-port API, mirroring the public surface of the POSIX `` / `tcgetattr(2)` / `cfmakeraw(3)` family.

Highlights
----------

[](#highlights)

- Open a serial device (`/dev/ttyUSB0`, `/dev/ttyAMA0`, etc.) and configure it in one call
- Automatic raw-mode setup (`cfmakeraw` semantics) — no line buffering, no character processing
- Typed `BaudRate` enum covers the full `speed_t` range from `B50` to `B4000000`
- Enum-typed termios flag sets for `c_iflag`, `c_oflag`, `c_cflag`, `c_lflag`, and `c_cc`
- Full termios attribute inspection and mutation via `uart_tcgetattr` / `uart_tcsetattr`
- Drain, flush, and flow control through `uart_drain`, `uart_flush`, `uart_flow`
- Thin global `uart_*` helper API — all functions are `function_exists`-guarded

Requirements
------------

[](#requirements)

- PHP 8.3+
- Linux kernel (any modern version with `/dev/tty*` devices)
- **ext-posi** ^0.4.0 — install from [php-io-extensions/posi](https://github.com/php-io-extensions/posi)
- **microscrap/posix** ^0.4.0

Installation
------------

[](#installation)

Confirm **ext-posi** is loaded:

```
php -m | grep posi
```

```
composer require microscrap/uart
```

Composer autoloads `src/Helpers/uart-serial.php` and `src/Helpers/uart-termios.php`, registering the global `uart_*` functions.

Usage
-----

[](#usage)

Serial I/O is controlled through **global helper functions** (`uart_open`, `uart_write`, `uart_read`, etc.). All helpers delegate to facade classes and are only defined once (`function_exists` guard).

Enums live under `Microscrap\Bindings\UART\Enums`. The port handle is `Microscrap\Bindings\UART\DataObjects\UARTPort`.

---

### Example — send a command and read the response

[](#example--send-a-command-and-read-the-response)

```
