Download the PHP package php-io-extensions/i2c without Composer

On this page you can find all versions of the php package php-io-extensions/i2c. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package i2c

I2C

PHP Zephir Platform

PHP-controllable Linux I²C extension built with Zephir.

The I2C extension allows PHP to communicate with I²C devices on Linux — selecting slave addresses, performing raw reads and writes, and executing combined transactions. Useful for sensors, displays, ADCs, and other hardware connected to an I²C bus.

Requirements

Installation

Install Zephir if you haven't already:

Install the FD extension first — I2C requires raw integer file descriptors that PHP's stream layer cannot provide:

Then clone and build this extension:

The install script handles the full workflow: ensures linux/i2c-dev.h headers are present, loads the i2c-dev kernel module, clean → build → copy .so → write 30-i2c.ini into all detected conf.d directories → verify php -m → reload php-fpm if present.

To use a specific Zephir binary:

API

All methods are static. File descriptors are plain integers. Use the FD extension to open and close them — PHP's stream-based fopen does not produce the raw integer FDs the kernel ioctls require.

I2c\I2CUse

Basic I/O operations on an I²C bus file descriptor.


slave(int $fd, int $address): int

Selects the slave device to communicate with. Must be called before read() or write(). Returns 0 on success, -1 on failure.


read(int $fd, int $bytes_to_read): string

Reads raw bytes from the currently selected slave. Returns the bytes as a binary string, or "" on error.


write(int $fd, string $data, int $bytes_to_write): int

Writes raw bytes to the currently selected slave. Returns the number of bytes written, or -1 on failure.


I2c\I2CConfig

Configuration and advanced transaction operations on an I²C bus file descriptor.


tenbit(int $fd, int $enable): int

Enables (1) or disables (0) 10-bit slave addressing. Returns 0 on success, -1 on failure.


pec(int $fd, int $enable): int

Enables (1) or disables (0) SMBus Packet Error Checking. Returns 0 on success, -1 on failure.


funcs(int $fd): int

Returns the adapter's functionality bitmask, or -1 on failure. Compare against I2C_FUNC_* values from linux/i2c.h.


rdwr(int $fd, array $messages): int

Performs a combined read/write transaction in a single atomic ioctl. Returns the number of messages transferred on success, or -1 on failure.

Each element of $messages is an associative array:

Key Type Description
addr int Slave address
flags int I2C_M_* flags — 0 = write, 0x0001 = read
data string Raw bytes; length determines bytes transferred

Usage

I2C_M flag values for rdwr. PHP does not define these — pass the values directly or define your own constants:

Constant Value Description
I2C_M_WR 0x0000 Write to slave
I2C_M_RD 0x0001 Read from slave
I2C_M_TEN 0x0010 Use 10-bit addressing
I2C_M_NOSTART 0x4000 Skip repeated START condition

Basic read/write


Combined transaction (write then read, no STOP)


Query adapter capabilities


10-bit addressing

License

Copyright © Project Saturn Studios, LLC. All rights reserved.


All versions of i2c with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package php-io-extensions/i2c contains the following files

Loading the files please wait ...