PATCH: Add a ftdi_usb_open_bus_port function.

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser
Hello all,

This patch adds a function that will open using the specified Bus and
Port. I don't know how useful it would be to others, but I decided to
submit it cause why not. I pretty much just copied
"ftdi_usb_open_desc_index" and modified the parameters and loop.

Maxwell.

--- PATCH Below This line ---
 From f49494b97dfeab9ebb5daeeea97ef622f9cc7c9c Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Sun, 9 Apr 2017 20:02:56 -0400
Subject: [PATCH] Add a ftdi_usb_open_bus_port function.

---
  src/ftdi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
  src/ftdi.h |  1 +
  2 files changed, 48 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index 2fff1ff..d44cbb3 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -824,6 +824,53 @@ int ftdi_usb_open_desc_index(struct ftdi_context
*ftdi, int vendor, int product,
  }

  /**
+    Opens the device at a given USB Bus and Port.
+
+    \param ftdi pointer to ftdi_context
+    \param bus Bus Number
+    \param port Port Number
+
+    \retval  0: all fine
+    \retval -1: usb_find_busses() failed
+    \retval -2: usb_find_devices() failed
+    \retval -3: usb device not found
+    \retval -4: unable to open device
+    \retval -5: unable to claim device
+    \retval -6: reset failed
+    \retval -7: set baudrate failed
+    \retval -8: get product description failed
+    \retval -9: get serial number failed
+    \retval -10: unable to close device
+    \retval -11: ftdi context invalid
+*/
+int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus,
uint8_t port)
+{
+    libusb_device *dev;
+    libusb_device **devs;
+    int i = 0;
+
+    if (ftdi == NULL)
+        ftdi_error_return(-11, "ftdi context invalid");
+
+    if (libusb_get_device_list(ftdi->usb_ctx, &devs) < 0)
+        ftdi_error_return(-12, "libusb_get_device_list() failed");
+
+    while ((dev = devs[i++]) != NULL)
+    {
+        if (libusb_get_bus_number(dev) == bus &&
libusb_get_port_number(dev) == port)
+        {
+            int res;
+            res = ftdi_usb_open_dev(ftdi, dev);
+            libusb_free_device_list(devs,1);
+            return res;
+        }
+    }
+
+    // device not found
+    ftdi_error_return_free_device_list(-3, "device not found", devs);
+}
+
+/**
      Opens the ftdi-device described by a description-string.
      Intended to be used for parsing a device-description given as
commandline argument.

diff --git a/src/ftdi.h b/src/ftdi.h
index ef174bf..5927c48 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -502,6 +502,7 @@ extern "C"
                             const char* description, const char* serial);
      int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int
vendor, int product,
                                   const char* description, const char*
serial, unsigned int index);
+    int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus,
uint8_t port);
      int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct
libusb_device *dev);
      int ftdi_usb_open_string(struct ftdi_context *ftdi, const char*
description);

--
2.9.3


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Fahrzin Hemmati
I have a version of this code internally, so I'd switch to this function if it got merged in. I use USB port paths to uniquely determine ftdi devices, but I can convert them to bus and port before calling into the ftdi library. 

On Apr 9, 2017 5:16 PM, "Maxwell Dreytser" <[hidden email]> wrote:
Hello all,

This patch adds a function that will open using the specified Bus and Port. I don't know how useful it would be to others, but I decided to submit it cause why not. I pretty much just copied "ftdi_usb_open_desc_index" and modified the parameters and loop.

Maxwell.

--- PATCH Below This line ---
From f49494b97dfeab9ebb5daeeea97ef622f9cc7c9c Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Sun, 9 Apr 2017 20:02:56 -0400
Subject: [PATCH] Add a ftdi_usb_open_bus_port function.

---
 src/ftdi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/ftdi.h |  1 +
 2 files changed, 48 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index 2fff1ff..d44cbb3 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -824,6 +824,53 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
 }

 /**
+    Opens the device at a given USB Bus and Port.
+
+    \param ftdi pointer to ftdi_context
+    \param bus Bus Number
+    \param port Port Number
+
+    \retval  0: all fine
+    \retval -1: usb_find_busses() failed
+    \retval -2: usb_find_devices() failed
+    \retval -3: usb device not found
+    \retval -4: unable to open device
+    \retval -5: unable to claim device
+    \retval -6: reset failed
+    \retval -7: set baudrate failed
+    \retval -8: get product description failed
+    \retval -9: get serial number failed
+    \retval -10: unable to close device
+    \retval -11: ftdi context invalid
+*/
+int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
+{
+    libusb_device *dev;
+    libusb_device **devs;
+    int i = 0;
+
+    if (ftdi == NULL)
+        ftdi_error_return(-11, "ftdi context invalid");
+
+    if (libusb_get_device_list(ftdi->usb_ctx, &devs) < 0)
+        ftdi_error_return(-12, "libusb_get_device_list() failed");
+
+    while ((dev = devs[i++]) != NULL)
+    {
+        if (libusb_get_bus_number(dev) == bus && libusb_get_port_number(dev) == port)
+        {
+            int res;
+            res = ftdi_usb_open_dev(ftdi, dev);
+            libusb_free_device_list(devs,1);
+            return res;
+        }
+    }
+
+    // device not found
+    ftdi_error_return_free_device_list(-3, "device not found", devs);
+}
+
+/**
     Opens the ftdi-device described by a description-string.
     Intended to be used for parsing a device-description given as commandline argument.

diff --git a/src/ftdi.h b/src/ftdi.h
index ef174bf..5927c48 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -502,6 +502,7 @@ extern "C"
                            const char* description, const char* serial);
     int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                                  const char* description, const char* serial, unsigned int index);
+    int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port);
     int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct libusb_device *dev);
     int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description);

--
2.9.3


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser

Nice to know that this is actually useful! I had a similar situation in my work.


On 04/09/2017 09:15 PM, Fahrzin Hemmati wrote:
I have a version of this code internally, so I'd switch to this function if it got merged in. I use USB port paths to uniquely determine ftdi devices, but I can convert them to bus and port before calling into the ftdi library. 

On Apr 9, 2017 5:16 PM, "Maxwell Dreytser" <[hidden email]> wrote:
Hello all,

This patch adds a function that will open using the specified Bus and Port. I don't know how useful it would be to others, but I decided to submit it cause why not. I pretty much just copied "ftdi_usb_open_desc_index" and modified the parameters and loop.

Maxwell.

--- PATCH Below This line ---
From f49494b97dfeab9ebb5daeeea97ef622f9cc7c9c Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Sun, 9 Apr 2017 20:02:56 -0400
Subject: [PATCH] Add a ftdi_usb_open_bus_port function.

---
 src/ftdi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/ftdi.h |  1 +
 2 files changed, 48 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index 2fff1ff..d44cbb3 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -824,6 +824,53 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
 }

 /**
+    Opens the device at a given USB Bus and Port.
+
+    \param ftdi pointer to ftdi_context
+    \param bus Bus Number
+    \param port Port Number
+
+    \retval  0: all fine
+    \retval -1: usb_find_busses() failed
+    \retval -2: usb_find_devices() failed
+    \retval -3: usb device not found
+    \retval -4: unable to open device
+    \retval -5: unable to claim device
+    \retval -6: reset failed
+    \retval -7: set baudrate failed
+    \retval -8: get product description failed
+    \retval -9: get serial number failed
+    \retval -10: unable to close device
+    \retval -11: ftdi context invalid
+*/
+int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
+{
+    libusb_device *dev;
+    libusb_device **devs;
+    int i = 0;
+
+    if (ftdi == NULL)
+        ftdi_error_return(-11, "ftdi context invalid");
+
+    if (libusb_get_device_list(ftdi->usb_ctx, &devs) < 0)
+        ftdi_error_return(-12, "libusb_get_device_list() failed");
+
+    while ((dev = devs[i++]) != NULL)
+    {
+        if (libusb_get_bus_number(dev) == bus && libusb_get_port_number(dev) == port)
+        {
+            int res;
+            res = ftdi_usb_open_dev(ftdi, dev);
+            libusb_free_device_list(devs,1);
+            return res;
+        }
+    }
+
+    // device not found
+    ftdi_error_return_free_device_list(-3, "device not found", devs);
+}
+
+/**
     Opens the ftdi-device described by a description-string.
     Intended to be used for parsing a device-description given as commandline argument.

diff --git a/src/ftdi.h b/src/ftdi.h
index ef174bf..5927c48 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -502,6 +502,7 @@ extern "C"
                            const char* description, const char* serial);
     int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                                  const char* description, const char* serial, unsigned int index);
+    int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port);
     int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct libusb_device *dev);
     int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description);

--
2.9.3


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Thomas Jarosch
In reply to this post by Maxwell Dreytser
Hi Maxwell,

On Monday, 10 April 2017 02:16:38 CEST Maxwell Dreytser wrote:
> This patch adds a function that will open using the specified Bus and
> Port. I don't know how useful it would be to others, but I decided to
> submit it cause why not. I pretty much just copied
> "ftdi_usb_open_desc_index" and modified the parameters and loop.
>
> Maxwell.

thanks for the patch. It looks good on a first glimpse,
I'll take a closer look after the short Easter holidays.

Best regards,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser
Great! I'll look forward to comments.


On 04/13/2017 12:07 PM, Thomas Jarosch wrote:

> Hi Maxwell,
>
> On Monday, 10 April 2017 02:16:38 CEST Maxwell Dreytser wrote:
>> This patch adds a function that will open using the specified Bus and
>> Port. I don't know how useful it would be to others, but I decided to
>> submit it cause why not. I pretty much just copied
>> "ftdi_usb_open_desc_index" and modified the parameters and loop.
>>
>> Maxwell.
> thanks for the patch. It looks good on a first glimpse,
> I'll take a closer look after the short Easter holidays.
>
> Best regards,
> Thomas
>
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to [hidden email]
>


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Thomas Jarosch
In reply to this post by Maxwell Dreytser
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
> Nice to know that this is actually useful! I had a similar situation in
> my work.

patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code
-12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new
"ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

 From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
  src/ftdi.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi,
int vendor, int product,
      \retval -9: get serial number failed
      \retval -10: unable to close device
      \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
  */
  int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor,
int product,
                               const char* description, const char*
serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context
*ftdi, int vendor, int product,
      \retval -9: get serial number failed
      \retval -10: unable to close device
      \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
  */
  int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus,
uint8_t port)
  {
--
2.9.3

--- End Patch ---


On 04/21/2017 12:04 PM, Thomas Jarosch wrote:

> Hi Maxwell,
>
> On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
>> Nice to know that this is actually useful! I had a similar situation in
>> my work.
> patch has been applied, thanks!
>
> The long code lines were mangled by our mail client,
> I had to apply the patch manually.
>
> Please double check everything is still correct in git.
>
> Cheers,
> Thomas
>


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Fahrzin Hemmati
Maxwell,

I think I found a discrepancy between our implementations that is going to be problematic. In yours, you use libusb_get_port_number, but I use libusb_get_device_address.

It looks like libusb_get_port_number returns the last digit of libusb_get_port_numbers, which is something like 1,3,1,1 so port_number is just 1. This allows conflicts since port_number isn't unique, despite what the documentation implies. The bus_number + device_address is the unique combination required.

On my Linux machines, device_address matches the sysfs node devnum (and bus_number is busnum), while port_number matches the path: /sys/bus/usb/devices/<bus_number>-<port_numbers>/{busnum,devnum}
I don't know how much this changes between systems, though, so I can't speak to whether this will be the case with your machines.

What do you think?


Farz Hemmati | Self-Driving Systems Testing and Tools Lead | [hidden email] | 650-253-8944


On Fri, Apr 21, 2017 at 9:56 AM, Maxwell Dreytser <[hidden email]> wrote:
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code -12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new "ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3

--- End Patch ---



On 04/21/2017 12:04 PM, Thomas Jarosch wrote:
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
Nice to know that this is actually useful! I had a similar situation in
my work.
patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser

Oh, so the bus number and port number are not enough to uniquely identify a device?

Maxwell.


On 05/04/2017 05:57 AM, Fahrzin Hemmati wrote:
Maxwell,

I think I found a discrepancy between our implementations that is going to be problematic. In yours, you use libusb_get_port_number, but I use libusb_get_device_address.

It looks like libusb_get_port_number returns the last digit of libusb_get_port_numbers, which is something like 1,3,1,1 so port_number is just 1. This allows conflicts since port_number isn't unique, despite what the documentation implies. The bus_number + device_address is the unique combination required.

On my Linux machines, device_address matches the sysfs node devnum (and bus_number is busnum), while port_number matches the path: /sys/bus/usb/devices/<bus_number>-<port_numbers>/{busnum,devnum}
I don't know how much this changes between systems, though, so I can't speak to whether this will be the case with your machines.

What do you think?


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Fri, Apr 21, 2017 at 9:56 AM, Maxwell Dreytser <[hidden email]> wrote:
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code -12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new "ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3

--- End Patch ---



On 04/21/2017 12:04 PM, Thomas Jarosch wrote:
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
Nice to know that this is actually useful! I had a similar situation in
my work.
patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Fahrzin Hemmati
No, the bus number and device number (device_address) match the currently-connected device uniquely, and the bus number + port_numbers match the port on which the device is connected (stable across reconnects). The bus number and port_number is unique only if you don't use any USB hubs (and there are none internal to your system). If there are hubs, then you need port_numbers


Farz Hemmati | Self-Driving Systems Testing and Tools Lead | [hidden email] | 650-253-8944


On Wed, May 10, 2017 at 9:25 PM, Maxwell Dreytser <[hidden email]> wrote:

Oh, so the bus number and port number are not enough to uniquely identify a device?

Maxwell.


On 05/04/2017 05:57 AM, Fahrzin Hemmati wrote:
Maxwell,

I think I found a discrepancy between our implementations that is going to be problematic. In yours, you use libusb_get_port_number, but I use libusb_get_device_address.

It looks like libusb_get_port_number returns the last digit of libusb_get_port_numbers, which is something like 1,3,1,1 so port_number is just 1. This allows conflicts since port_number isn't unique, despite what the documentation implies. The bus_number + device_address is the unique combination required.

On my Linux machines, device_address matches the sysfs node devnum (and bus_number is busnum), while port_number matches the path: /sys/bus/usb/devices/<bus_number>-<port_numbers>/{busnum,devnum}
I don't know how much this changes between systems, though, so I can't speak to whether this will be the case with your machines.

What do you think?


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Fri, Apr 21, 2017 at 9:56 AM, Maxwell Dreytser <[hidden email]> wrote:
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code -12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new "ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3

--- End Patch ---



On 04/21/2017 12:04 PM, Thomas Jarosch wrote:
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
Nice to know that this is actually useful! I had a similar situation in
my work.
patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser

Gotcha. I didn't read the libusb docs before answering. I'll submit a patch in a sec.

Maxwell.


On 05/11/2017 12:33 AM, Fahrzin Hemmati wrote:
No, the bus number and device number (device_address) match the currently-connected device uniquely, and the bus number + port_numbers match the port on which the device is connected (stable across reconnects). The bus number and port_number is unique only if you don't use any USB hubs (and there are none internal to your system). If there are hubs, then you need port_numbers


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Wed, May 10, 2017 at 9:25 PM, Maxwell Dreytser <[hidden email]> wrote:

Oh, so the bus number and port number are not enough to uniquely identify a device?

Maxwell.


On 05/04/2017 05:57 AM, Fahrzin Hemmati wrote:
Maxwell,

I think I found a discrepancy between our implementations that is going to be problematic. In yours, you use libusb_get_port_number, but I use libusb_get_device_address.

It looks like libusb_get_port_number returns the last digit of libusb_get_port_numbers, which is something like 1,3,1,1 so port_number is just 1. This allows conflicts since port_number isn't unique, despite what the documentation implies. The bus_number + device_address is the unique combination required.

On my Linux machines, device_address matches the sysfs node devnum (and bus_number is busnum), while port_number matches the path: /sys/bus/usb/devices/<bus_number>-<port_numbers>/{busnum,devnum}
I don't know how much this changes between systems, though, so I can't speak to whether this will be the case with your machines.

What do you think?


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Fri, Apr 21, 2017 at 9:56 AM, Maxwell Dreytser <[hidden email]> wrote:
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code -12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new "ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3

--- End Patch ---



On 04/21/2017 12:04 PM, Thomas Jarosch wrote:
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
Nice to know that this is actually useful! I had a similar situation in
my work.
patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser
Fixed. Combined with the previous minor comment change. I changed the name of the function name from ftdi_open_bus_port to ftdi_open_bus_addr.

--- Begin PATCH ---
From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser [hidden email]
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH 1/2] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3


From 2ab0e69d2e8bbc36207d3bf7c6fabba2ab95abfd Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser [hidden email]
Date: Thu, 11 May 2017 01:14:39 -0400
Subject: [PATCH 2/2] Change ftdi_open_bus_port to ftdi_open_bus_addr, since
 libusb_get_port_number is not always unique.

---
 src/ftdi.c | 8 ++++----
 src/ftdi.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index ac8f18a..175befc 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -825,11 +825,11 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
 }
 
 /**
-    Opens the device at a given USB bus and port.
+    Opens the device at a given USB bus and device address.
 
     \param ftdi pointer to ftdi_context
     \param bus Bus number
-    \param port Port number
+    \param addr Device address
 
     \retval  0: all fine
     \retval -1: usb_find_busses() failed
@@ -845,7 +845,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -11: ftdi context invalid
     \retval -12: libusb_get_device_list() failed
 */
-int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
+int ftdi_usb_open_bus_addr(struct ftdi_context *ftdi, uint8_t bus, uint8_t addr)
 {
     libusb_device *dev;
     libusb_device **devs;
@@ -859,7 +859,7 @@ int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 
     while ((dev = devs[i++]) != NULL)
     {
-        if (libusb_get_bus_number(dev) == bus && libusb_get_port_number(dev) == port)
+        if (libusb_get_bus_number(dev) == bus && libusb_get_device_address(dev) == addr)
         {
             int res;
             res = ftdi_usb_open_dev(ftdi, dev);
diff --git a/src/ftdi.h b/src/ftdi.h
index 5927c48..de02adf 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -502,7 +502,7 @@ extern "C"
                            const char* description, const char* serial);
     int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                                  const char* description, const char* serial, unsigned int index);
-    int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port);
+    int ftdi_usb_open_bus_addr(struct ftdi_context *ftdi, uint8_t bus, uint8_t addr);
     int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct libusb_device *dev);
     int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description);
 
--
2.9.3

--- End PATCH ---

On 05/11/2017 12:38 AM, Maxwell Dreytser wrote:

Gotcha. I didn't read the libusb docs before answering. I'll submit a patch in a sec.

Maxwell.


On 05/11/2017 12:33 AM, Fahrzin Hemmati wrote:
No, the bus number and device number (device_address) match the currently-connected device uniquely, and the bus number + port_numbers match the port on which the device is connected (stable across reconnects). The bus number and port_number is unique only if you don't use any USB hubs (and there are none internal to your system). If there are hubs, then you need port_numbers


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Wed, May 10, 2017 at 9:25 PM, Maxwell Dreytser <[hidden email]> wrote:

Oh, so the bus number and port number are not enough to uniquely identify a device?

Maxwell.


On 05/04/2017 05:57 AM, Fahrzin Hemmati wrote:
Maxwell,

I think I found a discrepancy between our implementations that is going to be problematic. In yours, you use libusb_get_port_number, but I use libusb_get_device_address.

It looks like libusb_get_port_number returns the last digit of libusb_get_port_numbers, which is something like 1,3,1,1 so port_number is just 1. This allows conflicts since port_number isn't unique, despite what the documentation implies. The bus_number + device_address is the unique combination required.

On my Linux machines, device_address matches the sysfs node devnum (and bus_number is busnum), while port_number matches the path: /sys/bus/usb/devices/<bus_number>-<port_numbers>/{busnum,devnum}
I don't know how much this changes between systems, though, so I can't speak to whether this will be the case with your machines.

What do you think?


Farz Hemmati |  Self-Driving Systems Testing and Tools Lead |  [hidden email] |  650-253-8944


On Fri, Apr 21, 2017 at 9:56 AM, Maxwell Dreytser <[hidden email]> wrote:
Hi Thomas,

All is fine. Just noticed a minor problem in the comments. Return code -12 was not mentioned in "ftdi_usb_open_desc_index" as well as the new "ftdi_usb_open_bus_port".

Maxwell.

--- Begin PATCH ---

From 66ae37ad943976401a54d3ff409634d332206d67 Mon Sep 17 00:00:00 2001
From: Maxwell Dreytser <[hidden email]>
Date: Fri, 21 Apr 2017 12:48:42 -0400
Subject: [PATCH] Minor comment fix.

---
 src/ftdi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c26ab72..ac8f18a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -750,6 +750,7 @@ int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
                              const char* description, const char* serial, unsigned int index)
@@ -842,6 +843,7 @@ int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
     \retval -9: get serial number failed
     \retval -10: unable to close device
     \retval -11: ftdi context invalid
+    \retval -12: libusb_get_device_list() failed
 */
 int ftdi_usb_open_bus_port(struct ftdi_context *ftdi, uint8_t bus, uint8_t port)
 {
--
2.9.3

--- End Patch ---



On 04/21/2017 12:04 PM, Thomas Jarosch wrote:
Hi Maxwell,

On Monday, 10 April 2017 04:43:24 CEST Maxwell Dreytser wrote:
Nice to know that this is actually useful! I had a similar situation in
my work.
patch has been applied, thanks!

The long code lines were mangled by our mail client,
I had to apply the patch manually.

Please double check everything is still correct in git.

Cheers,
Thomas



--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   



libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]





libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Thomas Jarosch
Hi Maxwell,

On Thursday, 11 May 2017 07:24:16 CEST Maxwell Dreytser wrote:
> Fixed. Combined with the previous minor comment change. I changed the
> name of the function name from ftdi_open_bus_port to ftdi_open_bus_addr.

thanks for the updated patch! Looks like the outgoing mailer
messed up the long lines by inserting newlines.

Please resend with the long lines intact. I can also fetch
from a git(hub) repo if that's easier for you.

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser
Here it is attached.


On 05/12/2017 07:37 AM, Thomas Jarosch wrote:

> Hi Maxwell,
>
> On Thursday, 11 May 2017 07:24:16 CEST Maxwell Dreytser wrote:
>> Fixed. Combined with the previous minor comment change. I changed the
>> name of the function name from ftdi_open_bus_port to ftdi_open_bus_addr.
> thanks for the updated patch! Looks like the outgoing mailer
> messed up the long lines by inserting newlines.
>
> Please resend with the long lines intact. I can also fetch
> from a git(hub) repo if that's easier for you.
>
> Cheers,
> Thomas
>


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

CommentFixAndDevAddr.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Thomas Jarosch
In reply to this post by Maxwell Dreytser
Hi Maxwell,

Am 11.05.2017 um 07:24 schrieb Maxwell Dreytser:
> Fixed. Combined with the previous minor comment change. I changed the
> name of the function name from ftdi_open_bus_port to ftdi_open_bus_addr.

applied, thanks! Even learned something: I didn't knew you could
combine two or more patches into one file :)

ChangeLog file has been adapted accordingly.

Cheers,
Thomas

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Maxwell Dreytser

Hey Thomas,

When will a version with this be released?

Maxwell.

P.S. To make patches, I clone git, create branch, do stuff, then " git format-patch master --stdout > mypatch.patch".


On 05/23/2017 02:55 PM, Thomas Jarosch wrote:
Hi Maxwell,

Am 11.05.2017 um 07:24 schrieb Maxwell Dreytser:
Fixed. Combined with the previous minor comment change. I changed the
name of the function name from ftdi_open_bus_port to ftdi_open_bus_addr.
applied, thanks! Even learned something: I didn't knew you could
combine two or more patches into one file :)

ChangeLog file has been adapted accordingly.

Cheers,
Thomas

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]   




libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PATCH: Add a ftdi_usb_open_bus_port function.

Thomas Jarosch
Hi Maxwell,

On Thursday, 25 May 2017 04:53:11 CEST Maxwell Dreytser wrote:
> Hey Thomas,
>
> When will a version with this be released?

I think a release in June is very likely.
Unless stuff like SambaCry keeps me busy ;)

Let's see if we can work out the reported problem from Matthias Janke
and then do one hopefully final -rc2 release.

> P.S. To make patches, I clone git, create branch, do stuff, then " git
> format-patch master --stdout > mypatch.patch".

ah ok, the "--stdout" is the trick here. I normally use git format-patch
to create patch series only. Thanks for sharing.

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Loading...