libftdi Archives

Subject: Re: ftdi_usb_open_dev & ftdi_set_baudrate

From: Tim Schneider <schneid5@xxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 18 Jan 2011 14:28:35 +0100
Hello Thomas,

thank you for your quick reply :)

> Hello Tim,
> 
> How you do detect the sensor by the eeprom?
> Do you look for the device serial or something?

In the eeprom is a field called "product" which let's me see which sensor I'm 
dealing with.

> 
> Usually by the serial. Which libftdi version is this?
Is this serial you're talking about the one in the eeprom structure, or is 
there another Serial I can read out?
I've tried libftdi version 0.18 and the current svn version. I'm using libusb 
version 0.1.

> 
> 
> Setting the baudrate should be always working. Can you post some small 
> example code? Also try running your program with "valgrind", since version 
> 3.6.0 it also supports the ARM platform (I used it on my ARM based N900).

Sorry, that was my mistake... I forgot to remove a ftdi_usb_close() which I 
used for testing... so actually the usb device was closed when I tried the 
set_baudrate... no wonder that doesn't work.

> 
> Cheers,
> Thomas

The code making the problem can be found below.

Thanks for your help

Tim


void discoverSensors(){
        int f,i, err;
        
        ftdic = malloc(sizeof(struct ftdi_context));
        
    // Init
    if (ftdi_init(ftdic) < 0)
    {
               exit(0);
    }
        
        struct ftdi_device_list * devlist = NULL;
        
        err = ftdi_usb_find_all(ftdic, &devlist, 0x0403, 0x6001);
        if(err < 0){
                switch(err){
                        case -1: printf("usb_find_busses failed\n"); break;
                        case -2: printf("usb_find_devices failes\n"); break;
                        case -3: printf("out of memory\n"); break;
                        default: printf("ftdi_usb_find_all failed\n");
                }
                exit(0);
        }
        
        if(err == 0){
                return;
        }
        struct ftdi_device_list * cur = devlist;

        while(cur != NULL){
                unsigned char eeprom[1024];
                struct ftdi_eeprom ep;
        
                //open FTDI device
                err = ftdi_usb_open_dev(ftdic, cur->dev);
                if(err < 0){
                        printf("Error in ftdi_usb_open_dev\n");
                        ftdi_deinit(ftdic);
                        ftdi_list_free(&devlist);
                        exit(-1);
                }
                
                //read eeprom
                err = ftdi_read_eeprom_getsize(ftdic, eeprom, sizeof(eeprom));
                if(err < 0){
                        printf("Error on read eeprom\n");
                        ftdi_usb_close(ftdic);
                        ftdi_deinit(ftdic);
                        ftdi_list_free(&devlist);
                        exit(-1);
                }
                
                
                err = ftdi_eeprom_decode(&ep, eeprom, err);
                if(err < 0){
                        printf("Error on decode eeprom\n");
                        ftdi_usb_close(ftdic);
                        ftdi_deinit(ftdic);
                        ftdi_list_free(&devlist);
                        exit(-1);
                }
                
                if(strncmp(ep.product, "Mikrowaage", 10) == 0){
                        //this is the sensor I'm looking for
                        cur = cur->next;
                }

                ftdi_usb_close(ftdic);
                cur = cur->next;
        }
        ftdi_list_free(&devlist);
        ftdi_deinit(ftdic);
}



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

Current Thread