libftdi Archives

Subject: Re: Bug in libftdipp Context::open()

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 05 Feb 2011 18:34:15 +0100
Hello pit,

On 01/20/2011 01:27 PM, pitpompej@xxxxxxxx wrote:
> I found a bug in the cpp-wrapper for the ftdi-lib that concerns nearly all 
> open() functions of the Context-Class. All open-functions except the one with 
> the usb_device parameter return with -1 (and error string "all fine") even if 
> opening the device should be posssible (the ftdi-c version can open the same 
> device). The reason for that behavior is, that they all use for the first 
> connect to the device the correct ftdi-c-function concerning to the given 
> parameters (open(vendor,pid) uses ftdi_usb_open(ftdi, vendor, product), 
> open(description) uses ftdi_usb_open_string(ftdi, description.c_str()) and so 
> on) but after the first connect they all use the ftdi_usb_get_strings 
> function that needs as one parameter the usb_device. this has not been set 
> before when using these special open-functions so it returns with an error 
> and the open-function failes.
> I have already implemented a fix in my sources by adding to further functions 
> in the ftdi-c-lib that returns by reference the usb_device ande changed the 
> concerning calls in the cpp-wrapper. That all works fine for me now.
> But is a problem in the ftdi-cpp-wrapper worth a change in the ftdi-c-lib?
> I will try to commit it if possible today, otherwise next week.

Thanks for the report and your patch!

Looking at the C++ wrapper three years later,
I don't like the fact that I keeps an own "libusb_device *dev"
pointer -and- a pointer to the ftdi_context. 

I think it can be improved without bloating the open()
function of the C API. Something like this:

- Remove the libusb_device pointer in the C++ wrapper

- Provide a function in the C API to get the strings without
  closing the device. Thinking about it some more, the C API
  could do this by default, "wasting" some bytes for an
  already open device is a non-issue.

- Kill the get_strings_and_reopen() function

- Implement is_open() in the C API and kill the
  "open" flag, too.

What do you think?

Cheers,
Thomas

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

Current Thread