diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/.cvsignore libgpio/.cvsignore
--- libgpio.orig/.cvsignore	Fri Jul 21 20:56:24 2000
+++ libgpio/.cvsignore	Sat Aug  5 11:45:33 2000
@@ -25,3 +25,5 @@
 gpio-usb.lo
 gpioConf.sh
 libgpio.la
+Makefile
+Makefile.in
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/configure.in libgpio/configure.in
--- libgpio.orig/configure.in	Tue Aug  1 01:41:26 2000
+++ libgpio/configure.in	Sat Aug  5 11:45:33 2000
@@ -63,8 +63,8 @@
 AC_PATH_PROG(LIBUSB_CONFIG,libusb-config)
 if test -n "${LIBUSB_CONFIG}"; then
   IOLIB_SUBDIRS="$IOLIB_SUBDIRS usb"
-  IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lusb -lgpio_usb"
-  IOLIB_CFLAGS="$IOLIB_CFLAGS -DGPIO_USB"
+  IOLIB_LDFLAGS="$IOLIB_LDFLAGS `libusb-config --libs` -lgpio_usb"
+  IOLIB_CFLAGS="$IOLIB_CFLAGS -DGPIO_USB `libusb-config --cflags`"
 else
   AC_MSG_WARN([
 
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/include/gpio.h libgpio/include/gpio.h
--- libgpio.orig/include/gpio.h	Sun Aug 20 19:07:00 2000
+++ libgpio/include/gpio.h	Sat Aug  5 11:45:33 2000
@@ -248,6 +248,12 @@
 				  successful: number of bytes read
 				unsuccessful: GPIO_ERROR
 		*/
+       int gpio_update		(gpio_device *dev);
+       		/* Updates the settings by closing/reopening the device
+			return values:
+				  successful: GPIO_OK
+				unsuccessful: GPIO_ERROR
+		*/
 
 
 /* Serial and Parallel specific functions
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/libgpio/gpio.c libgpio/libgpio/gpio.c
--- libgpio.orig/libgpio/gpio.c	Sun Aug 20 19:07:00 2000
+++ libgpio/libgpio/gpio.c	Sun Aug  6 15:43:20 2000
@@ -34,18 +34,16 @@
 int		 device_count;
 
 /* Toggle to turn on/off debugging */
-int		 device_debug=0;
+int		 device_debug=1;
 
 void gpio_debug_printf (char *format, ...) {
 
         va_list         pvar;
 
         if (device_debug) {
-                fprintf(stderr, "gpio: ");
                 va_start(pvar, format);
                 vfprintf(stderr, format, pvar);
                 va_end(pvar);
-                fprintf(stderr, "\n");
         }
 }
 
@@ -226,6 +224,11 @@
 {
 	memcpy(settings, &dev->settings, sizeof(gpio_device_settings));
 	return GPIO_OK;
+}
+
+int gpio_update(gpio_device *dev)
+{
+	return dev->ops->update(dev);
 }
 
 /* Serial and Parallel-specific functions */
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/libgpio/library.c libgpio/libgpio/library.c
--- libgpio.orig/libgpio/library.c	Tue Aug  1 02:20:11 2000
+++ libgpio/libgpio/library.c	Sun Aug  6 17:50:45 2000
@@ -1,3 +1,5 @@
+#include <dirent.h>
+#include <string.h>
 #include <dlfcn.h>
 #include <stdio.h>
 
@@ -13,11 +15,12 @@
         void *lh;
 
         if ((lh = dlopen(filename, RTLD_LAZY))==NULL) {
-		gpio_debug_printf("%s is not a library (%s) ", filename, dlerror());
+		gpio_debug_printf("%s is not a library (%s)\n",
+				filename, dlerror());
                 return (GPIO_ERROR);
 	}
 
-	gpio_debug_printf("%s is a library ", filename);
+	gpio_debug_printf("%s is a library\n", filename);
         dlclose(lh);
 
         return (GPIO_OK);
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/serial/unix.c libgpio/serial/unix.c
--- libgpio.orig/serial/unix.c	Fri Aug  4 16:37:48 2000
+++ libgpio/serial/unix.c	Sat Aug  5 11:45:33 2000
@@ -56,6 +56,8 @@
 static struct sgttyb term_old;
 #endif
 
+extern int device_debug;
+
 /* Serial prototypes
    ------------------------------------------------------------------ */
 int 		gpio_serial_init(gpio_device *dev);
@@ -159,6 +161,7 @@
    ------------------------------------------------------------------ */
 
 int gpio_serial_init (gpio_device *dev) {
+	gpio_debug_printf("gpio_serial_init() called\n");
 	/* save previous setttings in to dev->settings_saved */
 #if HAVE_TERMIOS_H
 	if (tcgetattr(dev->device_fd, &term_old) < 0) {
@@ -175,11 +178,11 @@
 }
 
 int gpio_serial_exit (gpio_device *dev) {
-
 }
 
 int gpio_serial_open(gpio_device * dev)
 {
+	gpio_debug_printf("gpio_serial_open() called\n");
 
 #ifdef __FreeBSD__
 	dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_NONBLOCK);
@@ -200,6 +203,7 @@
 
 int gpio_serial_close(gpio_device * dev)
 {
+	gpio_debug_printf("gpio_serial_close() called\n");
 	if (close(dev->device_fd) == -1) {
 		perror("gpio_serial_close: tried closing device file descriptor");
 		return GPIO_ERROR;
@@ -210,6 +214,14 @@
 int gpio_serial_write(gpio_device * dev, char *bytes, int size)
 {
 	int len, ret;
+	int i;
+
+	if (device_debug) {
+		gpio_debug_printf("gpio_serial_write(): ");
+		for (i = 0; i < size; i++)
+			gpio_debug_printf("%02x ", (unsigned char)bytes[i]);
+		gpio_debug_printf("\n");
+	}
 
 	len = 0;
 	while (len < size) {	/* Make sure we write all data while handling */
@@ -279,6 +291,14 @@
 			return GPIO_ERROR;
 		}
 	}
+	if (device_debug) {
+		int i;
+
+		gpio_debug_printf("gpio_serial_read(timeout=%d): ",dev->timeout);
+		for (i = 0; i < readen; i++)
+		  gpio_debug_printf("%02x ", (unsigned char)(bytes[i]));
+		gpio_debug_printf("\n");
+	}
 	return readen;
 }
 
@@ -330,29 +350,38 @@
 {
 	int bit,request;
 
+	gpio_debug_printf("gpio_serial_set_pin(): ");
+
 	switch(pin) {
 		case PIN_RTS:
+			gpio_debug_printf("pin=PIN_RTS ");
 			bit = TIOCM_RTS;
 			break;
 		case PIN_DTR:
+			gpio_debug_printf("pin=PIN_DTR ");
 			bit = TIOCM_DTR;
 			break;
 		case PIN_CTS:
+			gpio_debug_printf("pin=PIN_CTS ");
 			bit = TIOCM_CTS;
 			break;
 		case PIN_DSR:
+			gpio_debug_printf("pin=PIN_DSR ");
 			bit = TIOCM_DSR;
 			break;
 		case PIN_CD:
+			gpio_debug_printf("pin=PIN_CD ");
 			bit = TIOCM_CD;
 			break;
 		case PIN_RING:
+			gpio_debug_printf("pin=PIN_RING ");
 			bit = TIOCM_RNG;
 			break;
 		default:
 			return GPIO_ERROR;
 	}
 	
+	gpio_debug_printf("level=%d\n", level);
 	switch(level) {
 		case 0:
 			request = TIOCMBIS;
@@ -378,6 +407,7 @@
  */
 int gpio_serial_update(gpio_device * dev)
 {
+	gpio_debug_printf("gpio_serial_update() called\n");
 	memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings));
 
 	if (dev->device_fd != 0) {
@@ -402,6 +432,8 @@
 #if HAVE_TERMIOS_H
 	struct termios tio;
 
+	gpio_debug_printf("gpio_serial_set_baudrate(speed=%d) called\n",
+		dev->settings.serial.speed);
 	if (tcgetattr(dev->device_fd, &tio) < 0) {
 		perror("tcgetattr");
 		return GPIO_ERROR;
@@ -440,6 +472,8 @@
 #else
 	struct sgttyb ttyb;
 
+	gpio_debug_printf("gpio_serial_set_baudrate(speed=%d) called\n",
+		dev->settings.serial.speed);
 	if (ioctl(dev->device_fd, TIOCGETP, &ttyb) < 0) {
 		perror("ioctl(TIOCGETP)");
 		return GPIO_ERROR;
diff -u --recursive --new-file --exclude-from=/tmp/cvs.exclude.libgpio libgpio.orig/usb/libusb.c libgpio/usb/libusb.c
--- libgpio.orig/usb/libusb.c	Sun Aug 20 19:07:00 2000
+++ libgpio/usb/libusb.c	Thu Aug 10 16:06:56 2000
@@ -31,7 +31,7 @@
 #include <usb.h>
 #include "gpio.h"
 
-#undef GPIO_USB_DEBUG
+extern int device_debug;
 
 int gpio_usb_list(gpio_device_info *list, int *count);
 int gpio_usb_init(gpio_device *dev);
@@ -52,12 +52,14 @@
 /* Dynamic library functions
    --------------------------------------------------------------------- */
 
-gpio_device_type gpio_library_type () {
+gpio_device_type 
+gpio_library_type () {
 
         return (GPIO_DEVICE_USB);
 }
 
-gpio_operations *gpio_library_operations () {
+gpio_operations *
+gpio_library_operations () {
 
         gpio_operations *ops;
 
@@ -79,7 +81,8 @@
         return (ops);
 }
 
-int gpio_library_list(gpio_device_info *list, int *count)
+int 
+gpio_library_list(gpio_device_info *list, int *count)
 {
 	usb_init();
 	usb_find_busses();
@@ -94,21 +97,22 @@
 	return GPIO_OK;
 }
 
-int gpio_usb_init(gpio_device *dev)
+int 
+gpio_usb_init(gpio_device *dev)
 {
 }
 
-int gpio_usb_exit(gpio_device *dev)
+int 
+gpio_usb_exit(gpio_device *dev)
 {
 }
 
-int gpio_usb_open(gpio_device *dev)
+int 
+gpio_usb_open(gpio_device *dev)
 {
 	int ret;
 
-#ifdef GPIO_USB_DEBUG
-	printf ("gpio_usb_open() called\n");
-#endif
+	gpio_debug_printf ("gpio_usb_open() called\n");
 	dev->device_handle = usb_open(dev->usb_device);
 	if (!dev->device_handle)
 		return GPIO_ERROR;
@@ -138,13 +142,12 @@
 	return GPIO_OK;
 }
 
-int gpio_usb_close(gpio_device *dev)
+int 
+gpio_usb_close(gpio_device *dev)
 {
 	int ret;
 
-#ifdef GPIO_USB_DEBUG
-	printf ("gpio_usb_close() called\n");
-#endif
+	gpio_debug_printf ("gpio_usb_close() called\n");
 	if (usb_close(dev->device_handle) < 0)
 		fprintf(stderr, "gpio_usb_close: %s\n",
 			strerror(errno));
@@ -154,7 +157,8 @@
 	return GPIO_OK;
 }
 
-int gpio_usb_reset(gpio_device *dev)
+int 
+gpio_usb_reset(gpio_device *dev)
 {
 	gpio_usb_close(dev);
 	return gpio_usb_open(dev);
@@ -179,71 +183,173 @@
 	}
 	if (ret)
 		gpio_debug_printf ("gpio_usb_clear_halt() : ioctl() returns %d\n",ret);
+	if (ret) {
+		gpio_debug_printf ("gpio_usb_clear_halt() : calling usb_clear_halt() again...\n");
+		if (ep==GPIO_USB_IN_ENDPOINT)
+			ret=usb_clear_halt(dev->device_handle, dev->settings.usb.inep);
+		else
+			ret=usb_clear_halt(dev->device_handle, dev->settings.usb.outep);
+		if (ret)
+			gpio_debug_printf ("gpio_usb_clear_halt() : clear_halt() fails again and returns %d\n",ret);
+#if 0
+		gpio_debug_printf ("gpio_usb_clear_halt() : calling usb_resetep() now...\n");
+		if (ep==GPIO_USB_IN_ENDPOINT)
+			ret=usb_resetep(dev->device_handle, dev->settings.usb.inep);
+		else
+			ret=usb_resetep(dev->device_handle, dev->settings.usb.outep);
+		if (ret)
+			gpio_debug_printf ("gpio_usb_clear_halt() : usb_resetep() returns %d\n",ret);
+		gpio_debug_printf ("gpio_usb_clear_halt() : calling usb_reset() now...\n");
+		ret=usb_reset(dev->device_handle);
+		if (ret)
+			gpio_debug_printf ("gpio_usb_clear_halt() : usb_reset() returns %d\n",ret);
+#endif
+	}
 	return (ret ? GPIO_ERROR : GPIO_OK);
 }
 
-int gpio_usb_write(gpio_device * dev, char *bytes, int size)
+int 
+gpio_usb_write(gpio_device * dev, char *bytes, int size)
 {
 	int i;
 
-#ifdef GPIO_USB_DEBUG
-	printf("gpio_usb_write(): ");
-	for (i = 0; i < size; i++)
-	  printf("%02x ",(unsigned char)bytes[i]);
-	printf("\n");
-#endif
+	if (device_debug) {
+		gpio_debug_printf("gpio_usb_write(): ");
+		if (device_debug > 1)
+			for (i = 0; i < size; i++)
+				gpio_debug_printf("%02x ",
+					(unsigned char)bytes[i]);
+		else
+			for (i = 0; i < size; i++) {
+				gpio_debug_printf("%02x ",
+					(unsigned char)bytes[i]);
+				if (i==16) {
+					gpio_debug_printf("...");
+					break;
+				}
+			}
+		gpio_debug_printf("\n");
+	}
 	return usb_bulk_write(dev->device_handle, dev->settings.usb.outep,
 			      bytes, size, dev->timeout);
 }
 
-int gpio_usb_read(gpio_device * dev, char *bytes, int size)
+int
+gpio_usb_read(gpio_device * dev, char *bytes, int size)
 {
 	int i, ret;
 
 	ret = usb_bulk_read(dev->device_handle, dev->settings.usb.inep,
 			     bytes, size, dev->timeout);
+	if (device_debug) {
+		gpio_debug_printf("gpio_usb_read(timeout=%d,ret=%d): ",
+				  dev->timeout,ret);
+		if (device_debug > 1)
+			for (i = 0; i < ret; i++)
+				gpio_debug_printf("%02x ",
+					(unsigned char)(bytes[i]));
+		else
+			for (i = 0; i < ret; i++) {
+				gpio_debug_printf("%02x ",
+					(unsigned char)(bytes[i]));
+				if (i==16) {
+					gpio_debug_printf("...");
+					break;
+				}
+			}
+		gpio_debug_printf("\n");
+	}
 	if (ret < 0)
 		return GPIO_ERROR;
 
-#ifdef GPIO_USB_DEBUG
-	printf("gpio_usb_read(timeout=%d): ", dev->timeout);
-	for (i = 0; i < ret; i++)
-	  printf("%02x ",(unsigned char)(bytes[i]));
-	printf("\n");
-#endif
 	return ret;
 }
 
-int gpio_usb_msg_write_lib(gpio_device * dev, int value, char *bytes, int size)
+int 
+gpio_usb_msg_write_lib(gpio_device * dev, int value, char *bytes, int size)
 {
+	int i;
+
+	if (device_debug) {
+		gpio_debug_printf("gpio_usb_msg_write_lib(value=%d): ",value);
+		if (device_debug > 1)
+			for (i = 0; i < size; i++)
+				gpio_debug_printf("%02x ",
+					(unsigned char)bytes[i]);
+		else
+			for (i = 0; i < size; i++) {
+				gpio_debug_printf("%02x ",
+					(unsigned char)bytes[i]);
+				if (i==16) {
+					gpio_debug_printf("...");
+					break;
+				}
+			}
+
+		gpio_debug_printf("\n");
+	}
 	return usb_control_msg(dev->device_handle,
 		USB_TYPE_VENDOR | USB_RECIP_DEVICE,
 		size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout);
 }
 
-int gpio_usb_msg_read_lib(gpio_device * dev, int value, char *bytes, int size)
+int
+gpio_usb_msg_read_lib(gpio_device * dev, int value, char *bytes, int size)
 {
-	return usb_control_msg(dev->device_handle,
+	int ret, i;
+
+	ret=  usb_control_msg(dev->device_handle,
 		USB_TYPE_VENDOR | USB_RECIP_DEVICE | 0x80,
 		size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout);
+	if (device_debug) {
+		gpio_debug_printf("gpio_usb_msg_read_lib"
+				  "(value=%d,timeout=%d,ret=%d): ",
+				  value,dev->timeout,ret);
+		if (device_debug > 1)
+			for (i = 0; i < ret; i++)
+				gpio_debug_printf("%02x ",
+					(unsigned char)(bytes[i]));
+		else
+			for (i = 0; i < ret; i++) {
+				gpio_debug_printf("%02x ",
+					(unsigned char)(bytes[i]));
+				if (i==16) {
+					gpio_debug_printf("...");
+					break;
+				}
+			}
+		gpio_debug_printf("\n");
+	}
+	return ret;
 }
 
 /*
  * This function applys changes to the device
  * (At this time it does nothing)
  */
-int gpio_usb_update(gpio_device * dev)
+int 
+gpio_usb_update(gpio_device * dev)
 {
+	gpio_debug_printf ("gpio_usb_update() called\n");
 	memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings));
-
 	return GPIO_OK;
 }
 
-int gpio_usb_find_device_lib(gpio_device * d, int idvendor, int idproduct)
+int 
+gpio_usb_find_device_lib(gpio_device * d, int idvendor, int idproduct)
 {
 	struct usb_bus *bus;
 	struct usb_device *dev;
 
+	gpio_debug_printf ("gpio_usb_find_device_lib(%x,%x) called\n",
+		idvendor,idproduct);
+	if (!usb_busses) {
+		gpio_debug_printf ("gpio_usb_find_device_lib() : "
+				   "reseting usb.\n");
+		usb_init();
+		usb_find_busses();
+		usb_find_devices();
+	}
 	for (bus = usb_busses; bus; bus = bus->next) {
 		for (dev = bus->devices; dev; dev = dev->next) {
 			if ((dev->descriptor.idVendor == idvendor) &&
