USB Insufficient Permissions Error

I am receiving an error when trying to connect to a USB device.

The program is running in a container deployed using the Torizon IDE add on in VSC.

The device has been added to the docker-compose.yml as follows:

devices:
  - dev/bus/usb/001/003

A rule file has been created under /etc/udev/rules.d:
94-toradex-pwm.rules

SUBSYSTEM==“usb”, ATTRS{idVendor}==“0x0403”, ATTRS{idProduct==“0x6002”}, MODE=“0666”, GROUP=“Torizon”
SUBSYSTEM==“usb_device”, ATTRS{idVendor}==“0x0403”, ATTRS{idPrdouct==“0x6001”}, MODE=“0666”, Group=“Torizon”

I am using the pyusb library to connect and setup the device.

The USB device is asynchronous and constantly streaming data.

The Error Received:

Exception has occurred: USBError
[Errno 13] Access denied (insufficient permissions)
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

Code:

import usb.core

def measure_func():
dev = usb.core.find(idVendor=0x0403,idProduct=0x6001)
ep = dev[0].interfaces()[0].endpoints()[0]
i = dev[0].interfaces()[0].bInterfaceNumber
dev.reset()

if dev.is_kernel_driver_active(i):
    dev.detach_kernal_driver(i)

dev.set_configuration()
eaddr = ep.bEndpointAddress

r = dev.read(eaddr, 1024)
print(len(r))

Module: Verdin IMX8M Plus
Carrier: Verdin Dev Board V1.1E

Greetings @justincunningham,

First of all what kind of USB device is this?

I see you’re targeting /dev/bus/usb/001/003 directly, though it’s rather rare to interact with a USB device like this. Usually this would get used by some kernel driver or such that then creates another interface, and then you would interact with that rather than the raw USB bus enumeration.

Best Regards,
Jeremias

Hi Jeremias,

The USB device is a digital ammeter: 9103 USB Picoammeter | RBD Instruments

Can you recommend another way to expose the usb port so that the usb device can be accessed?

Well looking at the technical documentation for this hardware it seems the USB port acts as a kind of serial communications port to the ammeter. The provided python samples here back this up: 9103 USB Picoammeter | RBD Instruments

The python examples use the python serial libraries to access COM devices in Windows, which are basically serial ports. Therefore I would assume this USB device enumerates itself as a serial device, assuming it uses standard serial protocols, which should already be a part of TorizonCore.

When you plug this device do you notice any new /dev/*tty entries? I would assume something like a /dev/ttyUSB* or something similar. You could also check the dmesg logs when you attach this device to see if that gives any hints on how this USB device gets enumerated.

Best Regards,
Jeremias

Got it, for some reason I got on the train of thinking I wasn’t able to use the pyserial library. Changing the port references to the /dev/ttyUSB0 did the trick.

Glad I was able to help clear things up!