Android Termux Writing to USB with Bulk Transfer

101 Views Asked by At

I'm using the Termux app with Termux API and termux-usb. I'm able to use pyusb and libusb to successfully query metadata and read from my device, but I'm unable to write to it. Specifically, libusb_bulk_transfer always times out with 0 bytes transferred for my device's Bulk Out endpoint, which works on mac, using essentially the same code (except for the file descriptor stuff for finding the device, as explained in the termux-usb wiki).

Is it possible to write to a USB device Bulk Out endpoint in Termux? Are there any settings in Android that are needed for write support? (For example in USB preferences, I can't switch "USB controlled by" to "this device").

LibUSB debug logs snippet:

[ 0.009169] [0000132d] libusb: debug [libusb_alloc_transfer] transfer 0x77a7caa200
[ 0.009178] [0000132d] libusb: debug [libusb_submit_transfer] transfer 0x77a7caa200
[ 0.009180] [0000132d] libusb: debug [add_to_flying_list] arm timerfd for timeout in 10000ms (first in line)
[ 0.009185] [0000132d] libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 4096
[ 0.009199] [0000132d] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.009201] [0000132d] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
[10.011307] [0000132d] libusb: debug [handle_events] poll() returned 1
[10.011516] [0000132d] libusb: debug [handle_events] timerfd triggered
[10.011536] [0000132d] libusb: debug [libusb_cancel_transfer] transfer 0x77a7caa200
[10.012862] [0000132d] libusb: debug [disarm_timerfd] 
[10.012933] [0000132d] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[10.012968] [0000132d] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
[10.012988] [0000132d] libusb: debug [handle_events] poll() returned 1
[10.013032] [0000132d] libusb: debug [reap_for_handle] urb type=3 status=-2 transferred=0
[10.013062] [0000132d] libusb: debug [handle_bulk_completion] handling completion status -2 of bulk urb 1/1
[10.013072] [0000132d] libusb: debug [handle_bulk_completion] abnormal reap: urb status -2
[10.013081] [0000132d] libusb: debug [handle_bulk_completion] abnormal reap: last URB handled, reporting
[10.013100] [0000132d] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[10.013126] [0000132d] libusb: debug [disarm_timerfd] 
[10.013134] [0000132d] libusb: debug [usbi_handle_transfer_completion] transfer 0x77a7caa200 has callback 0x76863376a8
[10.013143] [0000132d] libusb: debug [sync_transfer_cb] actual_length=0
[10.013161] [0000132d] libusb: debug [libusb_free_transfer] transfer 0x77a7caa200
0

There are 0 best solutions below