From 289c8180cbc36fc3566b32e4dd906033ef337547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 28 Feb 2011 01:02:17 +0100 Subject: check CloseDevice and fix a little --- libk8055/libk8055.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index 03925c9..7489759 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -247,23 +247,22 @@ int OpenDevice( long board_address ) { } /* Close the Current device */ -int CloseDevice() -{ - int rc; - - if (curr_dev->dev_no == 0) - { - if (debug) - fprintf(stderr, "Current device is not open\n" ); - return 0; - } - rc = usb_close(curr_dev->device_handle); - if (rc >= 0) - { - curr_dev->dev_no = 0; /* Not active nay more */ - curr_dev->device_handle = NULL; - } - return rc; +int CloseDevice() { + if (curr_dev->dev_no == 0) { + if (debug) fprintf(stderr, "Current device is not open\n" ); + return 0; + } + if(curr_dev->dev_hanlde==NULL) { + if (debug) fprintf(stderr, "Current device is marked as open, but device hanlde is NULL\n" ); + curr_dev->dev_no = 0; + return 0; + } + int rc = usb_close(curr_dev->device_handle); + if (rc >= 0) { + curr_dev->dev_no = 0; + curr_dev->device_handle = NULL; + } + return rc; } /* New function in version 2 of Velleman DLL, should return deviceno if OK */ -- cgit v1.1-2-g2b99