libftdi Archives

Subject: FT2XX wrapper

From: Janne Heikkinen <janne.m.heikkinen@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 23 Jun 2013 09:18:45 +0300
Hi,

I've been trying to make few wrapper functions so that I could build
code written for FTDI's FT2XX library.

Now I got the program to work but I'm just wondering if I'm doing
things right here. In the following code I
had to add the while loop to make it work.

FTD2XX_API FT_STATUS WINAPI FT_Read(FT_HANDLE ftHandle, LPVOID
lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned)
{
        ftdi_context *ftdi = NULL;
        int ret = 0;
        
        ftdi = (ftdi_context *)ftHandle;
        
        while ((ret = ftdi_read_data(ftdi, (unsigned char *)lpBuffer,
dwBytesToRead)) == 0);
                
        if (ret < 0)
        {
                fprintf(stderr,"ftdi_read_data failed: %d (%s)\n", ret,
ftdi_get_error_string(ftdi));
                return EXIT_FAILURE;
        }
        
        *lpBytesReturned = ret;
        
        return 0;
}

Also I haven't yet figured out how to implement FT_GetQueueStatus, but
it seems that I could live without
it by using #ifdef to get rid of it when compiling the code for Linux.

- Janne

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • FT2XX wrapper, Janne Heikkinen <=