Class CInterfaceFTDI
Defined in File CInterfaceFTDI.h
Inheritance Relationships
Base Type
public mrpt::io::CStream
Class Documentation
-
class CInterfaceFTDI : public mrpt::io::CStream
A definition of a CStream actually representing a USB connection to a FTDI chip.
This class implements the communication with FT245BM / FT245RL chips. Using this class makes a program to depend on:
Windows: “FT2XX.DLL” and the device drivers (see FTDI website).
Linux: “libusb.so” (quite standard!), and “libftdi.so” only if linking against the dynamic library.
If there is any error during the communications (or loading the Windows DLL), a std::exception will be raised.
To write bulk data, use CStream::ReadBuffer and CStream::WriteBuffer.
Warning: Avoid defining an object of this class in a global scope if you want to catch all potential exceptions during the constructors (like DLL not found, etc…)
VERSIONS:
11/APR/2005: Initial development. JLBC
16/FEB/2007: Integration into the MRPT framework. Support for device serial numbers. JLBC
15/APR/2008: Implemented for Linux using libftdi. JLBC
See also
Public Functions
-
CInterfaceFTDI()
Constructor, which loads driver interface (the DLL under Windows).
-
~CInterfaceFTDI() override
Destructor, which closes the connection with the chip and unloads the driver interface.
-
CInterfaceFTDI(const CInterfaceFTDI &o) = delete
This object cannot be copied
-
CInterfaceFTDI &operator=(const CInterfaceFTDI &o) = delete
This object cannot be copied
-
bool isOpen()
Checks whether the chip has been successfully open.
See also
-
void OpenBySerialNumber(const std::string &serialNumber)
Open by device serial number
-
void OpenByDescription(const std::string &description)
Open by device description
-
void Close()
Close the USB device
-
void ResetDevice()
Reset the USB device
-
void Purge()
Purge the I/O buffers
-
void SetLatencyTimer(unsigned char latency_ms)
Change the latency timer (in milliseconds) implemented on the FTDI chip: for a few ms, data is not sent to the PC waiting for possible more data, to save USB trafic.
-
void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
Change read & write timeouts, in milliseconds.
-
void ListAllDevices(TFTDIDeviceList &outList)
Generates a list with all FTDI devices connected right now.
-
inline size_t ReadSync(void *Buffer, size_t Count)
Tries to read, raising no exception if not all the bytes are available, but raising one if there is some communication error.
-
inline size_t WriteSync(const void *Buffer, size_t Count)
Tries to write, raising no exception if not all the bytes are available, but raising one if there is some communication error.
-
virtual size_t ReadBufferImmediate(void *Buffer, size_t Count) override
Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read, without waiting for more extra bytes to arrive (just those already enqued in the stream). In this class this method actually behaves as expected and does not fallback to ReadBuffer().
- Throws:
std::exception – On any error, or if ZERO bytes are read.
-
virtual size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream. It integrates a cache buffer to speed-up sequences of many, small readings.
-
virtual size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream. Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
-
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) override
This virtual method does nothing in this class.
-
virtual uint64_t getTotalBytesCount() const override
This virtual method does nothing in this class.
-
virtual uint64_t getPosition() const override
This virtual method does nothing in this class.
Protected Functions
-
void ftdi_read(void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytesRead)
-
void ftdi_write(const void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytes)
-
void recursive_fill_list_devices(void *usb_device_structure, TFTDIDeviceList &outList)
Process recursively a USB device and its children: