diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-02-28 01:02:17 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-02-28 01:02:17 +0100 |
commit | 289c8180cbc36fc3566b32e4dd906033ef337547 (patch) | |
tree | d1c741eb9009fb5bbc5c8d4e4825401533d7610b | |
parent | 4f654ed1f3164fc46dc9c3d693bc4676ac80b13c (diff) | |
download | k8055-289c8180cbc36fc3566b32e4dd906033ef337547.zip k8055-289c8180cbc36fc3566b32e4dd906033ef337547.tar.gz |
check CloseDevice and fix a little
-rw-r--r-- | libk8055/libk8055.c | 33 |
1 files 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 */ |