/*
 *
 * $Id: serialport_ftdi.h 2 2008-07-30 09:28:03Z mschneider $
 * $URL: svn://localhost/Bioloid/trunk/serialport_ftdi.h $
 
 * \version   $Rev: 2 $
 * \author    Markus Schneider
 * \date      17.07.08
 *
 */

#ifndef SERIALPORT_FTDI_H
#define SERIALPORT_FTDI_H

#include "ftdi.h"
#include "serialport.h"

class SerialPort_FTDI : public SerialPort
{
public:
  // call with int vendor=0x0403, int product=0x6001
  SerialPort_FTDI();
  SerialPort_FTDI(int vendor, int product);
  
  /**
   * read 1 byte from stream
   * @param byte Buffer to store byte
   * @return Number of bytes read. This is 1 of no error occures.
   */
  virtual int readByte(unsigned char * byte);
  
  /**
   * This method writes an array of bytes to the serial port.
   * @param TxBuff Pointer to the buffer that contains the data to be written to the device.
   * @param TxBytes Number of bytes to write to the device
   * @return Number of bytes written to the device
   */
  virtual int writeData(unsigned char TxBuff[], unsigned int TxBytes);  
  
  /**
   * write 1 byte to stream
   * @param byte The byte to write
   * @return Number of bytes written. This is 1 of no error occures.
   */  
  virtual int writeByte(unsigned char byte);  
  
  /**
   * This method reads an array of bytes from the serial port.
   * @param RxBuff Pointer to the buffer that receives the data from the device.
   * @param RxBytes Number of bytes to be read from the device
   * @return Number of bytes read from the device
   */  
  virtual int readData(unsigned char RxBuff[], unsigned int RxBytes); 
  
  /**
   * Set the timeout in msec for the read operation. The read
   * operation will return with an error if no bytes received 
   * during this time.
   * @param msec The timeout in milliseconds
   * @return 0 if no error
   */  
  virtual int setTimeout(unsigned int msec);
  
  /**
   * Perform close operation on serial port
   */
  virtual ~SerialPort_FTDI();
  
protected:
  virtual int setupDevice();
  struct ftdi_context ftdic;
};

#endif
