Package com.ftdi

Class FTDevice

java.lang.Object
com.ftdi.FTDevice

public class FTDevice extends Object
Java class to communicate easily to a FTDI device.
Author:
Peter Kocsis invalid input: '<'p. kocsis. 2. 7182 at gmail.com>
  • Method Details

    • getDevDescription

      public String getDevDescription()
      Get device description.
      Returns:
      device description
    • getDevID

      public int getDevID()
      Get device ID.
      Returns:
      device ID
    • getDevSerialNumber

      public String getDevSerialNumber()
      Get device serial number.
      Returns:
      device serial number
    • getDevType

      public DeviceType getDevType()
      Get device type.
      Returns:
      device type.
    • getDevLocationID

      public int getDevLocationID()
      Get device location.
      Returns:
      device location.
    • getFlag

      public int getFlag()
      Get device flag.
      Returns:
      flag.
    • isInUse

      public boolean isInUse()
      determines if the device is in use by anybody
      Returns:
      true if the device is in use by anybody, false otherwise
    • isOpen

      public boolean isOpen()
      determines if the device was opened already
      Returns:
      the open state
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setVidPid

      public static void setVidPid(int dwVID, int dwPID) throws FTD2XXException
      A command to include a custom VID and PID combination within the internal device list table. This will allow the driver to load for the specified VID and PID combination. Only supported on Linux and Mac OS X.
      Parameters:
      dwVID - Device Vendor ID (VID)
      dwPID - Device Product ID (PID)
      Throws:
      FTD2XXException - If something goes wrong.
    • getDevices

      public static List<FTDevice> getDevices() throws FTD2XXException
      Get the connected FTDI devices. It will not contain opened devices.
      Returns:
      List contain available FTDI devices.
      Throws:
      FTD2XXException - If something goes wrong.
    • getDevices

      public static List<FTDevice> getDevices(boolean isIncludeOpenedDevices) throws FTD2XXException
      Get the connected FTDI devices.
      Parameters:
      isIncludeOpenedDevices - Would you like to see opened devices?
      Returns:
      List contain available FTDI devices.
      Throws:
      FTD2XXException - If something goes wrong.
    • getDevicesByDescription

      public static List<FTDevice> getDevicesByDescription(String description) throws FTD2XXException
      Get the connected FTDI devices. It will not contain opened devices.
      Parameters:
      description - Filtering option, exact match need.
      Returns:
      List contain available FTDI devices.
      Throws:
      FTD2XXException - If something goes wrong.
    • getDevicesBySerialNumber

      public static List<FTDevice> getDevicesBySerialNumber(String serialNumber) throws FTD2XXException
      Get the connected FTDI devices. It will not contain opened devices.
      Parameters:
      serialNumber - Filtering option, exact match need.
      Returns:
      List contain available FTDI devices.
      Throws:
      FTD2XXException - If something goes wrong.
    • getDevicesByDeviceType

      public static List<FTDevice> getDevicesByDeviceType(DeviceType deviceType) throws FTD2XXException
      Get the connected FTDI devices. It will not contain opened devices.
      Parameters:
      deviceType - Filtering option.
      Returns:
      List contain available FTDI devices.
      Throws:
      FTD2XXException - If something goes wrong.
    • open

      public void open() throws FTD2XXException
      Open connection with device.
      Throws:
      FTD2XXException - If something goes wrong.
    • close

      public void close() throws FTD2XXException
      Close connection with device.
      Throws:
      FTD2XXException - If something goes wrong.
    • cyclePort

      public void cyclePort() throws FTD2XXException
      Send a cycle command to the USB port.
      Throws:
      FTD2XXException - If something goes wrong.
    • setBaudRate

      public void setBaudRate(long baudRate) throws FTD2XXException
      Set desired baud rate.
      Parameters:
      baudRate - The baud rate.
      Throws:
      FTD2XXException - If something goes wrong.
    • setDivisor

      public void setDivisor(int divisor) throws FTD2XXException
      Set device divisor. This function also sets the baud rate for the device. It is used to set non-standard baud rates.
      Parameters:
      divisor - The divisor.
      Throws:
      FTD2XXException - If something goes wrong.
    • setDataCharacteristics

      public void setDataCharacteristics(WordLength wordLength, StopBits stopBits, Parity parity) throws FTD2XXException
      This function sets the data characteristics for the device
      Parameters:
      wordLength - Number of bits per word
      stopBits - Number of stop bits
      parity - Parity
      Throws:
      FTD2XXException - If something goes wrong.
    • setTimeouts

      public void setTimeouts(long readTimeout, long writeTimeout) throws FTD2XXException
      Set the read and write timeouts for the device.
      Parameters:
      readTimeout - Read timeout in milliseconds.
      writeTimeout - Write timeout in milliseconds.
      Throws:
      FTD2XXException - If something goes wrong.
    • setFlowControl

      public void setFlowControl(FlowControl flowControl) throws FTD2XXException
      Sets the flow control for the device.
      Parameters:
      flowControl - Flow control type.
      Throws:
      FTD2XXException - If something goes wrong.
    • setFlowControl

      public void setFlowControl(FlowControl flowControl, byte uXon, byte uXoff) throws FTD2XXException
      Sets the flow control for the device.
      Parameters:
      flowControl - Flow control type.
      uXon - Character used to signal Xon. Only used if flow control is FT_FLOW_XON_XOFF
      uXoff - Character used to signal Xoff. Only used if flow control is FT_FLOW_XON_XOFF
      Throws:
      FTD2XXException - If something goes wrong.
    • setDtr

      public void setDtr(boolean status) throws FTD2XXException
      Set the Data Terminal Ready (DTR) control signal.
      Parameters:
      status - Status of DTR signal.
      Throws:
      FTD2XXException - If something goes wrong.
    • setRts

      public void setRts(boolean status) throws FTD2XXException
      Set the Request To Send (RTS) control signal
      Parameters:
      status - Status of RTS signal.
      Throws:
      FTD2XXException - If something goes wrong.
    • getDeviceStatus

      public EnumSet<DeviceStatus> getDeviceStatus() throws FTD2XXException
      Gets the modem status and line status from the device.
      Returns:
      Modem and line statuses
      Throws:
      FTD2XXException - If something goes wrong.
    • getQueueStatus

      public int getQueueStatus() throws FTD2XXException
      Gets the number of bytes in the receive queue.
      Returns:
      The number of bytes in the receive queue
      Throws:
      FTD2XXException - If something goes wrong.
    • getStatus

      public int[] getStatus() throws FTD2XXException
      Gets the modem status and line status from the device.
      Returns:
      array with amountInRxQueue, amountInTxQueue and eventStatus
      Throws:
      FTD2XXException - If something goes wrong.
    • getComPortNumber

      public int getComPortNumber() throws FTD2XXException
      Gets the com port number of the device.
      Returns:
      The com port number
      Throws:
      FTD2XXException - If something goes wrong.
    • SetEventNotification

      public void SetEventNotification(com.sun.jna.Pointer eventHandler, int eventMask) throws FTD2XXException
      Set the event notification handler.
      Parameters:
      eventHandler - The event handler
      eventMask - the event mask, e.g. FTD2XX.NotificationEvents.FT_EVENT_RXCHAR | FTD2XX.NotificationEvents.FT_EVENT_MODEM_STATUS
      Throws:
      FTD2XXException - If something goes wrong.
    • purgeBuffer

      public void purgeBuffer(boolean rxBuffer, boolean txBuffer) throws FTD2XXException
      Purge receive or transmit buffers in the device.
      Parameters:
      rxBuffer - Will rxBuffer be purged?
      txBuffer - Will txBuffer be purged?
      Throws:
      FTD2XXException - If something goes wrong.
    • resetDevice

      public void resetDevice() throws FTD2XXException
      Send a reset command to the device.
      Throws:
      FTD2XXException - If something goes wrong.
    • setLatencyTimer

      public void setLatencyTimer(short timer) throws FTD2XXException, IllegalArgumentException
      Set the latency timer value.
      Parameters:
      timer - Latency timer value in milliseconds. Valid range is 2 - 255.
      Throws:
      FTD2XXException - If something goes wrong.
      IllegalArgumentException - If timer was not in range 2 - 255.
    • getLatencyTimer

      public short getLatencyTimer() throws FTD2XXException
      Get the current value of the latency timer.
      Returns:
      latency timer value.
      Throws:
      FTD2XXException - If something goes wrong.
    • setBitMode

      public void setBitMode(byte ucMask, BitModes bitMode) throws FTD2XXException
      Enables different chip modes.
      Parameters:
      ucMask - Required value for bit mode mask. This sets up which bits are inputs and outputs. A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output. In the case of CBUS Bit Bang, the upper nibble of this value controls which pins are inputs and outputs, while the lower nibble controls which of the outputs are high and low.
      bitMode - Mode value.
      Throws:
      FTD2XXException - If something goes wrong.
    • getBitMode

      public BitModes getBitMode() throws FTD2XXException
      Gets the instantaneous value of the data bus.
      Returns:
      instantaneous data bus value
      Throws:
      FTD2XXException - If something goes wrong.
    • getPins

      public byte getPins() throws FTD2XXException
      Gets current state of pins. This function is usefull when CBUS Bit Bang was set
      Returns:
      pin values
      Throws:
      FTD2XXException - If something goes wrong.
    • setChars

      public void setChars(byte uEventChar, byte uEventCharEn, byte uErrorChar, byte uErrorCharEn) throws FTD2XXException
      Set the special characters for the device.
      Parameters:
      uEventChar - event characer.
      uEventCharEn - 0 if event character disabled, non-zero otherwise.
      uErrorChar - error character.
      uErrorCharEn - 0 if error character disabled, non-zero otherwise.
      Throws:
      FTD2XXException - If something goes wrong.
    • setUSBParameters

      public void setUSBParameters(int inTransferSize, int outTransferSize) throws FTD2XXException
      Set the USB request transfer size. This function can be used to change the transfer sizes from the default transfer size of 4096 bytes to better suit the application requirements. Transfer sizes must be set to a multiple of 64 bytes between 64 bytes and 64k bytes. When FT_SetUSBParameters is called, the change comes into effect immediately and any data that was held in the driver at the time of the change is lost. Note that, at present, only dwInTransferSize is supported.
      Parameters:
      inTransferSize - Transfer size for USB IN request
      outTransferSize - Transfer size for USB OUT request
      Throws:
      FTD2XXException - If something goes wrong.
    • writeEEPROM

      public void writeEEPROM(EEPROMData programData) throws FTD2XXException
      Program the EEPROM data
      Parameters:
      programData - EEPROM to program
      Throws:
      FTD2XXException - If something goes wrong.
    • readEEPROM

      public EEPROMData readEEPROM() throws FTD2XXException
      Read device EEPROM data
      Returns:
      EEPROM data
      Throws:
      FTD2XXException - If something goes wrong.
    • readEEPROM_X

      public EepromX readEEPROM_X() throws FTD2XXException
      Read X series device EEPROM data Check D2xx Programmer's Guide Appendix A for details
      Returns:
      FT_EEPROM_X_SERIES data
      Throws:
      FTD2XXException - If something goes wrong.
    • writeEEPROM_X

      public void writeEEPROM_X(EepromX eeprom) throws FTD2XXException
      Write X series device EEPROM data Check D2xx Programmer's Guide Appendix A for details
      Parameters:
      eeprom - data
      Throws:
      FTD2XXException - If something goes wrong.
    • getEEPROMUserAreaSize

      public int getEEPROMUserAreaSize() throws FTD2XXException
      Get the available size of the EEPROM user area
      Returns:
      available size in bytes, of the EEPROM user area
      Throws:
      FTD2XXException - If something goes wrong.
    • readEEPROMUserArea

      public byte[] readEEPROMUserArea(int numberOfBytes) throws FTD2XXException
      Read the contents of the EEPROM user area
      Parameters:
      numberOfBytes - Size in bytes, to be read
      Returns:
      User EEPROM content
      Throws:
      FTD2XXException - If something goes wrong.
    • readFullEEPROMUserArea

      public byte[] readFullEEPROMUserArea() throws FTD2XXException
      Read all contents of the EEPROM user area
      Returns:
      User EEPROM content
      Throws:
      FTD2XXException - If something goes wrong.
    • readFullEEPROMUserAreaAsString

      public String readFullEEPROMUserAreaAsString() throws IOException
      Read all contents of the EEPROM user area as String
      Returns:
      User EEPROM content as String
      Throws:
      FTD2XXException - If something goes wrong.
      IOException
    • writeEEPROMUserArea

      public void writeEEPROMUserArea(byte[] data) throws FTD2XXException
      Write data into the EEPROM user area
      Parameters:
      data - byte[] to write
      Throws:
      FTD2XXException - If something goes wrong.
    • writeEEPROMUserArea

      public void writeEEPROMUserArea(String data) throws FTD2XXException
      Write string into the EEPROM user area
      Parameters:
      data - byte[] to write
      Throws:
      FTD2XXException - If something goes wrong.
    • setBreakOn

      public void setBreakOn() throws FTD2XXException
      Sets the BREAK condition for the device.
      Throws:
      FTD2XXException - If something goes wrong.
    • setBreakOff

      public void setBreakOff() throws FTD2XXException
      Resets the BREAK condition for the device.
      Throws:
      FTD2XXException - If something goes wrong.
    • write

      public int write(byte[] bytes, int offset, int length) throws FTD2XXException
      Write bytes to device.
      Parameters:
      bytes - Byte array to send
      offset - Start index
      length - Amount of bytes to write
      Returns:
      Number of bytes actually written
      Throws:
      FTD2XXException - If something goes wrong.
    • write

      public int write(byte[] bytes) throws FTD2XXException
      Write bytes to device.
      Parameters:
      bytes - Byte array to send
      Returns:
      Number of bytes actually written
      Throws:
      FTD2XXException - If something goes wrong.
    • write

      public boolean write(int b) throws FTD2XXException
      Write byte to device.
      Parameters:
      b - Byte to send (0..255)
      Returns:
      It was success?
      Throws:
      FTD2XXException
    • read

      public int read(byte[] bytes, int offset, int lenght) throws FTD2XXException
      Read bytes from device.
      Parameters:
      bytes - Bytes array to store read bytes
      offset - Start index.
      lenght - Amount of bytes to read
      Returns:
      Number of bytes actually read
      Throws:
      FTD2XXException - If something goes wrong.
    • read

      public int read(byte[] bytes) throws FTD2XXException
      Read bytes from device.
      Parameters:
      bytes - Bytes array to store read bytes
      Returns:
      Number of bytes actually read
      Throws:
      FTD2XXException - If something goes wrong.
    • read

      public int read() throws FTD2XXException
      Read a byte from device.
      Returns:
      The byte what read or -1;
      Throws:
      FTD2XXException
    • read

      public byte[] read(int number) throws FTD2XXException
      Read given bytes from device.
      Parameters:
      number - How many bytes do you want to read?
      Returns:
      Read bytes
      Throws:
      FTD2XXException - If something goes wrong.
    • getInputStream

      public InputStream getInputStream()
      Get an InputStream to device.
      Returns:
      InputStream
    • getOutputStream

      public OutputStream getOutputStream()
      Get an OutputStream to device.
      Returns:
      OutputStream
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable