Device::FTDI - use USB-attached serial interface chips from FTDI.
Device::FTDI
use Device::FTDI qw( :bits :stop :parity :break :bitmode ); my $dev = Device::FTDI->new(); $dev->reset; $dev->set_baudrate( 57600 ); $dev->set_line_property( BITS_8, STOP_BIT_1, PARITY_NONE, BREAK_OFF ); $dev->write_data( "Hello, world!\n" );
WARNING: this is an alpha version
This is Perl bindings to libftdi library. It allows you to communicate with FTDI chips supported by this library.
$class->find_all(%params)
Finds all connected devices with specified vendor and product codes. Returns list of hashes describing devices. Following parameters are accepted:
vendor code. Default 0x0403.
0x0403
product code. Default 0x6001.
0x6001
$class->new(%params)
Opens specified device and returns the corresponding object reference. Dies if an attempt to open the device has failed. Accepts following parameters:
device description string. By default undefined.
device serial ID. By default undefined.
device index. By default 0.
if true, methods on this instance will use "croak" in Carp on failure. if false, they will return negative values.
In either case, the following constants may be used to specify vendor or product:
vendor
product
VID_FTDI
(export tag :vid)
:vid
PID_FT232, PID_FT2232C, PID_FT4232H, PID_FT232H
(export tag :pid)
:pid
Most of device methods return negative value in case of error. You can get error description using "error_string" method.
$dev->error_string
Returns string describing error after last operation
$dev->reset
Resets the device
$dev->set_interface($interface)
Open selected channels on a chip, otherwise use first channel. $interface may be one of:
INTERFACE_A, INTERFACE_B, INTERFACE_C, INTERFACE_D, INTERFACE_ANY
(export tag :interface)
:interface
$dev->purge_rx_buffer
Clears the read buffer on the chip and the internal read buffer.
$dev->purge_tx_buffer
Clears the write buffer on the chip.
$dev->purge_buffers
Clears the buffers on the chip and the internal read buffer.
$dev->set_flow_control($flowctrl)
Since version 0.07.
Set flow control for ftdi chip. Allowed values for $flowctrl are:
FLOW_RTS_CTS, FLOW_DTR_DSR, FLOW_XON_XOFF, FLOW_DISABLE
(export tag :flow)
:flow
This method is also available aliased as setflowctrl for back-compatibility and to match the name used by libftdi itself.
setflowctrl
$dev->set_line_property($bits, $stop_bit, $parity, $break)
Sets line characteristics. Last parameters may be omitted. Following values are acceptable for parameters (* marks default value):
BITS_7, BITS_8 (*)
(export tag :bits)
:bits
STOP_BIT_1, STOP_BIT_2, STOP_BIT_15 (*)
(export tag :stop)
:stop
PARITY_NONE (*), PARITY_EVEN, PARITY_ODD, PARITY_MARK, PARITY_SPACE
(export tag :parity)
:parity
BREAK_OFF (*), BREAK_ON
(export tag :break)
:break
Note that you have to import constants you need. You can import all constants using :all tag, or individual groups using the other named tags.
:all
$dev->set_baudrate($baudrate)
Sets the chip baudrate. Returns 0 on success or negative error code otherwise.
$dev->set_latency_timer($latency)
Sets latency timer. The FTDI chip keeps data in the internal buffer for a specific amount of time if the buffer is not full yet to decrease load on the USB bus. Latency must be between 1 and 255.
Returns 0 on success or negative error code otherwise.
$dev->get_latency_timer
Returns latency timer value or negative error code.
$dev->write_data_set_chunksize($chunksize)
Sets write buffer chunk size. Default 4096. Returns 0 on success or negative error code otherwise.
4096
$dev->write_data_get_chunksize
Returns write buffer chunk size or negative error code.
$dev->read_data_set_chunksize($chunksize)
Sets read buffer chunk size. Default 4096. Returns 0 on success or negative error code otherwise.
$dev->read_data_get_chunksize
Returns read buffer chunk size or negative error code.
$dev->write_data($data)
Writes data to the chip in chunks. Returns number of bytes written on success or negative error code otherwise.
$dev->read_data($buffer, $size)
Reads data from the chip (up to $size bytes) and stores it in $buffer. Returns when at least one byte is available or when the latency timer has elapsed. Automatically strips the two modem status bytes transfered during every read.
Returns number of bytes read on success or negative error code otherwise. Note, that if no data available it will return 0.
$dev->set_bitmode($mask, $mode)
Enable/disable bitbang modes. $mask -- bitmask to configure lines, High/ON value configures a line as output. $mode may be one of the following:
BITMODE_RESET, BITMODE_BITBANG, BITMODE_MPSSE, BITMODE_SYNCBB, BITMODE_MCU, BITMODE_OPTO, BITMODE_CBUS, BITMODE_SYNCFF.
(export tag :bitmode)
:bitmode
To use the BITMODE_MPSSE mode, you may prefer to use the Device::FTDI::MPSSE subclass instead.
BITMODE_MPSSE
FTDI, Win32::FTDI::FTD2XX, http://www.intra2net.com/en/developer/libftdi/
Pavel Shaydo, <zwon at cpan.org>
<zwon at cpan.org>
Maintained since 2015 by Paul Evans <leonerd@leonerd.org.uk>
Please report any bugs or feature requests via GitHub bugtracker for this project: https://github.com/leonerd/perl-Device-FTDI/issues.
Copyright 2012,2015 Pavel Shaydo. Copyright 2015 Paul "LeoNerd" Evans.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Device::FTDI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::FTDI
CPAN shell
perl -MCPAN -e shell install Device::FTDI
For more information on module installation, please visit the detailed CPAN module installation guide.