Here are two lines of code performing an interrupt transfer using libusb in C++:
libusb_fill_interrupt_transfer(transfer_receive, handle, LIBUSB_ENDPOINT_IN | USB_INTERFACE_OUT, buffer_receive, sizeof(buffer_receive), cb_in, &usb_data, 30000);
r = libusb_submit_transfer(transfer_receive);
How do I do the same thing in Python with PyUSB?
there are function interruptWrite(self, endpoint, buffer, timeout = 100)
and interruptRead(self, endpoint, size, timeout = 100)
, see
https://github.com/walac/pyusb/blob/master/usb/legacy.py
the interruptRead()
function is similar to the C++ code (poll device for interrupts, receive interrupt data from interrupt IN endpoint of device)
the LIBUSB_ENDPOINT_IN | USB_INTERFACE_OUT
(|
is bitwise OR ) in C++ is similar uses the specified USB interrupt interface USB_INTERFACE_OUT
to query data from its specified endpoint LIBUSB_ENDPOINT_IN
in the background PyUSB uses the same function ( write()
) for bulk, interrupt and isochronous transfer, only control transfers have special syntax. interruptWrite()
and interruptRead()
also use the write()
function that abstracts the underlying native USB tranfer types
USB has four flavors of transfers: bulk, interrupt, isochronous and control. [ ... ]
Control transfer is the only transfer that has structured data described in the spec, the others just send and receive raw data from USB point of view. Because of it, you have a different function to deal with control transfers, all the other transfers are managed by the same functions.
You issue a control transfer through the
ctrl_transfer
method. It is used both for OUT and IN transfers. The transfer direction is determined from thebmRequestType
parameter.
source: https://github.com/walac/pyusb/blob/master/docs/tutorial.rst
in general the device only answers on an interrupt transfer if it has interrupts pending, so the host polls the device for interrupts with an interrupt transfer. this becomes obvious in the C++ code that sends an interrupt request (transfer) and awaits to receive an answer
http://mvidner.blogspot.com/2017/01/usb-communication-with-python-and-pyusb.html