Package com.ftdi
Class FTDevice
java.lang.Object
com.ftdi.FTDevice
Java class to communicate easily to a FTDI device.
- Author:
- Peter Kocsis invalid input: '<'p. kocsis. 2. 7182 at gmail.com>
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close connection with device.voidSend a cycle command to the USB port.booleanprotected voidfinalize()Gets the instantaneous value of the data bus.intGets the com port number of the device.Get device description.Get the connected FTDI devices.getDevices(boolean isIncludeOpenedDevices) Get the connected FTDI devices.getDevicesByDescription(String description) Get the connected FTDI devices.getDevicesByDeviceType(DeviceType deviceType) Get the connected FTDI devices.getDevicesBySerialNumber(String serialNumber) Get the connected FTDI devices.Gets the modem status and line status from the device.intgetDevID()Get device ID.intGet device location.Get device serial number.Get device type.intGet the available size of the EEPROM user areaintgetFlag()Get device flag.Get an InputStream to device.shortGet the current value of the latency timer.Get an OutputStream to device.bytegetPins()Gets current state of pins.intGets the number of bytes in the receive queue.int[]Gets the modem status and line status from the device.inthashCode()booleanisInUse()determines if the device is in use by anybodybooleanisOpen()determines if the device was opened alreadyvoidopen()Open connection with device.voidpurgeBuffer(boolean rxBuffer, boolean txBuffer) Purge receive or transmit buffers in the device.intread()Read a byte from device.intread(byte[] bytes) Read bytes from device.intread(byte[] bytes, int offset, int lenght) Read bytes from device.byte[]read(int number) Read given bytes from device.Read device EEPROM dataRead X series device EEPROM data Check D2xx Programmer's Guide Appendix A for detailsbyte[]readEEPROMUserArea(int numberOfBytes) Read the contents of the EEPROM user areabyte[]Read all contents of the EEPROM user areaRead all contents of the EEPROM user area as StringvoidSend a reset command to the device.voidsetBaudRate(long baudRate) Set desired baud rate.voidsetBitMode(byte ucMask, BitModes bitMode) Enables different chip modes.voidResets the BREAK condition for the device.voidSets the BREAK condition for the device.voidsetChars(byte uEventChar, byte uEventCharEn, byte uErrorChar, byte uErrorCharEn) Set the special characters for the device.voidsetDataCharacteristics(WordLength wordLength, StopBits stopBits, Parity parity) This function sets the data characteristics for the devicevoidsetDivisor(int divisor) Set device divisor.voidsetDtr(boolean status) Set the Data Terminal Ready (DTR) control signal.voidSetEventNotification(com.sun.jna.Pointer eventHandler, int eventMask) Set the event notification handler.voidsetFlowControl(FlowControl flowControl) Sets the flow control for the device.voidsetFlowControl(FlowControl flowControl, byte uXon, byte uXoff) Sets the flow control for the device.voidsetLatencyTimer(short timer) Set the latency timer value.voidsetRts(boolean status) Set the Request To Send (RTS) control signalvoidsetTimeouts(long readTimeout, long writeTimeout) Set the read and write timeouts for the device.voidsetUSBParameters(int inTransferSize, int outTransferSize) Set the USB request transfer size.static voidsetVidPid(int dwVID, int dwPID) A command to include a custom VID and PID combination within the internal device list table.toString()intwrite(byte[] bytes) Write bytes to device.intwrite(byte[] bytes, int offset, int length) Write bytes to device.booleanwrite(int b) Write byte to device.voidwriteEEPROM(EEPROMData programData) Program the EEPROM datavoidwriteEEPROM_X(EepromX eeprom) Write X series device EEPROM data Check D2xx Programmer's Guide Appendix A for detailsvoidwriteEEPROMUserArea(byte[] data) Write data into the EEPROM user areavoidwriteEEPROMUserArea(String data) Write string into the EEPROM user area
-
Method Details
-
getDevDescription
Get device description.- Returns:
- device description
-
getDevID
public int getDevID()Get device ID.- Returns:
- device ID
-
getDevSerialNumber
Get device serial number.- Returns:
- device serial number
-
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:
trueif the device is in use by anybody,falseotherwise
-
isOpen
public boolean isOpen()determines if the device was opened already- Returns:
- the open state
-
equals
-
hashCode
public int hashCode() -
toString
-
setVidPid
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
Get the connected FTDI devices. It will not contain opened devices.- Returns:
- List contain available FTDI devices.
- Throws:
FTD2XXException- If something goes wrong.
-
getDevices
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
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
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
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
Open connection with device.- Throws:
FTD2XXException- If something goes wrong.
-
close
Close connection with device.- Throws:
FTD2XXException- If something goes wrong.
-
cyclePort
Send a cycle command to the USB port.- Throws:
FTD2XXException- If something goes wrong.
-
setBaudRate
Set desired baud rate.- Parameters:
baudRate- The baud rate.- Throws:
FTD2XXException- If something goes wrong.
-
setDivisor
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 wordstopBits- Number of stop bitsparity- Parity- Throws:
FTD2XXException- If something goes wrong.
-
setTimeouts
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
Sets the flow control for the device.- Parameters:
flowControl- Flow control type.- Throws:
FTD2XXException- If something goes wrong.
-
setFlowControl
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_XOFFuXoff- Character used to signal Xoff. Only used if flow control is FT_FLOW_XON_XOFF- Throws:
FTD2XXException- If something goes wrong.
-
setDtr
Set the Data Terminal Ready (DTR) control signal.- Parameters:
status- Status of DTR signal.- Throws:
FTD2XXException- If something goes wrong.
-
setRts
Set the Request To Send (RTS) control signal- Parameters:
status- Status of RTS signal.- Throws:
FTD2XXException- If something goes wrong.
-
getDeviceStatus
Gets the modem status and line status from the device.- Returns:
- Modem and line statuses
- Throws:
FTD2XXException- If something goes wrong.
-
getQueueStatus
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
Gets the modem status and line status from the device.- Returns:
- array with amountInRxQueue, amountInTxQueue and eventStatus
- Throws:
FTD2XXException- If something goes wrong.
-
getComPortNumber
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 handlereventMask- the event mask, e.g. FTD2XX.NotificationEvents.FT_EVENT_RXCHAR | FTD2XX.NotificationEvents.FT_EVENT_MODEM_STATUS- Throws:
FTD2XXException- If something goes wrong.
-
purgeBuffer
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
Send a reset command to the device.- Throws:
FTD2XXException- If something goes wrong.
-
setLatencyTimer
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
Get the current value of the latency timer.- Returns:
- latency timer value.
- Throws:
FTD2XXException- If something goes wrong.
-
setBitMode
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
Gets the instantaneous value of the data bus.- Returns:
- instantaneous data bus value
- Throws:
FTD2XXException- If something goes wrong.
-
getPins
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
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 requestoutTransferSize- Transfer size for USB OUT request- Throws:
FTD2XXException- If something goes wrong.
-
writeEEPROM
Program the EEPROM data- Parameters:
programData- EEPROM to program- Throws:
FTD2XXException- If something goes wrong.
-
readEEPROM
Read device EEPROM data- Returns:
- EEPROM data
- Throws:
FTD2XXException- If something goes wrong.
-
readEEPROM_X
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
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
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
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
Read all contents of the EEPROM user area- Returns:
- User EEPROM content
- Throws:
FTD2XXException- If something goes wrong.
-
readFullEEPROMUserAreaAsString
Read all contents of the EEPROM user area as String- Returns:
- User EEPROM content as String
- Throws:
FTD2XXException- If something goes wrong.IOException
-
writeEEPROMUserArea
Write data into the EEPROM user area- Parameters:
data- byte[] to write- Throws:
FTD2XXException- If something goes wrong.
-
writeEEPROMUserArea
Write string into the EEPROM user area- Parameters:
data- byte[] to write- Throws:
FTD2XXException- If something goes wrong.
-
setBreakOn
Sets the BREAK condition for the device.- Throws:
FTD2XXException- If something goes wrong.
-
setBreakOff
Resets the BREAK condition for the device.- Throws:
FTD2XXException- If something goes wrong.
-
write
Write bytes to device.- Parameters:
bytes- Byte array to sendoffset- Start indexlength- Amount of bytes to write- Returns:
- Number of bytes actually written
- Throws:
FTD2XXException- If something goes wrong.
-
write
Write bytes to device.- Parameters:
bytes- Byte array to send- Returns:
- Number of bytes actually written
- Throws:
FTD2XXException- If something goes wrong.
-
write
Write byte to device.- Parameters:
b- Byte to send (0..255)- Returns:
- It was success?
- Throws:
FTD2XXException
-
read
Read bytes from device.- Parameters:
bytes- Bytes array to store read bytesoffset- Start index.lenght- Amount of bytes to read- Returns:
- Number of bytes actually read
- Throws:
FTD2XXException- If something goes wrong.
-
read
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
Read a byte from device.- Returns:
- The byte what read or -1;
- Throws:
FTD2XXException
-
read
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
Get an InputStream to device.- Returns:
- InputStream
-
getOutputStream
Get an OutputStream to device.- Returns:
- OutputStream
-
finalize
-