Question

I have a raspberry pi (I'm using linux) and a device that measures some values.

I have a python server and when a client sends a "I want the values" command, I ask the device some values. This is the function for my device:

def usbDevice:
      dev = usb.core.find(idVendor=0xXXXX, idProduct=0xXXXX)
      if dev is None:
         return 'Not found'
      dev.set_configuration()
      dev.write(1, '\x05', 0) # ask for the values
      time.sleep(2)
      ret = dev.read(0x81,2048 , 0,1200) # endpoint, siz, interf, timeout ->meas. vals
      print ret
      return ret

When I start the communication it always goes well (both ways, I send the command and I get the proper response ...).However, the second time I try it (no matter if I wait too long or not) I'm getting no response from the device. I know I can send the request (I used a print "step XX" to see where it is failing), but I get no answer... I am usually getting a timeout exception, but sometimes getting a "resource busy" exception.

Should I close the usb communication after using it the first time? How? Despite, I'm always compiling with sudo permissions, I created a .rules file, so I think there's not the problem.

Apart from this, I would really like to know if something's wrong with this way to establish the USB communication as I used something similar in the past. ( and I'm not good with python...)

Was it helpful?

Solution

Can you provide additional information such as the linux distribution and kernel number e.g.

 uname -a

There are known USB issues. The good news is that a recent fix may have resolved them. Basically, use rpi-update and it should update the kernel (you want at least #389).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top