MRPT
1.9.9
|
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:
Definition at line 73 of file CInterfaceFTDI.h.
#include <mrpt/comms/CInterfaceFTDI.h>
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... | |
CInterfaceFTDI & | operator= (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 ('' 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_t > | m_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 |
Definition at line 209 of file CInterfaceFTDI.h.
|
private |
Definition at line 230 of file CInterfaceFTDI.h.
|
private |
Definition at line 206 of file CInterfaceFTDI.h.
|
private |
Definition at line 199 of file CInterfaceFTDI.h.
|
private |
Definition at line 202 of file CInterfaceFTDI.h.
|
private |
Definition at line 223 of file CInterfaceFTDI.h.
|
private |
Definition at line 212 of file CInterfaceFTDI.h.
|
private |
Definition at line 220 of file CInterfaceFTDI.h.
|
private |
Definition at line 234 of file CInterfaceFTDI.h.
|
private |
Definition at line 226 of file CInterfaceFTDI.h.
|
private |
Definition at line 216 of file CInterfaceFTDI.h.
|
private |
Enumerator | |
---|---|
dummy |
Definition at line 197 of file CInterfaceFTDI.h.
|
inherited |
Used in CStream::Seek.
Enumerator | |
---|---|
sFromBeginning | |
sFromCurrent | |
sFromEnd |
Definition at line 32 of file io/CStream.h.
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.
|
virtual |
Destructor, which closes the connection with the chip and unloads the driver interface.
Definition at line 166 of file CInterfaceFTDI_WIN.cpp.
|
delete |
This object cannot be copied.
|
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().
void CInterfaceFTDI::Close | ( | ) |
Close the USB device.
Definition at line 285 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, mrpt::containers::circular_buffer< T >::clear(), m_ftHandle, m_pClose, m_readBuffer, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), checkErrorAndRaise(), mrpt::hwdrivers::CServoeNeck::disableServo(), mrpt::hwdrivers::CServoeNeck::enableServo(), ftdi_open(), ftdi_openEx(), mrpt::hwdrivers::CServoeNeck::getRegisterValue(), mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed(), mrpt::hwdrivers::CSickLaserUSB::waitContinuousSampleFrame(), and ~CInterfaceFTDI().
|
private |
Definition at line 361 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pGetQueueStatus, MRPT_END, and MRPT_START.
Definition at line 274 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_pListDevices, MRPT_END, and MRPT_START.
Referenced by ListAllDevices().
Definition at line 217 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), Close(), isOpen(), m_ftHandle, m_pOpen, MRPT_END, and MRPT_START.
Definition at line 228 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), Close(), isOpen(), m_ftHandle, m_pOpenEx, MRPT_END, and MRPT_START.
Referenced by OpenByDescription(), and OpenBySerialNumber().
|
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().
|
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().
|
inherited |
Reads from the stream until a '
' character is found ('' characters are ignored).
Definition at line 69 of file CStream.cpp.
|
virtual |
This virtual method does nothing in this class.
Implements mrpt::io::CStream.
Definition at line 67 of file CInterfaceFTDI_common.cpp.
|
virtual |
This virtual method does nothing in this class.
Implements mrpt::io::CStream.
Definition at line 66 of file CInterfaceFTDI_common.cpp.
bool CInterfaceFTDI::isOpen | ( | ) |
Checks whether the chip has been successfully open.
Definition at line 179 of file CInterfaceFTDI_WIN.cpp.
References m_ftHandle.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected(), mrpt::hwdrivers::CServoeNeck::disableServo(), mrpt::hwdrivers::CServoeNeck::enableServo(), ftdi_open(), ftdi_openEx(), mrpt::hwdrivers::CServoeNeck::getRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), and mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed().
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.
|
private |
Definition at line 180 of file CInterfaceFTDI_WIN.cpp.
References m_hmodule, m_pClose, m_pGetQueueStatus, m_pListDevices, m_pOpen, m_pOpenEx, m_pPurge, m_pRead, m_pResetDevice, m_pSetLatencyTimer, m_pSetTimeouts, m_pWrite, MRPT_END, MRPT_START, and THROW_EXCEPTION.
Referenced by CInterfaceFTDI().
void CInterfaceFTDI::OpenByDescription | ( | const std::string & | description | ) |
Open by device description.
Definition at line 437 of file CInterfaceFTDI_WIN.cpp.
References mrpt::containers::circular_buffer< T >::clear(), FT_OPEN_BY_DESCRIPTION, ftdi_openEx(), m_readBuffer, MRPT_END, and MRPT_START.
void CInterfaceFTDI::OpenBySerialNumber | ( | const std::string & | serialNumber | ) |
Open by device serial number.
Definition at line 425 of file CInterfaceFTDI_WIN.cpp.
References mrpt::containers::circular_buffer< T >::clear(), FT_OPEN_BY_SERIAL_NUMBER, ftdi_openEx(), m_readBuffer, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), and mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected().
|
delete |
This object cannot be copied.
|
virtualinherited |
Writes a string to the stream in a textual form.
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().
|
inlineinherited |
Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T
.
CONTAINER_TYPE | can be any vector<T>, deque<T> or alike. |
Definition at line 102 of file io/CStream.h.
References mrpt::io::CStream::printf().
Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel().
void CInterfaceFTDI::Purge | ( | ) |
Purge the I/O buffers.
Definition at line 337 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), mrpt::containers::circular_buffer< T >::clear(), FT_PURGE_RX, FT_PURGE_TX, m_ftHandle, m_pPurge, m_readBuffer, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect().
|
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().
|
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().
std::exception | On 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().
|
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 129 of file CInterfaceFTDI.h.
References Read().
Referenced by mrpt::hwdrivers::CSickLaserUSB::waitContinuousSampleFrame().
void CInterfaceFTDI::ResetDevice | ( | ) |
Reset the USB device.
Definition at line 325 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), mrpt::containers::circular_buffer< T >::clear(), m_ftHandle, m_pResetDevice, m_readBuffer, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected().
|
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:
Implemented in mrpt::io::CPipeBaseEndPoint, mrpt::io::CFileStream, mrpt::io::CMemoryStream, mrpt::io::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CFileOutputStream, and mrpt::io::CFileInputStream.
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.
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().
void CInterfaceFTDI::SetTimeouts | ( | unsigned long | dwReadTimeout_ms, |
unsigned long | dwWriteTimeout_ms | ||
) |
Change read & write timeouts, in milliseconds.
Definition at line 349 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pSetTimeouts, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), and mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected().
|
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().
|
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 133 of file CInterfaceFTDI.h.
References Write().
|
private |
Definition at line 193 of file CInterfaceFTDI.h.
Referenced by CInterfaceFTDI(), Close(), ftdi_getQueueStatus(), ftdi_open(), ftdi_openEx(), ftdi_read(), ftdi_write(), isOpen(), Purge(), ResetDevice(), SetLatencyTimer(), and SetTimeouts().
|
private |
Definition at line 192 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and ~CInterfaceFTDI().
|
private |
Definition at line 210 of file CInterfaceFTDI.h.
Referenced by Close(), and loadDriver().
|
private |
Definition at line 232 of file CInterfaceFTDI.h.
Referenced by ftdi_getQueueStatus(), and loadDriver().
|
private |
Definition at line 207 of file CInterfaceFTDI.h.
Referenced by ftdi_listDevices(), and loadDriver().
|
private |
Definition at line 200 of file CInterfaceFTDI.h.
Referenced by ftdi_open(), and loadDriver().
|
private |
Definition at line 204 of file CInterfaceFTDI.h.
Referenced by ftdi_openEx(), and loadDriver().
|
private |
Definition at line 224 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and Purge().
|
private |
Definition at line 214 of file CInterfaceFTDI.h.
Referenced by ftdi_read(), and loadDriver().
|
private |
Definition at line 221 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and ResetDevice().
|
private |
Definition at line 236 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and SetLatencyTimer().
|
private |
Definition at line 228 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and SetTimeouts().
|
private |
Definition at line 218 of file CInterfaceFTDI.h.
Referenced by ftdi_write(), and loadDriver().
|
protected |
Used in Read.
Definition at line 174 of file CInterfaceFTDI.h.
Referenced by Close(), OpenByDescription(), OpenBySerialNumber(), Purge(), Read(), and ResetDevice().
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020 |