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

#ifndef SERIALPORT_D2XX_H
#define SERIALPORT_D2XX_H

#include "serialport.h"
#include "ftd2xx.h"

class SerialPort_D2XX : public SerialPort
{
public:
 /**
  * Serial port constructor
  * @param iDevice Must be 0 if only one device is attached. For multiple devices 1, 2 etc.
  */
  SerialPort_D2XX(int iDevice=0);
  
 /**
  * Serial port constructor
  * @param deviceID The internal decie ID
  */  
  SerialPort_D2XX(char deviceID[]);
  
 /**
  * Read 1 byte from the device
  * @param byte Buffer to store read data
  * @return Number of bytes read
  */  
  virtual int readByte(unsigned char * byte);
  
 /**
  * Write a byte to the device
  * @param byte The byte to write
  * @return Number of bytes written
  */  
  virtual int writeByte(unsigned char byte);
  
 /**
  * Write data to the device
  * @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
  */  
  virtual int writeData(unsigned char TxBuff[], unsigned int TxBytes);
 
 /**
  * Read data from the device
  * @param RxBuff Buffer to store read data
  * @param RxBytes Number of bytes to read from decice
  * @return Number of bytes read
  */  
  virtual int readData(unsigned char RxBuff[], unsigned int RxBytes);
 
 /**
  * Set the read/write timeout
  * @param msec Timeout in milliseconds
  * @return The FT_STATU like in ftd2xx.h. 0 on no Error
  */ 
  virtual int setTimeout(unsigned int msec);
  
 /**
  * Clear the serialport. Make sure, that no bytes remaining in send/rcv buffer.
  * @return 0 if no error
  */    
  virtual int clear();
  
 /**
  * Perform close operation on serial port
  */  
  virtual ~SerialPort_D2XX();
  
protected:
 /**
  * This will set the device to 1,000,000 Baud, 8Bits, 1Stop, no Parity, no Flow
  * @return The FT_STATU like in ftd2xx.h. 0 on no Error
  */
  virtual int setupDevice();
  FT_HANDLE ftHandle;
};

#endif
