MRPT
2.0.1
|
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... | |
~CInterfaceFTDI () override | |
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... | |
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). More... | |
size_t | Read (void *Buffer, size_t Count) override |
Introduces a pure virtual method responsible for reading from the stream. More... | |
size_t | Write (const void *Buffer, size_t Count) override |
Introduces a pure virtual method responsible for writing to the stream. More... | |
uint64_t | Seek (int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override |
This virtual method does nothing in this class. More... | |
uint64_t | getTotalBytesCount () const override |
This virtual method does nothing in this class. More... | |
uint64_t | getPosition () const override |
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 210 of file CInterfaceFTDI.h.
|
private |
Definition at line 231 of file CInterfaceFTDI.h.
|
private |
Definition at line 207 of file CInterfaceFTDI.h.
|
private |
Definition at line 200 of file CInterfaceFTDI.h.
|
private |
Definition at line 203 of file CInterfaceFTDI.h.
|
private |
Definition at line 224 of file CInterfaceFTDI.h.
|
private |
Definition at line 213 of file CInterfaceFTDI.h.
|
private |
Definition at line 221 of file CInterfaceFTDI.h.
|
private |
Definition at line 235 of file CInterfaceFTDI.h.
|
private |
Definition at line 227 of file CInterfaceFTDI.h.
|
private |
Definition at line 217 of file CInterfaceFTDI.h.
|
private |
Enumerator | |
---|---|
dummy |
Definition at line 198 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 155 of file CInterfaceFTDI_WIN.cpp.
References loadDriver(), m_ftHandle, MRPT_END, and MRPT_START.
|
override |
Destructor, which closes the connection with the chip and unloads the driver interface.
Definition at line 168 of file CInterfaceFTDI_WIN.cpp.
References Close(), and m_hmodule.
|
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 386 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 287 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(), and ~CInterfaceFTDI().
|
private |
Definition at line 363 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pGetQueueStatus, MRPT_END, and MRPT_START.
|
private |
Definition at line 276 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_pListDevices, MRPT_END, and MRPT_START.
Referenced by ListAllDevices().
|
private |
Definition at line 219 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), Close(), isOpen(), m_ftHandle, m_pOpen, MRPT_END, and MRPT_START.
|
private |
Definition at line 230 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 303 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 315 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.
|
overridevirtual |
This virtual method does nothing in this class.
Implements mrpt::io::CStream.
Definition at line 67 of file CInterfaceFTDI_common.cpp.
|
overridevirtual |
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 181 of file CInterfaceFTDI_WIN.cpp.
References m_ftHandle.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), 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 244 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 182 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 439 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 427 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().
|
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 mrpt::system::os::vsnprintf().
Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), mrpt::io::CStream::printf_vector(), mrpt::apps::CGridMapAlignerApp::run(), mrpt::apps::RBPF_SLAM_App_Base::run(), and mrpt::apps::ICP_SLAM_App_Base::run().
|
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 339 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().
|
overridevirtual |
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, mrpt::containers::circular_buffer< T >::pop_many(), mrpt::containers::circular_buffer< T >::push_many(), and mrpt::containers::circular_buffer< T >::size().
Referenced by ReadSync().
|
overridevirtual |
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().
void CInterfaceFTDI::ResetDevice | ( | ) |
Reset the USB device.
Definition at line 327 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.
|
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::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CMemoryStream, mrpt::io::CFileOutputStream, and mrpt::io::CFileInputStream.
|
override |
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 373 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pSetLatencyTimer, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect().
void CInterfaceFTDI::SetTimeouts | ( | unsigned long | dwReadTimeout_ms, |
unsigned long | dwWriteTimeout_ms | ||
) |
Change read & write timeouts, in milliseconds.
Definition at line 351 of file CInterfaceFTDI_WIN.cpp.
References ASSERT_, checkErrorAndRaise(), m_ftHandle, m_pSetTimeouts, MRPT_END, and MRPT_START.
Referenced by mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect().
|
overridevirtual |
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 194 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 193 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and ~CInterfaceFTDI().
|
private |
Definition at line 211 of file CInterfaceFTDI.h.
Referenced by Close(), and loadDriver().
|
private |
Definition at line 233 of file CInterfaceFTDI.h.
Referenced by ftdi_getQueueStatus(), and loadDriver().
|
private |
Definition at line 208 of file CInterfaceFTDI.h.
Referenced by ftdi_listDevices(), and loadDriver().
|
private |
Definition at line 201 of file CInterfaceFTDI.h.
Referenced by ftdi_open(), and loadDriver().
|
private |
Definition at line 205 of file CInterfaceFTDI.h.
Referenced by ftdi_openEx(), and loadDriver().
|
private |
Definition at line 225 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and Purge().
|
private |
Definition at line 215 of file CInterfaceFTDI.h.
Referenced by ftdi_read(), and loadDriver().
|
private |
Definition at line 222 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and ResetDevice().
|
private |
Definition at line 237 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and SetLatencyTimer().
|
private |
Definition at line 229 of file CInterfaceFTDI.h.
Referenced by loadDriver(), and SetTimeouts().
|
private |
Definition at line 219 of file CInterfaceFTDI.h.
Referenced by ftdi_write(), and loadDriver().
|
protected |
Used in Read.
Definition at line 175 of file CInterfaceFTDI.h.
Referenced by Close(), OpenByDescription(), OpenBySerialNumber(), Purge(), Read(), and ResetDevice().
Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020 |