I want to give exclusive access to the input coming from a LASER barcode (point and trigger type) reader to a Python 3.6 program; that is, no other program should get input from the reader, regardless of UI focus (because the python program has already claimed the device for itself only.)
I've been able to this just fine on a Linux machine using Python 3.6 and pyusb library, but I can't replicate the funcionality in macOS, I get an error stating that I have insufficient permissions.
This actually happens in Linux too but it is easily worked-around by adding the current user to dialout
group and creating udev rules file in /etc/udev/rules.d/99-usb.rules
granting permissions to a user or group with this rule:
SUBSYSTEMS=="usb", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0666"
How can equivalent permissions be granted on macOS?
Example code does exatcly what I want on Linux, but fails completely on macOS:
import usb.core
import usb.util
device = usb.core.find(idVendor=0x0519, idProduct=0x2017)
if device.is_kernel_driver_active(0):
device.detach_kernel_driver(0)
print("Kernel driver detached")
else:
print("Kernel driver already detached")
try:
device.set_configuration()
device.reset()
usb.util.claim_interface(device, 0) # error happens here
print("Claimed device")
except Exception as e:
print("Error when claiming device", e)
sys.exit(1)
From what I've found on the Web, It doesn't seem like macOS has an equivalent mechanism to grant this access.
Error on macOS:
[Errno 13] Access denied (insufficient permissions)