com.ionetrics.lib.annotatorcomm.ftd2xx
Class FTD2XX

java.lang.Object
  extended by com.ionetrics.lib.annotatorcomm.ftd2xx.FTD2XX
All Implemented Interfaces:
java.io.Closeable

public class FTD2XX
extends java.lang.Object
implements java.io.Closeable

This class provides a device interface to FTDI's FTD2XX devices through their D2XX drivers. This is the primary class for device interaction.

Typical use:

 FTD2XX device;
 InputStream in;
 OutputStream out;

 System.out.println("Devices present: " + FTD2XX.getNumberOfDevices());
 for (FTD2XXDeviceInfo info : FTD2XX.getDeviceInfoList())
     System.out.println("   " + info);

 device = new FTD2XX(FTD2XX.getDeviceInfoList());
 in = device.getInputStream();
 out = device.getOutputStream();
 ... // configure device (baud rate, parity, data bits, stop bits, flow control, etc)
 ... // communicate through the I/O streams
 in.close();
 out.close();
 device.close();
 


Constructor Summary
FTD2XX(FTD2XXDeviceInfo deviceInfo)
          Construct a FTD2XX object and open the device.
 
Method Summary
 void close()
          Close the device and its I/O stream.
protected  void finalize()
          Release device resources.
 FTD2XXDeviceInfo getDeviceInfo()
          Get information about the device.
static FTD2XXDeviceInfo[] getDeviceInfoList()
          Get a listing of devices and information about their current state.
 java.io.InputStream getInputStream()
          Get an input stream to the device.
static int getNumberOfDevices()
          Get the number of devices connected.
 java.io.OutputStream getOutputStream()
          Get an output stream to the device.
 void purge(FTD2XXPurge purge)
          Purge RXTX buffers according to purge options.
 void reset()
          Reset the device.
 void setBaudRate(int rate)
          Set the baud rate.
 void setDataCharacteristics(FTD2XXDataBits dataBits, FTD2XXStopBits stopBits, FTD2XXParity parity)
          Set data bits, stop bits, and parity.
 void setDivisor(int divisor)
          Set baud rate divisor.
 void setFlowControl(FTD2XXFlowControl flowControl)
          Set the flow control mode.
 void setFlowControl(FTD2XXFlowControl flowControl, char xon, char xoff)
          Set the flow control mode specifying Xon and Xoff values.
 void setTimeouts(int rxTimeout, int txTimeout)
          Set the RX and TX timeouts.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FTD2XX

public FTD2XX(FTD2XXDeviceInfo deviceInfo)
       throws java.io.IOException
Construct a FTD2XX object and open the device.

Parameters:
deviceInfo - device information
Throws:
java.io.IOException - failure to open
See Also:
getDeviceInfoList()
Method Detail

close

public void close()
           throws java.io.IOException
Close the device and its I/O stream. All method calls throw an IOException once close() has been called. Further access to the device requires it to be reopened with a new FTD2XX object.

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException - failure to close

finalize

protected void finalize()
                 throws java.lang.Throwable
Release device resources.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - failure to release resources

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an input stream to the device.

Returns:
device input stream
Throws:
java.io.IOException - failure to get stream

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Get an output stream to the device.

Returns:
device output stream
Throws:
java.io.IOException - failure to get stream

getDeviceInfo

public FTD2XXDeviceInfo getDeviceInfo()
                               throws java.io.IOException
Get information about the device.

Returns:
device information
Throws:
java.io.IOException

purge

public void purge(FTD2XXPurge purge)
           throws java.io.IOException
Purge RXTX buffers according to purge options.

Parameters:
purge - purge options
Throws:
java.io.IOException - failure to purge

setTimeouts

public void setTimeouts(int rxTimeout,
                        int txTimeout)
                 throws java.io.IOException
Set the RX and TX timeouts.

Parameters:
rxTimeout - RX timeout in ms
txTimeout - TX timeout in ms
Throws:
java.io.IOException - failure to set timeouts

setBaudRate

public void setBaudRate(int rate)
                 throws java.io.IOException
Set the baud rate.

Parameters:
rate - baud rate
Throws:
java.io.IOException - failure to set baud rate

setDivisor

public void setDivisor(int divisor)
                throws java.io.IOException
Set baud rate divisor.

Parameters:
divisor - baud rate divisor
Throws:
java.io.IOException - failure to set divisor

setDataCharacteristics

public void setDataCharacteristics(FTD2XXDataBits dataBits,
                                   FTD2XXStopBits stopBits,
                                   FTD2XXParity parity)
                            throws java.io.IOException
Set data bits, stop bits, and parity.

Parameters:
dataBits - number of data bits
stopBits - number of stop bits
parity - parity type
Throws:
java.io.IOException - failure to set data characteristics

setFlowControl

public void setFlowControl(FTD2XXFlowControl flowControl)
                    throws java.io.IOException
Set the flow control mode. Xon and Xoff values are reset to null.

Parameters:
flowControl - flow control mode
Throws:
java.io.IOException - failure to set mode

setFlowControl

public void setFlowControl(FTD2XXFlowControl flowControl,
                           char xon,
                           char xoff)
                    throws java.io.IOException
Set the flow control mode specifying Xon and Xoff values.

Parameters:
flowControl - flow control mode
xon - Xon value
xoff - Xoff value
Throws:
java.io.IOException - failure to set mode

reset

public void reset()
           throws java.io.IOException
Reset the device. This is not equivalent to unplugging and replugging the device. It is only a soft reset.

Throws:
java.io.IOException - failure to reset

getNumberOfDevices

public static int getNumberOfDevices()
                              throws java.io.IOException
Get the number of devices connected.

Returns:
number of devices connected
Throws:
java.io.IOException - failure to get number of devices

getDeviceInfoList

public static FTD2XXDeviceInfo[] getDeviceInfoList()
                                            throws java.io.IOException
Get a listing of devices and information about their current state.

Returns:
device listing
Throws:
java.io.IOException - failure to get listing


Copyright © 2006 Ionetrics Corp. All Rights Reserved.