0

I'm writing a Linux program (using Qt 4.8 and libusb 1.0) which will communicate with a custom USB device (currently being programmed by a co-worker).

Step 1 is to have a "heartbeat" going back and forth over USB at regular intervals. I'm currently using asynchronous bulk transfer.

For testing, I've put my "Send_Heartbeat()" on a button click. If I click on the button a LOT and queue up a number of messages to send, as long as I keep my queue busy, the messages keep sending and my USB device keeps receiving them.

If I stop for a few seconds, then resume and add more messages to the queue, the USB device stops receiving them.

BUT, my program's Transfer Callback DOES return with a transfer status code of 0, indicating success, even though my USB device isn't receiving them.

My questions:

  1. Why does the callback's transfer status indicate success if my USB device appears to have stopped receiving them?
  2. Has anyone heard of this type of behaviour?

It's worth noting that if I disconnect the USB device, I get proper status codes returned in my callback indicating that the device has gone away.

If the USB Device is left connected and running, and I "Detatch" and then again "Attach" to force a re-connection and try sending more test heartbeats, it works! The USB device starts receiving messages again.

My "Detatch" is the following calls:

libusb_release_interface()
libusb_reset_device()
libusb_close()

Then my "Attach" is:

libusb_get_device_list()
libusb_get_device_descriptor()
libusb_open()
libusb_set_configuration()
libusb_claim_interface()

My next step is to narrow down which of the libusb commands is re-establishing the communication.

Meanwhile, I'm hoping someone recognizes these symptoms and has a suggestion. As it's my first time programming USB communication, I'm wondering if there is some fundamental which I've missed.

Thanks!

Doug
  • 131
  • 6

1 Answers1

0

The issue is here I guess:

My "Detatch" is the following calls:

libusb_release_interface(); In your detatch, you need to attach kernel driver detatch_kernel_driver(); libusb_reset_device(); libusb_close();

Then my "Attach" is:

libusb_get_device_list(); libusb_get_device_descriptor(); libusb_open(); libusb_set_configuration(); Here you need to check if the kernel driver is active or not. So, check what attach_kernel_driver(); returns, and call detatch_kernel_driver(); if needed libusb_claim_interface();