Yes, I'm looking at claim_interface/release_interface. It seems to take a
bit of a song and dance to get it to work.

And I'm definitely seeing different results between Linux and Windows. I
can live with that, platform.system() can be used to differentiate with
different solutions.

A bigger issue (especially for Windows which is the main target and
possibly macOS) will be playing nice with existing commercial programs.
Can't interfere with them, just need to find an available Ant+ dongle
without causing problems and then claiming it so other programs won't
attempt to use it.

Under Linux it appears that set_configuration() will fail if another
process has done a claim_interface(). It doesn't look like
claim_interface() can fail, which possibly means two processes could get
past the set_configuration() test and then both attempt to do a
claim_interface().


On Thu, Feb 3, 2022 at 4:22 PM Jonas Malaco via pyusb-users <
pyusb-users@lists.sourceforge.net> wrote:

> On Thu, Feb 3, 2022 at 7:25 PM stuart lynne <stuart.ly...@gmail.com>
> wrote:
> >
> > I am working with libant and pyusb to support Ant+ devices.
> >
> > The issue I am trying to fix is preventing access to a device that is
> already open by another process. There may (usually will) be multiple Ant+
> devices plugged in, and one or more may be in active use by another program.
> >
> > I need to find an unused device and then open that, without interfering
> with the use of the other open devices.
> >
> > Currently, I'm testing on Linux, but this will be deployed on Windows
> and macOS as well.
> >
> > There doesn't appear to be anything to prevent multiple access, and at
> least initial testing with two processes both using pyusb shows them
> interfering with each other as they open, close while attempting to access
> the Ant device.
>
> Hi Stuart,
>
> As far as I know there is no cross-platform way to unilaterally
> prevent other processes from accessing a USB device.
>
> However, careful use of [libusb_]claim_interface() by both processes
> can prevent one from trampling over the other: claiming the interface
> should fail if another process has already done it, so each process
> can use it as a pseudo-lock for the device it's working on.
>
> Note that I'm talking about *explicitly* claiming the interface – with
> usb.tools.claim_interface() – and not the automatic claiming/releasing
> that PyUSB does by default.
>
> Jonas
>
> >
> > Suggestions would be appreciated.
> >
> > Thanks!
> >
> >
> > --
> > __________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
>
>
> _______________________________________________
> 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)
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to