FTDI::D2XX - Perl extension for interface to FTDI d2xx library (tested with version 0.4.16 linux, see readme for windows)


FTDI-D2XX documentation Contained in the FTDI-D2XX distribution.

Index


Code Index:

NAME

Top

FTDI::D2XX - Perl extension for interface to FTDI d2xx library (tested with version 0.4.16 linux, see readme for windows)

SYNOPSIS

Top

  use FTDI::D2XX;
  my $FTD = FTDIId2xx->new(0); # open device with id 0
  unless( $FTD->FT_Write(\@data,@data,$written) == FT_OK ) {
	print "Write error";
  }

  # not needed due to destructor: $FTD->FT_Close();

  OR

  use FTDI::D2XX;
  my $handle;
  FTDI::D2XX::FT_Open($handle,0); # open device with id 0
  unless( FTDI::D2XX::FT_Write($handle,\@data,@data,$written) == FT_OK ) {
	print "Write error";
  }
  FTDI::D2XX::FT_Close($handle);










DESCRIPTION

Top

This is an interface to the d2xx library from Future Technology Devices International Limited (FTDI). The basic idea for this interface comes from the Win32::FTDI:FTD2XX perl module. It was started as a port from the Windows module to linux but it became a completly new implementation. This modules does not contain any code from the Win32::FTDI:FTD2XX module. Thanks for the source code from Scott K MacPherson as a starting point.

The mainly all standard functions of the D2XX library excluding the FT_W32_* functions are implemented. The functions can be used as in the D2XX documentation or in a object oriented way.

STATUS

This is a pre-alpha version. Only small tests have been done by using a test script included in this package and an FT2232L IC. Testers are welcome.

EXPORT

FT_OK is the only default export.

Other exportable symbols are: FT_INVALID_HANDLE FT_DEVICE_NOT_FOUND FT_DEVICE_NOT_OPENED FT_IO_ERROR FT_INSUFFICIENT_RESOURCES FT_INVALID_PARAMETER FT_INVALID_BAUD_RATE FT_DEVICE_NOT_OPENED_FOR_ERASE FT_DEVICE_NOT_OPENED_FOR_WRITE FT_FAILED_TO_WRITE_DEVICE FT_EEPROM_READ_FAILED FT_EEPROM_WRITE_FAILED FT_EEPROM_ERASE_FAILED FT_EEPROM_NOT_PRESENT FT_EEPROM_NOT_PROGRAMMED FT_INVALID_ARGS FT_NOT_SUPPORTED FT_OTHER_ERROR FT_OPEN_BY_SERIAL_NUMBER FT_OPEN_BY_DESCRIPTION FT_OPEN_BY_LOCATION FT_LIST_NUMBER_ONLY FT_LIST_BY_INDEX FT_LIST_ALL FT_LIST_MASK FT_BAUD_300 FT_BAUD_600 FT_BAUD_1200 FT_BAUD_2400 FT_BAUD_4800 FT_BAUD_9600 FT_BAUD_14400 FT_BAUD_19200 FT_BAUD_38400 FT_BAUD_57600 FT_BAUD_115200 FT_BAUD_230400 FT_BAUD_460800 FT_BAUD_921600 FT_BITS_8 FT_BITS_7 FT_BITS_6 FT_BITS_5 FT_STOP_BITS_1 FT_STOP_BITS_1_5 FT_STOP_BITS_2 FT_PARITY_NONE FT_PARITY_ODD FT_PARITY_EVEN FT_PARITY_MARK FT_PARITY_SPACE FT_FLOW_NONE FT_FLOW_RTS_CTS FT_FLOW_DTR_DSR FT_FLOW_XON_XOFF FT_PURGE_RX FT_PURGE_TX FT_EVENT_RXCHAR FT_EVENT_MODEM_STATUS FT_EVENT_LINE_STATUS FT_DEFAULT_RX_TIMEOUT FT_DEFAULT_TX_TIMEOUT FT_DEVICE_BM FT_DEVICE_AM FT_DEVICE_100AX FT_DEVICE_UNKNOWN FT_DEVICE_2232C FT_DEVICE_232R FT_DEVICE_2232H FT_DEVICE_4232H FT_BITMODE_RESET FT_BITMODE_ASYNC FT_BITMODE_MPSSE FT_BITMODE_SYNC FT_BITMODE_MCUHOST FT_BITMODE_FASTOPTO FT_BITMODE_CBUS FT_BITMODE_SINGLE245 CBUS_TXDEN CBUS_PWRON CBUS_RXLED CBUS_TXLED CBUS_TXRXLED CBUS_SLEEP CBUS_CLK48 CBUS_CLK24 CBUS_CLK12 CBUS_CLK6 CBUS_IOMODE CBUS_BITBANG_WR CBUS_BITBANG_RD

FUNCTIONS and METHODS

Top

The module provides a new constructor which connects a ftdi handle with the module by using bless. Therefore all FT_functions can be called as a method if a handle is the first parameter.

The following list describes only the differences to the original implementation by FTDI. All functions, except new() returns the status of the operation. Parameters marked by * will be changed by the function. Mosts of the * marked parameter are only feedback from the library. These scalars are not initialized by the xs code - result: $device->FT_GetBitMode($mode) works but not $device->FT_GetBitMode(\$mode) because the library generates a new variable instead of using the existing one.

Parameters: deviceID [mode]

Returns: Object Reference of the Object FTDI::D2XX

Purpose: Open a FTDI device and return the handle as a object reference. This function behaves like FT_Open with one parameter and like FT_OpenEx with two parameters.

Parameters: Scalar, Scalar

Parameters: Scalar*, Scalar*

Parameters: Scalar*

Parameters: Scalar, Scalar*, Scalar*, Scalar*, Scalar*, Scalar*, Scalar*, Reference*

Parameters: Scalar, Reference*

Parameters: Scalar, Scalar, Reference*

Parameters: Reference

Parameters: Reference, ReferenceToArray*, Scalar, Scalar*

Parameters: Reference, ReferenceToArray, Scalar, Scalar*

Parameters: Reference, Scalar

Parameters: Reference, Scalar

Parameters: Reference, Scalar, Scalar, Scalar

Parameters: Reference, Scalar, Scalar

Parameters: Reference, Scalar, Scalar, Scalar

Parameters: Reference

Parameters: Reference

Parameters: Reference

Parameters: Reference

Parameters: Reference, Scalar*

Parameters: Reference, Scalar*

Parameters: Reference, Scalar*, Scalar*, Scalar*, Scalar*, Scalar*, Scalar

Parameters: Reference, Scalar* Not supported under Linux and OS X

Parameters: Scalar* Not supported under Linux and OS X

Parameters: Reference, Scalar*, Scalar*, Scalar*

Currently not implemented in this module.

Parameters: Reference, Scalar, Scalar, Scalar, Scalar

Parameters: Reference

Parameters: Reference

Parameters: Reference, Scalar

Parameters: Reference

Parameters: Reference Only under Windows 2000 and higher supported.

Parameters: Reference Only under Windows 2000 and higher supported.

Parameters: Reference, Scalar Only under Windows 2000 and higher supported.

Parameters: Reference

Parameters: Reference

Parameters: Reference, Scalar

Parameters: Reference Not supported under Linux and OS X

Parameters: Reference Not supported under Linux and OS X

Parameters: Reference, Scalar, Scalar*

Parameters: Reference, Scalar, Scalar

Parameters: Reference

Not implemented so far. See FT_EE_ReadToArray

Parameters: Reference, ReferenceToArray* This functions read the EEPROM and saves every byte into an arrray. The conversion from array to hash will be implemented later.

Not implemented so far. See FT_EE_ProgramByArray.

Parameters: Reference, ReferenceToArray This function writes to EEPROM. The conversion from hash to array will be added later.

Parameters: Reference, Scalar*

Parameters: Reference, ReferenceToArray*, Scalar, Scalar*

Parameters: Reference, ReferenceToArray, Scalar,

Parameters: Reference, Scalar

Parameters: Reference, Scalar*

Parameters: Reference, Scalar, Scalar

Parameters: Reference, Scalar*

Parameters: Reference, Scalar, Scalar

DEPENDENCIES

Top

The FTDI/FTD2XX Drivers, at least CDM 2.04.16 (tested with this version under linux, see readme for windows), must be installed in conjunction with this module for it to be functional. This package does not contain the ftd2xx.h header file. Please download it from www.ftdichip.com

BUGS and THINGS TO DO

Top

Please report bugs to me at my email address below.

See the BUGS file in the distribution for known issues and their status.

Things to Do

1) Test, test, test it

2) Complete the functions list

SEE ALSO

Top

The list of functions showns only the difference to the FTDI D2XX Programmer's Guide. Use it as a reference.

AUTHOR

Top

Matthias Voelker, <mvoelker@cpan.org>

COPYRIGHT AND LICENSE

Top


FTDI-D2XX documentation Contained in the FTDI-D2XX distribution.

package FTDI::D2XX;

use 5.008008;
use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration	use FTDI::D2XX ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
	
) ] );

our @EXPORT = qw(
	FT_OK
);

our @EXPORT_OK = qw(
  FT_OK
  FT_INVALID_HANDLE
  FT_DEVICE_NOT_FOUND
  FT_DEVICE_NOT_OPENED
  FT_IO_ERROR
  FT_INSUFFICIENT_RESOURCES
  FT_INVALID_PARAMETER
  FT_INVALID_BAUD_RATE

  FT_DEVICE_NOT_OPENED_FOR_ERASE
  FT_DEVICE_NOT_OPENED_FOR_WRITE
  FT_FAILED_TO_WRITE_DEVICE
  FT_EEPROM_READ_FAILED
  FT_EEPROM_WRITE_FAILED
  FT_EEPROM_ERASE_FAILED
  FT_EEPROM_NOT_PRESENT
  FT_EEPROM_NOT_PROGRAMMED
  FT_INVALID_ARGS
  FT_NOT_SUPPORTED
  FT_OTHER_ERROR

  FT_OPEN_BY_SERIAL_NUMBER 
  FT_OPEN_BY_DESCRIPTION
  FT_OPEN_BY_LOCATION

  FT_LIST_NUMBER_ONLY
  FT_LIST_BY_INDEX
  FT_LIST_ALL
  FT_LIST_MASK
  
  FT_BAUD_300
  FT_BAUD_600
  FT_BAUD_1200
  FT_BAUD_2400
  FT_BAUD_4800
  FT_BAUD_9600
  FT_BAUD_14400
  FT_BAUD_19200
  FT_BAUD_38400
  FT_BAUD_57600
  FT_BAUD_115200
  FT_BAUD_230400
  FT_BAUD_460800
  FT_BAUD_921600

  FT_BITS_8
  FT_BITS_7
  FT_BITS_6
  FT_BITS_5

  FT_STOP_BITS_1
  FT_STOP_BITS_1_5
  FT_STOP_BITS_2

  FT_PARITY_NONE
  FT_PARITY_ODD
  FT_PARITY_EVEN
  FT_PARITY_MARK
  FT_PARITY_SPACE

  FT_FLOW_NONE
  FT_FLOW_RTS_CTS
  FT_FLOW_DTR_DSR
  FT_FLOW_XON_XOFF

  FT_PURGE_RX
  FT_PURGE_TX

  FT_EVENT_RXCHAR	
  FT_EVENT_MODEM_STATUS
  FT_EVENT_LINE_STATUS

  FT_DEFAULT_RX_TIMEOUT
  FT_DEFAULT_TX_TIMEOUT

  FT_DEVICE_BM
  FT_DEVICE_AM
  FT_DEVICE_100AX
  FT_DEVICE_UNKNOWN
  FT_DEVICE_2232C
  FT_DEVICE_232R
  FT_DEVICE_2232H
  FT_DEVICE_4232H

  FT_BITMODE_RESET
  FT_BITMODE_ASYNC
  FT_BITMODE_MPSSE
  FT_BITMODE_SYNC
  FT_BITMODE_MCUHOST
  FT_BITMODE_FASTOPTO
  FT_BITMODE_CBUS
  FT_BITMODE_SINGLE245

  CBUS_TXDEN 
  CBUS_PWRON 
  CBUS_RXLED  
  CBUS_TXLED  
  CBUS_TXRXLED 
  CBUS_SLEEP  
  CBUS_CLK48  
  CBUS_CLK24  
  CBUS_CLK12  
  CBUS_CLK6  
  CBUS_IOMODE  
  CBUS_BITBANG_WR  
  CBUS_BITBANG_RD 
);

our $VERSION = '0.06';

require XSLoader;
XSLoader::load('FTDI::D2XX', $VERSION);

# Preloaded methods go here.


###########################################
use constant FT_OK => 0;
use constant FT_INVALID_HANDLE => 1;
use constant FT_DEVICE_NOT_FOUND => 2;
use constant FT_DEVICE_NOT_OPENED => 3;
use constant FT_IO_ERROR => 4;
use constant FT_INSUFFICIENT_RESOURCES => 5;
use constant FT_INVALID_PARAMETER => 6;
use constant FT_INVALID_BAUD_RATE => 7;

use constant FT_DEVICE_NOT_OPENED_FOR_ERASE => 8;
use constant FT_DEVICE_NOT_OPENED_FOR_WRITE => 9;
use constant FT_FAILED_TO_WRITE_DEVICE => 10;
use constant FT_EEPROM_READ_FAILED => 11;
use constant FT_EEPROM_WRITE_FAILED => 12;
use constant FT_EEPROM_ERASE_FAILED => 13;
use constant FT_EEPROM_NOT_PRESENT => 14;
use constant FT_EEPROM_NOT_PROGRAMMED => 15;
use constant FT_INVALID_ARGS => 16;
use constant FT_NOT_SUPPORTED => 17;
use constant FT_OTHER_ERROR => 18;

use constant FT_OPEN_BY_SERIAL_NUMBER => 1;
use constant FT_OPEN_BY_DESCRIPTION => 2;
use constant FT_OPEN_BY_LOCATION => 4;

# Baud Rates
use constant FT_BAUD_300 => 300;
use constant FT_BAUD_600 => 600;
use constant FT_BAUD_1200 => 1200;
use constant FT_BAUD_2400 => 2400;
use constant FT_BAUD_4800 => 4800;
use constant FT_BAUD_9600 => 9600;
use constant FT_BAUD_14400 => 14400;
use constant FT_BAUD_19200 => 19200;
use constant FT_BAUD_38400 => 38400;
use constant FT_BAUD_57600 => 57600;
use constant FT_BAUD_115200 => 115200;
use constant FT_BAUD_230400 => 230400;
use constant FT_BAUD_460800 => 460800;
use constant FT_BAUD_921600 => 921600;

# Word Lengths
use constant FT_BITS_8 => 0x08;
use constant FT_BITS_7 => 0x07;
use constant FT_BITS_6 => 0x06;
use constant FT_BITS_5 => 0x05;

# Stop Bits
use constant FT_STOP_BITS_1 => 0x00;
use constant FT_STOP_BITS_1_5 => 0x01;
use constant FT_STOP_BITS_2 => 0x02;

# Parity
use constant FT_PARITY_NONE => 0x00;
use constant FT_PARITY_ODD => 0x01;
use constant FT_PARITY_EVEN => 0x02;
use constant FT_PARITY_MARK => 0x03;
use constant FT_PARITY_SPACE => 0x04;

# Flow Control
use constant FT_FLOW_NONE => 0x0000;
use constant FT_FLOW_RTS_CTS => 0x0100;
use constant FT_FLOW_DTR_DSR => 0x0200;
use constant FT_FLOW_XON_XOFF => 0x0400;

# Purge rx and tx buffers
use constant FT_PURGE_RX => 1;
use constant FT_PURGE_TX => 2;

use constant FT_EVENT_RXCHAR => 1;
use constant FT_EVENT_MODEM_STATUS => 2;
use constant FT_EVENT_LINE_STATUS => 4;

# Timeouts
use constant FT_DEFAULT_RX_TIMEOUT => 300;
use constant FT_DEFAULT_TX_TIMEOUT => 300;

# Enumerated Device types
use constant FT_DEVICE_BM => 0;
use constant FT_DEVICE_AM => 1;
use constant FT_DEVICE_100AX => 2;
use constant FT_DEVICE_UNKNOWN => 3;
use constant FT_DEVICE_2232C => 4;
use constant FT_DEVICE_232R => 5;
use constant FT_DEVICE_2232H => 6;
use constant FT_DEVICE_4232H => 7;

# modes
use constant FT_BITMODE_RESET => 0x00;
use constant FT_BITMODE_ASYNC => 0x01;
use constant FT_BITMODE_MPSSE => 0x02;
use constant FT_BITMODE_SYNC => 0x04;
use constant FT_BITMODE_MCUHOST => 0x08;
use constant FT_BITMODE_FASTOPTO => 0x10;
use constant FT_BITMODE_CBUS => 0x20;
use constant FT_BITMODE_SINGLE245 => 0x40;

# CBUS options
use constant CBUS_TXDEN =>  0x00 ;
use constant CBUS_PWRON =>  0x01 ;
use constant CBUS_RXLED =>  0x02 ;
use constant CBUS_TXLED =>  0x03 ;
use constant CBUS_TXRXLED =>  0x04 ;
use constant CBUS_SLEEP =>  0x05 ;
use constant CBUS_CLK48 =>  0x06 ;
use constant CBUS_CLK24 =>  0x07 ;
use constant CBUS_CLK12 =>  0x08 ;
use constant CBUS_CLK6 =>  0x09 ;
use constant CBUS_IOMODE =>  0x0A ;
use constant CBUS_BITBANG_WR =>  0x0B ;
use constant CBUS_BITBANG_RD =>  0x0C;

#############################################################
## Additional functions

## creat new object and open device
sub new
{
	my $this = shift;
	my $ID = shift;
	my $mode = -1;
	$mode = shift if (@ARGV > 0);
	my $object=0;
	my $status;

	# selct open mode
	if( $mode >= 0 ) {
		$status = FT_OpenEx($ID,$mode,$object);
	} else {
		$status = FT_Open($ID,$object);
	}

	# check result
	if( $status == FT_OK ) {
		bless($object,$this);
		return($object);
	} else {
		return(undef);
	}
}

## DESTROY function
sub DESTROY
{
	my $self = shift;
	if( ref($self) eq "undefinied" ) {
		return(FT_INVALID_HANDLE);
	} else {
		return(FT_Close($self));
	}
}



1;
__END__