Michael F. Toups replied to the topic 'Help with DIY CCD driver' in the forum. 7 years ago

Below are two diffs showing a quick mod that appears to take care of the "timing" issue due to the differences between D2XX and ftdi.

First I changed the calls to ftdi_read_data to ftdi_read_data_modified and created a new function ftdi_read_data_modified that continually calls ftdi_read_data until either too many attempts are made or all the data has been collected. This is a quick and dirty solution that appears to care of the problem. The number of tries and the usleep time are somewhat arbitrary and probably could be tuned. Not the cleanest solution, but this should allow your code to work with the ftdi library.

Michael

First in libcam84.h changes are

18,23d17
< #ifdef D2XX
< #else
< struct ftdi_context;
< int ftdi_read_data_modified(struct ftdi_context *ftdi, unsigned char *buf,  int size);
< #endif
< 

and in libcam84.c the changes are
312c312
<       dwBytesRead=ftdi_read_data_modified(CAM8A,FT_In_Buffer,0);
---
>       dwBytesRead=ftdi_read_data(CAM8A,FT_In_Buffer,0);
338c338
<       dwBytesRead=ftdi_read_data_modified(CAM8A,FT_In_Buffer, 8*mdeltX);
---
>       dwBytesRead=ftdi_read_data(CAM8A,FT_In_Buffer, 8*mdeltX);
367c367
< 	  dwBytesRead=ftdi_read_data_modified(CAM8A,FT_In_Buffer, 2*mdeltX);
---
> 	  dwBytesRead=ftdi_read_data(CAM8A,FT_In_Buffer, 2*mdeltX);
965,980d964
< }
< 
< int ftdi_read_data_modified(struct  ftdi_context * ftdi, unsigned char * buf, int size)
< {
< 	int rsize = ftdi_read_data(ftdi, buf, size);
< 	int nsize=size-rsize;
< 	int retry=0;
< 	while((nsize>0)&(retry<20))
< 	{
< 		retry++;
< 		usleep(500);
<  //	     	 fprintf(stderr,"Try %d since %d<>%d \n",retry, rsize,size);
< 	        rsize = rsize+ftdi_read_data(ftdi, buf+rsize, nsize);
< 		nsize = size - rsize;
< 	}
< 	return rsize;


Read More...