Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes
mrpt::comms::CInterfaceFTDI Class Referenceabstract

Detailed Description

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:

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:

See also
CStream

Definition at line 75 of file CInterfaceFTDI.h.

#include <mrpt/comms/CInterfaceFTDI.h>

Inheritance diagram for mrpt::comms::CInterfaceFTDI:
Inheritance graph

Public Types

enum  TSeekOrigin { sFromBeginning = 0, sFromCurrent = 1, sFromEnd = 2 }
 Used in CStream::Seek. More...
 

Public Member Functions

 CInterfaceFTDI ()
 Constructor, which loads driver interface (the DLL under Windows). More...
 
virtual ~CInterfaceFTDI ()
 Destructor, which closes the connection with the chip and unloads the driver interface. More...
 
 CInterfaceFTDI (const CInterfaceFTDI &o)=delete
 This object cannot be copied. More...
 
CInterfaceFTDIoperator= (const CInterfaceFTDI &o)=delete
 This object cannot be copied. More...
 
bool isOpen ()
 Checks whether the chip has been successfully open. More...
 
void OpenBySerialNumber (const std::string &serialNumber)
 Open by device serial number. More...
 
void OpenByDescription (const std::string &description)
 Open by device description. More...
 
void Close ()
 Close the USB device. More...
 
void ResetDevice ()
 Reset the USB device. More...
 
void Purge ()
 Purge the I/O buffers. More...
 
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. More...
 
void SetTimeouts (unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
 Change read & write timeouts, in milliseconds. More...
 
void ListAllDevices (TFTDIDeviceList &outList)
 Generates a list with all FTDI devices connected right now. More...
 
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. More...
 
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. More...
 
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). More...
 
size_t Read (void *Buffer, size_t Count)
 Introduces a pure virtual method responsible for reading from the stream. More...
 
size_t Write (const void *Buffer, size_t Count)
 Introduces a pure virtual method responsible for writing to the stream. More...
 
uint64_t Seek (int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)
 This virtual method does nothing in this class. More...
 
uint64_t getTotalBytesCount () const
 This virtual method does nothing in this class. More...
 
uint64_t getPosition () const
 This virtual method does nothing in this class. More...
 
virtual uint64_t Seek (int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)=0
 Introduces a pure virtual method for moving to a specified position in the streamed resource. More...
 
virtual int printf (const char *fmt,...) MRPT_printf_format_check(2
 Writes a string to the stream in a textual form. More...
 
template<typename CONTAINER_TYPE >
virtual int void printf_vector (const char *fmt, const CONTAINER_TYPE &V, char separator=',')
 Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T. More...
 
bool getline (std::string &out_str)
 Reads from the stream until a '
' character is found ('\r' characters are ignored). More...
 

Protected Member Functions

void ftdi_read (void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytesRead)
 
void ftdi_write (const void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytes)
 

Protected Attributes

mrpt::containers::circular_buffer< uint8_tm_readBuffer
 Used in Read. More...
 

Private Types

enum  FT_STATUS { dummy }
 
typedef FT_STATUS(__stdcall * PtrToOpen) (void *, unsigned long *)
 
typedef FT_STATUS(__stdcall * PtrToOpenEx) (void *, unsigned long, unsigned long *)
 
typedef FT_STATUS(__stdcall * PtrToListDevices) (void *, void *, unsigned long)
 
typedef FT_STATUS(__stdcall * PtrToClose) (unsigned long)
 
typedef FT_STATUS(__stdcall * PtrToRead) (unsigned long, void *, unsigned long, unsigned long *)
 
typedef FT_STATUS(__stdcall * PtrToWrite) (unsigned long, const void *, unsigned long, unsigned long *)
 
typedef FT_STATUS(__stdcall * PtrToResetDevice) (unsigned long)
 
typedef FT_STATUS(__stdcall * PtrToPurge) (unsigned long, unsigned long)
 
typedef FT_STATUS(__stdcall * PtrToSetTimeouts) (unsigned long, unsigned long, unsigned long)
 
typedef FT_STATUS(__stdcall * PtrToGetQueueStatus) (unsigned long, unsigned long *)
 
typedef FT_STATUS(__stdcall * PtrToSetLatencyTimer) (unsigned long, unsigned char)
 

Private Member Functions

void checkErrorAndRaise (int errorCode)
 
void ftdi_open (void *pvDevice)
 
void ftdi_openEx (void *pArg1, unsigned long dwFlags)
 
void ftdi_listDevices (void *pArg1, void *pArg2, unsigned long dwFlags)
 
void ftdi_getQueueStatus (unsigned long *lpdwAmountInRxQueue)
 
void loadDriver ()
 

Private Attributes

voidm_hmodule
 
unsigned long m_ftHandle
 
PtrToOpen m_pOpen
 
PtrToOpenEx m_pOpenEx
 
PtrToListDevices m_pListDevices
 
PtrToClose m_pClose
 
PtrToRead m_pRead
 
PtrToWrite m_pWrite
 
PtrToResetDevice m_pResetDevice
 
PtrToPurge m_pPurge
 
PtrToSetTimeouts m_pSetTimeouts
 
PtrToGetQueueStatus m_pGetQueueStatus
 
PtrToSetLatencyTimer m_pSetLatencyTimer
 

Member Typedef Documentation

◆ PtrToClose

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToClose) (unsigned long)
private

Definition at line 211 of file CInterfaceFTDI.h.

◆ PtrToGetQueueStatus

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToGetQueueStatus) (unsigned long, unsigned long *)
private

Definition at line 232 of file CInterfaceFTDI.h.

◆ PtrToListDevices

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToListDevices) (void *, void *, unsigned long)
private

Definition at line 208 of file CInterfaceFTDI.h.

◆ PtrToOpen

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToOpen) (void *, unsigned long *)
private

Definition at line 201 of file CInterfaceFTDI.h.

◆ PtrToOpenEx

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToOpenEx) (void *, unsigned long, unsigned long *)
private

Definition at line 204 of file CInterfaceFTDI.h.

◆ PtrToPurge

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToPurge) (unsigned long, unsigned long)
private

Definition at line 225 of file CInterfaceFTDI.h.

◆ PtrToRead

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToRead) (unsigned long, void *, unsigned long, unsigned long *)
private

Definition at line 214 of file CInterfaceFTDI.h.

◆ PtrToResetDevice

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToResetDevice) (unsigned long)
private

Definition at line 222 of file CInterfaceFTDI.h.

◆ PtrToSetLatencyTimer

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToSetLatencyTimer) (unsigned long, unsigned char)
private

Definition at line 236 of file CInterfaceFTDI.h.

◆ PtrToSetTimeouts

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToSetTimeouts) (unsigned long, unsigned long, unsigned long)
private

Definition at line 228 of file CInterfaceFTDI.h.

◆ PtrToWrite

typedef FT_STATUS(__stdcall* mrpt::comms::CInterfaceFTDI::PtrToWrite) (unsigned long, const void *, unsigned long, unsigned long *)
private

Definition at line 218 of file CInterfaceFTDI.h.

Member Enumeration Documentation

◆ FT_STATUS

Enumerator
dummy 

Definition at line 199 of file CInterfaceFTDI.h.

◆ TSeekOrigin

Used in CStream::Seek.

Enumerator
sFromBeginning 
sFromCurrent 
sFromEnd 

Definition at line 34 of file io/CStream.h.

Constructor & Destructor Documentation

◆ CInterfaceFTDI() [1/2]

CInterfaceFTDI::CInterfaceFTDI ( )

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

Definition at line 153 of file CInterfaceFTDI_WIN.cpp.

References loadDriver(), m_ftHandle, MRPT_END, and MRPT_START.

◆ ~CInterfaceFTDI()

CInterfaceFTDI::~CInterfaceFTDI ( )
virtual

Destructor, which closes the connection with the chip and unloads the driver interface.

Definition at line 166 of file CInterfaceFTDI_WIN.cpp.

References Close(), and m_hmodule.

◆ CInterfaceFTDI() [2/2]

mrpt::comms::CInterfaceFTDI::CInterfaceFTDI ( const CInterfaceFTDI o)
delete

This object cannot be copied.

Member Function Documentation

◆ checkErrorAndRaise()

void CInterfaceFTDI::checkErrorAndRaise ( int  errorCode)
private

Possible responses from the driver enum FT_STATUS { FT_OK = 0, FT_INVALID_HANDLE, FT_DEVICE_NOT_FOUND, FT_DEVICE_NOT_OPENED, FT_IO_ERROR, FT_INSUFFICIENT_RESOURCES, FT_INVALID_PARAMETER };

Definition at line 384 of file CInterfaceFTDI_WIN.cpp.

References Close(), and THROW_EXCEPTION.

Referenced by ftdi_getQueueStatus(), ftdi_listDevices(), ftdi_open(), ftdi_openEx(), ftdi_read(), ftdi_write(), Purge(), ResetDevice(), SetLatencyTimer(), and SetTimeouts().

◆ Close()

void CInterfaceFTDI::Close ( )

◆ ftdi_getQueueStatus()

void CInterfaceFTDI::ftdi_getQueueStatus ( unsigned long *  lpdwAmountInRxQueue)
private

◆ ftdi_listDevices()

void CInterfaceFTDI::ftdi_listDevices ( void pArg1,
void pArg2,
unsigned long  dwFlags 
)
private

Definition at line 274 of file CInterfaceFTDI_WIN.cpp.

References ASSERT_, checkErrorAndRaise(), m_pListDevices, MRPT_END, and MRPT_START.

Referenced by ListAllDevices().

◆ ftdi_open()

void CInterfaceFTDI::ftdi_open ( void pvDevice)
private

◆ ftdi_openEx()

void CInterfaceFTDI::ftdi_openEx ( void pArg1,
unsigned long  dwFlags 
)
private

◆ ftdi_read()

void CInterfaceFTDI::ftdi_read ( void lpvBuffer,
unsigned long  dwBuffSize,
unsigned long *  lpdwBytesRead 
)
protected

Definition at line 301 of file CInterfaceFTDI_WIN.cpp.

References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pRead, MRPT_END, and MRPT_START.

Referenced by Read(), and ReadBufferImmediate().

◆ ftdi_write()

void CInterfaceFTDI::ftdi_write ( const void lpvBuffer,
unsigned long  dwBuffSize,
unsigned long *  lpdwBytes 
)
protected

Definition at line 313 of file CInterfaceFTDI_WIN.cpp.

References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pWrite, MRPT_END, and MRPT_START.

Referenced by Write().

◆ getline()

bool CStream::getline ( std::string out_str)
inherited

Reads from the stream until a '
' character is found ('\r' characters are ignored).

Returns
false on EOF or any other read error.

Definition at line 69 of file CStream.cpp.

◆ getPosition()

uint64_t CInterfaceFTDI::getPosition ( ) const
virtual

This virtual method does nothing in this class.

Implements mrpt::io::CStream.

Definition at line 67 of file CInterfaceFTDI_common.cpp.

◆ getTotalBytesCount()

uint64_t CInterfaceFTDI::getTotalBytesCount ( ) const
virtual

This virtual method does nothing in this class.

Implements mrpt::io::CStream.

Definition at line 66 of file CInterfaceFTDI_common.cpp.

◆ isOpen()

bool CInterfaceFTDI::isOpen ( )

◆ ListAllDevices()

void CInterfaceFTDI::ListAllDevices ( TFTDIDeviceList outList)

Generates a list with all FTDI devices connected right now.

Definition at line 242 of file CInterfaceFTDI_WIN.cpp.

References mrpt::comms::TFTDIDevice::ftdi_description, ftdi_listDevices(), mrpt::comms::TFTDIDevice::ftdi_serial, MRPT_END, and MRPT_START.

◆ loadDriver()

void CInterfaceFTDI::loadDriver ( )
private

◆ OpenByDescription()

void CInterfaceFTDI::OpenByDescription ( const std::string description)

◆ OpenBySerialNumber()

void CInterfaceFTDI::OpenBySerialNumber ( const std::string serialNumber)

◆ operator=()

CInterfaceFTDI& mrpt::comms::CInterfaceFTDI::operator= ( const CInterfaceFTDI o)
delete

This object cannot be copied.

◆ printf()

int CStream::printf ( const char *  fmt,
  ... 
)
virtualinherited

Writes a string to the stream in a textual form.

See also
CStdOutStream

Definition at line 30 of file CStream.cpp.

References MRPT_END, MRPT_START, and vsnprintf.

Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), and mrpt::io::CStream::printf_vector().

◆ printf_vector()

template<typename CONTAINER_TYPE >
virtual int void mrpt::io::CStream::printf_vector ( const char *  fmt,
const CONTAINER_TYPE &  V,
char  separator = ',' 
)
inlineinherited

Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T.

Template Parameters
CONTAINER_TYPEcan be any vector<T>, deque<T> or alike.

Definition at line 104 of file io/CStream.h.

References mrpt::io::CStream::printf().

Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel().

◆ Purge()

void CInterfaceFTDI::Purge ( )

◆ Read()

size_t CInterfaceFTDI::Read ( void Buffer,
size_t  Count 
)
virtual

Introduces a pure virtual method responsible for reading from the stream.

It integrates a cache buffer to speed-up sequences of many, small readings.

Implements mrpt::io::CStream.

Definition at line 18 of file CInterfaceFTDI_common.cpp.

References mrpt::containers::circular_buffer< T >::available(), ftdi_read(), m_readBuffer, min, mrpt::containers::circular_buffer< T >::pop_many(), mrpt::containers::circular_buffer< T >::push_many(), and mrpt::containers::circular_buffer< T >::size().

Referenced by ReadSync().

◆ ReadBufferImmediate()

size_t CInterfaceFTDI::ReadBufferImmediate ( void Buffer,
size_t  Count 
)
virtual

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

Exceptions
std::exceptionOn any error, or if ZERO bytes are read.

Reimplemented from mrpt::io::CStream.

Definition at line 68 of file CInterfaceFTDI_common.cpp.

References ftdi_read().

◆ ReadSync()

size_t mrpt::comms::CInterfaceFTDI::ReadSync ( void Buffer,
size_t  Count 
)
inline

Tries to read, raising no exception if not all the bytes are available, but raising one if there is some communication error.

Definition at line 131 of file CInterfaceFTDI.h.

References Read().

Referenced by mrpt::hwdrivers::CSickLaserUSB::waitContinuousSampleFrame().

◆ ResetDevice()

void CInterfaceFTDI::ResetDevice ( )

◆ Seek() [1/2]

uint64_t CInterfaceFTDI::Seek ( int64_t  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
)

This virtual method does nothing in this class.

Definition at line 61 of file CInterfaceFTDI_common.cpp.

◆ Seek() [2/2]

virtual uint64_t mrpt::io::CStream::Seek ( int64_t  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
)
pure virtualinherited

Introduces a pure virtual method for moving to a specified position in the streamed resource.

he Origin parameter indicates how to interpret the Offset parameter. Origin should be one of the following values:

  • sFromBeginning (Default) Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
  • sFromCurrent Offset is from the current position in the resource. Seek moves to Position + Offset.
  • sFromEnd Offset is from the end of the resource. Offset must be <= 0 to indicate a number of bytes before the end of the file.
    Returns
    Seek returns the new value of the Position property.

Implemented in mrpt::io::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CMemoryStream, mrpt::io::CFileOutputStream, mrpt::io::CFileInputStream, mrpt::io::CFileStream, and mrpt::io::CPipeBaseEndPoint.

◆ SetLatencyTimer()

void CInterfaceFTDI::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.

Definition at line 371 of file CInterfaceFTDI_WIN.cpp.

References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pSetLatencyTimer, MRPT_END, and MRPT_START.

Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), and mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected().

◆ SetTimeouts()

void CInterfaceFTDI::SetTimeouts ( unsigned long  dwReadTimeout_ms,
unsigned long  dwWriteTimeout_ms 
)

◆ Write()

size_t CInterfaceFTDI::Write ( const void Buffer,
size_t  Count 
)
virtual

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.

Implements mrpt::io::CStream.

Definition at line 54 of file CInterfaceFTDI_common.cpp.

References ftdi_write().

Referenced by WriteSync().

◆ WriteSync()

size_t mrpt::comms::CInterfaceFTDI::WriteSync ( const void Buffer,
size_t  Count 
)
inline

Tries to write, raising no exception if not all the bytes are available, but raising one if there is some communication error.

Definition at line 135 of file CInterfaceFTDI.h.

References Write().

Member Data Documentation

◆ m_ftHandle

unsigned long mrpt::comms::CInterfaceFTDI::m_ftHandle
private

◆ m_hmodule

void* mrpt::comms::CInterfaceFTDI::m_hmodule
private

Definition at line 194 of file CInterfaceFTDI.h.

Referenced by loadDriver(), and ~CInterfaceFTDI().

◆ m_pClose

PtrToClose mrpt::comms::CInterfaceFTDI::m_pClose
private

Definition at line 212 of file CInterfaceFTDI.h.

Referenced by Close(), and loadDriver().

◆ m_pGetQueueStatus

PtrToGetQueueStatus mrpt::comms::CInterfaceFTDI::m_pGetQueueStatus
private

Definition at line 234 of file CInterfaceFTDI.h.

Referenced by ftdi_getQueueStatus(), and loadDriver().

◆ m_pListDevices

PtrToListDevices mrpt::comms::CInterfaceFTDI::m_pListDevices
private

Definition at line 209 of file CInterfaceFTDI.h.

Referenced by ftdi_listDevices(), and loadDriver().

◆ m_pOpen

PtrToOpen mrpt::comms::CInterfaceFTDI::m_pOpen
private

Definition at line 202 of file CInterfaceFTDI.h.

Referenced by ftdi_open(), and loadDriver().

◆ m_pOpenEx

PtrToOpenEx mrpt::comms::CInterfaceFTDI::m_pOpenEx
private

Definition at line 206 of file CInterfaceFTDI.h.

Referenced by ftdi_openEx(), and loadDriver().

◆ m_pPurge

PtrToPurge mrpt::comms::CInterfaceFTDI::m_pPurge
private

Definition at line 226 of file CInterfaceFTDI.h.

Referenced by loadDriver(), and Purge().

◆ m_pRead

PtrToRead mrpt::comms::CInterfaceFTDI::m_pRead
private

Definition at line 216 of file CInterfaceFTDI.h.

Referenced by ftdi_read(), and loadDriver().

◆ m_pResetDevice

PtrToResetDevice mrpt::comms::CInterfaceFTDI::m_pResetDevice
private

Definition at line 223 of file CInterfaceFTDI.h.

Referenced by loadDriver(), and ResetDevice().

◆ m_pSetLatencyTimer

PtrToSetLatencyTimer mrpt::comms::CInterfaceFTDI::m_pSetLatencyTimer
private

Definition at line 238 of file CInterfaceFTDI.h.

Referenced by loadDriver(), and SetLatencyTimer().

◆ m_pSetTimeouts

PtrToSetTimeouts mrpt::comms::CInterfaceFTDI::m_pSetTimeouts
private

Definition at line 230 of file CInterfaceFTDI.h.

Referenced by loadDriver(), and SetTimeouts().

◆ m_pWrite

PtrToWrite mrpt::comms::CInterfaceFTDI::m_pWrite
private

Definition at line 220 of file CInterfaceFTDI.h.

Referenced by ftdi_write(), and loadDriver().

◆ m_readBuffer

mrpt::containers::circular_buffer<uint8_t> mrpt::comms::CInterfaceFTDI::m_readBuffer
protected

Used in Read.

Definition at line 176 of file CInterfaceFTDI.h.

Referenced by Close(), OpenByDescription(), OpenBySerialNumber(), Purge(), Read(), and ResetDevice().




Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST