From: stuart l. <stu...@gm...> - 2022-02-03 22:25:01
|
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. Suggestions would be appreciated. Thanks! -- __________O___________ _______-\<,____________ _____(_)/_(_)___________ _________________________ Stuart_Lynne____<stu...@gm...>____604-518-1749(m)__604-461-7532(h) |
From: Jonas M. <jo...@pr...> - 2022-02-04 00:22:15
|
On Thu, Feb 3, 2022 at 7:25 PM stuart lynne <stu...@gm...> 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____<stu...@gm...>____604-518-1749(m)__604-461-7532(h) > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users |
From: stuart l. <stu...@gm...> - 2022-02-04 08:40:24
|
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 < pyu...@li...> wrote: > On Thu, Feb 3, 2022 at 7:25 PM stuart lynne <stu...@gm...> > 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____<stu...@gm... > >____604-518-1749(m)__604-461-7532(h) > > _______________________________________________ > > pyusb-users mailing list > > pyu...@li... > > https://lists.sourceforge.net/lists/listinfo/pyusb-users > > > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > -- __________O___________ _______-\<,____________ _____(_)/_(_)___________ _________________________ Stuart_Lynne____<stu...@gm...>____604-518-1749(m)__604-461-7532(h) |
From: Xiaofan C. <xia...@gm...> - 2022-02-04 10:14:34
|
On Fri, Feb 4, 2022 at 4:40 PM stuart lynne <stu...@gm...> wrote: > > 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(). Windows can be a big problem. What is the driver used with your ANT+ dongle? I remember my old Garmin ANT dongle (for use with the Garmin VivoFit 1 and 3) uses libusb-win32 driver. We have improved the support of libusb0.sys in libusb 1.0.25 release but there may still be some problems. Ref: https://github.com/libusb/libusb/wiki/FAQ#How_to_use_libusb_under_Windows Good thing is that pyusb does support libusb-0.1 backend even though libusb-1.0 backend is recommended. If your ANT+ dongle uses WinUSB driver, you have a problem as WinUSB does not support multiple concurrent applications. Ref: https://github.com/libusb/libusb/wiki/Windows#Known_Restrictions There is a workaround -- you have to write a daemon (eg: Windows service) to deal with them and then multiple applications can call the daemon to work with the ANT+ device. For macOS, as long as your ANT+ dongle is not claimed exclusively by existing kernel drivers, hopefully it will be fine. Read the libusb caveats as well for things to take note under all operating systems. https://libusb.sourceforge.io/api-1.0/libusb_caveats.html -- Xiaofan |
From: stuart l. <stu...@gm...> - 2022-02-05 02:25:59
|
Most people are using a generic libusb-win32 driver for Ant+ dongles. I have two types, Garmin and Cycplus, and both show up as Dynastream as the manufacturer, but they do have minor differences, so even if the same chip from Dynastream, different configuration possibly. In driver details, that shows up with the actual driver as libusb0.dll. On Fri, Feb 4, 2022 at 2:14 AM Xiaofan Chen <xia...@gm...> wrote: > On Fri, Feb 4, 2022 at 4:40 PM stuart lynne <stu...@gm...> > wrote: > > > > > > Windows can be a big problem. > > What is the driver used with your ANT+ dongle? I remember my old > Garmin ANT dongle (for use with the Garmin VivoFit 1 and 3) uses > libusb-win32 driver. We have improved the support of libusb0.sys > in libusb 1.0.25 release but there may still be some problems. > Ref: > https://github.com/libusb/libusb/wiki/FAQ#How_to_use_libusb_under_Windows > > Good thing is that pyusb does support libusb-0.1 backend even though > libusb-1.0 backend is recommended. > > If your ANT+ dongle uses WinUSB driver, you have a problem as > WinUSB does not support multiple concurrent applications. > Ref: https://github.com/libusb/libusb/wiki/Windows#Known_Restrictions > > There is a workaround -- you have to write a daemon (eg: Windows service) > to deal with them and then multiple applications can call the daemon to > work > with the ANT+ device. > > For macOS, as long as your ANT+ dongle is not claimed exclusively by > existing kernel drivers, hopefully it will be fine. > > Read the libusb caveats as well for things to take note under all > operating systems. > https://libusb.sourceforge.io/api-1.0/libusb_caveats.html > > -- > Xiaofan > > > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > -- __________O___________ _______-\<,____________ _____(_)/_(_)___________ _________________________ Stuart_Lynne____<stu...@gm...>____604-518-1749(m)__604-461-7532(h) |
From: Xiaofan C. <xia...@gm...> - 2022-02-05 10:05:03
|
On Sat, Feb 5, 2022 at 10:26 AM stuart lynne <stu...@gm...> wrote: > > Most people are using a generic libusb-win32 driver for Ant+ dongles. > I have two types, Garmin and Cycplus, and both show up as Dynastream > as the manufacturer, but they do have minor differences, so even if the same > chip from Dynastream, different configuration possibly. > > In driver details, that shows up with the actual driver as libusb0.dll. In that case, you will probably want to use pyusb libusb-0.1 backend as the driver (libusb0.sys) and libusb0.dll are already in place. You do not need to ship libusb-1.0.dll if you use the libusb-0.1 backend. I remember Garmin shipped a pretty old version of libusb0.sys and libusb0.dll but hopefully it does not cause issues for you. I may be wrong though. libusb-win32 official release is also very old -- 1.2.6.0 version was released in 2012. -- Xiaofan |
From: stuart l. <stu...@gm...> - 2022-02-05 19:14:43
|
Thanks for your suggestions. I'm also seeing some strange differences in how the two types of Ant+ dongles I have (current models from Garmin and Cycplus.) The Cycplus for example does not appear to support a get_interface control request. That prevented the libant library from using it. They were using that call to fetch the alternate setting which will always be zero, so just removing the extra request is OK. The Garmin has some trouble with closing and re-opening in Linux with libusb1 the backend. Typically will not function correctly on the first open. Second open works. Then in some cases, subsequent use fails entirely until the device is replugged. I'm just starting to test them in Windows, and both are reacting slightly differently there. But (currently) that is defaulting to libusb0, so I need to figure out how to switch that. And then make sure I can push that out in the app as built with pyinstaller. On Sat, Feb 5, 2022 at 2:05 AM Xiaofan Chen <xia...@gm...> wrote: > On Sat, Feb 5, 2022 at 10:26 AM stuart lynne <stu...@gm...> > wrote: > > > > Most people are using a generic libusb-win32 driver for Ant+ dongles. > > I have two types, Garmin and Cycplus, and both show up as Dynastream > > as the manufacturer, but they do have minor differences, so even if the > same > > chip from Dynastream, different configuration possibly. > > > > In driver details, that shows up with the actual driver as libusb0.dll. > > In that case, you will probably want to use pyusb libusb-0.1 backend > as the driver (libusb0.sys) and libusb0.dll are already in place. You > do not need to ship libusb-1.0.dll if you use the libusb-0.1 backend. > > I remember Garmin shipped a pretty old version of libusb0.sys and > libusb0.dll but hopefully it does not cause issues for you. I may be > wrong though. > > libusb-win32 official release is also very old -- 1.2.6.0 version > was released in 2012. > > > > -- > Xiaofan > > > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > -- __________O___________ _______-\<,____________ _____(_)/_(_)___________ _________________________ Stuart_Lynne____<stu...@gm...>____604-518-1749(m)__604-461-7532(h) |