package module
Version: v0.0.5 Latest Latest

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

Go to latest
Published: May 21, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0




Go binding for libFTDI library http://http://www.intra2net.com/en/developer/libftdi/



This section is empty.


This section is empty.


This section is empty.


type Break

type Break int

Break represents the break mode

const (
	// BreakOff disables the use of a break signal
	BreakOff Break = C.BREAK_OFF
	// BreakOn enables the use of a break signal
	BreakOn Break = C.BREAK_ON

type CBusFunction

type CBusFunction byte
const (
	CBusTxEn CBusFunction = iota

func (CBusFunction) String

func (c CBusFunction) String() string

type Channel

type Channel uint32

Channel represents channel (interface) of FTDI device. Some devices have more than one channel (eg. FT2232 has 2 channels, FT4232 has 4 channels).

const (
	ChannelAny Channel = iota

type ChannelType

type ChannelType byte
const (
	ChannelUART ChannelType = iota

func (ChannelType) String

func (ct ChannelType) String() string

type DataBits

type DataBits int

DataBits represents the number of data bits to expect

const (
	// DataBits7 indicates that 7 data bits are used
	DataBits7 DataBits = C.BITS_7
	// DataBits8 indicates that 8 data bits are used
	DataBits8 DataBits = C.BITS_8

type Device

type Device struct {
	// contains filtered or unexported fields

Device represents FTDI device.

func Open

func Open(vendor, product int, description, serial string, index uint,
	c Channel) (*Device, error)

Open opens the index-th device with a given vendor id, product id, description and serial. Uses specified channel c.

func OpenFirst

func OpenFirst(vendor, product int, c Channel) (*Device, error)

OpenFirst opens the first device with a given vendor and product ids. Uses specified channel c.

func OpenUSBDev

func OpenUSBDev(u *USBDev, c Channel) (*Device, error)

OpenUSBDev opens channel (interface) c of USB device u. u must be FTDI device.

func (*Device) ChipID

func (d *Device) ChipID() (uint32, error)

ChipID reads FTDI Chip-ID (not all devices support this).

func (*Device) Close

func (d *Device) Close() error

Close closes device

func (*Device) EEPROM

func (d *Device) EEPROM() EEPROM

EEPROM returns a handler to the device internal EEPROM subsystem.

func (*Device) LatencyTimer

func (d *Device) LatencyTimer() (int, error)

LatencyTimer returns latency timer value [ms].

func (*Device) Pins

func (d *Device) Pins() (b byte, err error)

Pins returns current state of pins (circumventing the read buffer).

func (*Device) PurgeBuffers

func (d *Device) PurgeBuffers() error

PurgeBuffers clears both (Tx and Rx) buffers.

func (*Device) PurgeReadBuffer

func (d *Device) PurgeReadBuffer() error

PurgeReadBuffer clears Tx buffer (buffer for data that will be sent to USB?).

func (*Device) PurgeWriteBuffer

func (d *Device) PurgeWriteBuffer() error

PurgeWriteBuffer clears Rx buffer (buffer for data received from USB?).

func (*Device) Read

func (d *Device) Read(data []byte) (int, error)

Read reads data from device to data. It returns number of bytes read.

func (*Device) ReadByte

func (d *Device) ReadByte() (byte, error)

ReadByte reads one byte from device.

func (*Device) ReadChunkSize

func (d *Device) ReadChunkSize() (int, error)

ReadChunkSize returns current value of read buffer chunk size.

func (*Device) Reset

func (d *Device) Reset() error

Reset resets device d.

func (*Device) SetBaudrate

func (d *Device) SetBaudrate(br int) error

SetBaudrate sets the rate of data transfer.

For standard USB-UART adapter it sets UART baudrate.

For bitbang mode the clock is actually 16 times the br. From the FTDI documentation for FT232R bitbang mode: "The clock for the Asynchronous Bit Bang mode is actually 16 times the Baud rate. A value of 9600 Baud would transfer the data at (9600x16) = 153600 bytes per second, or 1 every 6.5 μS."

FT232R suports baudrates from 183.1 baud to 3 Mbaud but for real applications it should be <= 1 Mbaud: Actual baudrate is set to discrete value that satisfies the equation br = 3000000 / (n + x) where n can be an integer between 2 and 16384 and x can be a sub-integer of the value 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, or 0.875. When n == 1 then x should be 0, i.e. baud rate divisors with values between 1 and 2 are not possible.

func (*Device) SetBitmode

func (d *Device) SetBitmode(iomask byte, mode Mode) error

SetBitmode sets operation mode for device d to mode. iomask bitmask configures lines corresponding to its bits as input (bit=0) or output (bit=1).

func (*Device) SetDTR

func (d *Device) SetDTR(dtr int) error

SetDTR manually sets the DTR output line from the least significant bit of dtr.

func (*Device) SetDTRRTS

func (d *Device) SetDTRRTS(dtr, rts int) error

SetDTRRTS manually sets the DTR and RTS output lines from the least significant bit of dtr and rts.

func (*Device) SetFlowControl

func (d *Device) SetFlowControl(flowctrl FlowCtrl) error

SetFlowControl sets the flow control parameter

func (*Device) SetLatencyTimer

func (d *Device) SetLatencyTimer(lt int) error

SetLatencyTimer sets latency timer to lt (value beetwen 1 and 255). If FTDI device has fewer data to completely fill one USB packet (<62 B) it waits for lt ms before sending data to USB.

func (*Device) SetLineProperties

func (d *Device) SetLineProperties(bits DataBits, stopbits StopBits, parity Parity) error

SetLineProperties sets the uart data bit count, stop bits count, and parity mode

func (*Device) SetLineProperties2

func (d *Device) SetLineProperties2(bits DataBits, stopbits StopBits, parity Parity, breaks Break) error

SetLineProperties2 sets the uart data bit count, stop bits count, parity mode, and break usage

func (*Device) SetRTS

func (d *Device) SetRTS(rts int) error

SetRTS manually sets the RTS output line from the least significant bit of rts.

func (*Device) SetReadChunkSize

func (d *Device) SetReadChunkSize(cs int) error

SetReadChunkSize configure read chunk size for device (default is 4096B) and size of software buffer dedicated for reading data from device...

func (*Device) SetWriteChunkSize

func (d *Device) SetWriteChunkSize(cs int) error

SetWriteChunkSize configure write chunk size (default is 4096). If more than cs bytes need to be send to device, they will be split to chunks of size cs.

func (*Device) SubmitRead

func (d *Device) SubmitRead(data []byte) (*Transfer, error)

func (*Device) SubmitWrite

func (d *Device) SubmitWrite(data []byte) (*Transfer, error)

func (*Device) Type

func (d *Device) Type() Type

Type returns type of device d.

func (*Device) Write

func (d *Device) Write(data []byte) (int, error)

Write writes data from buf to device. It retruns number of bytes written.

func (*Device) WriteByte

func (d *Device) WriteByte(b byte) error

WriteByte writes one byte to device.

func (*Device) WriteChunkSize

func (d *Device) WriteChunkSize() (int, error)

WriteChunkSize returns current value of write chunk size.

func (*Device) WriteString

func (d *Device) WriteString(s string) (int, error)

WriteString writes bytes from string s to device. It retruns number of bytes written.


type EEPROM struct {
	// contains filtered or unexported fields

func (EEPROM) Build

func (e EEPROM) Build() error

func (EEPROM) CBusFunction

func (e EEPROM) CBusFunction(n int) CBusFunction

func (EEPROM) ChannelDriver

func (e EEPROM) ChannelDriver(c Channel) bool

ChannelDriver returns true if c channel has a driver. c can be from range: ChannelA - ChannelD

func (EEPROM) ChannelRS485

func (e EEPROM) ChannelRS485(c Channel) bool

ChannelDriver returns true if c is RS485 channel. c can be from range: ChannelA - ChannelD

func (EEPROM) ChannelType

func (e EEPROM) ChannelType(c Channel) ChannelType

ChannelType returns type of c channel. c can be: ChannelA, ChannelB

func (EEPROM) ChipSize

func (e EEPROM) ChipSize() int

func (EEPROM) ChipType

func (e EEPROM) ChipType() byte

func (EEPROM) Decode

func (e EEPROM) Decode() error

func (EEPROM) HighCurrent

func (e EEPROM) HighCurrent(c Channel) bool

ChannelDriver returns true if c channel is in high current mode . c can be from range: ChannAny - ChannelD (use ChannAny for TypeR device).

func (EEPROM) Invert

func (e EEPROM) Invert() int

func (EEPROM) IsNotPNP

func (e EEPROM) IsNotPNP() bool

func (EEPROM) IsochronousInp

func (e EEPROM) IsochronousInp() bool

func (EEPROM) IsochronousOut

func (e EEPROM) IsochronousOut() bool

func (EEPROM) MaxPower

func (e EEPROM) MaxPower() int

MaxPower returns maximum power consumption (max. current) from USB in mA

func (EEPROM) ProductId

func (e EEPROM) ProductId() uint16

func (EEPROM) Read

func (e EEPROM) Read() error

func (EEPROM) ReleaseNumber

func (e EEPROM) ReleaseNumber() uint16

func (EEPROM) RemoteWakeup

func (e EEPROM) RemoteWakeup() bool

func (EEPROM) SelfPowered

func (e EEPROM) SelfPowered() bool

func (EEPROM) SetCBusFunction

func (e EEPROM) SetCBusFunction(n int, v CBusFunction)

func (EEPROM) SetChannelDriver

func (e EEPROM) SetChannelDriver(c Channel, v bool)

func (EEPROM) SetChannelRS485

func (e EEPROM) SetChannelRS485(c Channel, v bool)

func (EEPROM) SetChannelType

func (e EEPROM) SetChannelType(c Channel, v ChannelType)

func (EEPROM) SetChipType

func (e EEPROM) SetChipType(v byte)

func (EEPROM) SetHighCurrent

func (e EEPROM) SetHighCurrent(c Channel, v bool)

func (EEPROM) SetInvert

func (e EEPROM) SetInvert(v int)

func (EEPROM) SetIsNotPNP

func (e EEPROM) SetIsNotPNP(v bool)

func (EEPROM) SetIsochronousInp

func (e EEPROM) SetIsochronousInp(v bool)

func (EEPROM) SetIsochronousOut

func (e EEPROM) SetIsochronousOut(v bool)

func (EEPROM) SetMaxPower

func (e EEPROM) SetMaxPower(v int)

SetMaxPower sets maximum power consumption (max. current) from USB in mA

func (EEPROM) SetProductId

func (e EEPROM) SetProductId(v uint16)

func (EEPROM) SetReleaseNumber

func (e EEPROM) SetReleaseNumber(v uint16)

func (EEPROM) SetRemoteWakeup

func (e EEPROM) SetRemoteWakeup(v bool)

func (EEPROM) SetSelfPowered

func (e EEPROM) SetSelfPowered(v bool)

func (EEPROM) SetSuspendDBus7

func (e EEPROM) SetSuspendDBus7(v bool)

func (EEPROM) SetSuspendPullDowns

func (e EEPROM) SetSuspendPullDowns(v bool)

func (EEPROM) SetUSBVersion

func (e EEPROM) SetUSBVersion(v uint16)

func (EEPROM) SetUseSerial

func (e EEPROM) SetUseSerial(v bool)

func (EEPROM) SetUseUSBVersion

func (e EEPROM) SetUseUSBVersion(v bool)

func (EEPROM) SetVendorId

func (e EEPROM) SetVendorId(v uint16)

func (EEPROM) String

func (e EEPROM) String() string

func (EEPROM) SuspendDBus7

func (e EEPROM) SuspendDBus7() bool

func (EEPROM) SuspendPullDowns

func (e EEPROM) SuspendPullDowns() bool

func (EEPROM) USBVersion

func (e EEPROM) USBVersion() uint16

func (EEPROM) UseSerial

func (e EEPROM) UseSerial() bool

func (EEPROM) UseUSBVersion

func (e EEPROM) UseUSBVersion() bool

func (EEPROM) VendorId

func (e EEPROM) VendorId() uint16

func (EEPROM) Write

func (e EEPROM) Write() error

type Error

type Error struct {
	// contains filtered or unexported fields

func (*Error) Code

func (e *Error) Code() int

func (*Error) Error

func (e *Error) Error() string

type FlowCtrl

type FlowCtrl int

FlowCtrl represents the flow control mode.

const (
	// FlowCtrlDisable disables all automatic flow control.
	FlowCtrlDisable FlowCtrl = (1 << iota) >> 1
	// FlowCtrlRTSCTS enables RTS CTS flow control.
	// FlowCtrlDTRDSR enables DTR DSR flow control.
	// FlowCtrlXONXOFF enables XON XOF flow control.

type Mode

type Mode byte

Mode represents operation mode that FTDI device can work.

const (
	ModeReset Mode = (1 << iota) >> 1

type Parity

type Parity int

Parity represents the parity mode

const (
	// ParityNone indicates no parity bit is used
	ParityNone Parity = C.NONE
	// ParityOdd indicates an odd parity bit is used
	ParityOdd Parity = C.ODD
	// ParityEven indicates an even parity bit is used
	ParityEven Parity = C.EVEN
	// ParityMark indicates that the parity bit should be a 1
	ParityMark Parity = C.MARK
	// ParitySpace indicates that the parity bit should be a 0
	ParitySpace Parity = C.SPACE

type StopBits

type StopBits int

StopBits represents the number of stop bits to expect

const (
	// StopBits1 indicates only one stop bit is expected
	StopBits1 StopBits = C.STOP_BIT_1
	// StopBits15 indicates one and a half stop bits are expected
	StopBits15 StopBits = C.STOP_BIT_15
	// StopBits2 indicates two stop bits are expected
	StopBits2 StopBits = C.STOP_BIT_2

type Transfer

type Transfer struct {
	// contains filtered or unexported fields

func (*Transfer) Done

func (t *Transfer) Done() (int, error)

type Type

type Type uint32

Type is numeric type id of FTDI device.

const (
	TypeAM Type = iota

func (Type) String

func (t Type) String() string

String returns text name that describes type id.

type USBDev

type USBDev struct {
	Manufacturer, Description, Serial string
	// contains filtered or unexported fields

func FindAll

func FindAll(vendor, product int) ([]*USBDev, error)

FindAll search for all USB devices with specified vendor and product id. It returns slice od found devices.

func (*USBDev) Close

func (u *USBDev) Close()

type USBError

type USBError int

func (USBError) Error

func (e USBError) Error() string


Path Synopsis
Pin connection between FT232R and LCD (HD44780 compatible): TxD (DBUS0) <--> D4 RxD (DBUS1) <--> D5 RTS# (DBUS2) <--> D6 CTS# (DBUS3) <--> D7 DTR# (DBUS4) <--> E DSR# (DBUS5) <--> R/W# DCD# (DBUS6) <--> RS
Pin connection between FT232R and LCD (HD44780 compatible): TxD (DBUS0) <--> D4 RxD (DBUS1) <--> D5 RTS# (DBUS2) <--> D6 CTS# (DBUS3) <--> D7 DTR# (DBUS4) <--> E DSR# (DBUS5) <--> R/W# DCD# (DBUS6) <--> RS
Pin connection between FT232R and LCD (HD44780 compatible): TxD (DBUS0) <--> D4 RxD (DBUS1) <--> D5 RTS# (DBUS2) <--> D6 CTS# (DBUS3) <--> D7 DTR# (DBUS4) <--> E DSR# (DBUS5) <--> R/W# DCD# (DBUS6) <--> RS
Pin connection between FT232R and LCD (HD44780 compatible): TxD (DBUS0) <--> D4 RxD (DBUS1) <--> D5 RTS# (DBUS2) <--> D6 CTS# (DBUS3) <--> D7 DTR# (DBUS4) <--> E DSR# (DBUS5) <--> R/W# DCD# (DBUS6) <--> RS

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL