pcsensor-temper icon indicating copy to clipboard operation
pcsensor-temper copied to clipboard

Fata error> USB read failed

Open ghost opened this issue 11 years ago • 8 comments

When I use this driver, it successfully reads two devices but with the occasional error.

USB interupt read: Resource temporarily unavailable Fatal error> USB read failed

This results in the n0 and n1 device switching. I'm unsure if the issue lies with this driver or Linux. OS is Raspbian Wheezy. I've used other drivers which also result in this interrupt error.

ghost avatar Jul 08 '13 18:07 ghost

My gut feeling(!) is that this is due to the USB device somehow misbehaving and being reset and reenumerated. I have seen ordinary devices like keyboards and webcams run without any problem for weeks with no problem at all. With the temper, I could not get even one straight week of service without such a glitch.

Even worse: sometimes it returns but always return 0-values. That detail may well be due to this driver (I did not and do not fully understand the interaction pattern that it implements).

My conclusion: restart daily using a corn job to cleanup stuck devices and do not use more than one per raspi. Sorry, I know that is not good news... :-/

padelt avatar Jul 08 '13 18:07 padelt

To shed some more light, I've used temper.py and now pcsensor.c and both have shown this type of behavior in my custom python script. When running pcsensor in terminal with the loop (-L) option, at no point does it hang up. I've run two simultaneous terminals hitting both Temper sensors and it still runs great. When I run my custom python script and use pcsensor, that's when the collision seems to happen. I'm less inclined to think there is an issue with your driver.

import time
import subprocess
import re

while(True):
    device0=subprocess.check_output(["pcsensor","-n0","-f"])
    device1=subprocess.check_output(["pcsensor","-n1","-f"])
    dev0temp=re.search('[0-9]{1,3}\.[0-9]{2}',str(device0))
    dev1temp=re.search('[0-9]{1,3}\.[0-9]{2}',str(device1))
    try:
        temp0=float(dev0temp.group())
        temp1=float(dev1temp.group())
    except:
        pass
time.sleep(5)

ghost avatar Jul 09 '13 13:07 ghost

Hi,

Same problem here, but I can add some details. I hope it can help to locate the problem, even if I think the problem is inside the sensor. I tried on my raspberry pi (Debian7.2) and on my computer (Ubuntu10.04LTS). My temper sensor is this one : http://pcsensor.com/index.php?_a=viewProd&productId=7 /var/log/messages says it is a "RDing TEMPer1V1.4"

  1. The USB read fails every X times and X is constant. You can run pcsensor every second or every 10 seconds, it will fails every X times. For me, X=16. But if I add "sleep(5)" at line 244 in pcsensor.c, it will fails more often - every 4 times for me.

  2. I made some tests, and the error come in the interrupt_read function. Seems to be in the usb_interrupt_read call, but I cannot be sure about that. I only tested with some dirty "printf" :D

  3. There is no problem when using the -l option in order to loop. I tried "-l1" for a long time (about 1h) and I had no error.

  4. I tried some other drivers (temper.py and some other versions of pcsensor.c), I have the same problem.

Let me know if you need some other details.

One last question : you said "restart daily using a corn job to cleanup stuck devices". Can you explain that? What do you restart? The raspi?

Thank you for reading and sorry for my poor English ^^

JulienSchneider avatar Nov 15 '13 23:11 JulienSchneider

Same here

$ temperv14 -c USB interrupt read: Numerical result out of range Fatal error> USB read failed

With the following device:

$ lsusb -vd 0c45:7401

Bus 001 Device 036: ID 0c45:7401 Microdia Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x0c45 Microdia idProduct 0x7401 bcdDevice 0.01 iManufacturer 1 RDing iProduct 2 TEMPerV1.4 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 59 bNumInterfaces 2 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 (Bus Powered) Remote Wakeup MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 1 Boot Interface Subclass bInterfaceProtocol 1 Keyboard iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.10 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 65 Report Descriptor: (length is 65) Item(Global): Usage Page, data= [ 0x01 ] 1 Generic Desktop Controls Item(Local ): Usage, data= [ 0x06 ] 6 Keyboard Item(Main ): Collection, data= [ 0x01 ] 1 Application Item(Global): Report ID, data= [ 0x01 ] 1 Item(Global): Usage Page, data= [ 0x07 ] 7 Keyboard Item(Local ): Usage Minimum, data= [ 0xe0 ] 224 Control Left Item(Local ): Usage Maximum, data= [ 0xe7 ] 231 GUI Right Item(Global): Logical Minimum, data= [ 0x00 ] 0 Item(Global): Logical Maximum, data= [ 0x01 ] 1 Item(Global): Report Size, data= [ 0x01 ] 1 Item(Global): Report Count, data= [ 0x08 ] 8 Item(Main ): Input, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x01 ] 1 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Main ): Input, data= [ 0x01 ] 1 Constant Array Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x03 ] 3 Item(Global): Report Size, data= [ 0x01 ] 1 Item(Global): Usage Page, data= [ 0x08 ] 8 LEDs Item(Local ): Usage Minimum, data= [ 0x01 ] 1 NumLock Item(Local ): Usage Maximum, data= [ 0x03 ] 3 Scroll Lock Item(Main ): Output, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x05 ] 5 Item(Global): Report Size, data= [ 0x01 ] 1 Item(Main ): Output, data= [ 0x01 ] 1 Constant Array Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x05 ] 5 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Global): Logical Minimum, data= [ 0x00 ] 0 Item(Global): Logical Maximum, data= [ 0xff ] 255 Item(Global): Usage Page, data= [ 0x07 ] 7 Keyboard Item(Local ): Usage Minimum, data= [ 0x00 ] 0 No Event Item(Local ): Usage Maximum, data= [ 0xff ] 255 (null) Item(Main ): Input, data= [ 0x00 ] 0 Data Array Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Main ): End Collection, data=none Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 10 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 1 Boot Interface Subclass bInterfaceProtocol 2 Mouse iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.10 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 41 Report Descriptor: (length is 41) Item(Global): Usage Page, data= [ 0x00 0xff ] 65280 (null) Item(Local ): Usage, data= [ 0x01 ] 1 (null) Item(Main ): Collection, data= [ 0x01 ] 1 Application Item(Local ): Usage, data= [ 0x01 ] 1 (null) Item(Global): Logical Minimum, data= [ 0x00 ] 0 Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Global): Report Count, data= [ 0x08 ] 8 Item(Main ): Input, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Local ): Usage, data= [ 0x01 ] 1 (null) Item(Global): Report Count, data= [ 0x08 ] 8 Item(Main ): Output, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Usage Page, data= [ 0x0c ] 12 Consumer Item(Local ): Usage, data= [ 0x00 ] 0 Unassigned Item(Global): Logical Minimum, data= [ 0x80 ] 128 Item(Global): Logical Maximum, data= [ 0x7f ] 127 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Global): Report Count, data= [ 0x08 ] 8 Item(Main ): Feature, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Main ): End Collection, data=none Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 10 Device Status: 0x0000 (Bus Powered)

FogWatch avatar Nov 28 '13 06:11 FogWatch

confirming this as well, I see the same after exactly 16 reads when using the python script, see https://github.com/padelt/temper-python/issues/6

daudo avatar Dec 18 '13 18:12 daudo

I can read from the sensor (usb device) once and then not again until I take it out and insert it again.

wojci@build:~/remote-git/pcsensor-temper/src$ ./pcsensor -c USB interrupt read: Resource temporarily unavailable Fatal error> USB read failed wojci@build:~/remote-git/pcsensor-temper/src$ ./pcsensor -c -v usb_set_debug: Setting debugging level to 255 (on) usb_os_init: Found USB VFS at /dev/bus/usb usb_os_find_busses: Found 004 usb_os_find_busses: Found 003 usb_os_find_busses: Found 002 usb_os_find_busses: Found 001 usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 001 on 004 skipping descriptor 0x30 skipped 1 class/vendor specific endpoint descriptors error obtaining child information: Operation not permitted usb_os_find_devices: Found 017 on 003 skipped 1 class/vendor specific interface descriptors skipped 1 class/vendor specific interface descriptors usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 005 on 003 skipped 1 class/vendor specific interface descriptors usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 004 on 003 skipped 6 class/vendor specific interface descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors skipped 2 class/vendor specific interface descriptors skipping descriptor 0x25 skipped 1 class/vendor specific endpoint descriptors usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 003 on 003 skipped 1 class/vendor specific interface descriptors usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 002 on 003 usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 001 on 003 error obtaining child information: Inappropriate ioctl for device error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 002 on 002 usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 001 on 002 error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 002 on 001 usb_os_find_devices: couldn't get connect info usb_os_find_devices: Found 001 on 001 error obtaining child information: Operation not permitted error obtaining child information: Operation not permitted lvr_winusb with Vendor Id: c45 and Product Id: 7401 found. USB error: could not detach kernel driver from interface 0: No data available Device already detached USB error: could not detach kernel driver from interface 1: No data available Device already detached 01 01 00 00 00 00 00 00 01 80 33 01 00 00 00 00 USB interrupt read: Resource temporarily unavailable Fatal error> USB read failed

wojciiii avatar May 21 '15 08:05 wojciiii

@wojciiii , I have no real idea why that is happening. That said, I do not think much about this C-version of pcsensor-temper as I exclusively use the python-version here: https://github.com/padelt/temper-python

I do have one idea though: A year ago, @amorphic added a reset of the USB device after each read cycle. You can see the relevant code change in temper-python here:

https://github.com/padelt/temper-python/commit/a9c8b68570f94d4912c765a2b0c57e0399835c1f#diff-19c78b0104bf03153b342369297c254dR157

That may still be missing in pcsensor-temper and may help with this situation.

padelt avatar May 21 '15 08:05 padelt

I added a call to usb_reset(lvr_winusb) just before the call to usb_set_configuration() (here) and now I can run the program more than once. I moved the self._device.reset() call in temper-python to the same location (just before self._device.set_configuration()) and I can now run both of these programs after each other.

See my fork here: https://github.com/stefansundin/pcsensor-temper

stefansundin avatar Nov 27 '15 22:11 stefansundin