Introduction

This package provides a Tcl interface to the Future Technology Devices International Ltd. D2XX driver library. This is a commonly used USB device driver. See their web-site for more details about their products and the drivers themselves.

The author is not affiliated with Future Technology Devices International Ltd and this code does not represent the above company in any way.

The package provides some access to the commands exposed by the D2XX library and in particular provides a Tcl channel interface to the device over which you can send and receive data. The channel acts as a standard Tcl channel and supports fileevents and nonblocking reads. The device settings can be managed using the standard Tcl channel configuration configuration command. These include the timeouts and latency values along with buffersize and blocking mode.

FTDI provide a Linux driver for these devices and whilst this has not been tested there is no intrinsic reason why this package should not be easily ported to operate on that platform. At this time the package has only been used on Windows.

Updates - 15 Feb 2009

I have now created a Git repository on github in which to manage the source for this package. This is publicly clonable for anyone who might wish to fork and modify the code.

Updates - 28 May 2008

Since the initial release I have switched to dynamic loading of the D2XX library as this permits a Tcl application to detect a missing FTDI driver installation and produce user friendly error messages (see below). I also did some testing on Vista x64. There is a problem with the previous FTDI drivers that calling FT_SetEventNotification from a 32 bit application on 64-bit Vista fails. The solution to that is to make sure you are using the 2.4.6 drivers or newer.

The updated zip archive contains a binary for both Windows ix86 and amd64. Both have been checked on XP (x86) and Vista (both).

if {[catch {package require ftd2xx} err]} {
     set message "The FTDI interface library could not be loaded and this\
        program cannot continue without it."
    if {[lindex $::errorCode 0] eq "DLL_NOT_FOUND"} {
        set detail "The \"[lindex $::errorCode 1]\" library should be installed\
            with the device drivers. If the device drivers have not\
            been installed, please install them now."
    } else {
        set detail "The reported error message was \"$err\"\n\nError code: $errorCode"
    }
    tk_messageBox -icon error -type ok -title $Title \
        -message $message -detail $detail
    exit 1
}

Commands

ftd2xx open ?-serial? ?-description? ?-location? name

open the named device and create a channel for it. The driver supports naming devices using one of the serial number, a descriptive device name or on windows a location (port number). See the ftd2xx list command to obtain a list of attached devices with their names and locations.

ftd2xx list

list all the supported devices currently connected. Each list element is itself a name-value list providing all the information available on the device including the serial number, location, description, device id, device handle and status.

ftd2xx reset channel

this command resets the device identified by the given channel. It is likely that after this call the channel will need to be closed and the device re-opened. (untested)

ftd2xx purge channel

purge the device buffers for the device identified by the channel

ftd2xx rescan

Rescan the USB bus. This is a direct interface to FT_Rescan.

ftd2xx version

Query the FTDI library version (see FT_GetLibraryVersion).

Installation

The FTDI D2XX driver package should be downloaded from the FTDI web-site and the Makefile.vc file modified such that FTDI_INCLUDE points to the directory containing the ftdi2xx.h header and FTDI_LIB points to the directory containing the library files.

Using MSVC (6 to 9) do:
nmake -f Makefile.vc TCLDIR=c:\Tcl
nmake -f Makefile.vc TCLDIR=c:\Tcl install

If the ftd2xx.dll is not installed already, it should be manually copied to the installation folder (eg: c:\tcl\lib\tclftd2xx).

You may have to install drivers for your device (ftdibus.sys or ftd2xx.sys). This should be provided by the device manufacturer as the driver .INF file needs to be specifically configured for each device type.

Downloads

Name Description
github Git code repository
tclftd2xx.zip Source code and Windows release binary.
tclftd2xx.zip.asc Detached GPG signature (see my gpg key)

 

 
Valid XHTML 1.0! Valid CSS! Viewable with any browser