--===============1402403202374816106== Content-Type: multipart/alternative; boundary="00000000000072b8f805aaf65336" --00000000000072b8f805aaf65336 Content-Type: text/plain; charset="UTF-8" Hi, I have the code below to write some data to a bulk usb output endpoint using the sync api. // Find device // Write data do { r = libusb_bulk_transfer(handle, endpoint_out, wdata, swdata, &size, 1000); if (r == LIBUSB_ERROR_PIPE) { libusb_clear_halt(handle, endpoint_out); } i++; } while ((r == LIBUSB_ERROR_PIPE) && (istatus != LIBUSB_TRANSFER_COMPLETED) { fprintf(stderr, "Write transfer status %d?\n", transfer->status); libusb_free_transfer(transfer); transfer = NULL; return; } struct libusb_transfer *read_transfer = libusb_alloc_transfer(0); libusb_fill_bulk_transfer(read_transfer, handle, endpoint_in, rdata, srdata, cb_ready, NULL, 0); if (libusb_submit_transfer(read_transfer) < 0) printf("Failed to submit the read operation.\n"); else printf("Submitted the read operation.\n"); Then, I was thinking that I would need to do something for a read callback: static void cb_read(struct libusb_transfer *transfer) { if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fprintf(stderr, "Read transfer status: %d, data length: %d\n", transfer->status, transfer->length); libusb_free_transfer(transfer); transfer = NULL; return; } if (libusb_submit_transfer(transfer) < 0) printf("Failed to submit the transfer\n"); } So, I guess the real question is whether I am meant to handle the situation of write a request and then read the response in this way with the async libusb api or somehow different. Kind regards, Laszlo Papp PS.: I got most of this logic from the examples. --00000000000072b8f805aaf65336 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I have the code below to write some= data to a bulk usb output endpoint using the sync api.

// Find device
// Write data
do {
= =C2=A0 r =3D libusb_bulk_transfer(handle, endpoint_out, wdata, swdata, &= ;size, 1000);
=C2=A0 if (r =3D=3D LIBUSB_ERROR_PIPE) {
=C2=A0 =C2=A0 = libusb_clear_halt(handle, endpoint_out);
=C2=A0 }
=C2=A0 i++;
}= while ((r =3D=3D LIBUSB_ERROR_PIPE) && (i<RETRY_MAX));

/= / Read response
int rsize;
char rdata[srdata] =3D {0};
r =3D= libusb_bulk_transfer(handle, endpoint_in, &rdata, srdata, &rsize, = 1000);
if (r < 0)
{
=C2=A0 printf("libusb_bulk_trans= fer failed: %s\n", libusb_error_name(r));
}

=
How could I achieve the same with the async api? I have tried the code= below, but I do not seem to get the same data back.

=C2=A0 struct libusb_transfer *transfer =3D libusb_alloc_transfer(0);=C2=A0 libusb_fill_bulk_transfer(transfer, handle, endpoint_out, wdata, sw= data, cb_write, NULL, 0);
=C2=A0 if (libusb_submit_transfer(transfer) &= lt; 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("Failed to submit the rea= d command.");
=C2=A0 while (1) {
=C2=A0 =C2=A0 r =3D libusb_hand= le_events(context);
=C2=A0 =C2=A0 if (r < 0)
=C2=A0 =C2=A0 =C2=A0 = printf("Failed to handle events\n");
=C2=A0 =C2=A0 }
=

Then, in the write=C2=A0callback:

<= div>static void cb_write(struct libusb_transfer *transfer)
{
=C2=A0 = =C2=A0 if (transfer->status !=3D LIBUSB_TRANSFER_COMPLETED) {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Write transfer status %d?\n"= ;, transfer->status);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 libusb_free_transfe= r(transfer);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 transfer =3D NULL;
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 return;
=C2=A0 =C2=A0 } =C2=A0

struct libus= b_transfer *read_transfer =3D libusb_alloc_transfer(0);
libusb_fill_bulk= _transfer(read_transfer, handle, endpoint_in, rdata, srdata, cb_ready, NULL= , 0);
if (libusb_submit_transfer(read_transfer) < 0)
=C2=A0 =C2= =A0printf("Failed to submit the read operation.\n");
else
= =C2=A0 printf("Submitted the read operation.\n");

Then, I = was thinking that I would need to do something for a read callback:

static void cb_read(struct libusb_transfer *transfer)
= {
=C2=A0 =C2=A0 if (transfer->status !=3D LIBUSB_TRANSFER_COMPLETED) = {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Read transfer status= : %d, data length: %d\n", transfer->status, transfer->length);=C2=A0 =C2=A0 =C2=A0 =C2=A0 libusb_free_transfer(transfer);
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 transfer =3D NULL;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;=
=C2=A0 =C2=A0 } =C2=A0

=C2=A0 =C2=A0 if (libusb_submit_transfer= (transfer) < 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0printf("Failed to sub= mit the transfer\n");
}

So, I guess the re= al question is whether I am meant to handle the situation of write a reques= t and then read the response in this way with the async libusb api or someh= ow different.

Kind regards,
Laszlo Papp<= /div>

PS.: I got most of this logic from the examples.
--00000000000072b8f805aaf65336-- --===============1402403202374816106== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============1402403202374816106== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ libusb-devel mailing list libusb-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusb-devel --===============1402403202374816106==--