libftdi Archives

Subject: Re: [Resent/Corrected] Interface can not be changed on an already open device

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx, Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 Oct 2011 16:02:55 +0200
On Tuesday, 4. October 2011 18:49:26 Uwe Bonnes wrote:
> Please use "if (ftdi->usb_dev && ftdi->index != interface)" for the sake
> of simplicity.

How about this one, does it represent your original idea?

-----------------------------------------------------

Based upon code from Uwe Bonnes, improved by me.
---
 src/ftdi.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index 1f45e95..59a9eea 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -149,12 +149,23 @@ struct ftdi_context *ftdi_new(void)
     \retval  0: all fine
     \retval -1: unknown interface
     \retval -2: USB device unavailable
+    \retval -3: Device already open, interface can't be set in that state
 */
 int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface 
interface)
 {
     if (ftdi == NULL)
         ftdi_error_return(-2, "USB device unavailable");
 
+    if (ftdi->usb_dev != NULL)
+    {
+        int check_interface = interface;
+        if (check_interface == INTERFACE_ANY)
+            check_interface = INTERFACE_A;
+
+        if (ftdi->index != check_interface)
+            ftdi_error_return(-3, "Interface can not be changed on an already 
open device");
+    }
+
     switch (interface)
     {
         case INTERFACE_ANY:
-- 
1.7.4.4

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

Current Thread