I can confirm that doing the device reset on exit corrects this issue.

One additional note, it is probably impossible to protect everything with a
try: expect: for a KeyboardInterrupt. This exception can happen more or
less at random anywhere or anytime in your program when the user does a ^C.

The only way to have a stable solution is to install a signal handler for
SIGINT. Then implement a graceful exit strategy that can do the device
reset at the correct time as you bring down the program.

See: https://docs.python.org/3/library/signal.html

If a signal handler raises an exception, the exception will be propagated
> to the main thread and may be raised after any bytecode instruction. Most
> notably, a KeyboardInterrupt may appear at any point during execution. Most
> Python code, including the standard library, cannot be made robust against
> this, and so a KeyboardInterrupt (or any other exception resulting from a
> signal handler) may on rare occasions put the program in an unexpected
> state.
>

For many programs, especially those that merely want to exit on
> KeyboardInterrupt, this is not a problem, but applications that are complex
> or require high reliability should avoid raising exceptions from signal
> handlers. They should also avoid catching KeyboardInterrupt as a means of
> gracefully shutting down. Instead, they should install their own SIGINT
> handler.





On Sat, Apr 23, 2022 at 11:30 PM stuart lynne <stuart.ly...@gmail.com>
wrote:

> The device reset seems to help.
>
> When properly exited it went about eight restarts correctly.
>
> Interrupted (^C) exit I think misses the device reset in some cases (I can
> fix that) and eventually it got to the FUBAR state.
>
> Once in that state opening and closing with reset does not fix it.
> Physical replug necessary.
>
> I'll clean up the exception handling so that breaking to exit goes through
> the proper closing sequence and see if that helps.
>
>
> Thanks!
>
>
> On Sat, Apr 23, 2022 at 8:45 PM Xiaofan Chen <xiaof...@gmail.com> wrote:
>
>> On Sun, Apr 24, 2022 at 8:43 AM stuart lynne <stuart.ly...@gmail.com>
>> wrote:
>> >
>> > I am seeing a consistent issue with Garmin Ant+ dongles under Windows
>> with libusb0.
>> >
>> > They work the first time my application runs, but fail on the second
>> attempt.
>> >
>> > I have verified the same behaviour across three Garmin Dongles. I have
>> verified
>> >  that the Cycplus Dongle works correctly.
>> >
>> > To maintain compatibility with the other applications running (Zwift
>> and PerfPro
>> > CT Smart) which rely on libusb0 I need to use that backend.
>> >
>> > Those applications do not have any problems with the Garmin (or Cycplus)
>> > dongles, using them multiple times without a problem.
>> >
>> > Is it possible that I need to do something on exit that might cause
>> this?
>> >
>> > Is there anything I can do to remediate this when seen?
>> >
>>
>> Does it make a difference if you use the libusb-1.0 backend? This is not
>> a solution but rather a troubleshooting step. You can keep your driver
>> as it is, but switch to libusb-1.0 backend. You need to have libusbk.dll
>> and libusb-1.0.dll in place to make that work.
>>
>> I understand that you may have to keep with the libusb0.sys based
>> driver provided
>> by Garmin (I used to have one such USB dongle for my old Garmin Vivofit
>> 1).
>>
>> The other potential work-around is to add a device reset at exit. Usually
>> this kind of issue is caused by device firmware bug (eg: USB data toggle
>> issues) and the hope is that the device reset can put the firmware to a
>> good
>> state.
>>
>>
>>
>> --
>> Xiaofan
>>
>>
>> _______________________________________________
>> pyusb-users mailing list
>> pyusb-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>>
>
>
> --
> __________O___________
> _______-\<,____________
> _____(_)/_(_)___________
> _________________________
> Stuart_Lynne____<stuart.ly...@gmail.com
> >____604-518-1749(m)__604-461-7532(h)
>


-- 
__________O___________
_______-\<,____________
_____(_)/_(_)___________
_________________________
Stuart_Lynne____<stuart.ly...@gmail.com>____604-518-1749(m)__604-461-7532(h)
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to