Paul Evans > Device-FTDI-0.11 > Device::FTDI

Download:
Device-FTDI-0.11.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.11   Source  

NAME ^

Device::FTDI - use USB-attached serial interface chips from FTDI.

SYNOPSIS ^

    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" );

DESCRIPTION ^

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 METHODS ^

find_all

    $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

vendor code. Default 0x0403.

product

product code. Default 0x6001.

new

    $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:

vendor

vendor code. Default 0x0403.

product

product code. Default 0x6001.

description

device description string. By default undefined.

serial

device serial ID. By default undefined.

index

device index. By default 0.

autodie

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:

    VID_FTDI

(export tag :vid)

    PID_FT232, PID_FT2232C, PID_FT4232H, PID_FT232H

(export tag :pid)

DEVICE METHODS ^

Most of device methods return negative value in case of error. You can get error description using "error_string" method.

error_string

    $dev->error_string

Returns string describing error after last operation

reset

    $dev->reset

Resets the device

set_interface

    $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)

purge_rx_buffer

    $dev->purge_rx_buffer

Clears the read buffer on the chip and the internal read buffer.

purge_tx_buffer

    $dev->purge_tx_buffer

Clears the write buffer on the chip.

purge_buffers

    $dev->purge_buffers

Clears the buffers on the chip and the internal read buffer.

set_flow_control

    $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)

This method is also available aliased as setflowctrl for back-compatibility and to match the name used by libftdi itself.

set_line_property

    $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
    BITS_7, BITS_8 (*)

(export tag :bits)

$stop_bit
    STOP_BIT_1, STOP_BIT_2, STOP_BIT_15 (*)

(export tag :stop)

$parity
    PARITY_NONE (*), PARITY_EVEN, PARITY_ODD, PARITY_MARK, PARITY_SPACE

(export tag :parity)

$parity
    BREAK_OFF (*), BREAK_ON

(export tag :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.

set_baudrate

    $dev->set_baudrate($baudrate)

Sets the chip baudrate. Returns 0 on success or negative error code otherwise.

set_latency_timer

    $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.

get_latency_timer

    $dev->get_latency_timer

Returns latency timer value or negative error code.

write_data_set_chunksize

    $dev->write_data_set_chunksize($chunksize)

Sets write buffer chunk size. Default 4096. Returns 0 on success or negative error code otherwise.

write_data_get_chunksize

    $dev->write_data_get_chunksize

Returns write buffer chunk size or negative error code.

read_data_set_chunksize

    $dev->read_data_set_chunksize($chunksize)

Sets read buffer chunk size. Default 4096. Returns 0 on success or negative error code otherwise.

read_data_get_chunksize

    $dev->read_data_get_chunksize

Returns read buffer chunk size or negative error code.

write_data

    $dev->write_data($data)

Writes data to the chip in chunks. Returns number of bytes written on success or negative error code otherwise.

read_data

    $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.

set_bitmode

    $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)

To use the BITMODE_MPSSE mode, you may prefer to use the Device::FTDI::MPSSE subclass instead.

SEE ALSO ^

FTDI, Win32::FTDI::FTD2XX, http://www.intra2net.com/en/developer/libftdi/

AUTHOR ^

Pavel Shaydo, <zwon at cpan.org>

Maintained since 2015 by Paul Evans <leonerd@leonerd.org.uk>

BUGS ^

Please report any bugs or feature requests via GitHub bugtracker for this project: https://github.com/leonerd/perl-Device-FTDI/issues.

LICENSE AND COPYRIGHT ^

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.

syntax highlighting: