libftdi Archives

Subject: Re: FT232RL Reading DMX

From: Rui Barreiros <rui.barreiros@xxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx, Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Thu, 31 May 2012 11:24:34 +0100
Hello Thomas,

I did a ftdi_read_data_set_chunksize(ftdi, 513) and commented out the purge, still the data I'm receiving is not 'correct' there are 512 positions (the 1st of the 513 array is the start code which is always 0x00) which correspond to a DMX channel, and I keep getting the correct value but always on the wrong array positions, they keep changing.

Also, the break interrupt seems to be slower than what it should be.

Attached goes my latest test code.

Best regards,


On 05/30/2012 05:57 PM, Thomas Jarosch wrote:
Hi Rui,

On Wednesday, 30. May 2012 17:09:04 Rui Barreiros wrote:
   while(!exitRequested) {
     ftdi_poll_modem_status(ftdi, &status);

     if(status & 0x1000) { // BREAK_INTERRUPT
       f = ftdi_read_data(ftdi, buff, sizeof(buff));
       if(f < 0)
         sleep(1);
       else if(f > 0) {
         ftdi_usb_purge_rx_buffer(ftdi);
         fprintf(stdout, "Read %d bytes\n", f);
         for(i = 0; i < sizeof(buff); i++) {
           fprintf(stdout, "%02X ", ((unsigned char *) buff)[i] );
         }
I'm not sure if the ftdi_usb_purge_rx_buffer() is a good idea:

ftdi_read_data() reads data in "readbuffer_chunksize" blocks,
usually 4096 bytes. If the "sizeof(buff)" (=513) is smaller than that
and the chip returns more data, it will be buffered internally.

Next time you call ftdi_read_data(), it might return data
from the internal read buffer. The problem is that
ftdi_usb_purge_rx_buffer() clears the internal read buffer,
so you will experience data loss.


Do you really need ftdi_usb_purge_rx_buffer()?

Thomas


--

Rui Barreiros
rui.barreiros@xxxxxxxxxxxx
Tlm: +351 962 356 020
Rua Alminhas das Cais, 950
4410-497 Serzedo VNG
Portugal
NIF: 506 107 523
Tlm: +351 968 015 215
Tlf: +351 227 625 805
Fax: +351 227 534 304
geral@xxxxxxxxxxxx




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


Attachment: test.c
Description: Text Data

Current Thread