Download the PHP package microscrap/uart without Composer
On this page you can find all versions of the php package microscrap/uart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download microscrap/uart
More information about microscrap/uart
Files in microscrap/uart
Package uart
Short Description Unix UART / Serial Bindings for The PHP Posi Extension
License MIT
Homepage https://scrapyard-io.projectsaturnstudios.com/ecosystem/microscrap/uart/0.10.x/overview
Informations about the package uart
microscrap/uart — Linux UART / Serial bindings for ScrapyardIO
Docs (production): ScrapyardIO · microscrap/uart 0.7.x
PHP library that wraps the posi extension (Posi\Termios) plus microscrap/posix FD helpers with global helpers, enums, and data objects. Every helper delegates to a facade class under Microscrap\Bindings\UART.
This is the bindings package — not the native extension. Ecosystem docs: 0.7.x.
Highlights
- Open a serial device (
/dev/ttyUSB0,/dev/ttyAMA0, etc.) and configure it in one call - Automatic raw-mode setup (
cfmakerawsemantics) — no line buffering, no character processing - Typed
BaudRateenum covers the fullspeed_trange fromB50toB4000000 uart_open/uart_set_baud_ratealso accept plainintrates (Linux BOTHER / termios2 path)- Enum-typed termios flag sets for
c_iflag,c_oflag,c_cflag,c_lflag, andc_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 arefunction_exists-guarded
Requirements
- PHP
^8.4|^8.5|^8.6 - Linux kernel (any modern version with
/dev/tty*devices) - ext-posi
^0.7.0— install from php-io-extensions/posi - microscrap/posix
^0.7.0
Installation
Confirm ext-posi is loaded:
Composer also pulls microscrap/posix ^0.7.0. Autoloads src/Helpers/uart-serial.php and src/Helpers/uart-termios.php, registering the global uart_* functions.
Usage
Serial I/O is controlled through global helper functions (uart_open, uart_write, uart_read, uart_set_baud_rate, etc.). All helpers delegate to facade classes and are only defined once (function_exists guard).
Enums live under Microscrap\Bindings\UART\Enums — cases are FULLY UPPERCASE. The port handle is Microscrap\Bindings\UART\DataObjects\UARTPort (int $fd, string $path, int $baud).
Example — send a command and read the response
Example — non-standard baud (Linux BOTHER)
Example — manual termios configuration
API Reference
Serial port lifecycle
| Helper | Facade method | Description |
|---|---|---|
uart_open(string $path, BaudRate\|int $baud = BaudRate::B9600) |
Serial::uartOpen |
Open and configure a port; returns UARTPort\|null |
uart_set_baud_rate(UARTPort $port, BaudRate\|int $baud) |
Serial::uartSetBaudRate |
Change baud on an open port |
uart_close(UARTPort $port) |
Serial::uartClose |
Close the file descriptor; returns 0 or -1 |
uart_read(UARTPort $port, int $bytes) |
Serial::uartRead |
Read up to $bytes bytes; returns string\|false |
uart_write(UARTPort $port, string $data) |
Serial::uartWrite |
Write $data; returns bytes written |
uart_drain(UARTPort $port) |
Serial::uartDrain |
Block until TX FIFO is empty (tcdrain) |
uart_flush(UARTPort $port, TermiosQueue $queue = TermiosQueue::TCIOFLUSH) |
Serial::uartFlush |
Discard queued I/O (tcflush) |
uart_flow(UARTPort $port, TermiosFlow $action) |
Serial::uartFlow |
Suspend / resume I/O (tcflow) |
uart_make_raw(array $termios) |
Serial::makeRaw |
Apply cfmakeraw semantics to a termios array |
Termios attribute access
| Helper | Facade method | Description |
|---|---|---|
uart_tcgetattr(UARTPort $port) |
Termios::uartTcgetattr |
Read current attributes; returns array\|false |
uart_tcsetattr(UARTPort $port, array $t, TermiosAction $a = TermiosAction::TCSANOW) |
Termios::uartTcsetattr |
Apply attributes; returns 0 or -1 |
uart_cfsetispeed(array $t, BaudRate $baud) |
Termios::uartCfsetispeed |
Set input baud; returns new array\|false |
uart_cfsetospeed(array $t, BaudRate $baud) |
Termios::uartCfsetospeed |
Set output baud; returns new array\|false |
uart_cfgetispeed(array $t) |
Termios::uartCfgetispeed |
Decode input baud; returns BaudRate\|null |
uart_cfgetospeed(array $t) |
Termios::uartCfgetospeed |
Decode output baud; returns BaudRate\|null |
UARTPort data object
Termios array format
uart_tcgetattr returns — and uart_tcsetattr / uart_cfset*speed consume — a plain PHP array:
Enum quick reference
BaudRate
B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000
Enum values are POSIX speed_t constants. uart_open / uart_set_baud_rate convert cases to numeric rates via the case name (strip leading B).
TermiosAction
| Case | Value | When settings take effect |
|---|---|---|
TCSANOW |
0 | Immediately |
TCSADRAIN |
1 | After all output is transmitted |
TCSAFLUSH |
2 | After output drained and input discarded |
TermiosQueue
| Case | Value | What tcflush discards |
|---|---|---|
TCIFLUSH |
0 | Received but unread input |
TCOFLUSH |
1 | Written but untransmitted output |
TCIOFLUSH |
2 | Both queues |
TermiosFlow
| Case | Value | Effect |
|---|---|---|
TCOOFF |
0 | Suspend output |
TCOON |
1 | Resume output |
TCIOFF |
2 | Send STOP character to device |
TCION |
3 | Send START character to device |
InputFlag — c_iflag bits
IGNBRK, BRKINT, IGNPAR, PARMRK, INPCK, ISTRIP, INLCR, IGNCR, ICRNL, IUCLC, IXON, IXANY, IXOFF, IMAXBEL, IUTF8
OutputFlag — c_oflag bits
OPOST, OLCUC, ONLCR, OCRNL, ONOCR, ONLRET, OFILL, OFDEL
ControlFlag — c_cflag bits
CBAUD, CBAUDEX, CS5, CS6, CS7, CS8, CSTOPB, CREAD, PARENB, PARODD, HUPCL, CLOCAL, CRTSCTS
CSIZE is omitted (same integer as CS8); use CS8->value to clear/set the character-size field.
LocalFlag — c_lflag bits
ISIG, ICANON, XCASE, ECHO, ECHOE, ECHOK, ECHONL, NOFLSH, TOSTOP, ECHOCTL, ECHOPRT, ECHOKE, FLUSHO, PENDIN, IEXTEN, EXTPROC
ControlChar — c_cc indices
VINTR, VQUIT, VERASE, VKILL, VEOF, VTIME, VMIN, VSWTC, VSTART, VSTOP, VSUSP, VEOL, VREPRINT, VDISCARD, VWERASE, VLNEXT, VEOL2
Notes on uart_open defaults
uart_open applies the following configuration automatically:
O_RDWR | O_NOCTTY— read/write access; device does not become the controlling terminalcfmakerawsemantics — no input/output processing, 8N1, no parityVMIN=1,VTIME=0—read()blocks until at least one byte arrivesTCSANOW— settings applied immediately- Baud via
Posi\Termios::setBaudRate— standardBaudRatecases and non-standard ints
To override any of these defaults, call uart_tcgetattr, mutate the returned array with the flag enums, and reapply with uart_tcsetattr.
License
MIT. See LICENSE.
All versions of uart with dependencies
ext-posi Version ^0.10.0