As Michael Wilt <mike@xxxxxxxxx> pointed out with the libspi example, we
can't change the interface on an already open device. Appended patch prints
out a waring in that case.
Should this perhaps even abort? If the program doesn't check for the error,
it may talk to a different device.
Bye
--
Uwe Bonnes bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 8291a3f75c75b21f8687fbdd49a7acdd9e2ecaba Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 30 Sep 2011 12:44:14 +0200
Subject: Interface can not be changed on an already open device
---
src/ftdi.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 1f45e95..89575a2 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -149,12 +149,19 @@ struct ftdi_context *ftdi_new(void)
\retval 0: all fine
\retval -1: unknown interface
\retval -2: USB device unavailable
+ \retval -2: 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)
+ {
+ if ((ftdi->index != interface) && ((ftdi->index == INTERFACE_A) &&
(interface != INTERFACE_ANY))
+
+ ftdi_error_return(-3, "Interface can not be changed on an already
open device");
+ }
switch (interface)
{
case INTERFACE_ANY:
--
1.7.3.4
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|