Page 1 of 1

RPi4 pyusb and libusb1 detach kernel driver

Posted: Wed Sep 11, 2019 2:52 am
by chipace
I am trying to get my RPi4 to work just like my RPi3 and RPi2 when using pyusb and libusb1. In looking at the log files it appears that RPi3 and RPi2 detach the kernel driver, while the RPi4 does not when doing communication on a specific USB port.
I am using the same SD card and inserting it into the three Pis.
As the RPi4 uses PCIe to get USB connectivity, should I not expect to see "detach kernel driver" in the pyusb and libusb1 log files?

This is the only difference I can see in the log files.

Re: RPi4 pyusb and libusb1 detach kernel driver

Posted: Wed Sep 11, 2019 9:40 am
by jdb
Can you post the code you are using?

Re: RPi4 pyusb and libusb1 detach kernel driver

Posted: Thu Sep 12, 2019 7:06 am
by chipace
I'm using pyvisa and pyusb to download screen captures from my oscilloscope.

Code: Select all

import visa
import datetime
import time
import re
import csv
from math import floor, log10

class rigol_ds1054z:
	# Constructor
	def __init__(self, debug=False):
		resources = visa.ResourceManager('@py')
		# insert your device here
		# resources.list_resources() will show you the USB resource to put below
		self.oscilloscope = resources.open_resource('USB0::6833::1230::DS1ZA192107675::0::INSTR')
		self.debug = debug
		if (debug):

	def print_info(self):
		fullreading = self.oscilloscope.read_raw()
		readinglines = fullreading.splitlines()
		print("Scope information: " + readinglines[0])

	def write_screen_capture(self, filename=''):
		self.oscilloscope.write(':DISP:DATA? ON,OFF,PNG')
		raw_data = self.oscilloscope.read_raw()[11:] # strip off first 11 bytes
		# save image file
		if (filename == ''):
			filename = "rigol_" +"%Y-%m-%d_%H-%M-%S") +".png"
		fid = open(filename, 'wb')
		print ("Wrote screen capture to filename " + '\"' + filename + '\"')

Code: Select all

from rigol_ds1054z import rigol_ds1054z

scope = rigol_ds1054z(debug=True)
This works perfectly on my RPi2 and RPi3, but RPi4 only saves 41bytes out of 30kbytes. I enabled pyusb to create a logfile to compare the RPi3 and RPi4 activity and saw that the only difference in the logfile was:


Code: Select all

2019-09-09 23:09:40,097 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x74a47210>, 0)
2019-09-09 23:09:40,098 DEBUG:usb.backend.libusb1:_LibUSB.detach_kernel_driver(<usb.backend.libusb1._DeviceHandle object at 0x74a47210>, 0)

Code: Select all

2019-09-09 23:05:24,728 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0xb49d2170>, 0)
RPi3 and RPi2 detects that the kernel driver is active and detaches, while the RPi4 does not detect that the driver is active. I don't know if this is the root cause of my issue, but I am just trying to understand how RPi3 and RPi4 could have different data traffic when I am using the same python scripts and SD card.