[Ftdi-usb-sio-devel] Cant do simple serial-mode writes on FT2232H
Brought to you by:
bryder
From: T. H. <ts...@mr...> - 2009-11-25 15:58:02
|
Hi, I'm struggling with what ought to be the most straightforward thing. I'm trying to write to channel A of an FT2232H mini-module in serial mode, but after writing a total of 4096 bytes, the writes hang and I get an error -110 returned. Presumably the buffer on the mini-module has filled up. But why is this not being emptied as the device send things to its serial pin? I've set flow-control to SIO_DISABLE_FLOW_CTRL (does this function actually work? It seems to return success even if I try idiot values like -1 or 12345 for the flow-control parameter). Thanks, Terry My code: #include <stdio.h> #include <time.h> #include <unistd.h> #include <usb.h> #include <ftdi.h> const int vendor_id=0x0403; const int product_id=0x6010; //FT2232H int main(int argc, char **argv) { struct ftdi_context ftdicA,ftdicB; int f,i,j,k; printf("setting up channel A\n"); ftdi_init(&ftdicA); f = ftdi_usb_open(&ftdicA, vendor_id, product_id); if(f < 0 && f != -5) { fprintf(stderr, "unable to open ftdi device: %d - %s\n",f,ftdicA.error_str); exit(-1); } printf("ftdi open A succeeded: %d\n",f); printf("setting flowcontrol\n"); //i=ftdi_setflowctrl(&ftdicA, SIO_DISABLE_FLOW_CTRL); i=ftdi_setflowctrl(&ftdicA, 7); if (i != 0) { printf("setting channel A flow-control failed. stat=%i\n",i); exit(0); } #define BUFLEN 100000 unsigned char buf0[BUFLEN]; for (i=0; i<BUFLEN; i++) buf0[i]=0xff; for (j=0; j<5; j++) { printf("loop=%i\n",j); //write a buffer f = ftdi_write_data(&ftdicA, buf0, 1000); if(f < 0) { fprintf(stderr,"write failed for %x, error %d - %s\n",buf0[0],f,ftdicA.error_str); break; } } ftdi_usb_close(&ftdicA); ftdi_deinit(&ftdicA); return 0; } |