Hi Albert,

On Tuesday, 17. September 2013 17:27:32 Albert Kurucz wrote:
> Here I am sharing my solution to address specific devices by the
> ftdi_eeprom utility, in an environment where multiple FTDI devices are
> connected with the same VID/PID.
> 
> The addressing works through an additional parameter in the config file,
> named "description".
> 
> Example:
> description=d:001/009
> 
> When this parameter is given, the ftdi_usb_open_string(ftdi, description)
> function is called instead of the ftdi_usb_open(ftdi, vendor_id,
> product_id).
> 
> The ftdi_usb_open_string allows addressing the device in many ways:
> "
>     \param description NULL-terminated description-string, using this
> format: \li <tt>d:\<devicenode></tt> path of bus and device-node (e.g.
> "003/001") within usb device tree (usually at /proc/bus/usb/) \li
> <tt>i:\<vendor>:\<product></tt> first device with given vendor and
> product id, ids can be decimal, octal (preceded by "0") or hex (preceded
> by "0x") \li <tt>i:\<vendor>:\<product>:\<index></tt> as above with index
> being the number of the device (starting with 0) if there are more than
> one \li <tt>s:\<vendor>:\<product>:\<serial></tt> first device with given
> vendor id, product id and serial string "
> 
> The modified source file is attached.
> Maintainers, please let me know if you have found it worthy.

I've taken a look at your modifications (after "normalizing" the code 
formatting). The attached patch shows your changes only.

I think the new "description" field is a duplicate of "product".
Please explain why "description" was added.


> ==========================
> 
> This e-mail, including any attachments, is intended for the exclusive use
> of the person(s) to which it is addressed and may contain proprietary,
> confidential and/or privileged information. If the reader of this e-mail
> is not the intended recipient or his or her authorized agent, any review,
> use, printing, copying, disclosure, dissemination or distribution of this
> e-mail is strictly prohibited. If you think that you have received the
> e-mail in error, please notify the sender immediately by return e-mail,
> delete this communication and destroy all copies.
> 
> ==========================

yeah right... :)

Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   
diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index c7db6e8..7b44540 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -107,6 +107,7 @@ int main(int argc, char *argv[])
     */
     cfg_opt_t opts[] =
     {
+        CFG_STR("description", "", 0),
         CFG_INT("vendor_id", 0, 0),
         CFG_INT("product_id", 0, 0),
         CFG_BOOL("self_powered", cfg_true, 0),
@@ -214,15 +215,33 @@ int main(int argc, char *argv[])
 
     if (_read > 0 || _erase > 0 || _flash > 0)
     {
-        int vendor_id = cfg_getint(cfg, "vendor_id");
-        int product_id = cfg_getint(cfg, "product_id");
+        char *description = cfg_getstr(cfg, "description");
 
-        i = ftdi_usb_open(ftdi, vendor_id, product_id);
+        if (description != NULL && strlen(description) > 0)
+        {
+            i = ftdi_usb_open_string(ftdi, description);
+
+            if (i != 0)
+            {
+                printf("Unable to find FTDI devices under given description: %s\n", description);
+            }
+        }
+        else
+        {
+            int vendor_id = cfg_getint(cfg, "vendor_id");
+            int product_id = cfg_getint(cfg, "product_id");
+
+            i = ftdi_usb_open(ftdi, vendor_id, product_id);
 
+            if (i != 0)
+            {
+                printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id);
+            }
+        }
         if (i != 0)
         {
             int default_pid = cfg_getint(cfg, "default_pid");
-            printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id);
+
             printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi));
             printf("Retrying with default FTDI pid=%#04x.\n", default_pid);
 

Reply via email to