0

On host side, how to understand the device want to send data using libusb-1.0? I mean ways except polling or setting time interval. Is there any way to get it based on signals, interrupt, etc?

Mojtaba Ahmadi
  • 1,044
  • 19
  • 38
  • 1
    Write that yourself. Create a separate thread that endlessly polls. If the poll is successful it `raise()`s a signal to your process. This is usually the preferred way of implementing asynchronous callbacks on linux - create a thread that polls. Maybe you noticed, but it is really rarely that someone uses the asynchronous callbacks on file descriptors, the POSIX AIO. Usually people - create a separate thread, poll the file descriptor and execute action in that thread. It's easier taht way. – KamilCuk Apr 29 '19 at 15:52

1 Answers1

0

You can use "glibusb", read the documentation here: https://github.com/apmasell/vapis

"glibusb.h" includes all features of "libusb"*, this library was made by the bearded guy at https://github.com/apmasell

Dependencies:

  • gio-2.0
  • libusb-1.0

Code:

[CCode (cheader_filename = "glibusb.h")]
namespace LibUSB {
    /**
     * Create a source so that a context can be monitored using {@link GLib.MainLoop}.
     *
     * Once created, call {@link GLib.Source.attach} to attach it to a context.
     */
    [CCode (cname = "glibusb_create_gsource")]
    public GLib.Source create_source (owned Context ctx);

    /**
     * Initiate a USB control transfer on a device.
     *
     * @param dev the device to perform the transfer
     * @param timeout return if no data has been provided after the specified number of milliseconds
     * @param buffer the data to transfer
     * @param actual_length the number of bytes transferred
     */
    [CCode (cname = "glibusb_control_transfer")]
    public async TransferStatus control_transfer (DeviceHandle dev, uint timeout, uint8[] buffer, out int actual_length);

    /**
     * Initiate a USB interrupt transfer on a device.
     *
     * @param dev the device to perform the transfer
     * @param endpoint the target on the device
     * @param timeout return if no data has been provided after the specified number of milliseconds
     * @param buffer the data to transfer
     * @param actual_length the number of bytes transferred
     */
    [CCode (cname = "glibusb_interrupt_transfer")]
    public async TransferStatus interrupt_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length);

    /**
     * Initiate a USB bulk transfer on a device.
     *
     * @param dev the device to perform the transfer
     * @param endpoint the target on the device
     * @param timeout return if no data has been provided after the specified number of milliseconds
     * @param buffer the data to transfer
     * @param actual_length the number of bytes transferred
     */
    [CCode (cname = "glibusb_bulk_transfer")]
    public async TransferStatus bulk_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length);
}
SaschaM78
  • 4,376
  • 4
  • 33
  • 42
IchQuile
  • 27
  • 4