Welcome to ftd2xx’s documentation!

Control FTDI USB chips.

Use ftd2xx.open or ftd2xx.openEx. :example:

with open(0) as device:

device.write(b”Hello World!”)

exception ftd2xx.DeviceError(message)

Exception class for status messages

Initialize self. See help(type(self)) for accurate signature.

Parameters:

message (int | Any)

class ftd2xx.FTD2XX(handle, update=True)

Class for communicating with an FTDI device

Use open or openEx to create an instance of this class.

Create an instance of the FTD2XX class with the given device handle and populate the device info in the instance dictionary.

Parameters:
  • update (bool) – Set False to disable automatic (slow) call to createDeviceInfoList

  • handle (ftd2xx._ftd2xx.FT_HANDLE)

close()

Close the device handle

Return type:

None

clrDtr()

Clear the DTR signal of the FTDI device.

clrRts()

Clear the RTS signal of the FTDI device.

cyclePort()
eeProgram(progdata=None, **kwds)

Program the EEPROM with custom data. If SerialNumber is null, a new serial number is generated from ManufacturerId

Parameters:

progdata (ftd2xx._ftd2xx.ft_program_data | None)

Return type:

None

eeRead()

Get the program information from the EEPROM

Return type:

ftd2xx._ftd2xx.ft_program_data

eeUARead(b_to_read)

Read b_to_read bytes from the EEPROM user area

Parameters:

b_to_read (int)

Return type:

bytes

eeUASize()

Get the EEPROM user area size

Return type:

int

eeUAWrite(data)

Write data to the EEPROM user area. data must be a bytes object with appropriate byte values

Parameters:

data (bytes)

Return type:

None

getBitMode()
Return type:

int

getComPortNumber()

Return a long representing the COM port number

Return type:

int

getDeviceInfo()

Returns a dictionary describing the device.

Return type:

DeviceInfo

getDriverVersion()
Return type:

int

getEventStatus()
getLatencyTimer()
Return type:

int

getModemStatus()

Get the modem status of the FTDI device.

Return type:

ftd2xx.defines.ModemStatus

getQueueStatus()

Get number of bytes in receive queue.

Return type:

int

getStatus()

Return a 3-tuple of rx queue bytes, tx queue bytes and event status

handle
abstract ioctl()

Not implemented

purge(mask=0)

Purge the receive and/or transmit buffers

Parameters:

mask (int)

read(nchars, raw=True)

Read up to nchars bytes of data from the device. Can return fewer if timedout. Use getQueueStatus to find how many bytes are available

Parameters:
  • nchars (int)

  • raw (bool)

Return type:

bytes

resetDevice()

Reset the device

resetPort()
restartInTask()
setBaudRate(baud)

Set the baud rate

Parameters:

baud (int)

Return type:

None

setBitMode(mask, enable)
Parameters:
  • mask (int)

  • enable (int)

setBreakOff()
setBreakOn()
setChars(evch, evch_en, erch, erch_en)

Set the event and error characters for UART

Parameters:
  • evch (int)

  • evch_en (int)

  • erch (int)

  • erch_en (int)

setDataCharacteristics(wordlen, stopbits, parity)

Set the data characteristics for UART

Parameters:
  • wordlen (int)

  • stopbits (int)

  • parity (int)

setDeadmanTimeout(timeout)

Set the deadman timeout in milliseconds

Parameters:

timeout (int)

setDivisor(div)

Set the clock divider. The clock will be set to 6e6/(div + 1).

Parameters:

div (int)

setDtr()

Set the DTR (Data Terminal Ready) signal of the FTDI device.

setEventNotification(evtmask, evthandle)
Parameters:

evtmask (int)

setFlowControl(flowcontrol, xon=-1, xoff=-1)

Set the flow control for UART

Parameters:
  • flowcontrol (int)

  • xon (int)

  • xoff (int)

setLatencyTimer(latency)
Parameters:

latency (int)

setRestPipeRetryCount(count)
setRts()

Set the RTS (Request To Send) signal of the FTDI device.

setTimeouts(read, write)

Set the read and write timeouts in milliseconds

Parameters:
  • read (int)

  • write (int)

setUSBParameters(in_tx_size, out_tx_size=0)

Set the USB request transfer sizes

Parameters:
  • in_tx_size (int)

  • out_tx_size (int)

setWaitMask(mask)
Parameters:

mask (int)

status
stopInTask()
waitOnMask()
write(data)

Send the data to the device. Data must be a string representing the bytes to be sent

Parameters:

data (bytes)

ftd2xx.call_ft(function, *args)

Call an FTDI function and check the status. Raise exception on error

Parameters:

function (Callable)

ftd2xx.createDeviceInfoList()

Create the internal device info list and return number of entries

Return type:

int

ftd2xx.ft_program_data
ftd2xx.getDeviceInfoDetail(devnum=0, update=True)

Get an entry from the internal device info list. Set update to False to avoid a slow call to createDeviceInfoList.

Parameters:
  • devnum (int)

  • update (bool)

Return type:

DeviceInfoDetail

ftd2xx.getLibraryVersion()

Return a long representing library version

Return type:

int

ftd2xx.listDevices(flags=0)

Return a list of serial numbers(default), descriptions or locations (Windows only) of the connected FTDI devices depending on value of flags

Parameters:

flags (int)

Return type:

list[bytes] | None

ftd2xx.open(dev=0, update=True)

Open a handle to a usb device by index and return an FTD2XX instance for it. Set update to False to avoid a slow call to createDeviceInfoList.

Parameters:
  • dev (int) – The device number to open.

  • update (bool) – Set to False to disable automatic call to createDeviceInfoList.

Raises:

DeviceError – If the device cannot be opened.

Returns:

An instance of the FTD2XX class if successful. Use it as a context manager.

Return type:

FTD2XX

Example

with open(0, False) as dev:

dev.write(b”Hello World”)

ftd2xx.openEx(id_str, flags=defines.OPEN_BY_SERIAL_NUMBER, update=True)

Open a handle to a usb device by serial number(default), description or location(Windows only) depending on value of flags and return an FTD2XX instance for it. Set update to False to avoid a slow call to createDeviceInfoList.

Parameters:
  • id_str (bytes) – The ID string from listDevices.

  • flags (int) – Flag (consult D2XX Guide). Defaults to OPEN_BY_SERIAL_NUMBER.

  • update (bool) – Set to False to disable automatic call to createDeviceInfoList.

Raises:

DeviceError – If the device cannot be opened.

Returns:

An instance of the FTD2XX class if successful. Use it as a context manager.

Return type:

FTD2XX

Example

with openEx(b”MyDevice”, update=False) as dev:

dev.write(b”Hello World”)

Contents:

Indices and tables