chipace
Posts: 69
Joined: Sat Jun 29, 2019 2:56 am
Location: brown paper bag in a septic tank

RPi4 pyusb and libusb1 detach kernel driver

Wed Sep 11, 2019 2:52 am

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.

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2094
Joined: Thu Jul 11, 2013 2:37 pm

Re: RPi4 pyusb and libusb1 detach kernel driver

Wed Sep 11, 2019 9:40 am

Can you post the code you are using?
Rockets are loud.
https://astro-pi.org

chipace
Posts: 69
Joined: Sat Jun 29, 2019 2:56 am
Location: brown paper bag in a septic tank

Re: RPi4 pyusb and libusb1 detach kernel driver

Thu Sep 12, 2019 7:06 am

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):
			visa.log_to_screen()

	def print_info(self):
		self.oscilloscope.write('*IDN?')
		fullreading = self.oscilloscope.read_raw()
		readinglines = fullreading.splitlines()
		print("Scope information: " + readinglines[0])
		time.sleep(2)

	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_" + datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") +".png"
		fid = open(filename, 'wb')
		fid.write(raw_data)
		fid.close()
		print ("Wrote screen capture to filename " + '\"' + filename + '\"')
		time.sleep(5)

Code: Select all

from rigol_ds1054z import rigol_ds1054z

scope = rigol_ds1054z(debug=True)
scope.print_info()
scope.write_screen_capture()
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:

RPi3:

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)
RPi4:

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.

Return to “General discussion”