class mrpt::comms::CInterfaceFTDI

Overview

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:

CStream

#include <mrpt/comms/CInterfaceFTDI.h>

class CInterfaceFTDI: public mrpt::io::CStream
{
public:
    // construction

    CInterfaceFTDI();
    CInterfaceFTDI(const CInterfaceFTDI& o);

    // methods

    CInterfaceFTDI& operator = (const CInterfaceFTDI& o);
    bool isOpen();
    void OpenBySerialNumber(const std::string& serialNumber);
    void OpenByDescription(const std::string& description);
    void Close();
    void ResetDevice();
    void Purge();
    void SetLatencyTimer(unsigned char latency_ms);
    void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms);
    void ListAllDevices(TFTDIDeviceList& outList);
    size_t ReadSync(void* Buffer, size_t Count);
    size_t WriteSync(const void* Buffer, size_t Count);
    virtual size_t ReadBufferImmediate(void* Buffer, size_t Count);
    virtual size_t Read(void* Buffer, size_t Count);
    virtual size_t Write(const void* Buffer, size_t Count);
    uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning);
    virtual uint64_t getTotalBytesCount() const;
    virtual uint64_t getPosition() const;
};

// direct descendants

class CServoeNeck;

Inherited Members

public:
    // methods

    virtual size_t Read(void* Buffer, size_t Count) = 0;
    virtual size_t Write(const void* Buffer, size_t Count) = 0;
    virtual uint64_t getTotalBytesCount() const = 0;
    virtual uint64_t getPosition() const = 0;

Construction

CInterfaceFTDI()

Constructor, which loads driver interface (the DLL under Windows).

CInterfaceFTDI(const CInterfaceFTDI& o)

This object cannot be copied.

Methods

CInterfaceFTDI& operator = (const CInterfaceFTDI& o)

This object cannot be copied.

bool isOpen()

Checks whether the chip has been successfully open.

See also:

OpenBySerialNumber, OpenByDescription

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.

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.

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)

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().

Parameters:

std::exception

On any error, or if ZERO bytes are read.

virtual size_t Read(void* Buffer, size_t Count)

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)

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)

This virtual method does nothing in this class.

virtual uint64_t getTotalBytesCount() const

This virtual method does nothing in this class.

virtual uint64_t getPosition() const

This virtual method does nothing in this class.