ftdi

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BITS_8 bitsPerWord = 8
	BIST_7 bitsPerWord = 7
	STOP_1 stopBits    = 0
	STOP_2 stopBits    = 2
	NONE   parity      = 0
	ODD    parity      = 1
	EVEN   parity      = 2
	MARK   parity      = 3
	SPACE  parity      = 4
)
View Source
const (
	FT_OK                          = 0
	FT_INVALID_HANDLE              = 1
	FT_DEVICE_NOT_FOUND            = 2
	FT_DEVICE_NOT_OPENED           = 3
	FT_IO_ERROR                    = 4
	FT_INSUFFICIENT_RESOURCES      = 5
	FT_INVALID_PARAMETER           = 6
	FT_INVALID_BAUD_RATE           = 7
	FT_DEVICE_NOT_OPENED_FOR_ERASE = 8
	FT_DEVICE_NOT_OPENED_FOR_WRITE = 9
	FT_FAILED_TO_WRITE_DEVICE      = 10
	FT_EEPROM_READ_FAILED          = 11
	FT_EEPROM_WRITE_FAILED         = 12
	FT_EEPROM_ERASE_FAILED         = 13
	FT_EEPROM_NOT_PRESENT          = 14
	FT_EEPROM_NOT_PROGRAMMED       = 15
	FT_INVALID_ARGS                = 16
	FT_NOT_SUPPORTED               = 17
	FT_OTHER_ERROR                 = 18
)

FT_STATUS (DWORD)

View Source
const (
	CHECK_RX_DELAY_MS = 200
)

Variables

View Source
var (
	ErrInvalidHandle           = errors.New("FTDI :: Invalid device handle")
	ErrDeviceNotFound          = errors.New("FTDI :: Device not found")
	ErrDeviceNotOpened         = errors.New("FTDI :: Device not opened")
	ErrIO                      = errors.New("FTDI :: IO failed")
	ErrInsufficientResources   = errors.New("FTDI :: Insufficient resources")
	ErrInvalidParameter        = errors.New("FTDI :: Invalid parameter")
	ErrInvalidBaudRate         = errors.New("FTDI :: Invalid baud rate")
	ErrDeviceNotOpenedForErase = errors.New("FTDI :: Device not opened for erase")
	ErrDeviceNotOpenedForWrite = errors.New("FTDI :: Device not opened for write")
	ErrFailedToWriteDevice     = errors.New("FTDI :: Failed to write device")
	ErrEReadFailed             = errors.New("FTDI :: EEPROM read failed")
	ErrEWriteFailed            = errors.New("FTDI :: EEPROM write failed")
	ErrEEraseFailed            = errors.New("FTDI :: EEPROM erase failed")
	ErrENotPresent             = errors.New("FTDI :: EEPROM not present")
	ErrENotProgrammed          = errors.New("FTDI :: EEPROM not programmed")
	ErrInvalidArgs             = errors.New("FTDI :: Invalid arguments")
	ErrNotSupported            = errors.New("FTDI :: Device not supported")
	ErrOther                   = errors.New("FTDI :: Unknown FTDI error")
)

Functions

func GetLibraryVersion

func GetLibraryVersion() uint32

Return Library version, formatted to match D2XX

func Init

func Init() error

Types

type BitMode

type BitMode byte
const (
	RESET         BitMode = 0x00
	ASYNC_BITBANG BitMode = 0x01
	MPSSE         BitMode = 0x02
	SYNC_BITBANG  BitMode = 0x04
	HOST_EMU      BitMode = 0x08
	FAST_OPTO     BitMode = 0x10
	CBUS_BITBANG  BitMode = 0x20
	SYNCHRONOUS   BitMode = 0x40
)

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device serializes each data direction on its own lock: libftdi's read and write paths touch disjoint context state and libusb allows concurrent transfers, so a reader blocked in its ~latency-timer USB poll doesn't hold up writes (as D2XX on Windows doesn't). Everything else takes both.

func Open

func Open(di DeviceInfo, pid int) (d *Device, e error)

Open opens the FTDI device with di's serial number and product id pid. libftdi detaches the ftdi_sio kernel driver while the device is open (its /dev/ttyUSBn disappears); Close re-attaches it.

func (*Device) Close

func (d *Device) Close() (e error)

func (*Device) GetStatus

func (d *Device) GetStatus() (rx_queue, tx_queue, events int32, e error)

func (*Device) Purge

func (d *Device) Purge(flags PurgeFlag) (e error)

func (*Device) Read

func (d *Device) Read(p []byte) (n int, e error)

func (*Device) Reset

func (d *Device) Reset() (e error)

func (*Device) SetBaudRate

func (d *Device) SetBaudRate(baud uint) (e error)

func (*Device) SetBitMode

func (d *Device) SetBitMode(mode BitMode) (e error)

func (*Device) SetBreakOff

func (d *Device) SetBreakOff(props LineProperties) (e error)

func (*Device) SetBreakOn

func (d *Device) SetBreakOn(props LineProperties) (e error)

func (*Device) SetChars

func (d *Device) SetChars(event, err byte) (e error)

func (*Device) SetFlowControl

func (d *Device) SetFlowControl(f FlowControl) (e error)

func (*Device) SetLatency

func (d *Device) SetLatency(latency int) (e error)

func (*Device) SetLineProperty

func (d *Device) SetLineProperty(props LineProperties) (e error)

func (*Device) SetTimeout

func (d *Device) SetTimeout(read_timeout, write_timeout int) (e error)

func (*Device) SetTransferSize

func (d *Device) SetTransferSize(read_size, write_size int) (e error)

func (*Device) Write

func (d *Device) Write(p []byte) (n int, e error)

type DeviceInfo

type DeviceInfo struct {
	Index        uint64
	ID           uint64 // VID<<16 | PID, as D2XX reports it
	SerialNumber string
	Description  string
	Manufacturer string
}

func GetDeviceList

func GetDeviceList() (dl []DeviceInfo, e error)

GetDeviceList lists the FTDI devices libftdi knows by default PID (0x6001/6010/6011/6014/6015). Devices whose strings can't be read (no permission on the USB node) are skipped rather than failing the scan.

type EventMask

type EventMask uint16
const (
	FT_EVENT_RXCHAR       EventMask = 1
	FT_EVENT_MODEM_STATUS EventMask = 2
	FT_EVENT_LINE_STATUS  EventMask = 4
)

type FlowControl

type FlowControl uint16
const (
	DISABLED FlowControl = 0x0000
	RTS_CTS  FlowControl = 0x0100
	DTR_DSR  FlowControl = 0x0200
	XON_XOFF FlowControl = 0x0400
)

type LineProperties

type LineProperties struct {
	Bits     bitsPerWord
	StopBits stopBits
	Parity   parity
}

type PurgeFlag

type PurgeFlag uint8
const (
	FT_PURGE_RX   PurgeFlag = 0x01
	FT_PURGE_TX   PurgeFlag = 0x02
	FT_PURGE_BOTH PurgeFlag = FT_PURGE_RX | FT_PURGE_TX
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL