libpixyusb_swig / python: USB disconnect / re-connect from Pixy is not detected

Added by Sal Trupiano over 2 years ago

Running libpixyusb_swig on Raspberry Pi 3 Model B connected to a single Pixy using USB. No USB hub between the Pi and the Pixy.

libpixyusb_swig built from source on the Pi. Running a slightly modified version (for reasons not related to the Pixy) of

When the Pi is connected to the Pixy, everything is fine: when the Pixy is trained, it sends blocks when it recognizes something and can decode / display the data.

When the USB is disconnected from the Pixy, pixy_get_blocks() returns 0, not < 0 (which seem to be the errors from libusb).

When the USB is re-connected to the Pixy, pixy_get_blocks() continues to return 0.

In an attempt to recover, I changed so that if it doesn't get blocks after a certain period of time (since the pixy_get_blocks() return value doesn't seem to indicate errors), it calls pixy_close(), waits for 200ms, and calls pixy_init() again, and goes back to calling pixy_get_blocks(). This doesn't work either. At this point, calls to pixy_get_blocks() always return 0.

I even tried exiting and then restarting from within itself if it doesn't get blocks from pixy_get_blocks() after a while. This didn't work either.

So the basic issue is that in the system in which the Pi and Pixy are deployed, it is possible for the Pi and Pixy to be disconnected and then re-connected and I need to automatically recover from this situation.

I am just noticing now in pixy.i that pixy_init() has a return value, but I didn't check the value. Maybe that would be helpful to determine what's going on in the failure case?

I appreciate any feedback.


Replies (1)

RE: libpixyusb_swig / python: USB disconnect / re-connect from Pixy is not detected - Added by Edward Getz over 2 years ago

Hello Sal,
That's correct --- if pixy_init() returns an error (<0), there was some kind of problem connecting to Pixy. I'm wondering if the problem is with swig. Have you tried just running the hello_pixy example that comes with libpixyusb to see if it does what you expect? In general, we don't see issues with disconnect, reconnect. Let me know what you find.