10 #ifndef CInterfaceFTDI_H
11 #define CInterfaceFTDI_H
13 #include <mrpt/config.h>
39 #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)
41 void *usb_device_struct;
117 void SetTimeouts(
unsigned long dwReadTimeout_ms,
unsigned long dwWriteTimeout_ms);
128 return Read(Buffer,Count);
135 return Write(Buffer,Count);
148 size_t Read(
void *Buffer,
size_t Count);
155 size_t Write(
const void *Buffer,
size_t Count);
159 uint64_t
Seek(uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning);
170 void ftdi_read(
void *lpvBuffer,
unsigned long dwBuffSize,
unsigned long *lpdwBytesRead);
171 void ftdi_write(
const void *lpvBuffer,
unsigned long dwBuffSize,
unsigned long *lpdwBytes);
173 #if defined(MRPT_OS_WINDOWS)
175 void checkErrorAndRaise(
int errorCode);
177 void ftdi_open(
void* pvDevice);
178 void ftdi_openEx(
void* pArg1,
unsigned long dwFlags);
179 void ftdi_listDevices(
void *pArg1,
void *pArg2,
unsigned long dwFlags);
180 void ftdi_getQueueStatus(
unsigned long *lpdwAmountInRxQueue);
183 unsigned long m_ftHandle;
192 typedef FT_STATUS (__stdcall *PtrToOpen)(
void*,
unsigned long *);
195 typedef FT_STATUS (__stdcall *PtrToOpenEx)(
void*,
unsigned long,
unsigned long *);
196 PtrToOpenEx m_pOpenEx;
198 typedef FT_STATUS (__stdcall *PtrToListDevices)(
void*,
void*,
unsigned long);
199 PtrToListDevices m_pListDevices;
201 typedef FT_STATUS (__stdcall *PtrToClose)(
unsigned long );
204 typedef FT_STATUS (__stdcall *PtrToRead)(
unsigned long ,
void *,
unsigned long,
unsigned long *);
207 typedef FT_STATUS (__stdcall *PtrToWrite)(
unsigned long ,
const void *,
unsigned long,
unsigned long *);
210 typedef FT_STATUS (__stdcall *PtrToResetDevice)(
unsigned long );
211 PtrToResetDevice m_pResetDevice;
213 typedef FT_STATUS (__stdcall *PtrToPurge)(
unsigned long ,
unsigned long);
216 typedef FT_STATUS (__stdcall *PtrToSetTimeouts)(
unsigned long ,
unsigned long,
unsigned long);
217 PtrToSetTimeouts m_pSetTimeouts;
219 typedef FT_STATUS (__stdcall *PtrToGetQueueStatus)(
unsigned long ,
unsigned long *);
220 PtrToGetQueueStatus m_pGetQueueStatus;
222 typedef FT_STATUS (__stdcall *PtrToSetLatencyTimer )(
unsigned long ,
unsigned char);
223 PtrToSetLatencyTimer m_pSetLatencyTimer;
A definition of a CStream actually representing a USB connection to a FTDI chip.
bool isOpen()
Checks whether the chip has been successfully open.
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 ...
void ftdi_write(const void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytes)
void SetLatencyTimer(unsigned char latency_ms)
Change the latency timer (in milliseconds) implemented on the FTDI chip: for a few ms,...
void OpenBySerialNumber(const std::string &serialNumber)
Open by device serial number.
mrpt::utils::circular_buffer< uint8_t > m_readBuffer
Used in Read.
void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
Change read & write timeouts, in milliseconds.
void Purge()
Purge the I/O buffers.
CInterfaceFTDI(const CInterfaceFTDI &o)
This object cannot be copied.
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)
This virtual method does nothing in this class.
uint64_t getPosition()
This virtual method does nothing in this class.
void recursive_fill_list_devices(void *usb_device_structure, TFTDIDeviceList &outList)
Process recursively a USB device and its children:
void OpenByDescription(const std::string &description)
Open by device description.
void ResetDevice()
Reset the USB device.
void ftdi_read(void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytesRead)
void Close()
Close the USB device.
size_t Read(void *Buffer, size_t Count)
Introduces a pure virtual method responsible for reading from the stream.
CInterfaceFTDI()
Constructor, which loads driver interface (the DLL under Windows).
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 s...
virtual ~CInterfaceFTDI()
Destructor, which closes the connection with the chip and unloads the driver interface.
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,...
uint64_t getTotalBytesCount()
This virtual method does nothing in this class.
void ListAllDevices(TFTDIDeviceList &outList)
Generates a list with all FTDI devices connected right now.
size_t Write(const void *Buffer, size_t Count)
Introduces a pure virtual method responsible for writing to the stream.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
std::deque< TFTDIDevice > TFTDIDeviceList
Used in CInterfaceFTDI::ListAllDevices.
std::ostream HWDRIVERS_IMPEXP & operator<<(std::ostream &o, const TFTDIDevice &d)
Print out all the information of a FTDI device in textual form.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A list of FTDI devices and their descriptors.
std::string ftdi_manufacturer
std::string ftdi_description