PHP code example of microscrap / ftdi

1. Go to this page and download the library: Download microscrap/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/ */

    

microscrap / ftdi example snippets




$ftdi = ftdi_new();
if ($ftdi->handle < 0) {
    throw new RuntimeException('ftdi_new failed');
}

ftdi_init($ftdi);

// FT232RL defaults: vendor 0x0403, product 0x6001
if (ftdi_usb_open($ftdi, 0x0403, 0x6001) !== 0) {
    throw new RuntimeException(ftdi_get_error_string($ftdi));
}

ftdi_set_baudrate($ftdi, 115200);
ftdi_set_line_property($ftdi, 8, 1, 0); // 8N1

ftdi_write_data($ftdi, "hello\n", 6);
$response = ftdi_read_data($ftdi, 256);

ftdi_usb_close($ftdi);
ftdi_deinit($ftdi);
ftdi_free($ftdi);