libftdi Archives

Subject: Writing and reading to a FT232R

From: "Ampt,Maurice M.L." <m.ampt@xxxxxxxxxxxxxxxxx>
To: "libftdi@xxxxxxxxxxxxxxxxxxxxxxx" <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 4 Nov 2011 09:21:20 +0100
Hello everybody,

Currently I am trying to write some data to a FT232R USB device, this data is a 
command that will turn a device on or off depending on the data sent.
When I simply write the message once, the device almost never turns on/off, 
however if I send it at least twice the success rate is as far as I know 100%.
Another slight problem I'm having is the read part, this seems to instantly 
return 0, even when put in a while loop it will never output, even though my 
previous code using a simple read on /dev/ttyUSB0 did do this.

A short summary of my code:
struct ftdi_context ftdic;
ftdi_init(&ftdic);
ftdi_usb_open(&ftdic, 0x0403, 0x6001);
ftdi_set_baudrate(&ftdic, 115200);
ftdi_set_line_property(&ftdic,BITS_8,STOP_BIT_1,NONE);
char data[33]; //this is filled in my code but irrelevant to this summary as 
far as I know
ftdi_write_data(&ftdic,(unsigned char *)bytes,33);
while(1)
{
ftdi_read_data (&ftdic,buf,24 );
}

Some lines from lsusb -v -d 0403:6001 which may be important:
bEndpointAddress     0x81  EP 1 IN
bEndpointAddress     0x02  EP 2 OUT

So only 1 ftdi_write_data will work maybe 1 out of 10 times where calling the 
ftdi_write_data function twice hasn't failed me yet...
Also about that read function it doesn't matter wether I make the size 
parameter bigger, smaller or equal to what I am going to receive, it says it 
never receives data. (I also checked the read timeout, it is set to 5000, 
changing made no difference whatsoever)

Perhaps I'm forgetting just a simple set besides baudrate and line property, 
thank you in advance for your response.

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

Current Thread