1. Go to this page and download the library: Download php-io-extensions/ftdi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-io-extensions / ftdi example snippets
use Ftdi\FtdiProductId;
use Ftdi\FtdiVendorId;
$ftdi = ftdi_new() ?? throw new RuntimeException('ftdi_new() failed');
$found = ftdi_usb_find_all($ftdi, FtdiVendorId::FTDI->value, FtdiProductId::FT232H->value);
foreach ($found['devices'] as $device) {
$strings = ftdi_usb_get_strings($ftdi, $device);
printf("%s, serial %s\n", $strings['description'], $strings['serial']);
}
$ftdi = ftdi_new() ?? throw new RuntimeException('ftdi_new() failed');
if (ftdi_usb_open($ftdi, FtdiVendorId::FTDI->value, FtdiProductId::FT232H->value) < 0) {
throw new RuntimeException(ftdi_get_error_string($ftdi));
}
ftdi_usb_reset($ftdi);
ftdi_set_bitmode($ftdi, 0x00, BITMODE_RESET);
ftdi_set_bitmode($ftdi, 0x00, BITMODE_MPSSE);
ftdi_tcio_flush($ftdi);
// SEND_IMMEDIATE makes the chip answer now instead of when its buffer fills.
ftdi_write_data($ftdi, chr(GET_BITS_LOW) . chr(SEND_IMMEDIATE), 2);
$reply = '';
while (strlen($reply) < 1) {
$chunk = ftdi_read_data($ftdi, 1); // "" until the answer arrives
if ($chunk === false) {
throw new RuntimeException(ftdi_get_error_string($ftdi));
}
$reply .= $chunk;
}
printf("ADBUS 0b%08b\n", ord($reply));