greatscottgadgets / hackrf

low cost software radio platform
https://greatscottgadgets.com/hackrf/
GNU General Public License v2.0
6.55k stars 1.53k forks source link

recent hackrf_exit() returns "some hackrf is sill in use" #459

Closed guruofquality closed 6 years ago

guruofquality commented 6 years ago

Looks like hackrf_exit() never decrements open_devices. Its causing some strange errors for me, even when hackrf is not even used because I print the error code:

Added by commit: https://github.com/mossmann/hackrf/commit/73ca8c09 perhaps?

guruofquality commented 6 years ago

@gvz So hackrf_init increments the call, and hackrf_close decrements the call. But these arent matching calls, so naturally hackrf_exit() will return an error.

example: finding devices

call hackrf_init()
call hackrf_device_list_open()
hackrf_exit() - gives an error, open_devices never decremented

example: opening two hackrf

call hackrf_init()
d1 = hackrf_open()
d1 = hackrf_open()
hackrf_close(d1)
hackrf_close(d2)
hackrf_exit() - gives an error, open_devices is negative

Judging from the variable name, open_devices++ should be in the actual open* calls and not hackrf_init? That way it would count the actual number of open devices.

dominicgs commented 6 years ago

I agree, it looks like moving the open_devices++; line to the end of hackrf_open_setup() should do the trick.

gvz commented 6 years ago

Oh, I guess that was my fault. I used gnuradio to test my code, it calls init and open equally often. At the moment I can not perform any tests, as all my hackRFs a occupied in measurements. Therefore, I hesitate to make a pr that fixes this issue.

dominicgs commented 6 years ago

I believe that I fixed this in 65c7b5a